similar to: predict.lm removes rownames for a single row. Why?

Displaying 20 results from an estimated 10000 matches similar to: "predict.lm removes rownames for a single row. Why?"

2008 Apr 04
2
predict.glm & newdata
Hi all - I'm stumped by the following mdl <- glm(resp ~ . , data = df, family=binomial, offset = ofst) WORKS yhat <- predict(mdl) WORKS yhat <- predict(mdl,newdata = df) FAILS Error in drop(X[, piv, drop = FALSE] %*% beta[piv]) : subscript out of bounds I've tried without offset, quoting binomial. The offset variable ofst IS in df. Previous postings indicate possible
2004 Jun 11
4
rownames of single row matrices
Hi I want to extract rows of a matrix, and preserve rownames even if only one row is selected. Toy example: R> a <- matrix(1:9,3,3) R> rownames(a) <- letters[1:3] R> colnames(a) <- LETTERS[1:3] R> a A B C a 1 4 7 b 2 5 8 c 3 6 9 Extract the first two rows: R> wanted <- 1:2 R> a[wanted,] A B C a 1 4 7 b 2 5 8 rownames come through fine. Now extract just
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. >
2000 Apr 25
0
Wrong SEs in predict.lm(..., type="terms")
predict.lm(..., type="terms") gives wrong standard errors. Below, I have provided what I believe are the necessary fixes. However, there are subtleties, and the code needs careful checking. Some of the looping is surely not necessary, but it is surely best to begin with the minimum necessary changes. My tests, including checks against S-PLUS, have extended to fitting spline curves. I
2000 Apr 26
0
Wrong SEs in predict.lm(..., type="terms") (PR#528)
>From e980153 Tue Apr 25 14:42:27 2000 To: r-help@stat.math.ethz.ch Subject: Wrong SEs in predict.lm(..., type="terms") For what it is worth, I am using RW-1.0.0 under Windows 98. I submitted this earlier to r-help. There is one change below to my proposed corrected code: predict.lm(..., type="terms") gives wrong standard errors. Below, I have provided what I believe are
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
2006 May 19
1
How to use lm.predict to obtain fitted values?
I am writing a function to assess the out of sample predictive capabilities of a time series regression model. However lm.predict isn't behaving as I expect it to. What I am trying to do is give it a set of explanatory variables and have it give me a single predicted value using the lm fitted model. > model = lm(y~x) > newdata=matrix(1,1,6) > pred =
2010 Aug 16
1
Combining values from a data.frame row with matrix rownames.
Hello, I am trying to iteratively build a build a panel of variables to discriminate between two groups. My starting position is a matrix of experimental data and I have a function that will work through all pairs of variables and produce sensitivities, specificities and p-values for each pair and write it to a file (above particular cut-offs). I have a second function that will read that file
2005 Nov 18
1
pr[in]comp: predict single observation when data has colnames (PR#8324)
To my knowledge, this has not been reported previously, and doesn't seem to have been changed in R-devel or R-patched. If M is a matrix with coloumn names, and mod <- prcomp(M) # or princomp then predicting a single observation (row) with predict() gives the error Error in scale.default(newdata, object$center, object$scale) : length of 'center' must equal the number of
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
2006 Sep 01
1
difference between ns and bs in predict.glm
I am fittling a spline to a variable in a regression model, I am then using the predict.glm funtion to make some predictions. When I use bs to fit the spline I don't have any problems using the predict.glm function however when I use ns I get the following error: Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ (found for
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
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
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
2008 May 19
2
Sort matrix with duplicate row names alphabetically by rowname
Hi, I've a matrix that contains 4 replicates of each rowname. (4 a's, 4 b's, 4 c's in no particular order) Like this: # c 32 a 1 b 4 c 87 c 34 b 54 a 23 a 12 b 9 a 3 b 87 c 43 There are a couple of more columns but I'm using the above as an example I need to sort it so that the same rownames appear together in alpahbetical order. Like this: # a 1 a 23 a 12 a 3 b 4
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 )
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
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,
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
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) >