"number of items to replace is not a multiple of replacement length" error with MANOVA.RM
SilviaMorgenstern opened this issue · 8 comments
I am trying to run a repeated measure MANOVA in R, with two within subjects independent variables and three dependent variables.
I converted the df in long format and I am now trying to run the analysis using the RM.MANOVA package. There are no missing values in the data.
head(dflong)
ID IV1 IV2 DV1 DV2 DV3
1 1 BuiltSec OffSec 2.716667 2.504202 2.403361
2 2 BuiltSec OffSec 3.158333 3.134454 3.369748
3 3 BuiltSec OffSec 3.008333 2.361345 2.983193
4 4 BuiltSec OffSec 2.683333 1.865546 2.689076
5 5 BuiltSec OffSec 2.791667 2.798319 2.747899
6 6 BuiltSec OffSec 3.033333 2.680672 3.142857
> str(dflong)
'data.frame': 264 obs. of 6 variables:
$ ID: Factor w/ 44 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
$ IV1: Factor w/ 3 levels "BuiltSec","IntervSec",..: 1 1 1 1 1 1 1 1 1 1 ...
$ IV2: Factor w/ 2 levels "NoffSec","OffSec": 2 2 2 2 2 2 2 2 2 2 ...
$ DV1: num 2.72 3.16 3.01 2.68 2.79 ...
$ DV2: num 2.5 3.13 2.36 1.87 2.8 ...
$ DV3: num 2.4 3.37 2.98 2.69 2.75 ...
model.rm <- RM(cbind(dv1, dv2, dv3) ~ IV1*IV2, data = dflong, subject = "ID", no.subf=2)
I get
Error in WTS_out[i, ] <- round(results$WTS, dec) : number of items to
replace is not a multiple of replacement length"
It seems like there is some issue with the WTS index calculation, but I do not understand how to solve it. Can you help to understand why I get this error and if I am doing anything wrong?
If you want to analyze several dependent variables simultaneously, you need to use the multRM-function. RM can only handle one outcome, i.e. something like RM(dv1 ~ IV1*IV2, ....).
Hope that helps, let me know if it doesn't!
Best,
Sarah
Thank you for your answer. Sorry, in what package do I find the multRM function? I tried to run the command as
model.rm <- multRM(cbind(dv1, dv2, dv3) ~ IV1*IV2, data = dflong, subject = "ID", no.subf=2)
(the same as before, just substituting "RM" with "multRM") but apparently I cannot find this function.
Oh, sorry, I forgot to mention. multRM is not in the CRAN version yet (will be in a couple of days, though). Otherwise you need to install MANOVA.RM from Github, multRM is already available there.
So if I will update my R packages in the next week I will have this new function available? This is pretty amazing! Thank you very much!!!
Should be on CRAN today :-)
I just downloaded and... it works!!! Thank you very much!!!
Hi guys. I am running a repeated measures MANOVA with two within-subjects IVs (cond, time), and 6 IVs (dv1, dv2, dv3, dv4, dv5, dv6) using MultRM(); a copy of my script is below:
library(R.matlab)
f <- readMat('mydata.mat')
df <- as.data.frame(f)
names(df)[names(df) == "cc.L.task.Attention.1"] <- "subID"
names(df)[names(df) == "cc.L.task.Attention.2"] <- "cond"
names(df)[names(df) == "cc.L.task.Attention.3"] <- "time"
names(df)[names(df) == "cc.L.task.Attention.4"] <- "dv1"
names(df)[names(df) == "cc.L.task.Attention.5"] <- "dv2"
names(df)[names(df) == "cc.L.task.Attention.6"] <- "dv3"
names(df)[names(df) == "cc.L.task.Attention.7"] <- "dv4"
names(df)[names(df) == "cc.L.task.Attention.8"] <- "dv5"
names(df)[names(df) == "cc.L.task.Attention.9"] <- "dv6"
df$DV <- as.matrix(df[, 4:9])
library(MANOVA.RM)
m <- multRM( DV ~ cond*time, data = df, subject = "subID", within = c("cond", "time"), iter = 1000)
summary(m)
I got a warning that said
Warning message:
In multRM(DV ~ cond * time, data = df, subject = "subID", within = c("cond", :
The covariance matrix is singular. The WTS provides no valid test statistic!
mydata.mat.zip
Singular covariance matrix seems to suggest some collinearity or some degree of interdependence across DVs or perhaps across measures, but I couldn't figure out what exactly was the issue.
Any suggestions/comments will be much appreciated (attached is the mat file for the data in case it's needed for pondering).
Thanks in advance.
DH
Hi,
you can still use the MATS with its resampling-based p-value, though, since it does not require the covariance matrix to be non-singular.
Best, Sarah