Hi,
I am getting the below error. Tried many searches for hours, not able to fix it. Can anyone help me in understanding why I am getting this error?
Error:
Error in eval(predvars, data, env) : object 'Mass' not found
Code:
install.packages("investr")
library(investr)
Male_Display_Data_Set
Male_Display_Data_Set.lm=lm(Tcell~Mass, data = Male_Display_Data_Set)
newx=Male_Display_Data_Set$Tcell
newx=sort(newx)
prd_c=predict(Male_Display_Data_Set.lm, newdata = data.frame(Tcell = newx), interval = c("confidence"), type = c("response"), level = 0.95)
prd_c
Can you please share a small part of the data set in a copy-paste friendly format?
In case you don't know how to do it, there are many options, which include:
If you have stored the data set in some R object, dput function is very handy.
In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link .
the simple answer is that there is no Mass
column/variable in the Male_Display_Data_Set
It does seem the Mass
column is missing, as @nirgrahamuk suspected, but it looks like it's missing from the data passed as the value of the newdata =
argument in predict()
:
predict(Male_Display_Data_Set.lm, newdata = data.frame(Tcell = newx), ...
I think the error is telling you that predict()
needs the same predictor variables as used in the original formula, which is Mass
.
In your formula you have set x = Mass, but with this code you are selecting Tcell as new x, that contradiction is the source of your problem
system
Closed
April 8, 2020, 1:46pm
7
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.