predict

Doing linear prediction with R: How to access the predicted parameter(s)?

无人久伴 提交于 2019-12-08 02:17:11
问题 I am new to R and I am trying to do linear prediction. Here is some simple data: test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991)) Say if I want to predict the value for year=12 . This is what I am doing (experimenting with different commands): lma=lm(test.frame$value~test.frame$year) # let's get a linear fit summary(lma) # let's see some parameters attributes(lma) # let's see what parameters we can call lma$coefficients # I get the intercept and gradient predict(lm(test

predict and multiplicative variables / interaction terms in probit regressions

此生再无相见时 提交于 2019-12-07 20:37:32
I want to determine the marginal effects of each dependent variable in a probit regression as follows: predict the (base) probability with the mean of each variable for each variable, predict the change in probability compared to the base probability if the variable takes the value of mean + 1x standard deviation of the variable In one of my regressions, I have a multiplicative variable, as follows: my_probit <- glm(a ~ b + c + I(b*c), family = binomial(link = "probit"), data=data) Two questions: When I determine the marginal effects using the approach above, will the value of the

ROC curve in R using rpart package?

徘徊边缘 提交于 2019-12-07 17:38:42
问题 I split Train data set and Test data set. I used a package rpart for CART (classification tree) in R (only train set). And I want to carry out a ROC analysis using the ROCR package. Variable is `n. use' (response varible... 1=yes, 0=no): > Pred2 = prediction(Pred.cart, Test$n.use) Error in prediction(Pred.cart, Test$n.use) : **Format of predictions is invalid.** This is my code. What is problem? And what is right type ( "class" or "prob" ? library(rpart) train.cart = rpart(n.use~., data=Train

How to compute standard error for predicted data in R using predict

随声附和 提交于 2019-12-07 10:42:29
Here is my data: a <- c(60, 65, 70, 75, 80, 85, 90, 95, 100, 105) b <- c(26, 24.7, 20, 16.1, 12.6, 10.6, 9.2, 7.6, 6.9, 6.9) a_b <- cbind(a,b) plot(a,b, col = "purple") abline(lm(b ~ a),col="red") reg <- lm(b ~ a) I would like to use the predict function in order to compute the standard error for the predicted b value at 110. z <- predict(reg, newdata=data.frame(year=110), se.fit=TRUE) This is the output I get, but I think this is just giving me the standard errors for my 10 time points, but not the new 11th data point: z $fit 1 2 3 4 5 6 7 8 9 10 24.456364 22.146061 19.835758 17.525455 15

How can I use the predict function in R in a logistic regression fitted years ago?

点点圈 提交于 2019-12-07 07:57:15
问题 I have a problem that I am trying to resolve with no success. More than two days searching and I didn’t get a single clue. Sorry if the answer is out there and I didn’t find it. Suppose that you have a logistic equation regression (binary model) from an old model that you estimated some years ago. Therefore you know the parameters βk (k = 1, 2, ..., p) because they were estimated in the past. But you don’t have the data that were used to fit the model. My question is: can I introduce this old

Having issues using the lme4 predict function on my mixed models

二次信任 提交于 2019-12-07 06:09:31
问题 I’m having a bit of a struggle trying to use the lme4 predict function on my mixed models. When making predications I want to be able to set some of my explanatory variables to a specified level but average across others. Here’s some made up data that is a simplified, nonsense version of my original dataset: a <- data.frame( TLR4=factor(rep(1:3, each=4, times=4)), repro.state=factor(rep(c("a","j"),each=6,times=8)), month=factor(rep(1:2,each=8,times=6)), sex=factor(rep(1:2, each=4, times=12)),

Use Predict on data.table with Linear Regression

一笑奈何 提交于 2019-12-07 05:19:41
问题 Regrad to this Post, I have created an example to play with linear regression on data.table package as follows: ## rm(list=ls()) # anti-social library(data.table) set.seed(1011) DT = data.table(group=c("b","b","b","a","a","a"), v1=rnorm(6),v2=rnorm(6), y=rnorm(6)) setkey(DT, group) ans <- DT[,as.list(coef(lm(y~v1+v2))), by = group] return, group (Intercept) v1 v2 1: a 1.374942 -2.151953 -1.355995 2: b -2.292529 3.029726 -9.894993 I am able to obtain the coefficients of the lm function. My

Doing linear prediction with R: How to access the predicted parameter(s)?

可紊 提交于 2019-12-06 13:30:42
I am new to R and I am trying to do linear prediction. Here is some simple data: test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991)) Say if I want to predict the value for year=12 . This is what I am doing (experimenting with different commands): lma=lm(test.frame$value~test.frame$year) # let's get a linear fit summary(lma) # let's see some parameters attributes(lma) # let's see what parameters we can call lma$coefficients # I get the intercept and gradient predict(lm(test.frame$value~test.frame$year)) newyear <- 12 # new value for year predict.lm(lma, newyear) # predicted

How to use predict with multinom() with intercept in R?

早过忘川 提交于 2019-12-06 13:22:46
I have run the multinom() function in R, but when I try to predict on a new sample, it keeps giving an error. this is the code: library(nnet) dta=data.frame(replicate(10,runif(10))) names(dta)=c('y',paste0('x',1:9)) res4 <- multinom(y ~ as.matrix(dta[2:10]) , data=dta) #make new data to predict nd<-0.1*dta[1,2:10] pred<-predict(res4, newdata=nd) and this is the error: Error in predict.multinom(res4, newdata = nd) : NAs are not allowed in subscripted assignments I think it has to do with the intercept being included in the analysis, but not in the new prediction input. I tried to set it

Predictional Logic in Programming?

泪湿孤枕 提交于 2019-12-06 12:41:32
问题 I was thinking about how in the probably distant future many people think that we wont rely on physical input (i.e. keyboard) as much because the technology that reads brain waves (which already exists to some extent) will be available. Kinda scares me....anyway, I while I was daydreaming about this, the idea came to me that: what if a programmer could implement logic in their code to accurately predict the users intentions and then carry out the intended operation with no need for human