Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chapter 3, ex13. fix for calling rnorm with variance instead of … #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ch3/applied.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ suggests that there isn't a relationship between y and $x^2$.
----
```{r}
set.seed(1)
eps1 = rnorm(100, 0, 0.125)
eps1 = rnorm(100, 0, sqrt(0.125))
x1 = rnorm(100)
y1 = -1 + 0.5*x1 + eps1
plot(x1, y1)
Expand All @@ -424,7 +424,7 @@ As expected, the error observed in $R^2$ and $RSE$ decreases considerably.
----
```{r}
set.seed(1)
eps2 = rnorm(100, 0, 0.5)
eps2 = rnorm(100, 0, sqrt(0.5))
x2 = rnorm(100)
y2 = -1 + 0.5*x2 + eps2
plot(x2, y2)
Expand Down
41 changes: 22 additions & 19 deletions ch3/applied.html
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ <h2>13g.</h2>
<div id="h.-1" class="section level2">
<h2>13h.</h2>
<pre class="r"><code>set.seed(1)
eps1 = rnorm(100, 0, 0.125)
eps1 = rnorm(100, 0, sqrt(0.125))
x1 = rnorm(100)
y1 = -1 + 0.5*x1 + eps1
plot(x1, y1)
Expand All @@ -754,19 +754,19 @@ <h2>13h.</h2>
## lm(formula = y1 ~ x1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.29052 -0.07545 0.00067 0.07288 0.28665
## Min 1Q Median 3Q Max
## -0.8217 -0.2134 0.0019 0.2061 0.8108
##
## Coefficients:
## Estimate Std. Error t value Pr(&gt;|t|)
## (Intercept) -0.9864 0.0113 -87.3 &lt;2e-16 ***
## x1 0.4999 0.0118 42.2 &lt;2e-16 ***
## (Intercept) -0.9615 0.0319 -30.1 &lt;2e-16 ***
## x1 0.4997 0.0335 14.9 &lt;2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.113 on 98 degrees of freedom
## Multiple R-squared: 0.948, Adjusted R-squared: 0.947
## F-statistic: 1.78e+03 on 1 and 98 DF, p-value: &lt;2e-16</code></pre>
## Residual standard error: 0.319 on 98 degrees of freedom
## Multiple R-squared: 0.694, Adjusted R-squared: 0.691
## F-statistic: 223 on 1 and 98 DF, p-value: &lt;2e-16</code></pre>
<pre class="r"><code>abline(lm.fit1, lwd=3, col=2)
abline(-1, 0.5, lwd=3, col=3)
legend(-1, legend = c(&quot;model fit&quot;, &quot;pop. regression&quot;), col=2:3, lwd=3)</code></pre>
Expand All @@ -775,7 +775,7 @@ <h2>13h.</h2>
<div id="i.-2" class="section level2">
<h2>13i.</h2>
<pre class="r"><code>set.seed(1)
eps2 = rnorm(100, 0, 0.5)
eps2 = rnorm(100, 0, sqrt(0.5))
x2 = rnorm(100)
y2 = -1 + 0.5*x2 + eps2
plot(x2, y2)
Expand All @@ -787,18 +787,21 @@ <h2>13i.</h2>
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.1621 -0.3018 0.0027 0.2915 1.1466
## -1.6434 -0.4268 0.0038 0.4123 1.6215
##
## Coefficients:
## Estimate Std. Error t value Pr(&gt;|t|)
## (Intercept) -0.9456 0.0452 -20.9 &lt;2e-16 ***
## x2 0.4995 0.0474 10.6 &lt;2e-16 ***
## (Intercept) -0.9230 0.0639 -14.45 &lt; 2e-16 ***
## x2 0.4993 0.0670 7.46 3.6e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.451 on 98 degrees of freedom
## Multiple R-squared: 0.532, Adjusted R-squared: 0.527
## F-statistic: 111 on 1 and 98 DF, p-value: &lt;2e-16</code></pre>
## Residual standard error: 0.638 on 98 degrees of freedom
## Multiple R-squared: 0.362, Adjusted R-squared: 0.355
## F-statistic: 55.6 on 1 and 98 DF, p-value: 3.62e-11</code></pre>



<pre class="r"><code>abline(lm.fit2, lwd=3, col=2)
abline(-1, 0.5, lwd=3, col=3)
legend(-1, legend = c(&quot;model fit&quot;, &quot;pop. regression&quot;), col=2:3, lwd=3)</code></pre>
Expand All @@ -812,12 +815,12 @@ <h2>13j.</h2>
## x 0.3926 0.6064</code></pre>
<pre class="r"><code>confint(lm.fit1)</code></pre>
<pre><code>## 2.5 % 97.5 %
## (Intercept) -1.0088 -0.9640
## x1 0.4764 0.5234</code></pre>
## (Intercept) -1.0249 -0.8981
## x1 0.4332 0.5661</code></pre>
<pre class="r"><code>confint(lm.fit2)</code></pre>
<pre><code>## 2.5 % 97.5 %
## (Intercept) -1.0352 -0.8559
## x2 0.4055 0.5935</code></pre>
## (Intercept) -1.0498 -0.7963
## x2 0.3664 0.6323</code></pre>
<p>All intervals seem to be centered on approximately 0.5, with the second fit’s interval being narrower than the first fit’s interval and the last fit’s interval being wider than the first fit’s interval.</p>
</div>
<div id="a.-6" class="section level2">
Expand Down