10. Calculating P Values — R Tutorial
Maybe your like
10.1. Calculating a Single p Value From a Normal Distribution¶
We look at the steps necessary to calculate the p value for a particular test. In the interest of simplicity we only look at a two sided test, and we focus on one example. Here we want to show that the mean is not close to a fixed value, a.
\[ \begin{align}\begin{aligned}H_o: \mu_x & = & a,\\H_a: \mu_x & \neq & a,\end{aligned}\end{align} \]The p value is calculated for a particular sample mean. Here we assume that we obtained a sample mean, x and want to find its p value. It is the probability that we would obtain a given sample mean that is greater than the absolute value of its Z-score or less than the negative of the absolute value of its Z-score.
For the special case of a normal distribution we also need the standard deviation. We will assume that we are given the standard deviation and call it s. The calculation for the p value can be done in several of ways. We will look at two ways here. The first way is to convert the sample means to their associated Z-score. The other way is to simply specify the standard deviation and let the computer do the conversion. At first glance it may seem like a no brainer, and we should just use the second method. Unfortunately, when using the t-distribution we need to convert to the t-score, so it is a good idea to know both ways.
We first look at how to calculate the p value using the Z-score. The Z-score is found by assuming that the null hypothesis is true, subtracting the assumed mean, and dividing by the theoretical standard deviation. Once the Z-score is found the probability that the value could be less the Z-score is found using the pnorm command.
This is not enough to get the p value. If the Z-score that is found is positive then we need to take one minus the associated probability. Also, for a two sided test we need to multiply the result by two. Here we avoid these issues and insure that the Z-score is negative by taking the negative of the absolute value.
We now look at a specific example. In the example below we will use a value of a of 5, a standard deviation of 2, and a sample size of 20. We then find the p value for a sample mean of 7:
> a <- 5 > s <- 2 > n <- 20 > xbar <- 7 > z <- (xbar-a)/(s/sqrt(n)) > z [1] 4.472136 > 2*pnorm(-abs(z)) [1] 7.744216e-06We now look at the same problem only specifying the mean and standard deviation within the pnorm command. Note that for this case we cannot so easily force the use of the left tail. Since the sample mean is more than the assumed mean we have to take two times one minus the probability:
> a <- 5 > s <- 2 > n <- 20 > xbar <- 7 > 2*(1-pnorm(xbar,mean=a,sd=s/sqrt(20))) [1] 7.744216e-06Tag » What Is P And R
-
P And R Measures - Wikipedia
-
P & R - Urban Dictionary
-
P&R - What Does P&R Stand For? The Free Dictionary
-
Were P And R Once The Same Letter?
-
Hypothesis Testing - What Does P-value Mean In R? - Cross Validated
-
Park And Ride (P+R) - City Of Amsterdam
-
R Handbook: P-values And R-square Values For Models
-
R To P - VassarStats
-
How Is P Related To R ? | Logical Reasoning Questions - Toppr
-
What Is P / R Equal To?
-
T-test And Interpreting P Values Using R Programming - YouTube
-
How Do I Get P-values And Critical Values From R? - RPubs
-
What Is The Relationship Between R-squared And P-value In A ...