# Linear Regression Model

I'm taking a course on Supervised Learning in R: Regression. There is a section where I'm supposed to predict blood pressure given age and weight. This is was MY approach

# Create the formula and print it
fmla <- lm(blood_pressure ~ age + weight, data=bloodpressure)
fmla

# Fit the model: bloodpressure_model
bloodpressure_model <- fmla

# Print bloodpressure_model and call summary()
bloodpressure_model
summary(bloodpressure_model)


It was an incorrect submission. The message error message read - "The contents of the variable fmla aren't correct."

# bloodpressure is in the workspace
summary(bloodpressure)

# Create the formula and print it
fmla <- blood_pressure ~ age + weight
fmla <- lm(blood_pressure ~ age + weight, data=bloodpressure)

fmla

# Fit the model: bloodpressure_model
bloodpressure_model <- lm(fmla, data = bloodpressure)

# Print bloodpressure_model and call summary()
bloodpressure_model
summary(bloodpressure_model)


Both of these models had the same diagnostic results. What's the issue with MY approach?

• The „correct“ solution looks odd, since fmla is assigned twice. When you do ´lm(...)´ you fit a regression. So in your code fmla already contains the regression results – Peter Jun 15 '20 at 8:53

It should be a bug in their server. The fmla variable should have the same contents in your code and in theirs. This is because the last assignment on both scripts is

fmla <- lm(blood_pressure ~ age + weight, data=bloodpressure)

The fmla is the model formula: fmla <- formula(blood_pressure ~ age + weight)

So the correct solution should be

# bloodpressure is in the workspace
summary(bloodpressure)

# Create the formula and print it
fmla <- formula(blood_pressure ~ age + weight)

fmla

# Fit the model: bloodpressure_model
bloodpressure_model <- lm(fmla, data = bloodpressure)

# Print bloodpressure_model and call summary()
bloodpressure_model
summary(bloodpressure_model)