Module 7. Assignment

> x <- c(16, 17, 13, 18, 12, 14, 19, 11, 11, 10) 
> y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
> model <- lm(y ~ x) 
> summary(model)

Call:
lm(formula = y ~ x)

Residuals:
    Min      1Q  Median      3Q     Max 
-11.435  -7.406  -4.608   6.681  16.834 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)   19.206     15.691   1.224   0.2558  
x              3.269      1.088   3.006   0.0169 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 10.48 on 8 degrees of freedom
Multiple R-squared:  0.5303,	Adjusted R-squared:  0.4716 
F-statistic: 9.033 on 1 and 8 DF,  p-value: 0.01693

Question 1

1.1: This is a linear relationship model. X is the predictor and Y is the response.
The model shows how the predictor will affect the response in a straight line.

1.2: Given the regression formula, Y = a + bX +e  
 Looking at the model, the row labeled Intercept the Estimate is 19.206,
 which means when x=0, y is about 19.206. (a)
 In the row labeled X, the Estimate is 3.206, which is the slope, so for every 1 
 increase in x, y increases by 3.269. (b)
    
        y = 19.206 + 3.269x

Question 2
      

> discharge <- c(3.600, 1.800, 3.333, 2.283, 4.533, 2.883) # Dataset for discharge
> waiting <- c(79, 54, 74, 62, 85, 55)    # Dataset for waiting
> visit <- data.frame(discharge, waiting) # Create dataframe to group the two
> model <- lm(discharge ~ waiting, data = visit) # Create linear model
> summary(model) # Summary of the model

Call:
lm(formula = discharge ~ waiting, data = visit)

Residuals:
      1       2       3       4       5       6 
-0.2039 -0.3149 -0.1331 -0.3724  0.3238  0.7005 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept) -1.53317    1.12328  -1.365   0.2440  
waiting      0.06756    0.01623   4.162   0.0141 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.4724 on 4 degrees of freedom
Multiple R-squared:  0.8124,	Adjusted R-squared:  0.7655 
F-statistic: 17.32 on 1 and 4 DF,  p-value: 0.01413


2.1: The formula for this relationship model is
    discharge = a+b x waiting

This means that the discharge duration depends on the waiting time.

2.2: The estimated regression equation with the coefficient function is
            discharge = -1.5332 + 0.0676 x waiting

2.3: Using the regression equation with the coefficient functions, plug in 
 x=80 because there is 80 minutes in wait time.
        discharge = -1.5332 + 0.0676 x 80
            discharge = -1.5332 + 5.408
                discharge = 3.8748
When waiting 80 minutes, the predicted discharge time is around 3.87. 

Question 3

> input <- mtcars[,c("mpg","disp","hp","wt")] 
> lm(formula = mpg ~ disp + hp + wt, data = input)

Call:
lm(formula = mpg ~ disp + hp + wt, data = input)

Coefficients:
(Intercept)         disp           hp           wt  
  37.105505    -0.000937    -0.031157    -3.800891 


3.1: A Multi Regression Model is used in this example to see how mpg
(miles per gallon). The dependent variable. Is affected by disp, hp, and wt.
 The coefficients are disp (displacement), hp (horsepower), wt (weight) these
coefficients tell how mpg is changed when the coefficients are changed. Also
known as independent variables or predictors. 


Question 4

> library(ISwR)
> plot(metabolic.rate~body.weight,data=rmr)
> model <- lm(metabolic.rate ~ body.weight, data = rmr)
> summary(model)

Call:
lm(formula = metabolic.rate ~ body.weight, data = rmr)

Residuals:
    Min      1Q  Median      3Q     Max 
-245.74 -113.99  -32.05  104.96  484.81 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 811.2267    76.9755  10.539 2.29e-13 ***
body.weight   7.0595     0.9776   7.221 7.03e-09 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 157.9 on 42 degrees of freedom
Multiple R-squared:  0.5539,	Adjusted R-squared:  0.5433 
F-statistic: 52.15 on 1 and 42 DF,  p-value: 7.025e-09



4.1: Intercept = 811.2267 
     body.weight = 7.0595
        x = 70

 Linear Regression Formula:
    y = 8.11.2267 + 7.0595x
    

    
> coeff <- coefficients(model)
> predicted_rate <- coeff[1] + coeff[2] * 70
> predicted_rate
(Intercept) 
   1305.394 






Comments