Anova table: $ operator is invalid for atomic vectors

I am very new to R studio, may be this is a very basic question but I am really not understanding what's going on. Can someone please explain. Thanks in advance.

So, I am trying to fit a model and then use anova type 2. But while doing this, I am getting an error: Error: $ operator is invalid for atomic vectors

My code is:
data <- read.table("breadwrapper.txt",header=TRUE)
y <- data$Y
x1 <- data$X1
x2 <- data$X2
x3 <- data$X3

ModelA <- lm(y ~ x1+x2+x3, data = data)
summary(ModelA)
ModelA$coefficients
anova(ModelA, type=2)

I am using a local data file. What should I do further?

Hello SnehalD,

Happy to help you if you can share data/make this into a reprex for us :slight_smile: . See here: FAQ: How to do a minimal reproducible example ( reprex ) for beginners

I don't understand why you would pull out variables from the data df , and use them in the formula to lm, but still pass the lm the original data which has the columns in question.

The following is more succinct, consistent and by renaming data avoids possibilities of confusions. data is after all, already the name of a base function used for accessing data...

my_data <- read.table("breadwrapper.txt",header=TRUE)
ModelA <- lm(Y ~ X1+X2+X3, data = my_data )
1 Like

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.