similar to: How to use lm.predict to obtain fitted values?

Displaying 20 results from an estimated 10000 matches similar to: "How to use lm.predict to obtain fitted values?"

2002 Jan 09
1
na.action in predict.lm
I would like to predict a matrix containing missing values according to a fitted linear model. The predicted values must have the same length as the number of observations in newdata, where missing predicted values (due to missing explanatory values) are replaced by NA. How can I achieve this? I tried the following example: > x <- matrix(rnorm(100), ncol=10) > beta <- rep(1, 10) >
2005 Apr 13
3
A suggestion for predict function(s)
Maybe a useful addition to the predict functions would be to return the values of the predictor variables. It just (unless there are problems) requires an extra line. I have inserted an example below. "predict.glm" <- function (object, newdata = NULL, type = c("link", "response", "terms"), se.fit = FALSE,
2006 Nov 09
1
predict.lm "variables found" question
hello, I'm trying to predict some values based on a linear regression model. I've created the model using one dataframe, and have the prediction values in a second data frame (call it newdata). There are 56 rows in the dataframe used to create the model and 15 in newdata. I ran predict(model1, newdata) and get the warning: 'newdata' had 15 rows but variable(s) found have 56 rows
2012 Aug 28
4
predict.lm(...,type="terms") question
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 control samples containing a molecule at known (increasing) concentrations, first
2010 Aug 17
3
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) model <- lm(yy~XX) XX.pred <- data.frame(matrix(runif(6),ncol=2)) colnames(XX.pred) <- c("XX1","XX2") predict(model,newdata=XX.pred) I would have expected the last line to give me the
2006 May 27
1
Recommended package nlme: bug in predict.lme when an independent variable is a polynomial (PR#8905)
Full_Name: Renaud Lancelot Version: Version 2.3.0 (2006-04-24) OS: MS Windows XP Pro SP2 Submission from: (NULL) (82.239.219.108) I think there is a bug in predict.lme, when a polynomial generated by poly() is used as an explanatory variable, and a new data.frame is used for predictions. I guess this is related to * not * using, for predictions, the coefs used in constructing the orthogonal
2002 Feb 14
0
two comments regarding predict.lm
Here is the first one. It concerns the handling of multiple offsets. The following lines creates a list with 3 explanatory variables and one response. > x<-seq(0,1,length=10);y<-sin(x);z<-cos(x); w<-x+y+z+rnorm(x) > data<-list(x=x,y=y,z=z,w=w) A lm is fitted with one explanatory variable and two offsets. So far, so good. >
2005 Jul 20
1
predict.lm - standard error of predicted means?
Simple question. For a simple linear regression, I obtained the "standard error of predicted means", for both a confidence and prediction interval: x<-1:15 y<-x + rnorm(n=15) model<-lm(y~x) predict.lm(model,newdata=data.frame(x=c(10,20)),se.fit=T,interval="confidence")$se.fit 1 2 0.2708064 0.7254615
2008 Sep 09
2
How does predict.lm work?
Hi, Please could someone explain how this element of predict.lm works? From the help file ` newdata An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used. ' Does this dataframe (newdata) need to have the same variable names as was used in the original data frame used to fit the model? Or will R just look across consecutive
2010 Dec 16
1
predict.lm with new regressor names
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 correspond by name to the original regressors. I very! naively assumed that doing
2008 Jan 04
1
predict.lm removes rownames for a single row. Why?
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 names. tmp <- data.frame(x=1:4, y=c(1,3,2,5)) tmp.lm <- lm(y ~ x, data=tmp) tmp.new <-
2012 Sep 08
1
Using predict() After Adding a Factor to a glm.nb() Model
# Hello, # I have a data set that looks something like the following: site<-c(rep('a',5),rep('b',2),rep('c',4),rep('d',11)) year<-c(1980, 1981, 1982, 1993, 1995, 1980, 1983, 1981, 1993, 1995, 1999, c(1980:1990)) count<-c(60,35,36,12,8,112,98,20,13,15,15,65,43,49,51,34,33,33,33,40,11,0) data<-data.frame(site, year, count) # > site year count # 1
2010 Aug 14
1
Simple problem with lm/predict
Hi all, I've got an xts time series with monthly OHLC Dow Jones industrial index data from 1980 to present, the data is in stored in x. I've done an OLS fit on the data in 1982::1994 and stored it in extrapolate1 (x[,4] contains the closing value for the index). > t3 <- seq(1980,1994,length = length(x["1980::1994",4])) > t4<-t3^2 > extrapolate1 <-
2012 Jul 06
2
Graph showing fitted values obtained by binomial GLM
I have completed a binomial GLM in R (details attached (finalModel.docx)) and I am trying to create a graph of observed and fitted values using the following commands: > MyData<-data.frame(time=seq(from=0,to=1323,by=1)) > Pred<-predict(M2,newdata=MyData,type="response") > plot(x=turtle$time,y=turtle$success) > lines(MyData$time,Pred) However, I get the following
2012 Oct 03
3
predict.lm if regression vector is longer than predicton vector
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 for predict.lm(mod, newdata=dataframe) is shorter than the orginial vector that I did the regression
2006 May 20
1
(PR#8877) predict.lm does not have a weights argument for newdata
Dear R developers, I am a little disappointed that my bug report only made it to the wishlist, with the argument: Well, it does not say it has. Only relevant to prediction intervals. predict.lm does calculate prediction intervals for linear models from weighted regression, so they should be correct, right? As far as I can see they are bound to be wrong in almost all cases, if no weights
2006 Feb 05
1
how to extract predicted values from a quantreg fit?
Hi, I have used package quantreg to estimate a non-linear fit to the lowest part of my data points. It works great, by the way. But I'd like to extract the predicted values. The help for predict.qss1 indicates this: predict.qss1(object, newdata, ...) and states that newdata is a data frame describing the observations at which prediction is to be made. I used the same technique I used
2011 Mar 23
1
predict.lm How to introduce new data?
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 same names The resulting model is lms <- lm(vd ~ log(v1) + fv2+ fv5+ fv7 )
2006 May 30
0
(PR#8905) Recommended package nlme: bug in predict.lme when an independent variable is a polynomial
Many thanks for your very useful comments and suggestions. Renaud 2006/5/30, Prof Brian Ripley <ripley at stats.ox.ac.uk>: > On Tue, 30 May 2006, Prof Brian Ripley wrote: > > > This is not really a bug. See > > > > http://developer.r-project.org/model-fitting-functions.txt > > > > for how this is handled in other packages. All model-fitting in R used =
2002 Dec 19
0
Ongoing unhappiness with NA and factor behavior of distributed lm/predict.lm
Hi all, I''m still not quite happy with the NA and factor handling of lm and predict.lm in R1.6.1 (forcing me to use my not very skillfully crafted patches). Here is the problem 1: >