0% found this document useful (0 votes)
7 views5 pages

Practice Regression1

Biological statistics practice (regression analysis 1)

Uploaded by

ne9roswan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Practice Regression1

Biological statistics practice (regression analysis 1)

Uploaded by

ne9roswan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Regression 1 practice

Is there evidence of a relationship between height and mass for a


random sample of APES 2024 honours students?
90

80

70
mass

60

50

40
1.5 1.6 1.7 1.8 1.9
height

1
## # A tibble: 10 x 4
## ‘height[1:10]‘ ‘mass[1:10]‘ ‘height[11:20]‘ ‘mass[11:20]‘
## <dbl> <dbl> <dbl> <dbl>
## 1 1.72 67 1.75 64
## 2 1.66 66 1.55 65
## 3 1.59 67 1.61 75
## 4 1.5 42 1.65 70
## 5 1.78 83 1.61 55.4
## 6 1.71 52 1.67 84
## 7 1.57 61 1.53 52
## 8 1.74 76 1.66 76
## 9 1.73 63 1.59 64
## 10 1.93 71.1 1.93 90

Summary statistics
## # A tibble: 1 x 5
## Count AvHeight SDHeight AvWeight SDWeight
## <int> <dbl> <dbl> <dbl> <dbl>
## 1 20 1.67 0.117 67.2 11.7

1. Calculate β1 and β0 . You can use the short-cuts:

n n n
!2
2 1 X
Xi2
X X
(Xi − X̄) = − Xi
i=1 i=1 n i=1

n n n n
! !
X X 1 X X
(Xi − X̄)(Yi − Ȳ ) = Xi Yi − Xi Yi
i=1 i=1 n i=1 i=1

2. Calculate fits and residuals.

3. Calculate SSE/R, df, MSE/R = σ̂ 2 , RMSE/R = σ̂

4. Calculate SE(βˆ1 ) and SE(βˆ0 ).

5. Calculate t-statistics for each parameter.

6. Conclusion, scope of inference.

2
1. Calculate β̂1 and β̂0 .

n
1
(Xi − X̄)2 = 57.1214 − 1137.03842 = 0.26948
X

i=1 20

n
X 1
(Xi − X̄)(Yi − Ȳ ) = 2289.782 − (33.72)(1348) = 17.054
i=1 20

17.054
βˆ1 = = 63.28
0.26948

βˆ0 = 67.4 − (63.28)(1.686) = −39.2982

2. Calculate fits and residuals.

## # A tibble: 20 x 4
## X Y Fit Res
## <dbl> <dbl> <dbl> <dbl>
## 1 1.72 67 70.0 -2.98
## 2 1.66 66 66.3 -0.320
## 3 1.59 67 62.0 4.96
## 4 1.5 42 56.5 -14.5
## 5 1.78 83 73.6 9.35
## 6 1.71 52 69.4 -17.4
## 7 1.57 61 60.8 0.177
## 8 1.74 76 71.2 4.79
## 9 1.73 63 70.6 -7.60
## 10 1.93 71.1 82.8 -11.7
## 11 1.75 64 71.8 -7.82
## 12 1.55 65 59.6 5.40
## 13 1.61 75 63.3 11.7
## 14 1.65 70 65.7 4.29
## 15 1.61 55.4 63.3 -7.87
## 16 1.67 84 66.9 17.1
## 17 1.53 52 58.4 -6.38
## 18 1.66 76 66.3 9.68
## 19 1.59 64 62.0 1.96
## 20 1.93 90 82.8 7.19

3
3. Calculate SSE/R, df, MSE/R = σ̂ 2 , RMSE/R = σ̂

n
res2i = 1895.16
X
SSE =
i=1

df = n − 2 = 20 − 2 = 18

M SE = 1895.16/18 = 105.2867


RM SE = 105.2867 = 10.26093

4. Calculate SE(βˆ1 ) and SE(βˆ0 ).

s
1
SE(β1 ) = 10.26093 = 19.76621; df = 37
(20 − 1)(0.1190931)2
v
1 (1.686)2
u
u
SE(β0 ) = 10.26093t + = 33.40472; df = 18
20 (20 − 1)(0.1190931)2

5. Calculate t-statistics for each parameter.

βˆ1 : t = 63.28484/19.76621 = 3.201668; df = 18

βˆ0 : t = −39.29825/33.40472 = −1.1764; df = 18

6. There is strong evidence of a relationship between mass and height for the APES
honours 2024 stats class (slope: two-sided t18 = 3.2; p = 0.004).

Scope of inference.

4
R to make life easier (yes, R can do that sometimes)

library(Sleuth3)
library(tidyverse)

# load data set for analysis


studentData <- read_csv(file = 'StudentData2024.csv')

# fit linear regression


# compare your calculations to those in the model output
model1 <- lm(mass ~ height, data = studentData)
summary(model1)

# create a table with X, Y, fits and residuals


tibble(
X = height,
Y = mass,
Fit = predict(model1),
Res = residuals(model1)
)

# calculate SSR/E, df, MSR/E and RMSR/E from regression output


model1.res <- model1$residuals # or
model1.res <- resid(model1)
SSR <- sum(model1.resˆ2)
df <- model1$df.residual
MSR <- SSR/df
RMSR <- sqrt(MSR) # this value should be the same as 'Residual standard error'
# in the regression output

You might also like