Minimum Working example:
library(Matrix)
library(psych)
library(MASS)
set.seed(10)
N0 <- 1
n0 <- 5
p0 <- 2
q0 <- 4
n <- n0*q0
m2 <- matrix(c(0, 0), p0, 1)
s2 <- matrix(c(1, 0, 0, 1), p0, p0)
mardia_lst <- list()
for (i in 1:q0) {
for (j in 1:N0) {
Dat[, , j, i] <- mvrnorm(n=n0, m2, s2)
mardia_lst[[i]] <- mardia(Dat[, , j, i], plot=FALSE)
}
}
str(mardia_lst)
I want to store the multivariate skewness coefficients in mardia_lst
.
When I run the program it only gives the multivariate skewness of one multivariate data set and other three are omitted. I want a vector that shows the multivariate skewness coefficients of all four.
The problem was that you were overwriting mardi_lst[[I]]
with each iteration of j
. You can make each [[I]]
element of mardi_lst
itself a list and then you will save all the values like this:
library(Matrix)
library(psych)
library(MASS)
set.seed(10)
N0 <- 1
n0 <- 5
p0 <- 2
q0 <- 4
n <- n0*q0
m2 <- matrix(c(0,0),p0,1)
s2 <- matrix(c(1,0,0,1),p0,p0)
Dat <- array(dim=c(n0, length(m2), N0, q0))
mardia_lst <- vector(mode="list", length=q0)
for (i in 1:q0) {
mardia_lst[[i]] <- vector(mode="list", length=N0)
for (j in 1:N0) {
Dat[,,j,i] <- MASS::mvrnorm(n = n0, m2, s2)
mardia_lst[[i]][[j]] <- mardia(Dat[,,j,i], plot = FALSE)
}
}
mardia_lst
#> [[1]]
#> [[1]][[1]]
#> Call: mardia(x = Dat[, , j, i], plot = FALSE)
#>
#> Mardia tests of multivariate skew and kurtosis
#> Use describe(x) the to get univariate tests
#> n.obs = 5 num.vars = 2
#> b1p = 0.78 skew = 0.65 with probability <= 0.96
#> small sample skew = 1.55 with probability <= 0.82
#> b2p = 3.08 kurtosis = -1.38 with probability <= 0.17
#>
#> [[2]]
#> [[2]][[1]]
#> Call: mardia(x = Dat[, , j, i], plot = FALSE)
#>
#> Mardia tests of multivariate skew and kurtosis
#> Use describe(x) the to get univariate tests
#> n.obs = 5 num.vars = 2
#> b1p = 1.17 skew = 0.97 with probability <= 0.91
#> small sample skew = 2.34 with probability <= 0.67
#> b2p = 3.56 kurtosis = -1.24 with probability <= 0.21
#>
#> [[3]]
#> [[3]][[1]]
#> Call: mardia(x = Dat[, , j, i], plot = FALSE)
#>
#> Mardia tests of multivariate skew and kurtosis
#> Use describe(x) the to get univariate tests
#> n.obs = 5 num.vars = 2
#> b1p = 0.17 skew = 0.14 with probability <= 1
#> small sample skew = 0.34 with probability <= 0.99
#> b2p = 2.95 kurtosis = -1.41 with probability <= 0.16
#>
#> [[4]]
#> [[4]][[1]]
#> Call: mardia(x = Dat[, , j, i], plot = FALSE)
#>
#> Mardia tests of multivariate skew and kurtosis
#> Use describe(x) the to get univariate tests
#> n.obs = 5 num.vars = 2
#> b1p = 1.12 skew = 0.93 with probability <= 0.92
#> small sample skew = 2.23 with probability <= 0.69
#> b2p = 3.35 kurtosis = -1.3 with probability <= 0.19
Created on 2024-05-10 with reprex v2.0.2