187. Simple Linear Regression

𝑦=𝛽0+𝛽1𝑥1+𝜀
Example

Data

𝑥 (Hours Studied)𝑦 (Test Score)
12
23
35
44
56

Step 1: Calculate Means

𝑥̄=3𝑦̄=4

Step 2: Calculating Slope 𝛽1

𝛽1=𝑖=1𝑛(𝑥𝑖𝑥̄)(𝑦𝑖𝑦̄)𝑖=1𝑛(𝑥𝑖𝑥̄)2
  • The numerator
𝑖=1𝑛(𝑥𝑖𝑥̄)(𝑦𝑖𝑦̄)=9
  • The denominator
𝑖=1𝑛(𝑥𝑖𝑥̄)2=10
  • The slope 𝛽1 is
𝛽1=910=0.9

Step 3: Calculate Intercept 𝛽0

𝛽1=𝑦̄𝛽1𝑥̄=1.3

Step 4: Calculate p-Value

  • Calculate Standard Error of the Slope (𝑆𝐸𝛽1)
𝑆𝐸𝛽1=𝑛=1𝑛(𝑦𝑖𝑦̂𝑖)2(𝑛2)𝑖=1𝑛(𝑥𝑖𝑥̄)2
  • Calculate the Residual Sum of Squares (RSS)
𝑅𝑆𝑆=𝑖=1𝑛(𝑦𝑖𝑦̂𝑖)2
  • Calculate the t-statistic for the Slope
𝑡=𝛽1𝑆𝐸𝛽1
  • Determine Degrees of Freedom
df=𝑛2
  • Look up the p-value corresponding to 𝑡 with 3 degrees of freedom

Step 5: Calculate 𝑅2 (𝑅adj2)

𝑅2=SSregSStotal

SSreg (Regression Sum of Squares): sum of the squared differences between the predicted 𝑦̂ values and the mean of the observed 𝑦 values.

SSreg=𝑖=1𝑛(𝑦̂𝑖𝑦̄)2

SStotal (Total Sum of Squares): sum of the squared differences between the observed 𝑦 values and the mean of the observed 𝑦 values.

SStotal=𝑖=1𝑛(𝑦𝑖𝑦̄)2

Adjusting for the number of independent variables

𝑅adj2=1((1𝑅2)(𝑛1)𝑛𝑘1)
  • 𝑛: number of observations
  • 𝑘: number of independent variables