Reputation: 335
I'm creating the design matrix that I multiply by a vector of estimates to obtain the final vector. Then, I'd list the values of the final vector by the factor, seeing both levels.
An example below:
# create dataset
df <- data.frame(var_one = as.factor(sample(c(100,200), 10, replace = T)), var_two = rnorm(10))
# fit model
fit <- lm(var_two~var_one, data = df)
# create design matrix
mat <- model.matrix(~ var_one, data = df)
# extract coeffiecients
coef <- fit$coefficients
# product
vec <- mat %*% coef
# list values by var one
unique(vec)
What I get is:
[,1]
1 0.5106247
3 0.3279885
But instead I'd like to have:
Var_one==100 0.5106247
Var_one==200 0.3279885
Upvotes: 0
Views: 17