Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
That's what I am looking for. Thanks for being so helpful, I appreciate it very much. On Sun, Feb 23, 2014 at 10:16 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > On Sun, Feb 23, 2014 at 9:06 PM, C W wrote: > > Is there a way to rbind this? Do I have to use use a package like 'zoo

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread Gabor Grothendieck
On Sun, Feb 23, 2014 at 9:06 PM, C W wrote: > Is there a way to rbind this? Do I have to use use a package like 'zoo' and > merge()? > > p <- predict(model, data.frame(t = 1, q = factor(1, 1:4)) > rbind(tsdat, p) > If you want to append this to the end of the series then try this: ts(c(tsdat,

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
Is there a way to rbind this? Do I have to use use a package like 'zoo' and merge()? p <- predict(model, data.frame(t = 1, q = factor(1, 1:4)) rbind(tsdat, p) On Sun, Feb 23, 2014 at 8:43 PM, C W wrote: > I guess this is for anyone in the future. > > > predict(model, data.frame(t = 1, q = fac

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
I guess this is for anyone in the future. > predict(model, data.frame(t = 1, q = factor(1, 1:4)) This would be the answer. Thanks again, Gabor! Mike On Sun, Feb 23, 2014 at 8:23 PM, Gabor Grothendieck wrote: > On Sun, Feb 23, 2014 at 7:40 PM, C W wrote: > > Gabor, > > Your response worked p

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread Gabor Grothendieck
On Sun, Feb 23, 2014 at 7:40 PM, C W wrote: > Gabor, > Your response worked perfectly, list(t = 1, q = factor(1, 1:4) was what I > couldn't figure out. Thank you. > > In predict.lm(model, newdata), 2nd argument MUST be data.frame(). Why does > list() also work? > Yes, it would be better to use

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
Gabor, Your response worked perfectly, list(t = 1, q = factor(1, 1:4) was what I couldn't figure out. Thank you. In predict.lm(model, newdata), 2nd argument MUST be data.frame(). Why does list() also work? Mike On Sun, Feb 23, 2014 at 7:32 PM, Gabor Grothendieck wrote: > On Sun, Feb 23, 20

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread Gabor Grothendieck
On Sun, Feb 23, 2014 at 7:25 PM, C W wrote: > Gabor, > Let me change newdata since it's confusing. > > Suppose I want to predict, year 1990, and quarter 2. >> newdata <- data.frame(c(1990, 1, 0, 0) > > Since Q1 is a baseline, we will only see Q2, Q3, Q4. So, 4 parameters in > total. > The formul

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
Gabor, Let me change newdata since it's confusing. Suppose I want to predict, year 1990, and quarter 2. > newdata <- data.frame(c(1990, 1, 0, 0) Since Q1 is a baseline, we will only see Q2, Q3, Q4. So, 4 parameters in total. Mike On Sun, Feb 23, 2014 at 7:13 PM, Gabor Grothendieck wrote: >

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread Gabor Grothendieck
On Sun, Feb 23, 2014 at 6:56 PM, C W wrote: > Gabor, > I want the new data to be this, > newdata <- data.frame(c(1, 0, 0, 0)) > Its not clear what this means. There are two input variables so we must specify two inputs. For example, this would get the prediction for t=1 and for level 1 of q whic

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
Gabor, I want the new data to be this, newdata <- data.frame(c(1, 0, 0, 0)) Here the code with the new data, > dat <- rnorm(20) > tsdat <- ts(dat, start=c(1900, 1), freq=4) > q <- as.factor(rep(1:4, 5)) > t <- 1:20 > lm(tsdat~t+q) Call: lm(formula = tsdat ~ t + q) Coefficients: (Intercept)

Re: [R] predict.lm() does not take ts objects in formula

2014-02-23 Thread Gabor Grothendieck
On Sun, Feb 23, 2014 at 6:34 PM, C W wrote: > Hello, > I don't know how to use predict.lm() for ts object. > > Here's the time series regression. > y = t + Q1 + Q2 + Q3 + Q4 > > Here's my R code, > >> dat <- rnorm(20) >> tsdat <- ts(dat, start=c(1900, 1), freq=4) >> q <- as.factor(rep(1:4, 5)) >>

[R] predict.lm() does not take ts() objects in formula

2014-02-23 Thread C W
Hello list, Does predict.lm() take ts object. I am aware that it requires data to come in data.frame Here's the time series regression. y = t + Q1 + Q2 + Q3 + Q4 Here's my R code, > dat <- rnorm(20) > tsdat <- ts(dat, start=c(1900, 1), freq=4) > q <- as.factor(rep(1:4, 5)) > t <- 1:20 > lm(ts

[R] predict.lm() does not take ts objects in formula

2014-02-23 Thread C W
Hello, I don't know how to use predict.lm() for ts object. Here's the time series regression. y = t + Q1 + Q2 + Q3 + Q4 Here's my R code, > dat <- rnorm(20) > tsdat <- ts(dat, start=c(1900, 1), freq=4) > q <- as.factor(rep(1:4, 5)) > t <- 1:20 > lm(tsdat~t+q) Call: lm(formula = tsdat ~ t + q)

Re: [R] predict.lm (Michael Haenlein)

2013-04-09 Thread marKo
Michael Haenlein wrote Dear all, I would like to use predict.lm to obtain a set of predicted values based on a regression model I estimated. When I apply predict.lm to two vectors that have the same values, the predicted values will be identical. I know that my regress

Re: [R] predict.lm

2013-04-08 Thread S Ellison
> I would like to use predict.lm to obtain a set of predicted > values based on a regression model I estimated. > Do you want predictions - which will always be the same - or randomly distributed data that is based on the model prediction plus random error? *

[R] predict.lm

2013-04-08 Thread Michael Haenlein
Dear all, I would like to use predict.lm to obtain a set of predicted values based on a regression model I estimated. When I apply predict.lm to two vectors that have the same values, the predicted values will be identical. I know that my regression model is not perfect and I would like to take a

Re: [R] predict.lm if regression vector is longer than predicton vector

2012-10-03 Thread Greg Snow
The most common case that I see that error is when someone fits their model using syntax like: fit <- lm( mydata$y ~ mydata$x ) instead of the preferred method: fit <- lm( y ~ x, data=mydata ) The fix (if this is what you did and why you are getting the error) is to not use the first way and in

Re: [R] predict.lm if regression vector is longer than predicton vector

2012-10-03 Thread William Dunlap
e, because only data.frame forces all of its components to have the same length. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of frauke > Sent: Wed

Re: [R] predict.lm if regression vector is longer than predicton vector

2012-10-03 Thread S Ellison
> Of course I can extend the new dataframe with a few thousands > NAs, but is there a more elegant solution? That should not be necessary: predict.lm should work on any number of newdata rows, whether longer or shorter than the original data set. However, the help page for predict.lm says (among

[R] predict.lm if regression vector is longer than predicton vector

2012-10-03 Thread frauke
Hi everybody, recently a member of the community pointed me to the useful predict.lm() comment. While I was toying with it, I stumbled across the following problem. I do the regression with data from five years. But I want to do a prediction with predict.lm for only one year. Thus my dataframe f

Re: [R] predict.lm(...,type="terms") question

2012-09-02 Thread Rui Barradas
. Proposed: newdata An optional data frame in which to look for new values of terms with which to predict. If omitted, the fitted values are used. -John Thaden, Ph.D. College Station, TX --- On Sun, 9/2/12, peter dalgaard wrote: From: peter dalgaard

Re: [R] predict.lm(...,type="terms") question

2012-09-02 Thread John Thaden
h to predict. If omitted, the fitted values are used. -John Thaden, Ph.D. College Station, TX --- On Sun, 9/2/12, peter dalgaard wrote: > From: peter dalgaard > Subject: Re: [R] predict.lm(...,type="terms") question > To: "David Winsemius" > Cc: "R

Re: [R] predict.lm(...,type="terms") question

2012-09-01 Thread peter dalgaard
On Sep 2, 2012, at 03:38 , David Winsemius wrote: > > Why should predict not complain when it is offered a newdata argument that > does no contain a vector of values for "x"? The whole point of the terms > method of prediction is to offer estimates for specific values of items on > the RHS of

Re: [R] predict.lm(...,type="terms") question

2012-09-01 Thread David Winsemius
On Sep 1, 2012, at 4:33 AM, Rui Barradas wrote: Hello, John is right, there seems to be an error in predict.lm. It can be made to work but if the model is fitted with lm(...,data) then it messes things up. Apparently predict.lm disregards the data argument and uses whatever it finds in t

Re: [R] predict.lm(...,type="terms") question

2012-09-01 Thread Rui Barradas
Hello, John is right, there seems to be an error in predict.lm. It can be made to work but if the model is fitted with lm(...,data) then it messes things up. Apparently predict.lm disregards the data argument and uses whatever it finds in the global environment. In the examples below, after r

Re: [R] predict.lm(...,type="terms") question

2012-08-31 Thread David Winsemius
On Aug 31, 2012, at 3:48 PM, jjthaden wrote: On Aug 30, 2012, at 4:35 PM, David Windemius wrote: David said my newdata data frame 'new' must have a column named 'area'. It did. Nonetheless predict.lm throws an error with type = "terms" and newdata = new. I see nothing in the predict.lm

Re: [R] predict.lm(...,type="terms") question

2012-08-31 Thread David Winsemius
On Aug 31, 2012, at 5:27 PM, jjthaden wrote: The error is generated in the last line of code shown here from predict.lm The code you offered had an extra comma in the 'area' vector. Removing allowed the fitting and prediction to proceed without error, I do not see why you are producing c

Re: [R] predict.lm(...,type="terms") question

2012-08-31 Thread jjthaden
On Aug 30, 2012, at 4:35 PM, David Windemius wrote: >> David said my newdata data frame 'new' must have a column named 'area'. >> It did. Nonetheless predict.lm throws an error with type = "terms" and >> newdata = new. I see nothing in the predict.lm documentation that >> bars this usage. Is the

Re: [R] predict.lm(...,type="terms") question

2012-08-31 Thread jjthaden
The error is generated in the last line of code shown here from predict.lm > predict.lm function (object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), level = 0.95, type = c("response", "terms"), terms = NULL, na.action = na.pass,

Re: [R] predict.lm(...,type="terms") question

2012-08-30 Thread John Thaden
Dave said my newdata data frame 'new' must have a column named 'area'. It did. Nonetheless predict.lm throws an error with type = "terms" and newdata = new. I see nothing in the predict.lm documentation that bars this usage. Is there a bug? To illustrate an OLS behavior, I had cited Ludbrook '12.

Re: [R] predict.lm(...,type="terms") question

2012-08-30 Thread David Winsemius
On Aug 30, 2012, at 2:29 PM, John Thaden wrote: > Dave said my newdata data frame 'new' must have a column named 'area'. > It did. Nonetheless predict.lm throws an error with type = "terms" and > newdata = new. I see nothing in the predict.lm documentation that > bars this usage. Is there a bug?

Re: [R] predict.lm(...,type="terms") question

2012-08-30 Thread Rui Barradas
Hello, Instead of reversing the regression, that, like you say, may have problems, it's very easy to wrap the formula x' <- (y' - beta0)/beta1 in a function and use the direct regression to get new 'x' values from new 'y' ones. This function assumes a first order ols model. invpredict <- f

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread David Winsemius
On Aug 29, 2012, at 4:08 PM, John Thaden wrote: Draper & Smith sections (3.2, 9.6) address prediction interval issues, but I'm also concerned with the linear fit itself. The Model II regression literature Citations? makes it abundantly clear that OLS regression of x on y frequently yields

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread John Thaden
Draper & Smith sections (3.2, 9.6) address prediction interval issues, but I'm also concerned with the linear fit itself. The Model II regression literature makes it abundantly clear that OLS regression of x on y frequently yields a different line than of y on x. The example below is not so extreme

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread Rui Barradas
Hello, Ok, got it, thanks. Apparently I was right, the estimator is still x.pred = (y.new - b0)/b1 which can be obtained from predict.lm with the inverse regression model formula. According to the litterature, the main differences are in the confidence intervals for the true value of x.pred,

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread David Winsemius
On Aug 29, 2012, at 8:06 AM, John Thaden wrote: Could it be that my newdata object needs to include a column for the concn term even though I'm asking for concn to be predicted? The new data argument MUST contain a column with the name "area". If it does not hten the original data is used.

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread John Thaden
Could it be that my newdata object needs to include a column for the concn term even though I'm asking for concn to be predicted? If so, what numbers would I fill it with? Or should my newdata object include the original data, too? Is there another mailing list I can ask? Thanks, -John On Wed, Aug

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread Peter Ehlers
I think that what the OP is looking for comes under the heading of "inverse regression" or the "calibration" problem. One reference with a simple explanation including confidence intervals is "Applied regression analysis" by Draper and Smith. (It's in section 3.2 in my 3rd edition). Peter Ehlers

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread John Thaden
I think I may be misreading the help pages, too, but misreading how? I agree that inverting the fitted model is simpler, but I worry that I'm misusing ordinary least squares regression by treating my response, with its error distribution, as a predictor with no such error. In practice, with my rea

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread Rui Barradas
Hello, Inline. Em 29-08-2012 16:06, John Thaden escreveu: Could it be that my newdata object needs to include a column for the concn term even though I'm asking for concn to be predicted? If so, what numbers would I fill it with? Or should my newdata object include the original data, too? Is the

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread Rui Barradas
Hello, predict(..., type = "terms") returns the predicted regressors multiplied by the respective beta centered. The centering constant is also returned: model <- lm(area ~ concn, data) # Already run predict(model, type = "terms") concn 1 -11542.321 2 -8244.515 3 1648.903 4 18137.9

Re: [R] predict.lm(...,type="terms") question

2012-08-29 Thread Rui Barradas
Hello, You seem to be misreading the help pages for lm and predict.lm, argument 'terms'. A much simpler way of solving your problem should be to invert the fitted model using lm(): model <- lm(area ~ concn, data) # Your original model inv.model <- lm(concn ~ area, data = data) # Your probl

[R] predict.lm(...,type="terms") question

2012-08-28 Thread John Thaden
Hello all, How do I actually use the output of predict.lm(..., type="terms") to predict new term values from new response values? I'm a chromatographer trying to use R (2.15.1) for one of the most common calculations in that business: - Given several chromatographic peak areas measured for

Re: [R] predict.lm How to introduce new data?

2011-03-23 Thread David Winsemius
On Mar 23, 2011, at 10:05 AM, agent dunham wrote: Dear all, I've fitted a lm using 61 data (training data), and I'left 10 as test data. Training data and test data are stored in an excell. training <- read.xls("C:/./training.xls") , the same for test. That is: v1 v2 ... v15 When I

[R] predict.lm How to introduce new data?

2011-03-23 Thread agent dunham
Dear all, I've fitted a lm using 61 data (training data), and I'left 10 as test data. Training data and test data are stored in an excell. training <- read.xls("C:/./training.xls") , the same for test. That is: v1 v2 ... v15 When I type str(training) and str(test), both sets have the sam

Re: [R] predict.lm with new regressor names

2010-12-16 Thread Anirban Mukherjee
Thanks very much Dennis and Michael. That makes sense. I had some very sloppy code which did the equivalent of y<-rnorm(100) x<-list() x[[1]]<-rnorm(100) x[[2]]<-rnorm(100) lm.yx<-lm(y~x[[1]]+x[[2]]) To predict from lm.yx, I was trying to feed predict.lm a data.frame with columns called x[[1]] an

Re: [R] predict.lm with new regressor names

2010-12-15 Thread Dennis Murphy
Hi: On Wed, Dec 15, 2010 at 10:05 PM, Anirban Mukherjee wrote: > Hi all, > > Suppose: > > y<-rnorm(100) > x1<-rnorm(100) > lm.yx<-lm(y~x1) > > To predict from a new data source, one can use: > > # works as expected > dum<-data.frame(x1=rnorm(200)) > predict(lm.yx, newdata=dum) > Yup. > > Suppos

[R] predict.lm with new regressor names

2010-12-15 Thread Anirban Mukherjee
Hi all, Suppose: y<-rnorm(100) x1<-rnorm(100) lm.yx<-lm(y~x1) To predict from a new data source, one can use: # works as expected dum<-data.frame(x1=rnorm(200)) predict(lm.yx, newdata=dum) Suppose lm.yx has been run and we have the lm object. And we have a dataframe that has columns that don't

Re: [R] predict.lm with new regressor names

2010-12-15 Thread Michael Bedward
Hi Anirban, You can do it like this... lm.foobar <- lm(foo ~ bar) some.data <- rnorm(200) predict(lm.foobar, newdata=list(bar=some.data)) Hope that helps. Michael On 16 December 2010 17:05, Anirban Mukherjee wrote: > Hi all, > > Suppose: > > y<-rnorm(100) > x1<-rnorm(100) > lm.yx<-lm(y~x1) >

[R] predict.lm with new regressor names

2010-12-15 Thread Anirban Mukherjee
Hi all, Suppose: y<-rnorm(100) x1<-rnorm(100) lm.yx<-lm(y~x1) To predict from a new data source, one can use: # works as expected dum<-data.frame(x1=rnorm(200)) predict(lm.yx, newdata=dum) Suppose lm.yx has been run and we have the lm object. And we have a dataframe that has columns that don't

Re: [R] predict.lm[e] with formula passed as a variable

2010-12-13 Thread David L Lorenz
)) Dave From: "Thaler, Thorn, LAUSANNE, Applied Mathematics" To: Date: 12/13/2010 12:16 PM Subject: [R] predict.lm[e] with formula passed as a variable Sent by: r-help-boun...@r-project.org Dear all, In a function I paste a string and convert it to a formula which I pass to lm[e]. T

[R] predict.lm[e] with formula passed as a variable

2010-12-13 Thread Thaler, Thorn, LAUSANNE, Applied Mathematics
Dear all, In a function I paste a string and convert it to a formula which I pass to lm[e]. The idea is to write a function which takes the name of the response variable and the explanatory variable and the data frame as an argument and calculates an lm[e]. (see example below) This works fine, bu

Re: [R] predict.lm, matrix in formula and newdata

2010-08-17 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Stephan Kolassa > Sent: Tuesday, August 17, 2010 5:25 AM > To: R-help@r-project.org > Subject: [R] predict.lm, matrix in formula and newdata > > Dear a

Re: [R] predict.lm, matrix in formula and newdata

2010-08-17 Thread Charles Roosen
Of Stephan Kolassa Sent: 17 August 2010 14:25 To: R-help@r-project.org Subject: [R] predict.lm, matrix in formula and newdata Dear all, I am stumped at what should be a painfully easy task: predicting from an lm object. A toy example would be this: XX <- matrix(runif(8),ncol=2) yy <- runif(4

Re: [R] predict.lm, matrix in formula and newdata

2010-08-17 Thread Dimitris Rizopoulos
try it better this way: XX <- matrix(runif(8), ncol = 2) DF <- as.data.frame(XX) DF$yy <- runif(4) model <- lm(yy ~ ., DF) XX.pred <- as.data.frame(matrix(runif(6), ncol = 2)) predict(model, XX.pred) I hope it helps. Best, Dimitris On 8/17/2010 2:24 PM, Stephan Kolassa wrote: Dear all, I

[R] predict.lm, matrix in formula and newdata

2010-08-17 Thread Stephan Kolassa
Dear all, I am stumped at what should be a painfully easy task: predicting from an lm object. A toy example would be this: XX <- matrix(runif(8),ncol=2) yy <- runif(4) model <- lm(yy~XX) XX.pred <- data.frame(matrix(runif(6),ncol=2)) colnames(XX.pred) <- c("XX1","XX2") predict(model,newdata=XX.p

Re: [R] predict.lm with NAs

2010-04-15 Thread Walmes Zeviani
You can use predict() by specifying a complete data.frame() for prediction to the argument newdata=. Look: da <- expand.grid(x1=LETTERS[1:4], x2=1:9) da$y <- rnorm(da$x1) da$y[sample(length(da$y), 5)] <- NA m0 <- lm(y~x1+x2, data=da) predict(m0) # NA not predicted predict(m0, newdata=da) # NA pr

Re: [R] predict.lm with NAs

2010-04-14 Thread Wincent
see ?na.exclude you can set na.action='na.exclude' when fit the model. On 15 April 2010 09:06, Martin Batholdy wrote: > Hi, > > I wanted to use the predict.lm() function to compare the empirical data with > the predicted values. > The problem is that I have NAs in my data. > > I wanted to cbin

[R] predict.lm with NAs

2010-04-14 Thread Martin Batholdy
Hi, I wanted to use the predict.lm() function to compare the empirical data with the predicted values. The problem is that I have NAs in my data. I wanted to cbind my data.frame with the empirical values with the vector I get from predict.lm. But they don't have the same length because predict.

Re: [R] predict.lm

2010-04-06 Thread Tal Galili
Hi Felipe, Make sure "predictors" data.frame has the EXACT same column names as the data.frame you used for creating ModeloLineal. Cheers, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www

[R] predict.lm

2010-04-05 Thread Luis Felipe Parra
Hello I am trying to use predict.lm, but I am having trouble getting out of sample predictions. I am getting the same output if I use the following three commands: predict(ModeloLineal,predictors[721:768,]) predict(ModeloLineal,predictors[1:768,]) predict(ModeloLineal) where ModeloLineal is the o

[R] predict.lm() out-of-sample predictions - problem with data classes

2009-10-07 Thread Gero Schwenk
Hello! I'm still working on my problem, which also occurs with the predict.lm() function. - Providing newdata, which is a data.frame with all variables being "numeric", as str() shows, R tells me the following: ar1.xpred.test.pred <- predict(ar1.xpred.fitted, regdata.test, se.fit = FALSE) Feh

Re: [R] predict.lm() question

2008-04-07 Thread Rolf Turner
You called lm() with a predictor named ``D$X'' and called predict.lm() with a predictor name ``X''. Simplest remedy: Use fit <- lm(Y ~ X, data = D) Remark: Not a good idea to use ``D'' as the name of your data frame (``D'' is the name of a function --- derivative). Likewise don't u

Re: [R] predict.lm() question

2008-04-07 Thread Duncan Murdoch
On 07/04/2008 5:57 PM, Chip Barnaby wrote: > Dear R-people ... > > I'm a new user. I can't get predict.lm() to produce predictions for > new independent data. There are some messages in archived help about > this problem, but I still don't see my error after reviewing > those. I understand t

[R] predict.lm() question

2008-04-07 Thread Chip Barnaby
Dear R-people ... I'm a new user. I can't get predict.lm() to produce predictions for new independent data. There are some messages in archived help about this problem, but I still don't see my error after reviewing those. I understand that the new independent data must have the same name(s

Re: [R] predict.lm with matrix as newdata

2008-02-18 Thread Uwe Ligges
Marlin Keith Cox wrote: > Thank you in advance for helping me with this. > I included a part of the actual data. The result of pred.est and > pred.est1are different, but they should be identical. For > pred.est, I entered the slope and y intercept and received a value for each > individual numb

Re: [R] predict.lm with matrix as newdata

2008-02-18 Thread Marlin Keith Cox
Thank you in advance for helping me with this. I included a part of the actual data. The result of pred.est and pred.est1are different, but they should be identical. For pred.est, I entered the slope and y intercept and received a value for each individual number in the matrix (Z). For pred.est1

Re: [R] predict.lm with matrix as newdata

2008-02-16 Thread Uwe Ligges
Marlin Keith Cox wrote: > Z is a matrix and when I run the following line, it creates a prediction > estimate using each column, how can I get it an estimate for each individual > number. I have tried changing Z to a data.frame, but this does not do it > either. > > model.lm<-lm(w~x) > > pred.

[R] predict.lm with matrix as newdata

2008-02-15 Thread Marlin Keith Cox
Z is a matrix and when I run the following line, it creates a prediction estimate using each column, how can I get it an estimate for each individual number. I have tried changing Z to a data.frame, but this does not do it either. model.lm<-lm(w~x) pred.est <- predict.lm(model.lm, data.frame(x=Z

Re: [R] predict.lm removes rownames for a single row. Why?

2008-01-04 Thread Prof Brian Ripley
This is an inconsistency in drop: > x <- matrix(1:4, 4,1, dimnames=list(letters[1:4], NULL)) > x [,1] a1 b2 c3 d4 > drop(x) a b c d 1 2 3 4 > drop(x[1,,drop=FALSE]) [1] 1 S does not do that, and I don't think R should, given its documentation. (Note that x[1,] also drops names

[R] predict.lm removes rownames for a single row. Why?

2008-01-04 Thread Richard M. Heiberger
predict.lm keeps row names when working from several rows in newdata, but always removes rowname from a single row. The rownames are removed by the line in predict.lm predictor <- drop(X[, piv, drop = FALSE] %*% beta[piv]) What is the reason for that decision? I usually want to retain the row