Help with Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases

Hello,

I am trying to run a linear regression on my data
code in Rstudio
data_long$Field<-as.factor(data_long$Field)
data_long$Annual.Unemployment<-as.interger(data_long$Annual.Unemployment)
unempNPS.BASIC.lm <- lm(Values ~ Annual.Unemployment+Field=="Natural and Physical Sciences", data = data_long)
summ(unempNPS.BASIC.lm)

this is the sample dataset
|Field |Annual Unemployment |Values|
|Natural and Physical Sciences |6.15| |18085|
|Natural and Physical Sciences |5.98| |17750|
|Natural and Physical Sciences |6.4| |17965|
|Natural and Physical Sciences |5.75| |18220|
|Natural and Physical Sciences |5.35| |18120|
|Natural and Physical Sciences |5.35| |18150|
|Natural and Physical Sciences |5.1| |17895|
|Natural and Physical Sciences |4.73| |17385|
|Natural and Physical Sciences |4.28| |17700|
|Natural and Physical Sciences |4.05| |17595|

The Value~Annual.Unemployment excutes correctly but when i add the moderator Field=="Natural and Physical Sciences" i get an error "Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases"
Can anyone Help!

I have a couple of questions.
What are you trying to do by writing

Values ~ Annual.Unemployment+Field=="Natural and Physical Sciences"

Do you intend to use only the rows of data_long where Field is equal to "Natural and Physical Sciences"?
Do you really want to Annual.Unemployment and integer? This would throw away a lot of information. The unemployment in your example is in the range 4 to 6, so making everything an integer drastically bins the values.

I want to test what happens to the Enrolment(Values) when national Annual Unemployment rate increases, then i want to add the moderator for each Subject area(field) to test what happens to enrolment in a specific field when unemployment increases

I think you want

unempNPS.BASIC.lm <- lm(Values ~ Annual.Unemployment, 
     subset = data_long$Field=="Natural and Physical Sciences", data = data_long)

I do not see any benefit to changing Annual.Unemployment into an integer. Might you mean to convert it from characters to numbers with with as.numeric()?

I have converted it to a Numeric, ran your code and was successful, does the result below answer my question related to Natural and Physical Science that is Values~Annual.Unemployment + Field=="Natural and Physical Sciences")?
MODEL FIT:
F(1,8) = 4.70, p = 0.06
R² = 0.37
Adj. R² = 0.29

Standard errors: OLS

                            Est.     S.E.   t val.      p

(Intercept) 16764.25 522.51 32.08 0.00
Annual.Unemployment 211.19 97.37 2.17 0.06

This now seems like you are asking me to answer a homework problem for you. In any case, the fit does provide information about how Values changes with Annual.Unemployment when Field is held constant. How to interpret it depends on what p value you are willing to accept, which should have been determined before doing the analysis, and that should take into account how many different levels of Field you plan to investigate. If you are making many comparisons, it is more likely that one of them will produce a small p value.

I am new to R and research so, i was trying to find a solution to my problem. i have run all of the fields and have something to work with, appreaciate your help.
thanks

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.