Open YuHsiangLo opened 5 years ago
Hi, YuHsiangLo
Thanks to your review. I'm sorry that part of my results don't show up in md file, you could check the html version provided here.
Regarding to the mistake you pointed out, I' ve tested both with lifeExp ~ I(year - 1952) + I((year - 1952)^2)
and lifeExp ~ I(year - 1952) + I((year - 1952)^2)
. The results turn out to be the same including Intercept value, residual standard error , multiple R-squared and etc. I don't understand why you said that these two formulas produce different results. I highly recommend you test both of those first.
By the way, do you have any remarks on the first part of my assignment? I cannot find any comments on that.
Thanks agian for your review.
Maggie
Hi again,
I think your did great in the first part, so I didn't leave any comments.
Regarding the regression models, notice that the first-order terms are different in the two models, one have slope of 82.172151 and the other 1.049839.
# This is what you have in your implementation
gapminder %>%
filter(country == "Zimbabwe") %>%
lm(data = ., lifeExp ~ I(year - 1952) + I(year^2 - 1952^2)) %>%
summary()
Call:
lm(formula = lifeExp ~ I(year - 1952) + I(year^2 - 1952^2), data = .)
Residuals:
Min 1Q Median 3Q Max
-6.2522 -2.7543 -0.6202 2.7916 5.9329
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 45.697407 3.107870 14.704 1.34e-07 ***
I(year - 1952) 82.172151 18.220039 4.510 0.00147 **
I(year^2 - 1952^2) -0.020779 0.004602 -4.515 0.00146 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.203 on 9 degrees of freedom
Multiple R-squared: 0.711, Adjusted R-squared: 0.6467
F-statistic: 11.07 on 2 and 9 DF, p-value: 0.003753
# This should be the correct one
gapminder %>%
filter(country == "Zimbabwe") %>%
lm(data = ., lifeExp ~ I(year - 1952) + I((year - 1952)^2)) %>%
summary()
Call:
lm(formula = lifeExp ~ I(year - 1952) + I((year - 1952)^2), data = .)
Residuals:
Min 1Q Median 3Q Max
-6.2522 -2.7543 -0.6202 2.7916 5.9329
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 45.697407 3.107870 14.704 1.34e-07 ***
I(year - 1952) 1.049839 0.262699 3.996 0.00313 **
I((year - 1952)^2) -0.020779 0.004602 -4.515 0.00146 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.203 on 9 degrees of freedom
Multiple R-squared: 0.711, Adjusted R-squared: 0.6467
F-statistic: 11.07 on 2 and 9 DF, p-value: 0.003753
Peer-Review HW-06 for @MeiqiYu
Remarks:
lifeExp ~ I(year - 1952) + I((year - 1952)^2)
instead oflifeExp ~ I(year - 1952) + I(year2 - 1952^2)
as in your code. These two formulas produce different results.offset
is not used in the function body.lm()
function won't work because you didn't provide thedata
argument. It works here because you ranattach()
OUTSIDE the function definition. If others use this function in a new namespace, an error will occur.