Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyDoorn committed Oct 30, 2024
1 parent 2a4b740 commit 7d1a4a6
Show file tree
Hide file tree
Showing 27 changed files with 429 additions and 411 deletions.
3 changes: 3 additions & 0 deletions SSR/.quarto/xref/INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@
"2024/21. multiple_regression/21. multiple_regresson.qmd": {
"21. multiple_regresson.html": "58ddcc28",
"21. multiple_regresson.slide.html": "0cf5212e"
},
"topics/block3_opening/block3_opening.qmd": {
"block3_opening.html": "74fdf750"
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ format:
output-ext: slide.html
---

## Fishing Expedition!
<img src="qr_kkd7n.png">

Thank you Julia, Kim, Barnaba, Lioba, Joaquin, Tadeja, and Ewa!

<!-- Nikolas and Zeynep for error-spotting -->

```{r child="../../topics/block3_opening/block3_opening.qmd"}
```


```{r child="../../topics/correlation/correlation_albumsales.qmd"}
```


```{r child="../../topics/regression_one_predictor/regression_one_predictor.qmd", eval=TRUE}
```

Expand Down

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 37 additions & 21 deletions SSR/topics/block3_opening/block3_opening.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

<meta name="author" content="Sharon Klinkenberg &amp; Johnny van Doorn">

<title>block3_opening</title>
<style>
Expand Down Expand Up @@ -39,26 +40,43 @@

</head>

<body class="fullcontent">

<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<body>

<div id="quarto-content" class="page-columns page-rows-contents page-layout-article toc-left">
<div id="quarto-sidebar-toc-left" class="sidebar toc-left">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>

<ul class="collapse">
<li><a href="#some-opening-mantras" id="toc-some-opening-mantras" class="nav-link active" data-scroll-target="#some-opening-mantras">Some Opening Mantra’s</a>
<ul class="collapse">
<li><a href="#always-plot-your-data" id="toc-always-plot-your-data" class="nav-link" data-scroll-target="#always-plot-your-data">Always plot your data</a></li>
<li><a href="#always-plot-your-data-1" id="toc-always-plot-your-data-1" class="nav-link" data-scroll-target="#always-plot-your-data-1">Always plot your data</a></li>
<li><a href="#predicting-the-dv" id="toc-predicting-the-dv" class="nav-link" data-scroll-target="#predicting-the-dv">Predicting the DV</a></li>
<li><a href="#keep-your-models-simpleinterpretable" id="toc-keep-your-models-simpleinterpretable" class="nav-link" data-scroll-target="#keep-your-models-simpleinterpretable">Keep your models simple/interpretable</a></li>
<li><a href="#statistics-in-block-3" id="toc-statistics-in-block-3" class="nav-link" data-scroll-target="#statistics-in-block-3">Statistics in block 3</a></li>
</ul></li>
</ul>
<div class="quarto-alternate-formats"><h2>Other Formats</h2><ul><li><a href="block3_opening.html"><i class="bi bi-file-slides"></i>RevealJS</a></li></ul></div></nav>
</div>
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
</div>
<main class="content" id="quarto-document-content">



<section id="what-have-we-learnt-so-far" class="level1">
<h1>What have we learnt so far?</h1>
<section id="some-opening-mantras" class="level1">
<h1>Some Opening Mantra’s</h1>
<section id="always-plot-your-data" class="level2">
<h2 class="anchored" data-anchor-id="always-plot-your-data">Always plot your data</h2>
<p><img src="trex.png" class="img-fluid" width="800"></p>
<p><img src="raincloud.png" class="img-fluid" width="800"></p>
</section>
<section id="always-plot-your-data-1" class="level2">
<h2 class="anchored" data-anchor-id="always-plot-your-data-1">Always plot your data</h2>
<p><img src="raincloud.png" class="img-fluid" width="800"></p>
<p><img src="trex.png" class="img-fluid" width="800"></p>
</section>
<section id="explaining-variance" class="level2">
<h2 class="anchored" data-anchor-id="explaining-variance">Explaining variance</h2>
<section id="predicting-the-dv" class="level2 smaller">
<h2 class="smaller anchored" data-anchor-id="predicting-the-dv">Predicting the DV</h2>
<div class="incremental">
<ul class="incremental">
<li>The dependent variable (DV) varies</li>
Expand All @@ -71,27 +89,25 @@ <h2 class="anchored" data-anchor-id="explaining-variance">Explaining variance</h
<li>Accurate approximation/prediction of the DV? -&gt; high explained variance</li>
<li>Total variability of DV = explained variance + unexplained variance
<ul class="incremental">
<li><span class="math inline">\(\text{DV} = \text{model} + \text{error}\)</span></li>
<li><span class="math inline">\(\text{DV} = \text{model prediction} + \text{error}\)</span></li>
</ul></li>
<li>More explained variance than unexplained variance (e.g., <span class="math inline">\(F &gt;&gt; 1\)</span>) -&gt; success!</li>
</ul>
</div>
</section>
<section id="predictions" class="level2">
<h2 class="anchored" data-anchor-id="predictions">Predictions</h2>
<div class="incremental">
<ul class="incremental">
<li>The dependent variable (DV) varies</li>
<li>We try to recreate/predict the observed values by looking at predictor variables</li>
<li>Total variability of DV = explained variance + unexplained variance</li>
<li>More explained variance than unexplained variance (<span class="math inline">\(F &gt;&gt; 1\)</span>) -&gt; success!</li>
</ul>
</div>
</section>
<section id="keep-your-models-simpleinterpretable" class="level2">
<h2 class="anchored" data-anchor-id="keep-your-models-simpleinterpretable">Keep your models simple/interpretable</h2>
<p><img src="manyvars.png" class="img-fluid" width="800"></p>
</section>
<section id="statistics-in-block-3" class="level2">
<h2 class="anchored" data-anchor-id="statistics-in-block-3">Statistics in block 3</h2>
<ul>
<li>Simple regression (single predictor)</li>
<li>Multiple regression (two predictors)</li>
<li>Mediation analysis (i.e., modeling dependence)</li>
<li>Moderation analysis (i.e., modeling interactions)</li>
</ul>
</section>
</section>

</main>
Expand Down
6 changes: 6 additions & 0 deletions SSR/topics/block3_opening/block3_opening.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
![](manyvars.png){width="800px"}


## Statistics in block 3

- Simple regression (single predictor)
- Multiple regression (two predictors)
- Mediation analysis (i.e., modeling dependence)
- Moderation analysis (i.e., modeling interactions)
1 change: 0 additions & 1 deletion SSR/topics/correlation/correlation_albumsales.html
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ <h2 class="subsection anchored" data-anchor-id="significance-of-partial-correlat
<p><img src="correlation_albumsales_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid" width="672"></p>
</div>
</div>
<p>```</p>
</section>
</section>

Expand Down
1 change: 0 additions & 1 deletion SSR/topics/correlation/correlation_albumsales.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,3 @@ arrows(x0 = t.pr, x1 = t.pr, y0 = 0 , y1 = 0.25, col = "darkred", lwd = 2)
text(x = t.pr, y = 0.3, paste("t =", round(t.pr, 2)), cex = 1.2)
text(x = t.pr, y = 0.35, paste("p-val < 0.001"), cex = 1.2)
```
```
55 changes: 29 additions & 26 deletions SSR/topics/regression_one_predictor/regression_one_predictor.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h2 id="toc-title">Table of contents</h2>
<li><a href="#predicted-values" id="toc-predicted-values" class="nav-link" data-scroll-target="#predicted-values">Predicted values</a></li>
<li><a href="#y-vs-haty" id="toc-y-vs-haty" class="nav-link" data-scroll-target="#y-vs-haty"><span class="math inline">\(y\)</span> vs <span class="math inline">\(\hat{y}\)</span></a></li>
<li><a href="#error" id="toc-error" class="nav-link" data-scroll-target="#error">Error</a></li>
<li><a href="#homoscedasticity-1" id="toc-homoscedasticity-1" class="nav-link" data-scroll-target="#homoscedasticity-1">Homoscedasticity</a></li>
<li><a href="#model-fit" id="toc-model-fit" class="nav-link" data-scroll-target="#model-fit">Model fit</a></li>
<li><a href="#explained-variance" id="toc-explained-variance" class="nav-link" data-scroll-target="#explained-variance">Explained variance</a></li>
<li><a href="#explained-variance-visually-n-10" id="toc-explained-variance-visually-n-10" class="nav-link" data-scroll-target="#explained-variance-visually-n-10">Explained variance visually (<span class="math inline">\(n = 10\)</span>)</a></li>
Expand Down Expand Up @@ -142,30 +143,14 @@ <h2 class="smaller anchored" data-anchor-id="regression">Regression</h2>
<p><span class="math display">\[\LARGE{Y_i = \beta_0 + \beta_1 X_i + \epsilon_i}\]</span></p>
<p>In linear regression, the relationships are modeled using linear predictor functions whose unknown model parameters are estimated from the data.</p>
<p>Source: <a href="https://en.wikipedia.org/wiki/Linear_regression">wikipedia</a></p>
<!-- ## Outcome vs Model -->
<!-- ```{r, fig.align='center', fig.asp=.5} -->
<!-- set.seed(123) -->
<!-- error = c(2, 1, .5, .1) -->
<!-- n = 10 -->
<!-- layout(matrix(1:4,1,4)) -->
<!-- for(e in error) { -->
<!-- x = rnorm(n) -->
<!-- y = x + rnorm(n, 0 , e) -->
<!-- r = round(cor(x,y), 2) -->
<!-- r.2 = round(r^2, 2) -->
<!-- plot(x,y, las = 1, ylab = "y", xlab = "x", -->
<!-- main = paste("r =", r," r2 = ", r.2), ylim=c(-2,2), xlim=c(-2,2)) -->
<!-- fit <- lm(y ~ x) -->
<!-- abline(fit, col = "red") -->
<!-- } -->
<!-- ``` -->
</section>
<section id="assumptions" class="level2">
<h2 class="anchored" data-anchor-id="assumptions">Assumptions</h2>
<p>A selection from Field:</p>
<p>A selection from Field (Section 8.4):</p>
<ul>
<li>Sensitivity</li>
<li>Homoscedasticity</li>
<li>Sensitivity (Section 6.4)</li>
<li>Homoscedasticity (Section 6.7)</li>
<li>Normality (Section 6.7)</li>
</ul>
</section>
<section id="sensitivity" class="level2">
Expand All @@ -174,7 +159,7 @@ <h2 class="anchored" data-anchor-id="sensitivity">Sensitivity</h2>
<ul>
<li>Extreme residuals</li>
<li>Cook’s distance (&lt; 1)</li>
<li>Check Q-Q and residuals plots</li>
<li>Check Q-Q, residuals plots, casewise diagnostics</li>
</ul>
</section>
<section id="sensitivity-1" class="level2">
Expand All @@ -194,8 +179,8 @@ <h2 class="anchored" data-anchor-id="homoscedasticity">Homoscedasticity</h2>
<div class="columns">
<div class="column">
<ul>
<li>Variance of residual should be equal across all expected values</li>
<li>Look at scatterplot of standardized: predicted values <span class="math inline">\(\times\)</span> residuals. Roughly round shape is needed</li>
<li>Variance of residuals should be equal across all expected values</li>
<li>Look at scatterplot of standardized: predicted values vs.&nbsp;residuals. Roughly round shape is needed</li>
<li>After the analysis is complete because it’s based on the residuals</li>
</ul>
</div><div class="column">
Expand All @@ -213,6 +198,9 @@ <h2 class="anchored" data-anchor-id="homoscedasticity">Homoscedasticity</h2>
</section>
<section id="the-data" class="level2 smaller">
<h2 class="smaller anchored" data-anchor-id="the-data">The data</h2>
<blockquote class="blockquote">
<p>Predict album sales (x 1,000 copies) based on airplay (no. plays).</p>
</blockquote>
<div class="cell">
<div class="cell-output-display">

Expand Down Expand Up @@ -357,6 +345,21 @@ <h2 class="smaller anchored" data-anchor-id="error">Error</h2>
</div>
</div>
</section>
<section id="homoscedasticity-1" class="level2">
<h2 class="anchored" data-anchor-id="homoscedasticity-1">Homoscedasticity</h2>
<blockquote class="blockquote">
<p>Is there any systematic error?</p>
</blockquote>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid figure-img" width="480"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="model-fit" class="level2 smaller">
<h2 class="smaller anchored" data-anchor-id="model-fit">Model fit</h2>
<ul>
Expand Down Expand Up @@ -387,7 +390,7 @@ <h2 class="smaller anchored" data-anchor-id="explained-variance-visually-n-10">E
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-19-1.png" class="img-fluid figure-img" width="1440"></p>
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-20-1.png" class="img-fluid figure-img" width="1440"></p>
</figure>
</div>
</div>
Expand Down Expand Up @@ -460,7 +463,7 @@ <h2 class="anchored" data-anchor-id="section"></h2>
<h2 class="anchored" data-anchor-id="p-values-of-b_1">P-values of <span class="math inline">\(b_1\)</span></h2>
<div class="cell">
<div class="cell-output-display">
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-24-1.png" class="img-fluid" width="672"></p>
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
Expand All @@ -469,7 +472,7 @@ <h2 class="anchored" data-anchor-id="visualize">Visualize</h2>
<p>Instead of obtaining the p-value by locating the t in the t-distribution, we can locate the F in the F-distribution</p>
<div class="cell">
<div class="cell-output-display">
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid" width="672"></p>
<p><img src="regression_one_predictor_files/figure-html/unnamed-chunk-26-1.png" class="img-fluid" width="672"></p>
</div>
</div>
</section>
Expand Down
51 changes: 20 additions & 31 deletions SSR/topics/regression_one_predictor/regression_one_predictor.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,22 @@ In linear regression, the relationships are modeled using linear predictor funct

Source: [wikipedia](https://en.wikipedia.org/wiki/Linear_regression)

<!-- ## Outcome vs Model -->

<!-- ```{r, fig.align='center', fig.asp=.5} -->
<!-- set.seed(123) -->
<!-- error = c(2, 1, .5, .1) -->
<!-- n = 10 -->

<!-- layout(matrix(1:4,1,4)) -->
<!-- for(e in error) { -->

<!-- x = rnorm(n) -->
<!-- y = x + rnorm(n, 0 , e) -->

<!-- r = round(cor(x,y), 2) -->
<!-- r.2 = round(r^2, 2) -->

<!-- plot(x,y, las = 1, ylab = "y", xlab = "x", -->
<!-- main = paste("r =", r," r2 = ", r.2), ylim=c(-2,2), xlim=c(-2,2)) -->
<!-- fit <- lm(y ~ x) -->
<!-- abline(fit, col = "red") -->

<!-- } -->

<!-- ``` -->


## Assumptions

A selection from Field:
A selection from Field (Section 8.4):

* Sensitivity
* Homoscedasticity
* Sensitivity (Section 6.4)
* Homoscedasticity (Section 6.7)
* Normality (Section 6.7)

## Sensitivity

Outliers

* Extreme residuals
* Cook's distance (< 1)
* Check Q-Q and residuals plots
* Check Q-Q, residuals plots, casewise diagnostics

## Sensitivity

Expand Down Expand Up @@ -111,8 +87,8 @@ text(0.5, y[1], bquote("r ="~ .(r) ~ "," ~ r^2 ~ " = " ~ .(r.2)), pos = 2, col =

::: {.column}

* Variance of residual should be equal across all expected values
* Look at scatterplot of standardized: predicted values $\times$ residuals. Roughly round shape is needed
* Variance of residuals should be equal across all expected values
* Look at scatterplot of standardized: predicted values vs. residuals. Roughly round shape is needed
* After the analysis is complete because it's based on the residuals
:::

Expand Down Expand Up @@ -296,6 +272,19 @@ data$error <- round(error, 2)
datatable(data, rownames = FALSE, options = list(searching = FALSE, scrollY = 300, paging = F, info = F))
```

## Homoscedasticity

>Is there any systematic error?
```{r, fig.height=5, fig.width=5, fig.align='center', echo=FALSE}
plot(prediction, error, xlim = c(0,360), ylim = c(-200,200), main = "Predictions vs. Residuals",
xlab = "Predicted Sales", ylab = "Model Error (Residuals)",
las = 1, pch = 21, bg = "lightgreen")
abline(lm(error ~ prediction),
col='darkred')
text(50, -150, bquote("cor = " ~.(round(cor(prediction, error), 5))))
```

## Model fit {.smaller}

- The fit of the model can be viewed in terms of the correlation ($r$) between the predictions and the observed values: if the predictions are perfect, the correlation will be 1.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d1a4a6

Please sign in to comment.