1

I want to get mancova for two level group and I have two variables but after I enter data and variable I get an error and I don't know how to fix it.

library(jmv)
Data=read.csv(file.choose())
  Data
  attach(Data)
  names(Data)
y1 = mancova(
    data = Data,
    deps = vars(postTotalcorrecttrial, postmemoryspan),
    covs = vars(preTotalcorrecttrail, preMemoryspan),
    factors = group,
    multivar ="wilks")

Error in summary.manova(model, test = "Pillai") : residuals have rank 1 < 2

> Data4=read.csv(file.choose())
>   Data4
   group ` preTotalcorrecttrail` preMemoryspan `postTotalcorrecttrial `postmemoryspan
1      2                    7           4.5                    12            7.0
2      2                    5           3.5                     6            4.0
3      2                    4           3.0                     7            4.5
4      2                   10           6.0                     9            5.5
5      2                    4           3.0                     6            4.0
6      2                    5           3.5                     8            5.0
7      2                    8           5.0                     7            4.5
8      2                    5           3.5                     6            4.0
9      2                    5           3.5                     6            4.0
10     2                    3           2.5                     5            3.5
11     2                    7           4.5                     6            4.0
12     2                    4           3.0                     6            4.0
13     2                    3           2.5                     5            3.5
14     2                    4           3.0                     5            3.5
15     3                    4           3.0                     5            3.5
16     3                    3           2.5                     4            3.0
17     3                    5           3.5                     6            4.0
18     3                    8           5.0                     8            5.0
19     3                    9           5.5                     7            4.5
20     3                    5           3.5                     4            3.0
21     3                    6           4.0                     5            3.5
22     3                    4           3.0                     5            3.5
23     3                    4           3.0                     4            3.0
24     3                    6           4.0                     6            4.0
25     3                    3           2.5                     5            3.5
26     3                    4           3.0                     5            3.5
27     3                    4           3.0                     5            3.5
  • 1
    It's nearly impossible to help with questions of the form "Why do I get error XYZ" without you providing reproducible sample data and code to reproduce the error. I suggest reviewing [how to ask](https://stackoverflow.com/help/how-to-ask) questions, and what you can (and should) do in order to provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Then please edit your question accordingly. – Maurits Evers Feb 20 '20 at 01:50
  • PS. Always *explicitly* include any non-base R packages you've been using. For example, where does `mancova` come from? Is it package `jmv`? – Maurits Evers Feb 20 '20 at 02:14
  • @MauritsEvers you can help me? plaese now . I done change for my question – Mahboube_Mohebbi Feb 20 '20 at 06:11

1 Answers1

1

You get that error because your variables are perfectly correlated.

Your data which I got from the example:

structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L), .Label = c("2", "3"), class = "factor"), preTotalcorrecttrail = c(7L, 
5L, 4L, 10L, 4L, 5L, 8L, 5L, 5L, 3L, 7L, 4L, 3L, 4L, 4L, 3L, 
5L, 8L, 9L, 5L, 6L, 4L, 4L, 6L, 3L, 4L, 4L), preMemoryspan = c(4.5, 
3.5, 3, 6, 3, 3.5, 5, 3.5, 3.5, 2.5, 4.5, 3, 2.5, 3, 3, 2.5, 
3.5, 5, 5.5, 3.5, 4, 3, 3, 4, 2.5, 3, 3), postTotalcorrecttrial = c(12L, 
6L, 7L, 9L, 6L, 8L, 7L, 6L, 6L, 5L, 6L, 6L, 5L, 5L, 5L, 4L, 6L, 
8L, 7L, 4L, 5L, 5L, 4L, 6L, 5L, 5L, 5L), postmemoryspan = c(7, 
4, 4.5, 5.5, 4, 5, 4.5, 4, 4, 3.5, 4, 4, 3.5, 3.5, 3.5, 3, 4, 
5, 4.5, 3, 3.5, 3.5, 3, 4, 3.5, 3.5, 3.5)), row.names = c(NA, 
-27L), class = "data.frame")

We check the correlation:

cor(Data[,-1])
                      preTotalcorrecttrail preMemoryspan
preTotalcorrecttrail             1.0000000     1.0000000
preMemoryspan                    1.0000000     1.0000000
postTotalcorrecttrial            0.6469337     0.6469337
postmemoryspan                   0.6469337     0.6469337
                      postTotalcorrecttrial postmemoryspan
preTotalcorrecttrail              0.6469337      0.6469337
preMemoryspan                     0.6469337      0.6469337
postTotalcorrecttrial             1.0000000      1.0000000
postmemoryspan                    1.0000000      1.0000000

From what I can see, postmemoryspan = 1 + 0.5*postTotalcorrecttrial . There's no point in doing a mancova. You just do a linear regression.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72