06.09.2021 Views

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3 placebo 0.1 0.45 -0.350 0.1225<br />

4 anxifree 0.6 0.72 -0.117 0.0136<br />

5 anxifree 0.4 0.72 -0.317 0.1003<br />

BLAH BLAH BLAH<br />

16 joyzepam 1.8 1.48 0.317 0.1003<br />

17 joyzepam 1.3 1.48 -0.183 0.0336<br />

18 joyzepam 1.4 1.48 -0.083 0.0069<br />

If you compare this output to the contents of the table I’ve been constructing by h<strong>and</strong>, you can see that<br />

R has done exactly the same calculations that I was doing, <strong>and</strong> much faster too. So, if we want to finish<br />

the calculations of the <strong>with</strong>in-group sum of squares in R, we just ask <strong>for</strong> the sum() of the squared.devs<br />

variable:<br />

> SSw print( SSw )<br />

[1] 1.39<br />

Obviously, this isn’t the same as what I calculated, because R used all 18 observations. But if I’d typed<br />

sum( squared.devs[1:5] ) instead, it would have given the same answer that I got earlier.<br />

Okay. Now that we’ve calculated the <strong>with</strong>in groups variation, SS w , it’s time to turn our attention<br />

to the between-group sum of squares, SS b . The calculations <strong>for</strong> this case are very similar. The main<br />

difference is that, instead of calculating the differences between an observation Y ik <strong>and</strong> a group mean Ȳk<br />

<strong>for</strong> all of the observations, we calculate the differences between the group means Ȳk <strong>and</strong> the gr<strong>and</strong> mean<br />

Ȳ (in this case 0.88) <strong>for</strong> all of the groups...<br />

group group mean gr<strong>and</strong> mean deviation squared deviations<br />

k Ȳ k Ȳ Ȳ k ´ Ȳ pȲk ´ Ȳ q2<br />

placebo 0.45 0.88 -0.43 0.18<br />

anxifree 0.72 0.88 -0.16 0.03<br />

joyzepam 1.48 0.88 0.60 0.36<br />

However, <strong>for</strong> the between group calculations we need to multiply each of these squared deviations by<br />

N k , the number of observations in the group. We do this because every observation in the group (all N k<br />

of them) is associated <strong>with</strong> a between group difference. So if there are six people in the placebo group,<br />

<strong>and</strong> the placebo group mean differs from the gr<strong>and</strong> mean by 0.19, then the total between group variation<br />

associated <strong>with</strong> these six people is 6 ˆ 0.16 “ 1.14. So we have to extend our little table of calculations...<br />

group ... squared deviations sample size weighted squared dev<br />

k ... pȲk ´ Ȳ q2 N k N k pȲk ´ Ȳ q2<br />

placebo ... 0.18 6 1.11<br />

anxifree ... 0.03 6 0.16<br />

joyzepam ... 0.36 6 2.18<br />

And so now our between group sum of squares is obtained by summing these “weighted squared deviations”<br />

over all three groups in the study:<br />

SS b “ 1.11 ` 0.16 ` 2.18<br />

“ 3.45<br />

As you can see, the between group calculations are a lot shorter, so you probably wouldn’t usually want<br />

to b<strong>other</strong> using R as your calculator. However, if you did decide to do so, here’s one way you could do it:<br />

- 435 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!