liveBook · Manning

P-value

As explained in Statistics Every Programmer Needs

A p-value is the probability, under a specified null hypothesis, of obtaining a result at least as extreme as the observed result.

A p-value measures how surprising a test result would be if a specified null hypothesis were true: it is the probability of a result at least as extreme as the observed one under that assumption. Compare it with a chosen significance level, often 5%. A smaller p-value supports rejecting the null; a larger one calls for failing to reject it, not declaring it true. The 5% cutoff is a convention, not a property of the data. section 4.2.3 section 12.5.1

Read the p-value alongside the question its test asks:

  • In linear regression, the F-statistic’s p-value tests the model-wide null that every predictor coefficient is zero. Coefficient p-values address individual predictors; R² answers a different question about explained variation. section 4.2.3 section 4.3
  • In logistic regression, the log-likelihood ratio (LLR) p-value tests the model as a whole. Individual predictor p-values can point to variables worth reconsidering, but multicollinearity and classification performance also matter. section 5.2.2 section 5.3
  • In a chi-square goodness-of-fit test, the p-value helps assess whether observed category counts differ significantly from counts expected under a proposed distribution. section 12.5.1

Check leading digits against Benford’s law

For world-population leading digits, set the null hypothesis to conformity with a Benford distribution. Compute expected counts, then run `stats.chisquare(bf_populations.Counts, bf_populations.Expected_Counts)`. The result is a statistic of about 7.193 and a p-value of 0.516. Because 0.516 exceeds 0.05, fail to reject the null: these counts do not provide statistically significant evidence against that distribution. section 12.5.1

Separate model and predictor decisions

A `statsmodels` logistic regression predicts raisin variety from morphological measurements. Its model-wide LLR p-value is reported as 0, yet two individual predictors have p-values of 0.473 and 0.822. The model-wide result does not make every predictor significant. A reduced model drops insignificant predictors and considers multicollinearity before its fit and classification results are evaluated. section 5.2.2 section 5.2.3

>>> import scipy.stats as stats
>>> x2 = stats.chisquare(bf_populations.Counts, 
>>>                      bf_populations.Expected_Counts)
>>> print(x2)
Power_divergenceResult(statistic=7.192526063677557, pvalue=0.5160103482305225)

The SciPy call shows the observed and expected counts passed to `stats.chisquare()` and the statistic and p-value returned together. section 12.5.1

Significance is only one part of evaluation. Check regression assumptions and fit measures, and assess a classifier’s prediction metrics before using its result to make a decision. section 4.3 section 5.3

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the conditional probability, works through threshold decisions, and demonstrates a chi-square computation without deriving a general p-value formula.
Examples
Uses runner-time regression, raisin-variety classification, and a SciPy test of world-population leading digits against Benford’s law.
What it assumes
Builds on basic probability, samples, and hypothesis tests while showing the Python calls used to obtain results.
What you can do after
Apply it via SciPy and statsmodels to interpret significance while checking fit, assumptions, and predictive performance separately.
How it connects
Links hypothesis testing to F-tests, logistic regression likelihood-ratio tests, chi-square goodness-of-fit, regression assumptions, and classification metrics.

Also explained in

Compare how 5 books explain p-value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.