[R] Problems with Shapiro Wilk's test of normality.

Fredrik Karlsson dargosch at gmail.com
Wed Nov 9 16:33:38 CET 2005


Hi,

I am trying to create a table with information from Shapiro Wilk's
test of normality.
However, it fails due to lack of sample size, it says, but the way I
see it, this is not a problem.
(See the table of sample sizes (almost) at the bottom).

Applying a different function using a similar ftable call is not a
problem (See the bottom table).

This is R 2.1.0 on Linux (Gentoo).

/Fredrik

> shapiro.p.value <- function(x){
+   if(length(! is.na(x)) > 3 & length(! is.na(x)) < 5000 ){
+     p <- shapiro.test(x)$p.value
+     return(p)
+    }else{
+      return(NA)
+      }
+ }
>
> distribution.table.fun <- function(x,na.rm=T,digits=1){
+
+   if(length(! is.na(x)) > 3 & length(! is.na(x)) < 5000){
+    # shapTest <- shapiro.test(x)
+    # W <- shapTest$statistic
+     W <- "W"
+   }
+
+
+
+   shap <- shapiro.p.value(x)
+   stars <- ''
+   premark <- ''
+   postmark <- ''
+   if(length(x) < 10){
+       premark <- '\\textit{'
+       postmark <- '}'
+   }
+
+   #skapa stjärnor
+   if(! is.na(shap)){
+     if( shap <= 0.001 ){
+       stars <- '***'
+     }else{
+       if( shap <= 0.01 ){
+         stars <- '**'
+       }else{
+         if( shap <= 0.05 ){
+           stars <- '*'
+         }
+
+       }
+
+     }
+
+     outstr <- paste(premark,'W=',W,',p=',shap,postmark,stars,sep="")
+   }
+   else{
+     outstr <-  ""
+   }
+
+
+   return(outstr)
+
+ }
>
> ftable(tapply(aspvotwork$ampratio,list(Place=aspvotwork$Place,Age=aspvotwork$agemF,voicetype=aspvotwork$Type),FUN="length" ))
               voicetype Voiced Voiceless unaspirated Voiceless aspirated
Place  Age
Velar  18 - 24               44                    41                  34
       24 - 30               70                    81                  71
       30 - 36               59                    66                  64
       36 - 42               25                    27                  22
       42 - 48               22                    23                  23
       48 - 54               12                     9                   7
Dental 18 - 24               48                    61                  54
       24 - 30               82                   101                  89
       30 - 36               57                    82                  72
       36 - 42               19                    31                  34
       42 - 48               25                    33                  31
       48 - 54               10                    12                  14
Labial 18 - 24               74                   141                  84
       24 - 30              142                   264                 162
       30 - 36              124                   213                 148
       36 - 42               50                    91                  50
       42 - 48               49                    82                  64
       48 - 54               17                    26                  16
> ftable(tapply(aspvotwork$ampratio,list(Place=aspvotwork$Place,Age=aspvotwork$agemF,voicetype=aspvotwork$Type),FUN="distribution.table.fun",digits=4))
Error in shapiro.test(x) : sample size must be between 3 and 5000
>
  > ftable(tapply(aspvotwork$ampratio,list(Place=aspvotwork$Place,Age=aspvotwork$agemF,voicetype=aspvotwork$Type),FUN="mean",digits=4,na.rm=TRUE
))
               voicetype    Voiced Voiceless unaspirated Voiceless aspirated
Place  Age
Velar  18 - 24           0.4816810             0.4461307           0.4513994
       24 - 30           0.5289028             0.4778686           0.4888445
       30 - 36           0.5452949             0.5208633           0.4756369
       36 - 42           0.5631310             0.4697789           0.4709779
       42 - 48           0.4968318             0.4174068           0.4088855
       48 - 54           0.3057712             0.4483639           0.4561953
Dental 18 - 24           0.4058078             0.4596251           0.4091731
       24 - 30           0.4609731             0.4502778           0.4483340
       30 - 36           0.5095430             0.4726149           0.4315419
       36 - 42           0.4935719             0.4687774           0.4528758
       42 - 48           0.4344465             0.4220429           0.4362018
       48 - 54           0.3697664             0.4338549           0.4897856
Labial 18 - 24           0.4327926             0.4879985           0.4503917
       24 - 30           0.5309634             0.4839031           0.5927699
       30 - 36           0.4094516             0.4444757           0.3964693
       36 - 42           0.5010130             0.4855550           0.4540598
       42 - 48           0.4949510             0.4329442           0.3935921
       48 - 54           0.5217893             0.5124186           0.5011346
>




More information about the R-help mailing list