Young Cho wrote:
> I am trying to extract coefficients from lars fit and can't find how to get
> intercept. E.g.
Are we talking about the function lars() from package "lars"?
> y = rnorm(10)
> x = matrix(runif(50),nrow=10)
> X = data.frame(y,x)
> fit1 = lars(as.matrix(X[,2:6]),as.matrix(X[,1]))
> fit2 = lm(y~.,data=X)
> Then, if I do:
> X1 X2 X3 X4 X5
> 0.3447570 0.7715479 -1.1224714 1.0841587 -1.6259571
> (Intercept) X1 X2 X3 X4 X5
> 0.3979150 0.3447570 0.7715479 -1.1224714 1.0841587 -1.6259571
> I expect them to be the same but can't find the intercept. How to extract
> intercept from lars fit object?
No idea, perhaps a question for the package author/maintainer?
> Also, if I do:
>  0.2596246
> This is not intercept from lm fit. what am I missing here?
You are missing how lm() works!
For the model y ~ x, consider x=c(0,1) and y=c(0,1) then the fit has
intercept 0 but mean(X$y) is 0.5 ...