Re: [R] User error in calling predict/model.frame

2011-01-30 Thread russell . s . pierce
Subject: Re: [R] User error in calling predict/model.frame On Sun, Jan 30, 2011 at 5:59 PM, Russell Pierce wrote: > R-help list and interested parties, > > On Cross Validated mpiktas correctly noted that both the I() and rms > Glm/Predict solution produce incorrect results You proba

Re: [R] User error in calling predict/model.frame

2011-01-30 Thread Joshua Wiley
On Sun, Jan 30, 2011 at 5:59 PM, Russell Pierce wrote: > R-help list and interested parties, > > On Cross Validated mpiktas correctly noted that both the I() and rms > Glm/Predict solution produce incorrect results You probably meant it this way anyways, but I would say it produces undesired resu

Re: [R] User error in calling predict/model.frame

2011-01-30 Thread Russell Pierce
R-help list and interested parties, On Cross Validated mpiktas correctly noted that both the I() and rms Glm/Predict solution produce incorrect results (http://stats.stackexchange.com/questions/6684/how-can-one-use-the-predict-function-on-a-lm-object-where-the-ivs-have-been-dynam/6718#6718). As f

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 1:23 PM, Joshua Wiley wrote: >> xxAB <- dat$xxA * dat$xxB >> meanAB <- meanA * meanB >> sdAB <- sqrt(sdA^2 + sdB^2 + meanA^2 * sdB^2 + meanB^2 * sdA^2) don't know why I did that the hard way (besides I think I messed up the formula slightly), but the point is there's still

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 1:05 PM, David Winsemius wrote: > > On Jan 29, 2011, at 3:49 PM, Joshua Wiley wrote: > >> On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius >> wrote: >>> >>> Huh?. With the same model and data, they should be the same: >> >> I must be missing something, because that is wha

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 3:49 PM, Joshua Wiley wrote: On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius wrote: Huh?. With the same model and data, they should be the same: I must be missing something, because that is what I would have expected too, but it is not what I get (at least when I run t

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 12:31 PM, David Winsemius wrote: > Huh?. With the same model and data, they should be the same: I must be missing something, because that is what I would have expected too, but it is not what I get (at least when I run the code as shown below). >> lm.mod2 <- lm(out ~ scal

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 2:36 PM, Joshua Wiley wrote: On Sat, Jan 29, 2011 at 11:10 AM, David Winsemius wrote: On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: Just in case someone else stumbles onto this thread and is facing a similar issue: The quick solution for me turned out to be using

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Russell Pierce
David, Thanks for your feedback. However, I think if you look at the mean of your output (which, as a minor point, doesn't provide the same data to predict as expand.grid(X1=c(-1,0,1),X2=c(-1,0,1)), you'll see it is very different from the mean of dat$out. Like Ista's previous answer, I think in

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Ista Zahn
Another option is set.seed(10) dat <- data.frame(xxA = rnorm(20,10), xxB = rnorm(20,20)) dat$out <- with(dat,xxA+xxB+xxA*xxB+rnorm(20,20)) lm.mod <- lm(out ~ I(scale(xxA))*I(scale(xxB)), data=dat) newdata <- data.frame(xxA=c(-1,0,1),xxB=c(-1,0,1)) preds <- predict(lm.mod, newdata) Best, Ista

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Joshua Wiley
On Sat, Jan 29, 2011 at 11:10 AM, David Winsemius wrote: > > On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: > >> Just in case someone else stumbles onto this thread and is facing a >> similar issue:  The quick solution for me turned out to be using Glm >> and Predict in the rms package.  Than

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread David Winsemius
On Jan 29, 2011, at 12:12 PM, Russell Pierce wrote: Just in case someone else stumbles onto this thread and is facing a similar issue: The quick solution for me turned out to be using Glm and Predict in the rms package. Thanks go to Joshua and Ista for helping me out with this issue. Double

Re: [R] User error in calling predict/model.frame

2011-01-29 Thread Russell Pierce
Just in case someone else stumbles onto this thread and is facing a similar issue:  The quick solution for me turned out to be using Glm and Predict in the rms package. Thanks go to Joshua and Ista for helping me out with this issue. Double thanks go to Joshua for suggesting I take a closer look

Re: [R] User error in calling predict/model.frame

2011-01-28 Thread Joshua Wiley
Dear Russell, On Fri, Jan 28, 2011 at 5:59 PM, Russell Pierce wrote: > Ista & r-help list, > > I guess I left out the most important part of any question, my reason > for doing this.  I am interested in the predicted y value at the mean, > 1 SD above of the mean, and 1 SD below the mean for each

Re: [R] User error in calling predict/model.frame

2011-01-28 Thread Russell Pierce
Ista & r-help list, I guess I left out the most important part of any question, my reason for doing this. I am interested in the predicted y value at the mean, 1 SD above of the mean, and 1 SD below the mean for each predictor. Since I conducted my analysis with my IVs in the scale of Z (i.e. my

Re: [R] User error in calling predict/model.frame

2011-01-28 Thread Ista Zahn
On Fri, Jan 28, 2011 at 6:26 PM, Russell Pierce wrote: > Thanks for your response Ista, > I'm looking at the results in newdata following your command.  I agree that > predict ran, but I don't think it did what I expect it to do. I may be > mistaken, but shouldn't the mean of dat$out be close to t

Re: [R] User error in calling predict/model.frame

2011-01-28 Thread Russell Pierce
Thanks for your response Ista, I'm looking at the results in newdata following your command. I agree that predict ran, but I don't think it did what I expect it to do. I may be mistaken, but shouldn't the mean of dat$out be close to the mean of newdata$Y? Shouldn't the values in newdata$Y (assum

Re: [R] User error in calling predict/model.frame

2011-01-28 Thread Ista Zahn
Hi Russell, There may be some subtleties that I'm not picking up on, but the obvious problem is that the names of the predictors in newdata do not match the names of the predictors in dat. names(newdata) <- names(dat)[1:2] newdata$Y <- predict(lm.obj,newdata) does work on my machine. Best, Is

[R] User error in calling predict/model.frame

2011-01-28 Thread Russell Pierce
I want to predict values from an existing lm (linear model, e.g. lm.obj) result in R using a new set of predictor variables (e.g. newdata). However, it seems that because my linear models was made by calling scale() on the target predictor that predict exits with an error, "Error in scale(xxA, cen