Skip to content

Commit

Permalink
Merge pull request #29 from philmcaleer/main
Browse files Browse the repository at this point in the history
welch basis added
  • Loading branch information
philmcaleer authored Jan 24, 2022
2 parents 9277aff + 4c21a90 commit d23f9cd
Show file tree
Hide file tree
Showing 30 changed files with 843 additions and 306 deletions.
55 changes: 55 additions & 0 deletions book/03-ttest-c2.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Between-Subjects Welch's t-test

**between-subjects Welch's t-test:** Compare two groups or conditions where the participants are different in each group and have not been matched or are only matched on broad demographics, e.g. only age.

## The Worked Example

```{r we, echo = FALSE}
set.seed(1410)
mx <- runif(1, 0, 100) %>% round2(2)
sdx <- runif(1, 0, 5) %>% round2(2)
N <- seq(10, 100, 2) %>% sample(1)
dat <- tibble(Group = rep(c("A","B"), each = N/2),
scores = rnorm(N, mx, sdx)) %>%
mutate(scores = scores + rep(c(0,2), each = N/2))
desc <- dat %>%
group_by(Group) %>%
summarise(Npg = n(),
Means = mean(scores) %>% round2(2),
SDs = sd(scores) %>% round2(2),
Variance = var(scores) %>% round2(2),
`Standard Err.` = (SDs/sqrt(Npg)) %>% round2(2))
sdp <- sqrt((((N/2 - 1) * desc$SDs[1]^2) + ((N/2 - 1) * desc$SDs[2]^2))/(N/2 + N/2 - 2))
t.value <- ((desc$Means[1] - desc$Means[2])/(sdp * sqrt(((1/(N/2)) + (1/(N/2)))))) %>% round2(2)
cohensd <- ((2* t.value)/sqrt(N-2)) %>% round2(2)
results <- t.test(dat %>% filter(Group == "A") %>% pull(scores),
dat %>% filter(Group == "B") %>% pull(scores),
var.equal = TRUE) %>%
tidy() %>%
mutate(cohensd_t = (2*statistic)/sqrt(parameter))
```

Here is your data:

```{r, echo = FALSE}
desc %>%
select(-Variance, -`Standard Err.`) %>%
rename(N = Npg, Mean = Means, SD = SDs) %>%
knitr::kable(align = "c")
```

Let's look at the main t-test formula for Welch's t-test:

$$t = \frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}}$$

**Degrees of Freedom**

$$df = \frac{\left(\frac{s^2_{x_1}}{n_1}+\frac{s^2_{x_2}}{n_2}\right)^2}{\frac{\left(\frac{s^2_{x_1}}{n_1}\right)^2}{n_1 - 1}+\frac{\left(\frac{s^2_{x_2}}{n_2}\right)^2}{n_2 - 1}}$$

Binary file modified book/template.rds
Binary file not shown.
43 changes: 43 additions & 0 deletions docs/03-ttest-c2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Between-Subjects Welch's t-test

**between-subjects Welch's t-test:** Compare two groups or conditions where the participants are different in each group and have not been matched or are only matched on broad demographics, e.g. only age.

## The Worked Example



Here is your data:

<table>
<thead>
<tr>
<th style="text-align:center;"> Group </th>
<th style="text-align:center;"> N </th>
<th style="text-align:center;"> Mean </th>
<th style="text-align:center;"> SD </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;"> A </td>
<td style="text-align:center;"> 18 </td>
<td style="text-align:center;"> 25.58 </td>
<td style="text-align:center;"> 2.25 </td>
</tr>
<tr>
<td style="text-align:center;"> B </td>
<td style="text-align:center;"> 18 </td>
<td style="text-align:center;"> 29.07 </td>
<td style="text-align:center;"> 2.53 </td>
</tr>
</tbody>
</table>

Let's look at the main t-test formula for Welch's t-test:

$$t = \frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}}$$

**Degrees of Freedom**

$$df = \frac{\left(\frac{s^2_{x_1}}{n_1}+\frac{s^2_{x_2}}{n_2}\right)^2}{\frac{\left(\frac{s^2_{x_1}}{n_1}\right)^2}{n_1 - 1}+\frac{\left(\frac{s^2_{x_2}}{n_2}\right)^2}{n_2 - 1}}$$

8 changes: 4 additions & 4 deletions docs/05-regression-b.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Here we are going to try out a few examples based on the above. First we will us



* To two decimal places, what would be the predicted value of IQ if the HeadSize was 37.8? <div class='webex-radiogroup' id='radio_YVWSUBWQWM'><label><input type="radio" autocomplete="off" name="radio_YVWSUBWQWM" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_YVWSUBWQWM" value="answer"></input> <span>93.88</span></label><label><input type="radio" autocomplete="off" name="radio_YVWSUBWQWM" value=""></input> <span>120.51</span></label></div>
* To two decimal places, what would be the predicted value of IQ if the HeadSize was 37.8? <div class='webex-radiogroup' id='radio_SLGLQOGTVU'><label><input type="radio" autocomplete="off" name="radio_SLGLQOGTVU" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_SLGLQOGTVU" value="answer"></input> <span>93.88</span></label><label><input type="radio" autocomplete="off" name="radio_SLGLQOGTVU" value=""></input> <span>120.51</span></label></div>



Expand Down Expand Up @@ -282,7 +282,7 @@ Giving a predicted value of $\hat{Y}$ = 93.88, to two decimal places.



* To two decimal places, what would be the predicted value of IQ if the HeadSize was 24.2? <div class='webex-radiogroup' id='radio_ZNPKUXYLRZ'><label><input type="radio" autocomplete="off" name="radio_ZNPKUXYLRZ" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_ZNPKUXYLRZ" value="answer"></input> <span>93.88</span></label><label><input type="radio" autocomplete="off" name="radio_ZNPKUXYLRZ" value=""></input> <span>77.64</span></label></div>
* To two decimal places, what would be the predicted value of IQ if the HeadSize was 24.2? <div class='webex-radiogroup' id='radio_QIJLLRWAPK'><label><input type="radio" autocomplete="off" name="radio_QIJLLRWAPK" value=""></input> <span>77.64</span></label><label><input type="radio" autocomplete="off" name="radio_QIJLLRWAPK" value="answer"></input> <span>93.88</span></label><label><input type="radio" autocomplete="off" name="radio_QIJLLRWAPK" value=""></input> <span>119.67</span></label></div>



Expand Down Expand Up @@ -311,7 +311,7 @@ Giving a predicted value of $\hat{Y}$ = 77.64, to two decimal places.



* To two decimal places, what would be the predicted value of IQ if the HeadSize was 52.9? <div class='webex-radiogroup' id='radio_EQGKVQRWBU'><label><input type="radio" autocomplete="off" name="radio_EQGKVQRWBU" value="answer"></input> <span>120.51</span></label><label><input type="radio" autocomplete="off" name="radio_EQGKVQRWBU" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_EQGKVQRWBU" value=""></input> <span>111.91</span></label></div>
* To two decimal places, what would be the predicted value of IQ if the HeadSize was 52.9? <div class='webex-radiogroup' id='radio_LLUJERVTKT'><label><input type="radio" autocomplete="off" name="radio_LLUJERVTKT" value=""></input> <span>111.91</span></label><label><input type="radio" autocomplete="off" name="radio_LLUJERVTKT" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_LLUJERVTKT" value="answer"></input> <span>120.51</span></label></div>



Expand Down Expand Up @@ -339,7 +339,7 @@ Giving a predicted value of $\hat{Y}$ = 111.91, to two decimal places.
</div>


* To two decimal places, what would be the predicted value of IQ if the HeadSize was 48.4? <div class='webex-radiogroup' id='radio_ZTWSWUUVLA'><label><input type="radio" autocomplete="off" name="radio_ZTWSWUUVLA" value=""></input> <span>119.67</span></label><label><input type="radio" autocomplete="off" name="radio_ZTWSWUUVLA" value=""></input> <span>77.64</span></label><label><input type="radio" autocomplete="off" name="radio_ZTWSWUUVLA" value="answer"></input> <span>106.54</span></label></div>
* To two decimal places, what would be the predicted value of IQ if the HeadSize was 48.4? <div class='webex-radiogroup' id='radio_KPZKMZVYNW'><label><input type="radio" autocomplete="off" name="radio_KPZKMZVYNW" value="answer"></input> <span>106.54</span></label><label><input type="radio" autocomplete="off" name="radio_KPZKMZVYNW" value=""></input> <span>77.64</span></label><label><input type="radio" autocomplete="off" name="radio_KPZKMZVYNW" value=""></input> <span>119.67</span></label></div>



Expand Down
15 changes: 8 additions & 7 deletions docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ <h1>
<li class="book-part">t-tests</li>
<li><a class="" href="one-sample-t-test.html"><span class="header-section-number">6</span> One-Sample t-test</a></li>
<li><a class="" href="between-subjects-students-t-test.html"><span class="header-section-number">7</span> Between-Subjects Student's t-test</a></li>
<li><a class="" href="within-subjects-t-test.html"><span class="header-section-number">8</span> Within-Subjects t-test</a></li>
<li><a class="" href="between-subjects-welchs-t-test.html"><span class="header-section-number">8</span> Between-Subjects Welch's t-test</a></li>
<li><a class="" href="within-subjects-t-test.html"><span class="header-section-number">9</span> Within-Subjects t-test</a></li>
<li class="book-part">Correlations</li>
<li><a class="" href="pearson-correlation.html"><span class="header-section-number">9</span> Pearson Correlation</a></li>
<li><a class="" href="spearman-correlation.html"><span class="header-section-number">10</span> Spearman Correlation</a></li>
<li><a class="" href="pearson-correlation.html"><span class="header-section-number">10</span> Pearson Correlation</a></li>
<li><a class="" href="spearman-correlation.html"><span class="header-section-number">11</span> Spearman Correlation</a></li>
<li class="book-part">Linear Regression</li>
<li><a class="" href="simple-linear-regression.html"><span class="header-section-number">11</span> Simple Linear Regression</a></li>
<li><a class="" href="simple-linear-regression.html"><span class="header-section-number">12</span> Simple Linear Regression</a></li>
<li class="book-part">ANOVAs</li>
<li><a class="" href="anova.html"><span class="header-section-number">12</span> ANOVA</a></li>
<li><a class="" href="anova.html"><span class="header-section-number">13</span> ANOVA</a></li>
<li class="book-part">Additional</li>
<li><a class="" href="random-formulas.html"><span class="header-section-number">13</span> Random formulas</a></li>
<li><a class="" href="the-rounding-chapter.html"><span class="header-section-number">14</span> The Rounding Chapter</a></li>
<li><a class="" href="random-formulas.html"><span class="header-section-number">14</span> Random formulas</a></li>
<li><a class="" href="the-rounding-chapter.html"><span class="header-section-number">15</span> The Rounding Chapter</a></li>
<li class="book-part">Appendices</li>
<li><a class="" href="installing-r.html"><span class="header-section-number">A</span> Installing R</a></li>
<li><a class="" href="symbols.html"><span class="header-section-number">B</span> Symbols</a></li>
Expand Down
15 changes: 8 additions & 7 deletions docs/a-full-descriptive.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ <h1>
<li class="book-part">t-tests</li>
<li><a class="" href="one-sample-t-test.html"><span class="header-section-number">6</span> One-Sample t-test</a></li>
<li><a class="" href="between-subjects-students-t-test.html"><span class="header-section-number">7</span> Between-Subjects Student's t-test</a></li>
<li><a class="" href="within-subjects-t-test.html"><span class="header-section-number">8</span> Within-Subjects t-test</a></li>
<li><a class="" href="between-subjects-welchs-t-test.html"><span class="header-section-number">8</span> Between-Subjects Welch's t-test</a></li>
<li><a class="" href="within-subjects-t-test.html"><span class="header-section-number">9</span> Within-Subjects t-test</a></li>
<li class="book-part">Correlations</li>
<li><a class="" href="pearson-correlation.html"><span class="header-section-number">9</span> Pearson Correlation</a></li>
<li><a class="" href="spearman-correlation.html"><span class="header-section-number">10</span> Spearman Correlation</a></li>
<li><a class="" href="pearson-correlation.html"><span class="header-section-number">10</span> Pearson Correlation</a></li>
<li><a class="" href="spearman-correlation.html"><span class="header-section-number">11</span> Spearman Correlation</a></li>
<li class="book-part">Linear Regression</li>
<li><a class="" href="simple-linear-regression.html"><span class="header-section-number">11</span> Simple Linear Regression</a></li>
<li><a class="" href="simple-linear-regression.html"><span class="header-section-number">12</span> Simple Linear Regression</a></li>
<li class="book-part">ANOVAs</li>
<li><a class="" href="anova.html"><span class="header-section-number">12</span> ANOVA</a></li>
<li><a class="" href="anova.html"><span class="header-section-number">13</span> ANOVA</a></li>
<li class="book-part">Additional</li>
<li><a class="" href="random-formulas.html"><span class="header-section-number">13</span> Random formulas</a></li>
<li><a class="" href="the-rounding-chapter.html"><span class="header-section-number">14</span> The Rounding Chapter</a></li>
<li><a class="" href="random-formulas.html"><span class="header-section-number">14</span> Random formulas</a></li>
<li><a class="" href="the-rounding-chapter.html"><span class="header-section-number">15</span> The Rounding Chapter</a></li>
<li class="book-part">Appendices</li>
<li><a class="" href="installing-r.html"><span class="header-section-number">A</span> Installing R</a></li>
<li><a class="" href="symbols.html"><span class="header-section-number">B</span> Symbols</a></li>
Expand Down
Loading

0 comments on commit d23f9cd

Please sign in to comment.