[R] intercept in lars fit
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sun Nov 25 16:50:48 CET 2007
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:
>> predict(fit1,s=1,mode='fraction',type='coefficients')$coef
> X1 X2 X3 X4 X5
> 0.3447570 0.7715479 -1.1224714 1.0841587 -1.6259571
>> coef(fit2)
> (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:
>> mean(X$y)
> [1] 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 ...
Uwe Ligges
> Thanks so much.
>
> Young
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list