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?
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 )