Multivariate test in R

38 Views Asked by At

I am trying to run a multivariate model where I have 3 dvs and no iv in r using the lm function

I have this sas code:

    proc glm; 
    model a b c = / nouni; 
    repeated shoe / mean nouni; 
    run;

I am trying to replicate this in r and I have been having a lot of troubles. I specified the model this way: mod <- lm(cbind(a, b, c) ~ 1, data = track_wi), and then used tried to use the Manova function in the "car" package, for example: Manova(mod). The problem is the output, the df r is outputting seem wrong. I have 6 participants and 3 variables, so df denominator should be 4, and df numerator should be 2. But R is outputting 3 for both df numerator and df denominator

below is a sample data

track <- data.frame(ID = c(1, 2, 3, 4, 5, 6), 
                     a = c(20, 12, 18, 16, 21, 15),
                     b = c(18, 14, 19, 13, 19, 15),
                     c = c(10, 8, 14, 10, 15, 11))

This is my sas's output that I am trying to replicate in r: sas's output using proc glm

1

There are 1 best solutions below

3
Cesar Saucedo On

You can use the manova function, this will give you an output similar to what you would get from the proc glm procedure in SAS.

    #Manova
library(car)
track <- data.frame(ID = c(1, 2, 3, 4, 5, 6), 
                     a = c(20, 12, 18, 16, 21, 15),
                     b = c(18, 14, 19, 13, 19, 15),
                     c = c(10, 8, 14, 10, 15, 11))

mod <- manova(cbind(a, b, c) ~ 1, data = track)
summary(mod)

Or if you're looking to specifically extract the degrees of freedom from the model, you can do it as follows:

    # Extrae los grados de libertad
df_residual <- mod$stats$Residual[1] 

residuales df_total <- mod$stats$Totals[1]
df_residual df_total