October 18, 2026

The question

Research question: In this illustrative basketball dataset, is more weekly practice associated with a higher free-throw percentage?

  • Explanatory variable (\(x\)): Hours of practice per week
  • Response variable (\(y\)): Free-throw percentage
  • Statistical tools: Scatterplots, Pearson correlation, hypothesis test, and simple linear regression
  • Story we will tell: Question → Statistical idea → Mathematics → R → Visualization → Insight

Important: This dataset is simulated (n = 40 players) to demonstrate the analysis. It is not real player data.

Why correlation?

Correlation describes the direction and strength of a linear relationship between two numerical variables.

  • Positive: Larger values of one variable tend to accompany larger values of the other.
  • Negative: Larger values of one tend to accompany smaller values of the other.
  • Near zero: Little linear association, although a curved relationship may still exist.

Regression goes one step further: it fits a line so we can describe how much the response changes, on average, for each extra unit of the predictor.

Correlation does not establish causation. Talent, coaching, fatigue, and motivation could affect both practice and performance.

The example data

We create a reproducible dataset to demonstrate the methods. Free-throw percentage is built to rise with practice, plus random player-to-player variation.

n <- 40

basketball <- data.frame(
  player = paste("Player", sprintf("%02d", 1:n)),
  practice_hours = round(runif(n, min = 1, max = 12), 1)
)

basketball$free_throw_pct <- pmin(98, pmax(45,
  round(58 + 2.8 * basketball$practice_hours + rnorm(n, 0, 7), 1)))
Player Practice (hrs/wk) Free throws (%)
Player 01 7.6 73.0
Player 02 2.5 67.5
Player 03 1.0 66.9
Player 04 9.3 83.5
Player 05 7.8 67.9
Player 06 5.8 77.4

The random seed (set.seed(301)) makes the data reproducible every time the document is knitted.

Visual 1: practice and free throws

What it shows: Each point is one simulated player. The points drift upward from left to right, so players who practice more tend to shoot a higher percentage. The shaded band shows uncertainty about the average trend.

Mathematics 1: Pearson correlation

Pearson’s sample correlation measures the direction and strength of a linear association.

\[ r = \frac{ \sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y}) }{ \sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2}\, \sqrt{\sum_{i=1}^{n}(y_i-\bar{y})^2} } \]

  • \(x_i\): practice hours for player \(i\); \(y_i\): free-throw percentage for player \(i\)
  • \(\bar{x}\) and \(\bar{y}\): sample means
  • \(r\) always lies between \(-1\) and \(1\)

A value near \(1\) means a strong positive linear association, near \(-1\) a strong negative one, and near \(0\) little linear association.

Calculate the correlation in R

correlation <- cor(
  basketball$practice_hours,
  basketball$free_throw_pct,
  method = "pearson"
)

round(correlation, 3)
## [1] 0.703

Interpretation: The sample correlation is \(r =\) 0.703, a strong positive linear association. Practice hours alone account for about 49.5% of the variation in free-throw percentage (\(r^2\)). This describes association only, not cause and effect.

Hypothesis test for the correlation

Is the correlation we saw bigger than what random chance alone would produce?

\[ H_0:\ \rho = 0 \qquad \text{versus} \qquad H_a:\ \rho \neq 0 \]

\[ t = \frac{r\sqrt{n-2}}{\sqrt{1-r^2}} \quad \text{with } n-2 \text{ degrees of freedom} \]

cor.test(basketball$practice_hours, basketball$free_throw_pct)
## 
##  Pearson's product-moment correlation
## 
## data:  basketball$practice_hours and basketball$free_throw_pct
## t = 6.0996, df = 38, p-value = 4.157e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5017923 0.8324707
## sample estimates:
##       cor 
## 0.7033577

Conclusion: \(t =\) 6.1, p-value < 0.001. A 95% confidence interval for the population correlation \(\rho\) is (0.502, 0.832). Because the p-value is below 0.05, we reject H0: the data provide strong evidence of a linear association in this simulated population.

Visual 2: compare practice groups

What it shows: The lower-practice group averages 73.2% and the higher-practice group averages 82%, a gap of about 8.8 percentage points. Grouping is a descriptive aid; it discards information compared with using practice hours continuously.

Mathematics 2: simple linear regression

A simple linear regression models the average response as a straight line:

\[ \hat{y} = b_0 + b_1x \]

The least-squares estimates minimize \(\sum_{i=1}^{n}(y_i-\hat{y}_i)^2\) and are

\[ b_1 = \frac{ \sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y}) }{ \sum_{i=1}^{n}(x_i-\bar{x})^2 } = r\,\frac{s_y}{s_x}, \qquad b_0 = \bar{y} - b_1\bar{x} \]

Here \(b_1\) estimates the average change in free-throw percentage points associated with one additional weekly practice hour. It does not prove that adding an hour causes that change.

Fit the model in R

fit <- lm(free_throw_pct ~ practice_hours, data = basketball)

summary(fit)
## 
## Call:
## lm(formula = free_throw_pct ~ practice_hours, data = basketball)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.7587  -3.5860  -0.2196   3.4820  11.8163 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     61.7431     2.7703   22.29  < 2e-16 ***
## practice_hours   2.2969     0.3766    6.10 4.16e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.11 on 38 degrees of freedom
## Multiple R-squared:  0.4947, Adjusted R-squared:  0.4814 
## F-statistic:  37.2 on 1 and 38 DF,  p-value: 4.157e-07

Interpreting the model

  • Fitted line: \(\hat{y} =\) 61.74 \(+\) 2.3 \(x\)
  • Slope: Each additional practice hour per week is associated with about 2.3 more percentage points in free-throw percentage. A 95% confidence interval for the true slope is (1.53, 3.06).
  • Intercept: Predicted percentage at zero practice hours (61.7%). This is an extrapolation because the simulated hours start near 1.
  • \(R^2\) = 0.495: the line accounts for about 49.5% of the sample variation in free-throw percentage.
  • Typical miss: The residual standard error is 6.11 percentage points.

Mathematics 3: inference for the slope

To test whether practice has any linear relationship with performance:

\[ H_0:\ \beta_1 = 0 \qquad \text{versus} \qquad H_a:\ \beta_1 \neq 0 \]

\[ t = \frac{b_1}{SE(b_1)}, \qquad SE(b_1) = \frac{s}{\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2}}, \qquad b_1 \pm t^{*}_{n-2}\, SE(b_1) \]

Result: \(t =\) 6.1 with p-value < 0.001. This matches the correlation test above, because in simple regression testing \(\beta_1 = 0\) is equivalent to testing \(\rho = 0\).

Visual 3: checking the model (residuals)

What it shows: The residuals scatter around zero with no strong curve or funnel shape, so a straight-line model is reasonable for these data.

Interactive view: explore three dimensions

The interactive Plotly chart adds a third variable: the simulated player’s free-throw attempts. Drag to rotate and hover to inspect each player.

Explore: Along the practice axis, free-throw percentage climbs for both groups. Attempts were simulated independently of performance, so the points spread evenly up the attempts axis with no extra pattern.

What did we learn?

  • Answer to our question: In this simulated sample, practice hours and free-throw percentage show a strong positive linear association (\(r =\) 0.703; p-value < 0.001).
  • Size of the effect: The fitted slope is 2.3 percentage points per additional weekly practice hour (95% CI: 1.53 to 3.06), and the model explains about 49.5% of the variation.
  • Group view: The higher-practice group averaged about 8.8 points higher than the lower-practice group.
  • Model check: Residuals show no clear pattern, so the linear model is a reasonable summary.
  • Caution: Correlation alone does not show cause and effect, and these data are simulated, so the results demonstrate the methods and not a conclusion about real players.

Reproducibility and sources

  • Data: Simulated in this document using set.seed(301); no external dataset was used.
  • Software: R with ggplot2, dplyr, plotly, and knitr.
  • Methods: Pearson sample correlation, correlation and slope hypothesis tests, and ordinary least-squares simple linear regression.
  • Reproducibility: Knit in a fresh R session; all numbers in the text are computed from the data by inline R code.
  • Interactive chart: Verify that the Plotly widget works on the published RPubs page.
  • Author: Sedona Adams.