jz7 at duke.edu
2006-Aug-21 21:39 UTC
[R] question about 'coef' method and fitted_value calculation
Dear all, I am trying to calculate the fitted values using a ridge model (lm.ridge(), MASS library). Since the predict() does not work for lm.ridge object, I want to get the fitted_value from the coefficients information. The following are the codes I use: fit = lm.ridge(myY~myX,lambda=lamb,scales=F,coef=T) coeff = fit$coef However, it seems that "coeff" (or "fit$coef") is not really the coefficients matrix. From the manual, "Note that these are not on the original scale and are for use by the 'coef' method...". Could anyone please point out what is the 'coef' method the manual mentioned, and how should I get the fitted value? I have tried simple multiplication of the coeff and my X matrix ("coeff%*%X"). But the results seems to be in the wrong scale. Thanks so much! Sincerely, Jeny
Berton Gunter
2006-Aug-21 21:51 UTC
[R] question about 'coef' method and fitted_value calculation
I'm ignorant about this, so no answer. But as you seem interested in coefficient shrinkage, have you tried the lars or lasso2 package? -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of jz7 at duke.edu > Sent: Monday, August 21, 2006 2:40 PM > To: r-help at stat.math.ethz.ch > Subject: [R] question about 'coef' method and fitted_value calculation > > Dear all, > > I am trying to calculate the fitted values using a ridge model > (lm.ridge(), MASS library). Since the predict() does not work > for lm.ridge > object, I want to get the fitted_value from the coefficients > information. > The following are the codes I use: > > fit = lm.ridge(myY~myX,lambda=lamb,scales=F,coef=T) > coeff = fit$coef > > However, it seems that "coeff" (or "fit$coef") is not really the > coefficients matrix. From the manual, "Note that these are not on the > original scale and are for use by the 'coef' method...". > > Could anyone please point out what is the 'coef' method the manual > mentioned, and how should I get the fitted value? I have tried simple > multiplication of the coeff and my X matrix ("coeff%*%X"). > But the results > seems to be in the wrong scale. > > Thanks so much! > > Sincerely, > Jeny > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Gabor Grothendieck
2006-Aug-21 21:59 UTC
[R] question about 'coef' method and fitted_value calculation
Try library(MASS) y.lmr <- lm.ridge(y ~., longley) coefs <- print(y.lmr) On 8/21/06, jz7 at duke.edu <jz7 at duke.edu> wrote:> Dear all, > > I am trying to calculate the fitted values using a ridge model > (lm.ridge(), MASS library). Since the predict() does not work for lm.ridge > object, I want to get the fitted_value from the coefficients information. > The following are the codes I use: > > fit = lm.ridge(myY~myX,lambda=lamb,scales=F,coef=T) > coeff = fit$coef > > However, it seems that "coeff" (or "fit$coef") is not really the > coefficients matrix. From the manual, "Note that these are not on the > original scale and are for use by the 'coef' method...". > > Could anyone please point out what is the 'coef' method the manual > mentioned, and how should I get the fitted value? I have tried simple > multiplication of the coeff and my X matrix ("coeff%*%X"). But the results > seems to be in the wrong scale. > > Thanks so much! > > Sincerely, > Jeny > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Dear all, I got a wierd problem when using lm.ridge() in MASS library. When my X matrix has few columns, there is no problem. But when my X matrix gets larger (over 1000 columns), I got the following error: Error in Xs$v %*% a : non-conformable arguments In addition: Warning messages: 1: longer object length is not a multiple of shorter object length in: d^2 + rep(lambda, rep(p, k)) 2: longer object length is not a multiple of shorter object length in: drop(d * rhs)/div The R code I use for the calculation is "lm.ridge( y ~ x,lambda=seq(1,15,1))". Please advice. Thanks a lot! Jeny
Martin Maechler
2006-Aug-24 08:17 UTC
[R] error message from lm.ridge() in MASS ***package***
>>>>> "jz7" == jz7 <jz7 at duke.edu> >>>>> on Tue, 22 Aug 2006 17:10:42 -0400 (EDT) writes:jz7> Dear all, jz7> I got a wierd problem when using lm.ridge() in MASS library. there is "MASS the book" and "MASS the package", and there is even a MASS library (namely the file MASS.so or MASS.dll depending on your platform) but you are really talking about the MASS *package* ! jz7> When my X matrix has few columns, there is no jz7> problem. But when my X matrix gets larger (over 1000 jz7> columns), I got the following error: and where is the "selfcontained reproducible code" which we ask you for, explicitly in the posting guide and at the footer of every R-help message ??? jz7> Error in Xs$v %*% a : non-conformable arguments jz7> In addition: Warning messages: jz7> 1: longer object length jz7> is not a multiple of shorter object length in: d^2 + rep(lambda, jz7> rep(p, k)) jz7> 2: longer object length jz7> is not a multiple of shorter object length in: drop(d * rhs)/div jz7> The R code I use for the calculation is "lm.ridge( y ~ x,lambda=seq(1,15,1))". jz7> Please advice. jz7> Thanks a lot! jz7> Jeny