228

  1. Consider a model for the long-term dining behavior of the students at College USA. It is found that 25% of the students who eat at the college’s Grease Dining Hall return to eat there again, wheras those who eat at Sweet Dining Hall have a 93% return rate. These are the only two dining halls available on campus, and assume that all students eat at one of these halls. Formulate a model to solve for the long-term percentage of students eating at each hall.

Based on the parameters of the problem

25% return rate at Grease, 75% at Sweet 93% return rate at Sweet, 7% at Grease

model <- function(Snaught, Gnaught)
{
  sweet <- Snaught
  grease <- Gnaught

  df <- data.frame(i=c(0), Sweet=c(sweet), Grease=c(grease))
  for(i in 1:100)
  {
    sweet1 <- 0.25 * grease + 0.07 * sweet
    grease1 <- 0.75 * grease + 0.93 * sweet
    sweet <- sweet1
    grease <- grease1
    df <- rbind(df, cbind(i=c(i), Sweet=sweet, Grease=grease))
  }
  return(df)
}

Snaught <- 50
Gnaught <- 50
df5050 <- model(Snaught, Gnaught)
knitr::kable(head(df5050,20))
i Sweet Grease
0 50.00000 50.00000
1 16.00000 84.00000
2 22.12000 77.88000
3 21.01840 78.98160
4 21.21669 78.78331
5 21.18100 78.81900
6 21.18742 78.81258
7 21.18626 78.81374
8 21.18647 78.81353
9 21.18643 78.81356
10 21.18644 78.81356
11 21.18644 78.81356
12 21.18644 78.81356
13 21.18644 78.81356
14 21.18644 78.81356
15 21.18644 78.81356
16 21.18644 78.81356
17 21.18644 78.81356
18 21.18644 78.81356
19 21.18644 78.81356

Steady state is reached after 10 iterations.

232

  1. Consider a stereo with CD player, FM-AM radio tuner, speakers (dual), and power amplifier (PA) componenets, as displayed with the reliabilities shown in Figure 6.11. Determine the system’s reliability. What assumptions are required in your model?
Figure 6.11

Figure 6.11

#Speakers are in parallel
speakers <- 0.99 + 0.99 - (0.99*0.99)
speakers
## [1] 0.9999
#radio and CD in parallel
radiocd <- 0.98 + 0.97 - (0.98*0.97)
radiocd
## [1] 0.9994
#PA is solo
PA <- 0.95

reliability <- PA * radiocd * speakers
reliability
## [1] 0.9493351

240

Use the basic linear model y = ax+b to fit the folowing data sets. Provide the model, provide the values of SSE, SSR, and \(R^2\), and provide a residual plot.

  1. For table 2.7, predict weight as function of height
Table 2.7

Table 2.7

height <- c(60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80)
weight <- c(132,136,141,145,150,155,160,165,170,175,180,185,190,195,201,206,212,218,223,229,234)
df <- data.frame(height, weight)

m <- nrow(df)

a <- (m * sum(df$height * df$weight) - sum(df$height) * sum(df$weight)) / 
  (m * sum(df$height^2) - sum(df$height)^2)

b <- (sum(df$height^2) * sum(df$weight) - sum(df$height * df$weight) * sum(df$height)) / 
  (m * sum(df$height^2) - sum(df$height)^2)

#linear regression model

#SSE
SSE <- sum((df$weight - (a * df$height + b))^2)
SSE
## [1] 24.6342
#SST
ybar <- mean(df$weight)
SST <- sum((df$weight - ybar)^2)
SST
## [1] 20338.95
#SSR
SSR <- SST - SSE
SSR
## [1] 20314.32
#Coefficient of determination
R2 <- 1 - (SSE / SST)
R2
## [1] 0.9987888
df$y_hat <- (a * df$height + b)
df$residual <- df$weight - df$y_hat
head(df)
##   height weight    y_hat    residual
## 1     60    132 129.6840  2.31601732
## 2     61    136 134.8203  1.17965368
## 3     62    141 139.9567  1.04329004
## 4     63    145 145.0931 -0.09307359
## 5     64    150 150.2294 -0.22943723
## 6     65    155 155.3658 -0.36580087