1
$\begingroup$

I believe this question is very simple, but I can't seem to google it right.

I have data on the efficiency o vehicles (Km/L) for several different routes, vehicles, models and several other categorical variables. Here some example data in R:

set.seed(1)
reprexData = data.frame(
  "vehicleEfficiency" = rnorm(20,mean=2.5,sd=0.6),
  "vehicleMake" = sample(c("Volvo","Volkswagen","Audi","Mercedes"),20,replace=T),
  "driverClass" = sample(c("A","B",20,replace=T)),
  "company" = sample(c("C1","C2"),20,replace=T),
  "route" = sample(c("X->B","X->A","Y->C"),20,replace=T)
)

I know that the routes are very different: some are uphill, some are downhill and others are flat. So I expect that the efficiency should change from route to route.

I want to test the influence of each other variable on the efficiency independently, while controlling for the different routes. Can I do something like this:

mod = lm(vehicleEfficiency ~ vehicleMake + driverClass + company + route,data=reprexData)
anova(mod)

And use the p-values from anova to determine significance? Am I already controlling for routes by including it in the model?

Or do I need to separate the data by route and test for significance on each route independently?

$\endgroup$
2
$\begingroup$

You should use a mixed effects model and include route as a random variable. This will allow you to test for an effect of vehicleMake, driverClass and company, while excluding the variation between routes.

You can do this in R if you load the lme4 package:

library(lme4)
mod <- lmer(vehicleEfficiency ~ vehicleMake + driverClass + company + (1|route),data=reprexData)
summary(mod)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.