shapiro: Shapiro Wilk's test

Description Usage Arguments Author(s) Examples

View source: R/shapiro.R

Description

This function is implemented in the unique function for univariate statistical analysis 'univariate'. Performs Shapiro Wilk's test for normality on the dataset according to the class definition provided in the second column of the file. For details see 'univariate'.

Usage

1

Arguments

file

a connection or a character string giving the name of the file containing the variables (matrix columns) to test.

Author(s)

Edoardo Gaude, Dimitrios Spiliotopoulos, Francesca Chignola, Silvia Mari, Andrea Spitaleri and Michela Ghitti

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## The function is currently defined as
function (file) 
{
    pwdfile = paste(getwd(), "/Univariate/DataTable.csv", sep = "")
    file = pwdfile
    x <- read.csv(file, sep = ",", header = TRUE)
    x.x = x[, 3:ncol(x)]
    rownames(x.x) = x[, 2]
    k = matrix(x[, 1], ncol = 1)
    x.n = cbind(k, x.x)
    sorted = x.n[order(x.n[, 1]), ]
    g = c()
    for (i in 1:nrow(sorted)) {
        if (any(g == sorted[i, 1])) {
            g = g
        }
        else {
            g = matrix(c(g, sorted[i, 1]), ncol = 1)
        }
    }
    dirout.r = paste(getwd(), "/Univariate/Groups", sep = "")
    dir.create(dirout.r)
    dirout.s = paste(getwd(), "/Univariate/Shapiro_Tests", sep = "")
    dir.create(dirout.s)
    for (i in 1:nrow(g)) {
        vuota <- c()
        fin = matrix(rep(NA, ncol(sorted)), nrow = 1)
        for (j in 1:nrow(sorted)) {
            if (sorted[j, 1] == i) {
                vuota <- matrix(sorted[j, ], nrow = 1)
                rownames(vuota) = rownames(sorted)[j]
                fin = rbind(fin, vuota)
            }
        }
        nam = paste("r", i, sep = ".")
        n = matrix(fin[-1, ], ncol = ncol(sorted))
        n.x = matrix(n[, -1], ncol = ncol(sorted) - 1)
        lastcol = ncol(sorted)
        n.x = n.x[, -lastcol]
        colnames(n.x) = colnames(x.x)
        name = as.matrix(assign(nam, n.x))
        shapname = paste("shapiro", i, sep = ".")
        shapiro = matrix(rep(NA, ncol(n.x)))
        for (q in 1:ncol(name)) {
            notAlist = c()
            notAlist = matrix(unlist(name[, q]))
            shapiro[q, ] = shapiro.test(notAlist)$p.value
            assign(shapname, shapiro)
        }
        outputfile = paste("r.", i, ".csv", sep = "")
        write.csv(name, paste(dirout.r, outputfile, sep = "/"))
        outshapiro = paste("ShapiroTest.", i, ".csv", sep = "")
        shapiro[is.na(shapiro)] = 1
        write.csv(shapiro, paste(dirout.s, outshapiro, sep = "/"))
    }
  }

muma documentation built on May 30, 2017, 1:13 a.m.

Search within the muma package
Search all R packages, documentation and source code