regression - order of coefficients in lm, R -
when running regression in r, order returned coefficients? example:
coef(lm(y ~ x + z, data=data.frame(x=1:10, y=10:1, z=1:5)))
is guaranteed coefficient associated x
returned before coefficient associated z
? order mean order in vector of returned coefficients. reason matters me test linear hypothesis coefficients in model , therefore order of coefficients in variance covariance matrix returned vcov
, actual estimates returned coef
matters.
index name, not position. right answer.
coef(lm(y ~ x+z, data=data.frame(x=1:10, y=10:1, z=1:5)))['x'] ## x ## -1 coef(lm(y ~ x+z, data=data.frame(x=1:10, y=10:1, z=1:5)))['z'] ## z ## -1.855301e-16
and both of them, in desired order:
coef(lm(y ~ x+z, data=data.frame(x=1:10, y=10:1, z=1:5)))[c('x', 'z')] ## x z ## -1.000000e+00 -1.855301e-16
Comments
Post a Comment