predict

Rolling regression and prediction with lm() and predict()

六眼飞鱼酱① 提交于 2019-12-19 09:42:01
问题 I need to apply lm() to an enlarging subset of my dataframe dat , while making prediction for the next observation. For example, I am doing: fit model predict ---------- ------- dat[1:3, ] dat[4, ] dat[1:4, ] dat[5, ] . . . . dat[-1, ] dat[nrow(dat), ] I know what I should do for a particular subset (related to this question: predict() and newdata - How does this work?). For example to predict the last row, I do dat1 = dat[1:(nrow(dat)-1), ] dat2 = dat[nrow(dat), ] fit = lm(log(clicks) ~ log

loess line not plotting correctly

烈酒焚心 提交于 2019-12-19 08:11:20
问题 I'm having trouble fitting a loess smooth plus confidence limits to a scatterplot of residuals. My model is height ~ weight + chest circumference. To check linearity of chest circumference, I've fitted a model without chest circumference (i.e. height ~ weight), and plotted the residuals of this model against chest circumference. So far so good. I then tried to use loess() and predict() to plot a loess line, plus confidence limits. The result looks like this (in the picture I've only plotted

predict method for felm from lfe package

南笙酒味 提交于 2019-12-18 18:46:06
问题 Does anyone have a nice clean way to get predict behavior for felm models? library(lfe) model1 <- lm(data = iris, Sepal.Length ~ Sepal.Width + Species) predict(model1, newdata = data.frame(Sepal.Width = 3, Species = "virginica")) # Works model2 <- felm(data = iris, Sepal.Length ~ Sepal.Width | Species) predict(model2, newdata = data.frame(Sepal.Width = 3, Species = "virginica")) # Does not work 回答1: As a workaround, you could combine felm , getfe , and demeanlist as follows: library(lfe) lm

predict() with arbitrary coefficients in r

巧了我就是萌 提交于 2019-12-17 19:36:54
问题 I've got some coefficients for a logit model set by a non-r user. I'd like to import those coefficients into r and generate some goodness of fit estimates on the same dataset (ROC and confusion matrix) vs my own model. My first thought was to coerce the coefficients into an existing GLM object using something like summary(fit)$coefficients[,1] <- y or summary(fit)$coefficients <- x where y and x are matrices containing the coefficients I'm trying to use to predict and fit is a previously

r predict function returning too many values [closed]

我们两清 提交于 2019-12-17 16:53:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I've read other postings regarding named variables and tried implementing the answers but still get too many values for my new data that I want to run my existing model on. Here is working example code: set.seed(123) mydata <- data.frame("y"=rnorm(100,mean=0, sd = 1),"x"=c(1:100)) mylm <- lm(y ~ x, data=mydata)

Predict() - Maybe I'm not understanding it

試著忘記壹切 提交于 2019-12-16 19:52:12
问题 I posted earlier today about an error I was getting with using the predict function. I was able to get that corrected, and thought I was on the right path. I have a number of observations (actuals) and I have a few data points that I want to extrapolate or predict. I used lm to create a model, then I tried to use predict with the actual value that will serve as the predictor input. This code is all repeated from my previous post, but here it is: df <- read.table(text = ' Quarter Coupon Total

Fitting a quadratic curve for each data set that has different lengths

我的梦境 提交于 2019-12-13 03:45:33
问题 I would like to fit a quadratic to (Time,SkinTemp) for each id in the following data.frame df. Each id has a different number of Time,SkinTemp entries so I'm stuck with 'predict' df<-data.frame(Time=seq(65), SkinTemp=rnorm(65,37,0.5), id=rep(1:10,c(5,4,10,6,7,8,9,8,4,4))) So far I have: #Fit the model y=x^2+x+C fitted_models = df %>% group_by(id) %>% do(model = lm(SkinTemp ~ Time+I(Time^2), data = .)) So far so good. Here's where I'm stuck. How do I pass the original Time data into the

R - factor examcard has new levels

只谈情不闲聊 提交于 2019-12-13 02:15:33
问题 I built a classification model in R using C5.0 given below: library(C50) library(caret) a = read.csv("All_SRN.csv") set.seed(123) inTrain <- createDataPartition(a$anatomy, p = .70, list = FALSE) training <- a[ inTrain,] test <- a[-inTrain,] Tree <- C5.0(anatomy ~ ., data = training, trControl = trainControl(method = "repeatedcv", repeats = 10, classProb = TRUE)) TreePred <- predict(Tree, test) The training set has features like - examcard, coil_used, anatomy_region, bodypart_anatomy and

predict and model.matrix give different predicted means within levels of a factor variable

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 01:46:57
问题 This question arose as a result of another question posted here: non-conformable arguments error from lmer when trying to extract information from the model matrix When trying to obtain predicted means from an lmer model containing a factor variable, the output varies depending on how the factor variable is specified. I have a variable agegroup, which can be specified using the groups "Children <15 years", "Adults 15-49 years", "Elderly 50+ years" or "0-15y", "15-49y", "50+y". My choice

How to get Stata to produce a dynamic forecast when using lagged outcome as a regressor?

落花浮王杯 提交于 2019-12-13 00:43:08
问题 I am currently dealing witha very small data set (20 observations, I know it's terrible). But I need to somehow forecast out the values. When I simply regress time on the dependent variable I am able to get a prediction, but when I add lagged or differenced variables it does not predict more than one year into the future. Is this due to having too few observations? Here is my code for context. The two lines have have commented out result in a better fitting prediction for present data, but