Multiple linear regression: $ operator is invalid for atomic vectors

Hi community,

I am very new to RStudio so this is probably a very basic questions, but I get the error " $ operator is invalid for atomic vectors" when I want to get the plots of a multiple linear regression with General Happiness as my dependent variable and Job Satisfaction as the independent variable. I want to use Age and Gender as the controll variables. I only get 2 plots, but there should be 2 (Cook's Distance and fitted vs. residuals).

This is the data I use:
https://www.file-upload.net/download-13706401/ESS1-8e01.sav.html
This is my code so far:

library(haven)
mult.reg <-lm(ESS$happy ~ ESS$stfjb + ESS$agea + ESS$gndr)
plot(mult.reg)

Can someone help me out and tell me what the problem is and what's to be done to solve it?

labels imported from the sav file are causing the issue, try with this

mult.reg <-lm(happy ~ stfjb + agea + gndr, data = zap_labels(ESS))
plot(mult.reg)

awesome, thank you so much, Andres! :slight_smile:

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

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