Module #7 Assignment

Module 7 Assignment


1.1) Defining the relationship model between the predictor and the response variable:


The relationship model between the predictor (X) and the response variable (Y) is defined as:


Y = a + bX + e


Y = dependent variable (what is being predicted or explained).

X = independent variable (what is predicting or explaining the value of Y).

a = constant, representing the value of Y when X = 0.

b = coefficient of X, indicating the slope of the regression line, i.e., how much Y changes for each one-unit change in X.

e = the error term, which represents the error in predicting the value of Y given the value of X.


1.2) Calculating the coefficients:


To calculate the coefficients (a and b) for the given data:


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)


a <- coef(model)[1] # Intercept (a)

b <- coef(model)[2] # Slope (b)


cat("Intercept (a):", a, "\n")

cat("Slope (b):", b, "\n")

This code fits a linear regression model to the data and extracts the coefficients a and b. You can use these coefficients to describe the relationship between X and Y.


2.1) Defining the relationship model between the predictor and the response variable:


The relationship model for the data set "visit" can be defined as:


discharge = a + b * waiting


"discharge" = dependent variable (response).

"waiting" = independent variable (predictor).

"a" = constant (intercept).

"b" = coefficient of "waiting" (slope).


2.2) Extracting the parameters of the estimated regression equation with the coefficients function:

To extract the parameters of the estimated regression equation in 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)


This will give you the values of the intercept (a) and slope (b) for the estimated regression equation.


2.3) Determining the fit of the eruption duration using the estimated regression equation:

To predict the discharge duration when waiting time is 80 minutes using the estimated regression equation:


predicted_discharge <- predict(model, newdata = data.frame(waiting = 80))

cat("Predicted discharge duration for waiting time of 80 minutes:", predicted_discharge, "\n")


This will provide you with the predicted discharge duration based on the linear regression model.


3.1) Examining the relationship Multi Regression Model as stated above and its Coefficients using 4 different variables from mtcars (mpg, disp, hp, and wt):


input <- mtcars[, c("mpg", "disp", "hp", "wt")]

model <- lm(mpg ~ disp + hp + wt, data = input)

coefficients(model)


You can determine the connections between the predictors (disp, hp, and wt) and the response (mpg) by looking at the coefficients. In more detail, the coefficients show how the response variable (mpg) changes when each predictor is changed by one unit while the other predictors remain unchanged.


Plotting metabolic rate versus body weight and fit a linear regression model:


library(ISwR)

plot(metabolic.rate ~ body.weight, data = rmr)

model <- lm(metabolic.rate ~ body.weight, data = rmr)


predicted_metabolic_rate <- predict(model, newdata = data.frame(body.weight = 70))

cat("Predicted metabolic rate for a body weight of 70 kg:", predicted_metabolic_rate, "\n")


The data will be fitted to a linear regression model using this code, and you can use the resulting model to predict the metabolic rate for a 70 kg body weight.

Comments

Popular posts from this blog

LIS 4370: Module # 10 Building your own R package

LIS 4317 Final Project: Fuel Economy Data from the U.S Dept. of Energy

LIS 4317: Module # 10 assignment