# [R] P values

Greg Snow 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.

Notice that:

> (1-0.7335039)*2
 0.5329922

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
Intermountain Healthcare
greg.snow at imail.org
801.408.8111

> -----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
>
>
> 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
> ve
> gone wrong?  cheers
> --
> View this message in context: http://r.789695.n4.nabble.com/P-values-
> tp2131646p2131646.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help