开发者

Error when using mshapiro.test: "U[] is not a matrix with number of columns (sample size) between 3 and 5000"

I am trying to perform a multivariate test for normality on some density data from five sites, using mshapiro.test from the mvnormtest package. Each site is a column, and densities are below. It is 5 columns and 5 rows, with the top row as the header (site names). Here is how I loaded my data:

datafilename="/Users/megsiesiple/Documents/Lisa/lisadensities.csv"
data.nc5=read.csv(datafilename,header=T)
attach(data.nc5)` 

The data look like this:

       B07      B08      B09      B10        M  
1 72571.43 17714.29  3142.86 22571.43  8000.00
2 44571.43 46857.14 49142.86 16857.14  7142.86
3 54571.43 44000.00 26571.43  6571.43 17714.29
4 57714.29 38857.14 32571.43  2000.00  5428.57

When I call mshapiro.test() for data.nc5 I get this message: Error in mshapiro.test(data.nc5) : U[] is not a matrix with number of column开发者_StackOverflow社区s (sample size) between 3 and 5000

I know that to perform a Shapiro-Wilk test using mshapiro.test(), the data has to be in a numeric matrix, with a number of columns between 3 and 5000. However, even when I make the .csv a matrix with only numbers (i.e., when I omit the Site names), I still get the error. Do I need to set up the matrix differently? Has anyone else had this problem? Thanks!


You need to transpose the data in a matrix, so that your variables are in rows, and observations in columns. The command will be :

M <- t(data.nc5[1:4,1:5])

mshapiro.test(M)

It works for me this way. The labels in the first row should be recognized during the import, so the data will start from row 1. Otherwise, there will be a "missing value" error.


If you read the numeric matrix into R via read.csv() using similar code to that you do show, it will be read in as a data frame, and that is not a matrix.

Try

mat <- data.matrix(data.nc5)
mshapiro.test(mat)

(Not tested as you don't give a reproducible example and it is late-ish in my time zone now ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜