Module #7
Amanda Hidalgo
Module #7
1.1 Define the relationship model between the predictor and the response variable:
- In this case, the relationship model between the predictor (x) and the response variable (y) can be defined as:
`y = a + bx + e`
Where:
- y is the response variable (value of the Dependent variable).
- x is the predictor variable (value of the Independent variable).
- a is the intercept or constant (the value of y when x=0).
- b is the coefficient of x (the slope of the regression line).
- e is the error term (the error in predicting y given x).
1.2 Calculate the coefficients?
- To calculate the coefficients a and b, you can use the lm() function in R. Here's the code to calculate them for your data:
```R
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)
coefficients(model)
```
2.1 Define the relationship model between the predictor and the response variable:
- The relationship model between the predictor (waiting time) and the response variable (discharge duration) can be defined as:
`discharge ~ waiting`
This indicates that we are predicting discharge duration based on waiting time.
2.2 Extract the parameters of the estimated regression equation with the coefficients function:
- You can use the `coefficients()` function to extract the parameters of the estimated regression equation. Here's the code:
```R
visit <- data.frame(discharge = c(3.600, 1.800, 3.333, 2.283, 4.533, 2.883),
waiting = c(79, 54, 74, 62, 85, 55))
model <- lm(discharge ~ waiting, data = visit)
coefficients(model)
```
2.3 Determine the fit of the eruption duration using the estimated regression equation:
- To determine the fit of the eruption duration for a waiting time of 80 minutes, you can use the `predict()` function. Here's the code:
```R
waiting_time <- 80
predicted_discharge <- predict(model, newdata = data.frame(waiting = waiting_time))
```
3.1 Examine the relationship Multi Regression Model and its Coefficients:
- To examine the relationship and coefficients for the multi-regression model, you can use the lm() function with the specified variables. Here's the code and interpretation:
```R
input <- mtcars[, c("mpg", "disp", "hp", "wt")]
model <- lm(mpg ~ disp + hp + wt, data = input)
summary(model)
```
The summary of the model will provide coefficients, significance levels, and other statistics. The coefficients indicate the impact of each variable (disp, hp, wt) on the response variable (mpg). You can interpret the coefficients to understand how each variable contributes to predicting mpg.
4. From our textbook pp. 110 Exercises # 5.1:
- To plot metabolic rate versus body weight and fit a linear regression, you can use the `lm()` function. Here's the code:
```R
library(ISwR)
plot(metabolic.rate ~ body.weight, data = rmr)
model <- lm(metabolic.rate ~ body.weight, data = rmr)
```
To predict the metabolic rate for a body weight of 70 kg, you can use:
```R
new_data <- data.frame(body.weight = 70)
predicted_metabolic_rate <- predict(model, newdata = new_data)
```
The predicted_metabolic_rate will give you the estimated metabolic rate for a body weight of 70 kg based on the linear regression model.
Comments
Post a Comment