I have a large amount of data which I break down into a collection of vectors of 100-125 values each. I would like to test the normality of the vectors and compare them. In the interactive mode I can test any one vector using the Shapiro-Wilk test or the Kolmogorov-Smirnov test. My problem is that when I try to write out the results to a file, the term output is a mixture of alpha characters along with the number value that I really want. How can I get it to write out just the p-values by themselves? Thank you very much for your time. Bruce Kindseth [[alternative HTML version deleted]]
On 2011-04-26 13:15, Bruce Kindseth wrote:> I have a large amount of data which I break down into a collection of > vectors of 100-125 values each. I would like to test the normality of the > vectors and compare them. In the interactive mode I can test any one vector > using the Shapiro-Wilk test or the Kolmogorov-Smirnov test. My problem is > that when I try to write out the results to a file, the term output is a > mixture of alpha characters along with the number value that I really want. > How can I get it to write out just the p-values by themselves?Try shapiro.test(rnorm(100))$p.value Put all your p.values into a vector and write that out. While you're at it, check ?str to see how handy the str() function is in identifying the pieces of an R object. Peter Ehlers> > Thank you very much for your time. > > Bruce Kindseth > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Tue, 2011-04-26 at 16:15 -0400, Bruce Kindseth wrote:> I have a large amount of data which I break down into a collection of > vectors of 100-125 values each. I would like to test the normality of the > vectors and compare them. In the interactive mode I can test any one vector > using the Shapiro-Wilk test or the Kolmogorov-Smirnov test. My problem is > that when I try to write out the results to a file, the term output is a > mixture of alpha characters along with the number value that I really want. > How can I get it to write out just the p-values by themselves?As seen below, the shapiro.test() output is a list of four components.> names(shapiro.test(rnorm(100, mean = 5, sd = 3)))[1] "statistic" "p.value" "method" "data.name" You can extract just the p-value with:> shapiro.test(rnorm(100, mean = 5, sd = 3))$p.value[1] 0.244 HTH, Jerome
Hi Bruce, One way is via apply() # some data set.seed(123) X <- matrix(rnorm(100), ncol = 5) X # tests t(apply(X, 2, function(x){ sw <- shapiro.test(x) c(sw$statistic, P = sw$p.value) })) See ?apply and ?str and ?shapiro.test for more information. HTH, Jorge On Tue, Apr 26, 2011 at 4:15 PM, Bruce Kindseth <> wrote:> I have a large amount of data which I break down into a collection of > vectors of 100-125 values each. I would like to test the normality of the > vectors and compare them. In the interactive mode I can test any one > vector > using the Shapiro-Wilk test or the Kolmogorov-Smirnov test. My problem is > that when I try to write out the results to a file, the term output is a > mixture of alpha characters along with the number value that I really want. > How can I get it to write out just the p-values by themselves? > > Thank you very much for your time. > > Bruce Kindseth > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]