Question

I am trying to build on a standard translog demand function, which is:

lnY = lnP + lnZ + lnY*lnZ + lnY^2 + lnZ^2

Where Y = demand, P = price, and Z = income.

However, when I include the squared terms in nlme or lme4, they just ignore them. I've tried:

model <- lme(asinh(gallons) ~ asinh(rprc) + asinh(rexp) + asinh(rexp)*asinh(rexp) + asinh(rprc)*asinh(rprc) + asinh(rprc)*asinh(rexp), random=~1|cuid, data = data)

and I've tried:

model <- lme(asinh(gallons) ~ asinh(rprc) + asinh(rexp) + asinh(rexp)^2 + asinh(rprc)^2 + asinh(rprc)*asinh(rexp), random=~1|cuid, data = data)

And I've tried the equivalents for lmer.

The squared terms just don't show up in summary(model), and I know they're being ignored because I've created separate vectors with the squared terms and passed those in and the estimates are different.

Anybody have any advice?

Was it helpful?

Solution

In formulas, the term ^2 is used to create interactions of variables. For example, (x+y+z)^2 creates the main effects and all possible interactions with two variables, i.e., x + y + z + x:y + x:z + y:z. Hence, x^2 inside a formula is the same as x.

Furthermore, also * is used to create interactions, For example, x*y creates x + y + x:y. Hence, x*x inside a formula is the same as x.

To create the squared value inside a formula, you have to use the function I, i.e., I(x^2) or I(x*x).

lme(asinh(gallons) ~ asinh(rprc) + asinh(rexp) +
      I(asinh(rexp)^2) + I(asinh(rprc)^2) + asinh(rprc)*asinh(rexp), 
    random=~1|cuid, data = data)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top