[R] P values
Greg.Snow at imail.org
Thu May 6 18:26:41 CEST 2010
We cannot be certain without knowing what the data in cw3_data.txt is, but here are some likely issues.
Which implies that the wolfram value comes from taking the smaller tail area and multiplying by 2, which is a common way to compute p-values for 2-sided tests. You took the absolute value implying 2-sided, but then you use the wrong tail and do not multiply by 2 (or compare to alpha/2 which is my preference, but I'm in a small minority there).
There is a z.test function in the TeachingDemos package that you could have used as another check of your calculations, or to do this with a single command.
Note also that read.table returns a data frame, it appears in your case that it had a single column and everything worked out in your calculations, but if you tried this again with a different file with multiple columns then the results could be confusing, it is best to make sure you understand how your data is stored and work with the correct types of data directly.
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of level
> Sent: Wednesday, May 05, 2010 2:41 PM
> To: r-help at r-project.org
> Subject: [R] P values
> How do u calculated p values for a z test..
> so far i ve done this
> A = read.table("cw3_data.txt")
> xbar = mean(A)
> s = 1
> n = 20
> mu = 0
> z.test = (xbar-mu)/(s/sqrt(n))
> p.value = pnorm(abs(z.test))
> error = qnorm(0.99)*s/sqrt(n)
> left = xbar - error
> right = xbar + error
> and have got values off of it...but the values for p dont match up with
> other sites that i have used to check it agaisnt..such as wolfram alpha
> value i got was 0.7335039 when wolfram got 0.533.. any ideas where i
> gone wrong? cheers
> View this message in context: http://r.789695.n4.nabble.com/P-values-
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help