2025-04-07

What is a p-value Testing?

A p-value can be thought of as a value with a set threshold that helps determine if two things are different enough from one another.

  • The p-value is set on a scale of 0-1 where a threshold is set with values closer to 0 meaning a more confidence in different between parameters.
  • A common threshold for a p-value is 0.05 percent to limit false positives without requiring to intensive effort for lower thresholds.
  • p-value goes hand in hand with hypothesis testing to determine the rejection of a null hypothesis.
  • The equation used to calculate the p-value in a function we will use in futures slides can be seen as \(p=2×P(T>∣t∣)\)

Simple Example 1

This simple example will just show how to calculate the p-value on two means and plot a sample of data. we will use the means of the CO2 uptake of grass when it is chilled vs. non chilled as a example data set and use the t.test() function to find the p-value of them.

  • Note: Originally we would calculate the mean using the formula \(Mean = (\sum_{i=1}^{n} x_i)/n\) but in this case the t.test() function will do this for us.

First we will build our plot and calculate P value

# Build our plot with data

g <-  ggplot(data = CO2, aes(x = Treatment, y = uptake, color = uptake)) + 
  geom_point() +
  xlab("Plant Treatment Type") +
  ylab("CO2 Uptake Rate") +
  ggtitle("CO2 Uptake rates vs Treatment") +
  theme (
  panel.border = element_rect(colour = "lightblue", fill=NA, linewidth=5))

#Calculate our p-value and extract is specifically
 pvalue = t.test(uptake ~ Treatment, data = CO2)$p.value

Simple Example 1 Cont.

Now we can view the data and see the p-value

## p-value is  0.003106937

Simple Example 2

Now we can begin to interpret p-values in the context of our data. In this example lets once again plot a sample of data, find the p-value, and interpret in the context of hypothesis. For this example we will find the p-value of the mean between the uptake of different plant origins. We will also construct a null hypothese of there will be no difference in the mean of the uptake of plants from different origins

# Build our plot with data

g <-  ggplot(data = CO2, aes(x = Type, y = uptake, color = uptake)) + geom_point() +
 scale_color_gradient(low = "darkgreen", high = "green") +
 xlab("Plant Origin") +
  ylab("CO2 Uptake Rate") +
  ggtitle("CO2 Uptake rates vs Plant Origins")+
  theme (panel.border = element_rect(colour = "lightgreen", fill=NA, linewidth=5))

#Calculate our p-value and extract is specifically

 pvalue = t.test(uptake ~ Type, data = CO2)$p.value

Simple Example 2 Cont.

Now we can view the data and see the p-value

## p-value is  4.450881e-09

Now looking at this p-value, we can use the common threshold of 0.05 and see it is far below it.In this instance the null hypothesis would be rejected and we can clearly see the p-value falls well under the threshold.

Advanced Example

Now for this final data set we will take a specific sample of only chilled plants and find the mean of the uptake at 1000 conc and 95 conc. We will have the Null hypothesis of carbon dioxide concentrations have no effect on uptake rates. with the alternate being carbon dioxide concentrations have a effect on uptake rates.

Advanced Example Cont.

Now we can view the data sample and see the p-value

##   Plant   Type Treatment conc uptake
## 1   Qc1 Quebec   chilled   95   14.2
## 2   Qc1 Quebec   chilled 1000   38.7
## 3   Qc2 Quebec   chilled   95    9.3
## 4   Qc2 Quebec   chilled 1000   42.4
## 5   Qc3 Quebec   chilled   95   15.1
## 6   Qc3 Quebec   chilled 1000   41.4
## p-value is  0.01356318

Now analyzing the p-value we can see it is below our threshold of 0.05 and thus we can reject our null hypothesis that carbon dioxide concentrations do not affect uptake of chilled plants.