I'm trying to run a multivariate multiple regression in R, i.e. including multiple predictors and multiple outcome variables in the same linear regression model. Does anybody know how to pull out the coefficients and p-values for the relationship between each predictor and outcome pair in a multivariate multiple regression? I cannot seem to work out how to do that (I've been trying!).
Let me explain with an example dataset, if it helps:
#Create example dataset df <- data.frame(pid=factor(501), y1=numeric(501), y2=numeric(501), y3=numeric(501), y4=numeric(501), x1=factor(501), x2=factor(501), x3=factor(501), x4=numeric(501), x5=numeric(501)) df$pid <- seq(1,501, by=1) df$y1 <- seq(1,101, by=0.2) df$y2 <- seq(401,201, by=-0.4) df$y3 <- sqrt(rnorm(501, 7, 0.5))^3 df$x1 <- c(rep(c("sad","happy"), each=250), "sad") df$x2 <- c(rep(c("human","vehicle","animal"), each=167)) df$x3 <- c(rep(seq(1,10, by=0.1), each=5), seq(1,46, by=1)) df$x4 <- rnorm(501, 3, .24) df$x5 <- sqrt(rnorm(501, 23, 3.5))
I then create the model using this:
#Specify the regression model model <- lm(cbind(y1, y2, y3) ~ x1 + x2 + x3 + x4 + x5, data=df)
I can't simply use
summary(lm) as doing so runs separate regressions without accounting for familywise error, nor does it account for the dependent variables possibly being correlated.
Reiterating my question. Does anybody know how to pull output so I can work out the coefficient and p-values but doing so in the same model? For example, I want to work out the coefficients and p-values of:
x1, x2, x3, x4 and x5 on y1 x1 and x2 on y2 x1, x2, x3, x4 and x5 on y3 ... etc etc
I tried the
modelanova <- car::Anova(model) summary(modelanova)
However, I couldn't get it to break down to a particular outcome variable, it'd only produce coefficients overall (as if a composite outcome variable had been created)
Any ideas would be wonderful. I know I could run several univariate multiple regressions but I am particularly interested in running a single multivariate multiple regression.