Error in eval(predvars, data, env) : object 'Mass' not found


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 in eval(predvars, data, env) : object 'Mass' not found

Male_Display_Data_Set.lm=lm(Tcell~Mass, data = Male_Display_Data_Set)
prd_c=predict(Male_Display_Data_Set.lm, newdata = data.frame(Tcell = newx), interval = c("confidence"), type = c("response"), level = 0.95)

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:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. 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

Here is the dataset:

Mass Tcell
3.33 0.252
4.62 0.263
5.43 0.251
5.73 0.251
6.12 0.183
6.29 0.213
6.45 0.332
6.51 0.203
6.65 0.252
6.75 0.342
6.81 0.471
7.56 0.431
7.83 0.312
8.02 0.304
8.06 0.37
8.18 0.381
9.08 0.43
9.15 0.43
9.35 0.213
9.42 0.508
9.95 0.411

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

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

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.