lm

convert string back into object in r [closed]

南楼画角 提交于 2020-01-15 15:56:12
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . In R, I get the content of a binary file as a string (because of design issues, I can't access the file directly). This file was originally an lm model. How do I convert that string back into the lm model? Thanks 回答1: I'm assuming you used base::dput() according to the following example (based on

How to use division in lm

自闭症网瘾萝莉.ら 提交于 2020-01-14 08:15:22
问题 I would like to use lm to predict y by a/b (the quotient of a by b) when I do lm(y~a/b) I get a and b interactions, how can I do ? 回答1: lm(y~I(a/b)) This is covered in ?formula . 来源: https://stackoverflow.com/questions/21587784/how-to-use-division-in-lm

How to use division in lm

牧云@^-^@ 提交于 2020-01-14 08:15:07
问题 I would like to use lm to predict y by a/b (the quotient of a by b) when I do lm(y~a/b) I get a and b interactions, how can I do ? 回答1: lm(y~I(a/b)) This is covered in ?formula . 来源: https://stackoverflow.com/questions/21587784/how-to-use-division-in-lm

How to fit predefined offsets to models containing categorical variables in R

雨燕双飞 提交于 2020-01-14 05:30:11
问题 Using the following data: http://pastebin.com/4wiFrsNg I am wondering how to fit a predefined offset to the raw relationship of another model i.e. how to fit the estimates from Model A, thus: ModelA<-lm(Dependent1~Explanatory) to model B thus: ModelB<-lm(Dependent2~Explanatory) Where the explanatory variable is either the variable "Categorical" in my dataset, or the variable "Continuous". I got a useful answer related to a similar question on CV: https://stats.stackexchange.com/questions

How do regression models deal with the factor variables?

喜夏-厌秋 提交于 2020-01-13 19:35:10
问题 Suppose I have a data with a factor and response variable. My questions: How linear regression and mixed effect models work with the factor variables? If I have a separate model for each level of the factor variable (m3 and m4) , how does that differ with models m1 and m2 ? Which one is the best model/approach? As an example I use Orthodont data in nlme package. library(nlme) data = Orthodont data2 <- subset(data, Sex=="Male") data3 <- subset(data, Sex=="Female") m1 <- lm (distance ~ age +

Linear model singular because of large integer datetime in R?

前提是你 提交于 2020-01-11 12:09:11
问题 Simple regression of random normal on date fails, but identical data with small integers instead of dates works as expected. # Example dataset with 100 observations at 2 second intervals. set.seed(1) df <- data.frame(x=as.POSIXct("2017-03-14 09:00:00") + seq(0, 199, 2), y=rnorm(100)) #> head(df) # x y # 1 2017-03-14 09:00:00 -0.6264538 # 2 2017-03-14 09:00:02 0.1836433 # 3 2017-03-14 09:00:04 -0.8356286 # Simple regression model. m <- lm(y ~ x, data=df) The slope is missing due to

warning when calculating predicted values

懵懂的女人 提交于 2020-01-11 02:27:08
问题 working with a data frame x Date Val 1/1/2012 7 2/1/2012 9 3/1/2012 20 4/1/2012 24 5/1/2012 50 a <- seq(as.Date(tail(x, 1)$Date), by="month", length=5) a <- data.frame(a) x.lm <- lm(x$Val ~ x$Date) x.pre<-predict(x.lm, newdata=a) I am getting this erro: Warning message: 'newdata' had 5 rows but variable(s) found have 29 rows what am I doing wrong? here is the dput output: dput(x) structure(list(Date = structure(c(14610, 14641, 14669, 14700, 14730, 14761, 14791, 14822, 14853, 14883, 14914,

Constrained least squares

百般思念 提交于 2020-01-10 19:59:33
问题 I am fitting a simple regression in R on gas usage per capita. The regression formulas looks like: gas_b <- lm(log(gasq_pop) ~ log(gasp) + log(pcincome) + log(pn) + log(pd) + log(ps) + log(years), data=gas) summary(gas_b) I want to include a linear constraint that the beta coefficients of log(pn)+log(pd)+log(ps)=1 (sum to one). Is there a simple way of implementing this (possibly in the lm function) in R without having to use constrOptim() function? 回答1: Modify your regression as follows: gas

R: multiple linear regression model and prediction model

会有一股神秘感。 提交于 2020-01-09 12:04:33
问题 Starting from a linear model1 = lm(temp~alt+sdist) i need to develop a prediction model, where new data will come in hand and predictions about temp will be made. I have tried doing something like this: model2 = predict.lm(model1, newdata=newdataset) However, I am not sure this is the right way. What I would like to know here is, if this is the right way to go in order to make prediction about temp . Also I am a bit confused when it comes to the newdataset . Which values should be filled in

R: multiple linear regression model and prediction model

℡╲_俬逩灬. 提交于 2020-01-09 12:04:09
问题 Starting from a linear model1 = lm(temp~alt+sdist) i need to develop a prediction model, where new data will come in hand and predictions about temp will be made. I have tried doing something like this: model2 = predict.lm(model1, newdata=newdataset) However, I am not sure this is the right way. What I would like to know here is, if this is the right way to go in order to make prediction about temp . Also I am a bit confused when it comes to the newdataset . Which values should be filled in