0
$\begingroup$

My regression model is this:

R2 <- lm(lnwage ~ educ + exper + hrswk + educ*exper + educ2 + exper2)

and I want to estimate: $\frac{\partial ln(wage)}{\partial educ}$ and $\frac{\partial ln(wage)}{\partial exper}$

Is there any way I can do this with R?

$\endgroup$
2
  • $\begingroup$ oh and educ2 and exper2 each refer to the quadratic model! $\endgroup$
    – Ethan
    Commented May 17, 2016 at 2:18
  • 5
    $\begingroup$ Do you know how to take derivatives of quadratic functions? $\endgroup$
    – Glen_b
    Commented May 17, 2016 at 5:40

3 Answers 3

1
$\begingroup$

I hope I'm not misunderstanding you, but can't you just calculate them from the estimated coefficients? $\frac{d lnwage}{d educ} (educ,exper,hrswk)$ Will just equal the coefficient on $educ$ plus $exper$ times the coefficient on $(educ*exper)$ plus 2 times the coefficient on $(educ^2)$ for instance.

$\endgroup$
0
$\begingroup$

You can do it on R but you'll have to write the code yourself (there's no explicit method for the lm class that will do it for you) If your model is $Y:=\beta_0+\beta_1a+\beta_2b+\beta_3ab+\beta_4a^2+\beta_5b^2+\epsilon$, then:

$\frac{\delta Y}{\delta a} = \beta_1 + b\beta_3 +2a\beta_4$

R will provide the $\beta_k$ coefficients with coefficients(R2), returning a numeric. But be careful, as coefficients(R2)[1] is the intercept, coefficients(R2)[2] is $\beta_1$ and so on!

$\endgroup$
0
$\begingroup$

Maybe this is what you're looking for, Ryacas lets you do a little algebra:

##### set your algebraic symbols
intercept = Ryacas::ysym("intercept")
educ = Ryacas::ysym("educ")
exper = Ryacas::ysym("exper")
hrswk = Ryacas::ysym("hrswk")
Coefeduc = Ryacas::ysym("Coefeduc")
Coefexper = Ryacas::ysym("Coefexper")
Coefhrswk = Ryacas::ysym("Coefhrswk")
Coefeduc2 = Ryacas::ysym("Coefeduc2")
Coefexper2 = Ryacas::ysym("Coefexper2")
Coefeducexper = Ryacas::ysym("Coefeducexper")

##### give the function (that equals lnwage)
f = intercept + Coefeduc*educ + Coefexper*exper + Coefhrswk*hrswk + Coefeducexper*educ*exper + Coefeduc2*educ^2 + Coefexper2*exper^2
f
# y: intercept+Coefeduc*educ+Coefexper*exper+Coefhrswk*hrswk+Coefeducexper*educ*exper+Coefeduc2*educ^2+Coefexper2*exper^2

##### find the derivatives of your functions with respect to your two variables
g_educ = deriv(f, "educ")
g_exper = deriv(f, "exper")

g_educ
# y: Coefeduc+Coefeducexper*exper+2*Coefeduc2*educ

g_exper
# y: Coefexper+Coefeducexper*educ+2*Coefexper2*exper
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.