Skip to content

Commit

Permalink
Built site for gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
LGraz committed Nov 29, 2024
1 parent 42f292e commit 9add92a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .nojekyll
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5df63f73
fa758123
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ <h2 data-anchor-id="some-statistical-investigations">Some Statistical Investigat
</tr>
</thead>
<tbody class="list">
<tr data-index="0" data-listing-date-sort="1732834800000" data-listing-file-modified-sort="1732893586347" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="238" data-listing-title-sort="One-sided tests for Linear Mixed Models" data-listing-filename-sort="index.qmd">
<tr data-index="0" data-listing-date-sort="1732834800000" data-listing-file-modified-sort="1732893975053" data-listing-date-modified-sort="NaN" data-listing-reading-time-sort="2" data-listing-word-count-sort="303" data-listing-title-sort="One-sided tests for Linear Mixed Models" data-listing-filename-sort="index.qmd">
<td>
<span class="listing-date">Nov 29, 2024</span>
</td>
Expand Down
9 changes: 7 additions & 2 deletions posts/lmm-one-sided-t-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,12 @@ <h1>fit linear mixed model</h1>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(lmerTest)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>D<span class="sc">$</span>group <span class="ot">&lt;-</span> <span class="fu">factor</span>(D<span class="sc">$</span>group)</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>fit <span class="ot">&lt;-</span> <span class="fu">lmer</span>(AUC <span class="sc">~</span> group <span class="sc">+</span> repetition <span class="sc">+</span> (<span class="dv">1</span><span class="sc">|</span>cage), <span class="at">data=</span>D)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="co"># if we only analyze the first repetition:</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="co"># fit &lt;- lmer(AUC ~ group + (1|cage), data=D)</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="co"># otherwise:</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>fit <span class="ot">&lt;-</span> <span class="fu">lmer</span>(AUC <span class="sc">~</span> group <span class="sc">+</span> repetition <span class="sc">+</span> (<span class="dv">1</span><span class="sc">|</span>cage), <span class="at">data=</span>D)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
<section id="anova-and-two-sided-t-test" class="level1">
Expand Down Expand Up @@ -683,7 +688,7 @@ <h1>one-sided t-test</h1>
B &gt; A : 0.9709984 </code></pre>
</div>
</div>
<p>The one-sided p-value corresponds to half the two-sided p-value, if and only if the reference group is the one supposed to be smaller.</p>
<p>The one-sided p-value corresponds to half the two-sided p-value, if and only if the reference group is the one supposed to be smaller. The reference group is a term in R, and is (unless specified) the groupname that comes first in the alphabet. In this case, the reference group is groupA. So the one-sided p-value for groupB &gt; groupA is 0.029 which also equals 0.058/2.</p>


</section>
Expand Down
2 changes: 1 addition & 1 deletion search.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"href": "posts/lmm-one-sided-t-tests/index.html",
"title": "One-sided tests for Linear Mixed Models",
"section": "",
"text": "Simulate (and show) some Data\nfit linear mixed model\nanova and two-sided t-test\none-sided t-test\n\n\nsimulate data\nSimulate data for 2 groups, 3 repetition, 5 cages per repetition, 2 mice of each group per cage\n\n\nCode\ngroup_effect &lt;- 1\n\nset.seed(321)\nD &lt;- data.frame(\n repetition = rep(as.factor(1:3), each=20),\n cage = factor(rep(1:15, each=4)),\n group = rep(c(\"A\", \"B\"), each=2, times=15)\n)\n\n# cage effect\ncage_effect &lt;- data.frame(\n cage = unique(D$cage),\n cage_effect = rnorm(length(unique(D$cage)), sd=0.4) |&gt; round(2)\n)\n\nD &lt;- merge(cage_effect, D, by=\"cage\", sort=FALSE)\nD$AUC &lt;- rnorm(nrow(D), mean=10, sd=2) + D$cage_effect + \n ifelse(D$group == \"B\", group_effect, 0)\nD$cage_effect &lt;- NULL\n\nknitr::kable(D)\n\n\n\n\n\ncage\nrepetition\ngroup\nAUC\n\n\n\n\n1\n1\nA\n9.070657\n\n\n1\n1\nA\n11.592138\n\n\n1\n1\nB\n12.520665\n\n\n1\n1\nB\n12.835169\n\n\n2\n1\nA\n10.612712\n\n\n2\n1\nA\n11.554511\n\n\n2\n1\nB\n10.505877\n\n\n2\n1\nB\n12.696671\n\n\n3\n1\nA\n7.745522\n\n\n3\n1\nA\n8.373969\n\n\n3\n1\nB\n11.080001\n\n\n3\n1\nB\n6.228138\n\n\n4\n1\nA\n10.785032\n\n\n4\n1\nA\n7.709345\n\n\n4\n1\nB\n10.000631\n\n\n4\n1\nB\n7.889176\n\n\n5\n1\nA\n10.781430\n\n\n5\n1\nA\n11.218396\n\n\n5\n1\nB\n13.411695\n\n\n5\n1\nB\n10.640873\n\n\n6\n2\nA\n10.339079\n\n\n6\n2\nA\n5.657473\n\n\n6\n2\nB\n14.381581\n\n\n6\n2\nB\n10.791359\n\n\n7\n2\nA\n10.346535\n\n\n7\n2\nA\n7.216693\n\n\n7\n2\nB\n11.446316\n\n\n7\n2\nB\n11.790792\n\n\n8\n2\nA\n10.578174\n\n\n8\n2\nA\n11.689476\n\n\n8\n2\nB\n11.772819\n\n\n8\n2\nB\n11.607435\n\n\n9\n2\nA\n12.047757\n\n\n9\n2\nA\n12.412829\n\n\n9\n2\nB\n9.171424\n\n\n9\n2\nB\n9.320691\n\n\n10\n2\nA\n8.001816\n\n\n10\n2\nA\n9.281320\n\n\n10\n2\nB\n11.421702\n\n\n10\n2\nB\n9.449261\n\n\n11\n3\nA\n8.122167\n\n\n11\n3\nA\n10.822403\n\n\n11\n3\nB\n11.916796\n\n\n11\n3\nB\n14.680328\n\n\n12\n3\nA\n11.015324\n\n\n12\n3\nA\n13.514035\n\n\n12\n3\nB\n11.700311\n\n\n12\n3\nB\n14.086357\n\n\n13\n3\nA\n8.083916\n\n\n13\n3\nA\n12.421829\n\n\n13\n3\nB\n6.086836\n\n\n13\n3\nB\n10.293708\n\n\n14\n3\nA\n10.653113\n\n\n14\n3\nA\n12.397645\n\n\n14\n3\nB\n9.655439\n\n\n14\n3\nB\n9.994885\n\n\n15\n3\nA\n8.795892\n\n\n15\n3\nA\n9.361011\n\n\n15\n3\nB\n11.279876\n\n\n15\n3\nB\n11.528820\n\n\n\n\n\n\n\nfit linear mixed model\n\nlibrary(lmerTest)\nD$group &lt;- factor(D$group)\nfit &lt;- lmer(AUC ~ group + repetition + (1|cage), data=D)\n\n\n\nanova and two-sided t-test\n\nanova(fit)\n\nType III Analysis of Variance Table with Satterthwaite's method\n Sum Sq Mean Sq NumDF DenDF F value Pr(&gt;F) \ngroup 13.0512 13.0512 1 44 3.7887 0.0580 .\nrepetition 1.4311 0.7156 2 12 0.2077 0.8153 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nsummary(fit) # look at the p-value of groupB\n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: AUC ~ group + repetition + (1 | cage)\n Data: D\n\nREML criterion at convergence: 246.2\n\nScaled residuals: \n Min 1Q Median 3Q Max \n-2.4500 -0.6722 0.1466 0.6608 1.9061 \n\nRandom effects:\n Groups Name Variance Std.Dev.\n cage (Intercept) 0.5942 0.7709 \n Residual 3.4448 1.8560 \nNumber of obs: 60, groups: cage, 15\n\nFixed effects:\n Estimate Std. Error df t value Pr(&gt;|t|) \n(Intercept) 9.8962 0.5903 17.0200 16.764 5.14e-12 ***\ngroupB 0.9328 0.4792 44.0000 1.946 0.058 . \nrepetition2 0.0736 0.7630 12.0000 0.096 0.925 \nrepetition3 0.4579 0.7630 12.0000 0.600 0.560 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nCorrelation of Fixed Effects:\n (Intr) groupB rpttn2\ngroupB -0.406 \nrepetition2 -0.646 0.000 \nrepetition3 -0.646 0.000 0.500\n\n\nSo groupB is 0.93 bigger than groupA. The p-value is 0.058.\n\n\none-sided t-test\nsee this stackoverflow post\n\nCOEFS &lt;- coef(summary(fit))\n\n# put here your names for the groups\ngroup_A_name &lt;- levels(D$group)[1]\ngroup_B_name &lt;- levels(D$group)[2]\n\nt_val &lt;- COEFS[2, \"t value\"]\ndf &lt;- COEFS[2, \"df\"]\n\n# PVALUE: one-sided t-test for groupB &gt; groupA\np_val &lt;- pt(t_val, df, lower.tail=FALSE)\n\ncat(\"p-value for one-sided t-test for the alternative hypothethis:\\n\", \n levels(D$group)[2], \"&gt;\", levels(D$group)[1], \":\", p_val, \"\\n\")\n\np-value for one-sided t-test for the alternative hypothethis:\n B &gt; A : 0.02900157 \n\n# PVALUE: one-sided t-test for groupB &lt; groupA\np_val &lt;- pt(t_val, df, lower.tail=TRUE)\ncat(\"p-value for one-sided t-test for the alternative hypothethis:\\n\", \n levels(D$group)[2], \"&gt;\", levels(D$group)[1], \":\", p_val, \"\\n\")\n\np-value for one-sided t-test for the alternative hypothethis:\n B &gt; A : 0.9709984 \n\n\nThe one-sided p-value corresponds to half the two-sided p-value, if and only if the reference group is the one supposed to be smaller."
"text": "Simulate (and show) some Data\nfit linear mixed model\nanova and two-sided t-test\none-sided t-test\n\n\nsimulate data\nSimulate data for 2 groups, 3 repetition, 5 cages per repetition, 2 mice of each group per cage\n\n\nCode\ngroup_effect &lt;- 1\n\nset.seed(321)\nD &lt;- data.frame(\n repetition = rep(as.factor(1:3), each=20),\n cage = factor(rep(1:15, each=4)),\n group = rep(c(\"A\", \"B\"), each=2, times=15)\n)\n\n# cage effect\ncage_effect &lt;- data.frame(\n cage = unique(D$cage),\n cage_effect = rnorm(length(unique(D$cage)), sd=0.4) |&gt; round(2)\n)\n\nD &lt;- merge(cage_effect, D, by=\"cage\", sort=FALSE)\nD$AUC &lt;- rnorm(nrow(D), mean=10, sd=2) + D$cage_effect + \n ifelse(D$group == \"B\", group_effect, 0)\nD$cage_effect &lt;- NULL\n\nknitr::kable(D)\n\n\n\n\n\ncage\nrepetition\ngroup\nAUC\n\n\n\n\n1\n1\nA\n9.070657\n\n\n1\n1\nA\n11.592138\n\n\n1\n1\nB\n12.520665\n\n\n1\n1\nB\n12.835169\n\n\n2\n1\nA\n10.612712\n\n\n2\n1\nA\n11.554511\n\n\n2\n1\nB\n10.505877\n\n\n2\n1\nB\n12.696671\n\n\n3\n1\nA\n7.745522\n\n\n3\n1\nA\n8.373969\n\n\n3\n1\nB\n11.080001\n\n\n3\n1\nB\n6.228138\n\n\n4\n1\nA\n10.785032\n\n\n4\n1\nA\n7.709345\n\n\n4\n1\nB\n10.000631\n\n\n4\n1\nB\n7.889176\n\n\n5\n1\nA\n10.781430\n\n\n5\n1\nA\n11.218396\n\n\n5\n1\nB\n13.411695\n\n\n5\n1\nB\n10.640873\n\n\n6\n2\nA\n10.339079\n\n\n6\n2\nA\n5.657473\n\n\n6\n2\nB\n14.381581\n\n\n6\n2\nB\n10.791359\n\n\n7\n2\nA\n10.346535\n\n\n7\n2\nA\n7.216693\n\n\n7\n2\nB\n11.446316\n\n\n7\n2\nB\n11.790792\n\n\n8\n2\nA\n10.578174\n\n\n8\n2\nA\n11.689476\n\n\n8\n2\nB\n11.772819\n\n\n8\n2\nB\n11.607435\n\n\n9\n2\nA\n12.047757\n\n\n9\n2\nA\n12.412829\n\n\n9\n2\nB\n9.171424\n\n\n9\n2\nB\n9.320691\n\n\n10\n2\nA\n8.001816\n\n\n10\n2\nA\n9.281320\n\n\n10\n2\nB\n11.421702\n\n\n10\n2\nB\n9.449261\n\n\n11\n3\nA\n8.122167\n\n\n11\n3\nA\n10.822403\n\n\n11\n3\nB\n11.916796\n\n\n11\n3\nB\n14.680328\n\n\n12\n3\nA\n11.015324\n\n\n12\n3\nA\n13.514035\n\n\n12\n3\nB\n11.700311\n\n\n12\n3\nB\n14.086357\n\n\n13\n3\nA\n8.083916\n\n\n13\n3\nA\n12.421829\n\n\n13\n3\nB\n6.086836\n\n\n13\n3\nB\n10.293708\n\n\n14\n3\nA\n10.653113\n\n\n14\n3\nA\n12.397645\n\n\n14\n3\nB\n9.655439\n\n\n14\n3\nB\n9.994885\n\n\n15\n3\nA\n8.795892\n\n\n15\n3\nA\n9.361011\n\n\n15\n3\nB\n11.279876\n\n\n15\n3\nB\n11.528820\n\n\n\n\n\n\n\nfit linear mixed model\n\nlibrary(lmerTest)\nD$group &lt;- factor(D$group)\n\n# if we only analyze the first repetition:\n# fit &lt;- lmer(AUC ~ group + (1|cage), data=D)\n\n# otherwise:\nfit &lt;- lmer(AUC ~ group + repetition + (1|cage), data=D)\n\n\n\nanova and two-sided t-test\n\nanova(fit)\n\nType III Analysis of Variance Table with Satterthwaite's method\n Sum Sq Mean Sq NumDF DenDF F value Pr(&gt;F) \ngroup 13.0512 13.0512 1 44 3.7887 0.0580 .\nrepetition 1.4311 0.7156 2 12 0.2077 0.8153 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nsummary(fit) # look at the p-value of groupB\n\nLinear mixed model fit by REML. t-tests use Satterthwaite's method [\nlmerModLmerTest]\nFormula: AUC ~ group + repetition + (1 | cage)\n Data: D\n\nREML criterion at convergence: 246.2\n\nScaled residuals: \n Min 1Q Median 3Q Max \n-2.4500 -0.6722 0.1466 0.6608 1.9061 \n\nRandom effects:\n Groups Name Variance Std.Dev.\n cage (Intercept) 0.5942 0.7709 \n Residual 3.4448 1.8560 \nNumber of obs: 60, groups: cage, 15\n\nFixed effects:\n Estimate Std. Error df t value Pr(&gt;|t|) \n(Intercept) 9.8962 0.5903 17.0200 16.764 5.14e-12 ***\ngroupB 0.9328 0.4792 44.0000 1.946 0.058 . \nrepetition2 0.0736 0.7630 12.0000 0.096 0.925 \nrepetition3 0.4579 0.7630 12.0000 0.600 0.560 \n---\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1\n\nCorrelation of Fixed Effects:\n (Intr) groupB rpttn2\ngroupB -0.406 \nrepetition2 -0.646 0.000 \nrepetition3 -0.646 0.000 0.500\n\n\nSo groupB is 0.93 bigger than groupA. The p-value is 0.058.\n\n\none-sided t-test\nsee this stackoverflow post\n\nCOEFS &lt;- coef(summary(fit))\n\n# put here your names for the groups\ngroup_A_name &lt;- levels(D$group)[1]\ngroup_B_name &lt;- levels(D$group)[2]\n\nt_val &lt;- COEFS[2, \"t value\"]\ndf &lt;- COEFS[2, \"df\"]\n\n# PVALUE: one-sided t-test for groupB &gt; groupA\np_val &lt;- pt(t_val, df, lower.tail=FALSE)\n\ncat(\"p-value for one-sided t-test for the alternative hypothethis:\\n\", \n levels(D$group)[2], \"&gt;\", levels(D$group)[1], \":\", p_val, \"\\n\")\n\np-value for one-sided t-test for the alternative hypothethis:\n B &gt; A : 0.02900157 \n\n# PVALUE: one-sided t-test for groupB &lt; groupA\np_val &lt;- pt(t_val, df, lower.tail=TRUE)\ncat(\"p-value for one-sided t-test for the alternative hypothethis:\\n\", \n levels(D$group)[2], \"&gt;\", levels(D$group)[1], \":\", p_val, \"\\n\")\n\np-value for one-sided t-test for the alternative hypothethis:\n B &gt; A : 0.9709984 \n\n\nThe one-sided p-value corresponds to half the two-sided p-value, if and only if the reference group is the one supposed to be smaller. The reference group is a term in R, and is (unless specified) the groupname that comes first in the alphabet. In this case, the reference group is groupA. So the one-sided p-value for groupB &gt; groupA is 0.029 which also equals 0.058/2."
},
{
"objectID": "posts/lmer-slopes-new/index.html",
Expand Down
2 changes: 1 addition & 1 deletion sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</url>
<url>
<loc>https://lgraz.com/posts/lmm-one-sided-t-tests/index.html</loc>
<lastmod>2024-11-29T15:19:46.347Z</lastmod>
<lastmod>2024-11-29T15:26:15.053Z</lastmod>
</url>
<url>
<loc>https://lgraz.com/posts/lmer-slopes-new/index.html</loc>
Expand Down

0 comments on commit 9add92a

Please sign in to comment.