Note that there are some explanatory texts on larger screens.

plurals
  1. POusing tapply/dapply etc for t.tests
    primarykey
    data
    text
    <p>I have a data frame from an interlab study as follows <a href="http://pastebin.com/AD57AYD1" rel="nofollow">http://pastebin.com/AD57AYD1</a></p> <p>Essentially lab=Laboratory, mat=material, fab=strength, thick=thickness</p> <p>I want t.test data to compare each lab for each type of material. </p> <p>I.e., for mat=v, I want to run a t.test to compare lab B against lab S.</p> <p>Similarly for materials c, n and l.</p> <p>Due to my inability to work out how to do this efficiently, I create a column using the intaraction function (I know there must be easier ways!) and then run t.tests for each combination I am interested in.</p> <pre><code># create a new column with lab/mat factors combined interlab$allfacts&lt;-interaction(interlab$lab,interlab$mat) tv&lt;-with(interlab, t.test(fab[allfacts == "S.v"], fab[allfacts == "B.v"],var.equal=FALSE)) tv tl&lt;-with(interlab, t.test(fab[allfacts == "S.l"], fab[allfacts == "B.l"],var.equal=FALSE)) tl ... etc etc </code></pre> <p>I am sure that I should be able to use one of the plyr functions, perhaps something like this:</p> <pre><code>tapply(interlab$fab, list(interlab$lab,interlab$mat), t.test) </code></pre> <p>but this isn't working out.</p> <p>Any help much appreciated. Pete</p> <p>EDIT: Further to the comment below, I had also looked at the pairwise.t.test function in this respect, but it did too many comparisons (i.e., it did a t-test of lab B nitrile versus lab S vinyl - which is irrelevant. I called it like this:</p> <pre><code>pairwise.t.test(interlab$fab,interaction(interlab$mat,interlab$lab),paired=FALSE, pool.sd=FALSE) </code></pre> <p>and it gave me</p> <pre><code>&gt; pairwise.t.test(interlab$fab,interaction(interlab$mat,interlab$lab),paired=FALSE, pool.sd=FALSE) Pairwise comparisons using t tests with non-pooled SD data: interlab$fab and interaction(interlab$mat, interlab$lab) c.B l.B n.B v.B c.S l.S n.S l.B 0.54484 - - - - - - n.B 3.8e-07 1.9e-06 - - - - - v.B 0.93881 0.22393 3.6e-07 - - - - c.S 0.00576 0.93881 1.2e-05 0.00026 - - - l.S 0.00067 0.48601 2.5e-05 4.6e-05 0.89883 - - n.S 4.3e-12 2.2e-10 0.92366 5.4e-12 6.7e-10 7.7e-10 - v.S 0.93881 0.93881 1.9e-06 0.31885 0.01217 0.00169 1.3e-10 P value adjustment method: holm </code></pre> <p>I understand the problem with undertaking multiple comparisons and having to adjust the significance criteria. I just couldn't get the pairwise call to only do the tests I was interested in. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload