Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205399

How do I interpret my categorical coefficient in my mixed-effects linear model in R?

$
0
0

I would like to know how to interpret my coefficient 'Diet' in this multi-level model. The 'Diet' category is 1-4, and refers to what diet the chick is on. Time is in days, and weight is in grams. So the chicks all increase in weight over time, but at different rates due to different diets. 'Chick' is a chick's unique ID.

Using the code below you should get the MLE estimates/coefficients as intercept :23.018, Time : 8.443 and Diet: 2.979

I can see that as time increases 1 unit, weight increase by 8.443. However how can this be true for Diet, being a categorical variable, when '3' leads to more weight increase than '4'? (I know this from plotting the data, see code below).

Perhaps it is a modelling problem and I'm doing something wrong. Does the diet variable need to be text in nature, so R dummy codes it?

Info about the data is here if you need it: http://vincentarelbundock.github.io/Rdatasets/doc/datasets/ChickWeight.html

Thanks.

library(tidyverse)
library(lme4)
library(lmerTest)

chickdiet <- read_csv('http://vincentarelbundock.github.io/Rdatasets/csv/datasets/ChickWeight.csv')

chickm3 <- lmer(weight ~ Time + Diet + (Time | Chick), data = chickdiet)

summary(chickm3)

#from plotting the data with the code below I can see that the diet that increases the chicks' weight the most, in ascending order are 1, 2, 4, 3

ggplot(chickdiet, aes(x = Time, y = weight, colour = as.factor(Diet))) + geom_point() +
  stat_smooth(method = lm, se = F) + theme_minimal()

Viewing all articles
Browse latest Browse all 205399

Trending Articles