[R] mardia's test

Jiao Yang yj316 at gwu.edu
Sat Jun 16 22:50:08 CEST 2007


In the R code of Mardia's test, what does the line " x1 = x[x[, p] == i, -p]" mean?  Thanks a lot!

function (x) 
{
    p = dim(x)[2]
    f = p - 1
    clases = length(table(x[, p]))
    for (i in 1:clases) {
        x1 = x[x[, p] == i, -p]



        ndat = dim(x1)[1]
        mo3 = mo3(x1)
        mard1 = ndat * mo3/6
        cat("Mardia's test for class", i, "\n")
        cat("mard1=", mard1, "\n")
        p1 = 1 - pchisq(mard1, df = f * (f + 1) * (f + 2)/6)
        cat("pvalue for m3=", p1, "\n")
        mo4 = mo4(x1)
        mard2 = (mo4 - f * (f + 2))/sqrt(8 * f * (f + 2)/ndat)
        cat("mard2=", mard2, "\n")
        p2 = 2 * (1 - pnorm(abs(mard2)))
        cat("p-value for m4=", p2, "\n")
        if (p1 < 0.05 || p2 < 0.05) 
            cat("There is not statistical evidence for normality in class", 
                i, "\n")
        else cat("There is statistical evidence for normality", 
            "\n")
    }
}



More information about the R-help mailing list