0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9These z-scores are
-1.28 -0.84 -0.52 -0.25 -0.00 0.25 0.52 0.84 1.28
> qnorm(seq(0.1, 0.9, 0.1)) [1] -1.2815516 -0.8416212 -0.5244005 -0.2533471 0.0000000 [6] 0.2533471 0.5244005 0.8416212 1.2815516
| Obs: | 1 | 2 | 3 | 4 | 5 |
| x: | 1 | 2 | 3 | 4 | 5 |
| y: | 1 | 3 | 2 | 5 | 4 |
> x <- 1:5 > x [1] 1 2 3 4 5 > y <- c(1, 3, 2, 5, 4) > y [1] 1 3 2 5 4 > cor(x, y) [1] 0.8
> setwd("c:/workspace")
> getwd( )
[1] "c:/workspace"
> data_frame <- read.csv("laundry-detergent.txt")
> r <- data_frame$Rating
> p <- data_frame$Price
> r
[1] 61 55 50 46 35 32 59 52 48 46 34 29 56 51
[15] 4 8 45 33 26 55 50 48 36 32 26
> p
[1] 17 30 9 13 8 5 22 23 16 13 12 14 22 11
[15] 15 17 7 11 16 15 18 8 6 13
> model <- lm(p ~ r) > model Call: lm(formula = p ~ r) Coefficients: (Intercept) r -2.1443 0.3727The regression equation for predicting r from p is:
> plot(r, p, xlab="Price", ylab="Rating", + main="Laundry Detergent Dataset") > pred <- predict(model) > lines(r, pred, col="red")
> # Correlation between p and r > cor(p, r) [1] 0.6707535 > # R-squared value > cor(p, r)^2 [1] 0.4499103
> pred <- predict(model) > lines(r, pred, col="red") > res <- resid(model) > plot(pred, res, xlab="Predicted Values", ylab="Residuals", + main="Laundry Detergent Residual Plot") > lines(pred, rep(0, length(pred)), col="red")
> qqnorm(res, main="Normal Plot of Residuals") > qqline(res, col="red")
> setwd("c:/workspace")
> getwd( )
[1] "c:/workspace"
> bearsDf <- read.csv("bears-2024-roster.txt")
> h <- (bearsDf$HtFt + bearsDf$HtIn / 12) * 0.3048
> h
[1] 1.8796 1.9050 1.8542 1.9304 1.8542 1.8288 1.9558
[8] 1.8542 1.8034 1.9304 1.9050 1.9304 1.8288 1.8288
[15] 1.9304 1.9050 1.9812 1.9050 1.9558 1.8796 1.9304
[22] 1.8288 1.9050 1.9304 1.8034 1.8796 1.7526 1.8034
[29] 1.7780 1.9558 1.9812 1.8288 1.8288 1.8542 1.9558
[36] 1.8034 1.8288 1.9304 1.9812 1.8796 1.8288 1.8796
[43] 1.8288 1.8542 1.9304 1.8288 1.8034 1.8288 1.9304
[50] 2.0066 1.9558 1.8796 1.8796 1.7272 1.9050 1.7780
[57] 1.8542 1.9050 1.8288 1.8288 1.8034 1.9812 1.7272
[64] 1.8796 1.9304 1.7526 1.9558
> w <- bearsDf$WtLb * 0.4536
> w
[1] 95.7096 96.6168 101.6064 136.9872 141.0696 105.6888
[7] 151.0488 90.7200 96.1632 108.8640 141.0696 139.7088
[13] 92.9880 90.7200 132.4512 136.0800 143.3376 143.3376
[19] 141.5232 134.2656 113.4000 109.7712 111.1320 99.3384
[25] 90.7200 108.8640 96.1632 90.7200 91.6272 145.6056
[31] 100.6992 88.9056 94.3488 102.0600 140.6160 86.1840
[37] 90.7200 121.5648 117.9360 136.0800 102.0600 109.7712
[43] 95.2560 90.7200 139.2552 104.7816 95.2560 88.4520
[49] 136.0800 150.5952 114.7608 91.6272 106.1424 79.3800
[55] 102.5136 83.9160 114.7608 129.2760 93.8952 92.5344
[61] 81.6480 118.8432 97.5240 95.2560 127.0080 81.6480
[67] 151.0488
Find the simple linear regression equation for predicting weight in kilos from height in meters.> model <- lm(w ~ h) > model Call: lm(formula = w ~ h) Coefficients: (Intercept) h -331.5 236.0The linear regression line for predicting weight from height is
plot(h, w, xlab="Height (meters)", ylab="Weight (kilos)", + main="Plot of Weight vs. Height for 2024 Bears") > pred <- predict(model) > lines(h, pred, col="red")
> res <- resid(model) > plot(h, res, xlab="Height (meters)", ylab="Residuals", + main="Residual Plot 2024 Bears") > lines(h, rep(0, length(h)), col="red")
> qqnorm(res, main="Normal Plot of Residuals 2024 Bears") > qqline(res, col="red")

