DC_output and wind_velocity.DC_output on vertical scale.
Call:
lm(formula = DC_output ~ wind_velocity, data = windmill)
Residuals:
Min 1Q Median 3Q Max
-0.59869 -0.14099 0.06059 0.17262 0.32184
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.13088 0.12599 1.039 0.31
wind_velocity 0.24115 0.01905 12.659 7.55e-12 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.2361 on 23 degrees of freedom
Multiple R-squared: 0.8745, Adjusted R-squared: 0.869
F-statistic: 160.3 on 1 and 23 DF, p-value: 7.546e-12
broom has these:showing R-squared, and:
showing intercept and slope and their significance.
lm actually fits the regression. Store results in a variable. Then look at the results, eg. via summary or glance/tidy.glance and tidy are dataframes, so are helpful for pulling out results from, eg.:wind.velocity strongly significant, R-squared (0.874) high.augment from broom packageRows: 25
Columns: 8
$ wind_velocity <dbl> 5.00, 6.00, 3.40, 2.70, 10.00, 9.70,…
$ DC_output <dbl> 1.582, 1.822, 1.057, 0.500, 2.236, 2…
$ .fitted <dbl> 1.3366195, 1.5777683, 0.9507813, 0.7…
$ .resid <dbl> 0.24538052, 0.24423165, 0.10621871, …
$ .hat <dbl> 0.04834508, 0.04011347, 0.08860703, …
$ .sigma <dbl> 0.2353240, 0.2354330, 0.2401887, 0.2…
$ .cooksd <dbl> 0.0288421683, 0.0233028359, 0.010799…
$ .std.resid <dbl> 1.0655959, 1.0560493, 0.4713466, -1.…
lm by adding \(x^2\) to right side of model formula with +:I() necessary because ^ in model formula otherwise means something different (to do with interactions in ANOVA).
Call:
lm(formula = DC_output ~ wind_velocity + I(wind_velocity^2),
data = windmill)
Residuals:
Min 1Q Median 3Q Max
-0.26347 -0.02537 0.01264 0.03908 0.19903
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.155898 0.174650 -6.618 1.18e-06 ***
wind_velocity 0.722936 0.061425 11.769 5.77e-11 ***
I(wind_velocity^2) -0.038121 0.004797 -7.947 6.59e-08 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1227 on 22 degrees of freedom
Multiple R-squared: 0.9676, Adjusted R-squared: 0.9646
F-statistic: 328.3 on 2 and 22 DF, p-value: < 2.2e-16
This distribution has long tails, which should worry us at least some.
geom_point);DC.1a);DC.2a)geom_line: use the predictions as the y-values to join by lines (from DC.1a and DC.2a), instead of the original data points. Without the data and aes in the geom_lines, original data points (not predictions) would be joined by lines.Curve clearly fits better than line.
There is a problem with parabolas, which we’ll see later.
Ask engineer, “what should happen as wind velocity increases?”:
Mathematically, asymptote. Straight lines and parabolas don’t have them, but eg. \(y = 1/x\) does: as \(x\) gets bigger, \(y\) approaches zero without reaching it.
What happens to \(y = a + b(1/x)\) as \(x\) gets large?
Fit this, call it asymptote model.
Fitting the model here because we have math to justify it.
This is very close to straight.
Define new explanatory variable to be \(1/x\), and predict \(y\) from it.
\(x\) is velocity, distance over time.
So \(1/x\) is time over distance. In walking world, if you walk 5 km/h, take 12 minutes to walk 1 km, called your pace.
in a model formula, / has special meaning (as ^ does)
so in lm, wrap 1 / wind_velocity in I() (like I(wind_velocity^2)).
Call:
lm(formula = DC_output ~ I(1/wind_velocity), data = windmill)
Residuals:
Min 1Q Median 3Q Max
-0.20547 -0.04940 0.01100 0.08352 0.12204
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.9789 0.0449 66.34 <2e-16 ***
I(1/wind_velocity) -6.9345 0.2064 -33.59 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.09417 on 23 degrees of freedom
Multiple R-squared: 0.98, Adjusted R-squared: 0.9792
F-statistic: 1128 on 1 and 23 DF, p-value: < 2.2e-16
wind.velocity and its square).1 / wind_velocity (unsurprisingly) strongly significant.This is skewed (left), but is not bad (and definitely better than the one for the parabola model).
DC.output).wind.velocity higher. [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
[12] 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5
[23] 12.0 12.5 13.0 13.5 14.0 14.5 15.0 15.5 16.0
predict, which requires values to predict for, as data frame.wind_velocity.wind_velocity.wv_new with values in:wv_newmy_fitsggplot likes having the x and y for a plot in single columns, with additional columns labelling things (like the model, here)pivot_longer can help us with.DC.output between 0 and 3 from asymptote model. Add rectangle to graph around where the data were:wind.velocity, asymptote model behaves reasonably, parabola model does not.wind.velocity goes to zero? Should find DC.output goes to zero as well. Does it?wind.velocity heads to 0, its reciprocal heads to \(+\infty\), so DC.output heads to \(−\infty\)!wind.velocity to understand relationship. (Is there a lower asymptote?)DC.output to be zero for small wind.velocity.
Comments
geom_smoothsmooths scatterplot trend.