I got my posting bounced and sorry if I accidentally post twice.
I have been looking at 'lars' pkg and got puzzled by the behavior of
function 'lars'. I want to do weighted lasso regression and can't get a
match from lars output with lm output. Here is an example:

y = rnorm(10)
x = matrix(runif(50),nrow=10)
X = data.frame(y,x)
z = runif(10)
X = data.frame(y,x,z)
X$z = X$z / sum(X$z)   # this is not necessary.
fit1 =  lars(as.matrix(X[,2:6])*matrix(sqrt(X[,7]),10,5),as.matrix
(X[,1])*sqrt(X[,7]))
fit2 = lm(y~.-z,data=X,weights=z)
coef(fit1,mode='fraction',s=1)
fit2

I got this:

> coef(fit1,mode='fraction',s=1)
        X1         X2         X3         X4         X5
-2.8603082 -0.8303739  0.1064474  3.6563283  2.8342368
> fit2

Call:
lm(formula = y ~ . - z, data = X, weights = z)

Coefficients:
(Intercept)           X1           X2           X3           X4
X5
    -0.4227      -2.4817      -0.7105      -0.2611       2.6908       2.0295


Shouldn't they match? If not, what did I miss and how to correctly do lasso
with weights? Thanks a lot for any advice.

Young

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to