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: Hours of practice per week
  • Response variable: Free-throw percentage
  • Statistical tools: Scatterplots, Pearson correlation, and simple linear regression
  • Important: This dataset is simulated for demonstrating 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.

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

The example data

We create a reproducible dataset to demonstrate the methods. The simulated values are designed to show a plausible positive trend with individual 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, mean = 0, sd = 7),
      1
    )
  )
)

head(basketball, 8)
##      player practice_hours free_throw_pct
## 1 Player 01            7.6           73.0
## 2 Player 02            2.5           67.5
## 3 Player 03            1.0           66.9
## 4 Player 04            9.3           83.5
## 5 Player 05            7.8           67.9
## 6 Player 06            5.8           77.4
## 7 Player 07            8.3           70.0
## 8 Player 08           11.8           97.4

These rows are fictional examples. The random seed makes the simulated dataset reproducible when the document is knitted.

Visual 1: practice and free throws

How to read it: Each point represents one simulated player. The fitted line summarizes the average linear trend; the shaded band shows uncertainty around the estimated mean 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\) ranges from \(-1\) to \(1\)

A value near \(1\) indicates a strong positive linear association. A value near \(-1\) indicates a strong negative linear association. A value near \(0\) indicates 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

Interpret the printed result after knitting: State the sign and approximate strength of the association shown by your output. Do not describe the relationship as causal.

Visual 2: compare practice groups

The boxplots compare the distribution of free-throw percentages in the two practice groups. Look at their medians, spread, and overlap. Grouping is a descriptive aid; it discards some information compared with analyzing 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 slope is

\[ b_1 = \frac{ \sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y}) }{ \sum_{i=1}^{n}(x_i-\bar{x})^2 }, \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 in this model. It does not prove that adding an hour causes that change.

Fit and interpret the model

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
coef(fit)
##    (Intercept) practice_hours 
##      61.743075       2.296871

Use the output to report:

  • Slope: Estimated change in free-throw percentage points per additional practice hour.
  • Intercept: Predicted percentage at zero practice hours. This may be an extrapolation because the simulated practice hours start above zero.
  • \(R^2\): Proportion of the sample variation in the response accounted for by this linear model.

Interactive view: explore three dimensions

The interactive Plotly chart adds a third variable: the simulated player’s free-throw attempts. Hover over points to inspect the player, practice hours, percentage, and attempts.

Explore: Does the relationship between practice and free-throw percentage look similar across players with different numbers of attempts? Remember that attempts are simulated too.

What did we learn?

  • Correlation summarizes the direction and strength of a linear association.
  • A scatterplot helps reveal the pattern, spread, and unusual observations.
  • Regression estimates a linear trend and summarizes how the response changes with the predictor.
  • The plots and numerical results should tell a consistent story, but correlation alone does not show cause and effect.
  • Because these observations are simulated, the findings demonstrate the methods—not a conclusion about real basketball players.

Conclusion to personalize: After knitting, use the actual R output to complete this statement:

“In this simulated sample, practice hours and free-throw percentage showed a [positive/negative/weak] linear association (\(r =\) [insert value]). The fitted slope was [insert value] percentage points per additional practice hour. These results are illustrative and do not establish causation.”

Reproducibility and sources

  • Data: Simulated in this document using set.seed(301); no external player dataset was used.
  • Software: R, ggplot2, dplyr, plotly, and knitr.
  • Methods: Pearson sample correlation and ordinary least-squares simple linear regression.
  • Reproducibility: Knit the document in a fresh R session and confirm that all plots render.
  • Interactive chart: Verify that the Plotly widget works on the published RPubs page.
  • Author: Sedona Adams.