0
$\begingroup$

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."

DataCamp's solution was this

# 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?

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$
    – Peter
    Jun 15, 2020 at 8:53

2 Answers 2

0
$\begingroup$

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)

$\endgroup$
0
$\begingroup$

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) 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.