
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.rajkumar.in/index.php?action=history&amp;feed=atom&amp;title=Anova-Oneway</id>
	<title>Anova-Oneway - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.rajkumar.in/index.php?action=history&amp;feed=atom&amp;title=Anova-Oneway"/>
	<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;action=history"/>
	<updated>2026-07-09T20:58:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=4861&amp;oldid=prev</id>
		<title>Raj at 05:18, 28 October 2016</title>
		<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=4861&amp;oldid=prev"/>
		<updated>2016-10-28T05:18:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:18, 28 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
	<entry>
		<id>https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2995&amp;oldid=prev</id>
		<title>Raj at 09:30, 6 August 2013</title>
		<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2995&amp;oldid=prev"/>
		<updated>2013-08-06T09:30:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:30, 6 August 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/ins&gt;Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
	<entry>
		<id>https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2994&amp;oldid=prev</id>
		<title>Raj at 09:26, 6 August 2013</title>
		<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2994&amp;oldid=prev"/>
		<updated>2013-08-06T09:26:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:26, 6 August 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:&lt;/del&gt;Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:R]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source line&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
	<entry>
		<id>https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2991&amp;oldid=prev</id>
		<title>Raj: Created page with &quot;:Category:R  &lt;source line&gt;  # oneway.r # code for 1-way ANOVA examples in R  diet &lt;- read.csv(&#039;diet.csv&#039;, as.is=T) diet &lt;- diet[diet$diet !=&#039;lopro&#039;,]  # I use as.is=T to f...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Oneway&amp;diff=2991&amp;oldid=prev"/>
		<updated>2013-08-06T09:22:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php/Category:R&quot; title=&quot;Category:R&quot;&gt;Category:R&lt;/a&gt;  &amp;lt;source line&amp;gt;  # oneway.r # code for 1-way ANOVA examples in R  diet &amp;lt;- read.csv(&amp;#039;diet.csv&amp;#039;, as.is=T) diet &amp;lt;- diet[diet$diet !=&amp;#039;lopro&amp;#039;,]  # I use as.is=T to f...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[:Category:R]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source line&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# oneway.r&lt;br /&gt;
# code for 1-way ANOVA examples in R&lt;br /&gt;
&lt;br /&gt;
diet &amp;lt;- read.csv(&amp;#039;diet.csv&amp;#039;, as.is=T)&lt;br /&gt;
diet &amp;lt;- diet[diet$diet !=&amp;#039;lopro&amp;#039;,]&lt;br /&gt;
&lt;br /&gt;
# I use as.is=T to force me to explicitly declare &lt;br /&gt;
#   factors. default conversion does not convert &lt;br /&gt;
#   factors with numeric levels.&lt;br /&gt;
&lt;br /&gt;
diet$diet.f &amp;lt;- factor(diet$diet)&lt;br /&gt;
&lt;br /&gt;
# anova using lm:&lt;br /&gt;
diet.lm &amp;lt;- lm(longevity ~ diet.f, data=diet)&lt;br /&gt;
&lt;br /&gt;
# lm() has lots of helper / reporting functions:&lt;br /&gt;
coef(diet.lm)         &lt;br /&gt;
   # coefficients&lt;br /&gt;
vcov(diet.lm)         &lt;br /&gt;
   # and their variance-covariance matrix&lt;br /&gt;
sqrt(diag(vcov(diet.lm)))  &lt;br /&gt;
   # se&amp;#039;s of the coefficients&lt;br /&gt;
anova(diet.lm)        &lt;br /&gt;
   # ANOVA table using type I = sequential SS&lt;br /&gt;
summary(diet.lm)      &lt;br /&gt;
   # lots of information&lt;br /&gt;
plot(predict(diet.lm), resid(diet.lm))   &lt;br /&gt;
   # plot of residuals vs predicted values&lt;br /&gt;
&lt;br /&gt;
# model comparison by hand:&lt;br /&gt;
diet.m0 &amp;lt;- lm(longevity ~ +1, data=diet)   &lt;br /&gt;
   # intercept only model&lt;br /&gt;
anova(diet.m0, diet.lm)    &lt;br /&gt;
   # change in SS from 1st to 2nd model&lt;br /&gt;
&lt;br /&gt;
drop1(diet.lm)         &lt;br /&gt;
   # drop one term at a time = type II SS&lt;br /&gt;
&lt;br /&gt;
# orthogonal contrasts&lt;br /&gt;
diet.means &amp;lt;- tapply(diet$longevity, diet$diet, mean)  &lt;br /&gt;
   # mean for each diet&lt;br /&gt;
diet.helm &amp;lt;- contr.helmert(5)   &lt;br /&gt;
   # matrix of Helmert coeff. for 5 groups&lt;br /&gt;
diet.c1 &amp;lt;- t(diet.helm) %*% diet.means   &lt;br /&gt;
   # estimate of each contrast&lt;br /&gt;
diet.ss1 &amp;lt;- 49*diet.c1^2/apply(diet.helm^2,2,sum)  &lt;br /&gt;
   # SS for each contrast&lt;br /&gt;
sum(diet.ss1)&lt;br /&gt;
&lt;br /&gt;
# second set of contrasts were hand entered&lt;br /&gt;
#  using diet.2nd &amp;lt;- rbind(c(-2,-1,0,1,2), ...)&lt;br /&gt;
&lt;br /&gt;
# third set: &lt;br /&gt;
diet.trt &amp;lt;- -contr.treatment(5)&lt;br /&gt;
diet.trt[1,] &amp;lt;- 1&lt;br /&gt;
&lt;br /&gt;
diet.c3 &amp;lt;- t(diet.trt) %*% diet.means   &lt;br /&gt;
   # estimate of each contrast&lt;br /&gt;
diet.ss3 &amp;lt;- 49*diet.c3^2/apply(diet.trt^2,2,sum)  &lt;br /&gt;
   # SS for each contrast&lt;br /&gt;
sum(diet.ss3)&lt;br /&gt;
&lt;br /&gt;
# C beta tests&lt;br /&gt;
diet.c1 &amp;lt;- t(diet.helm) %*% diet.means   &lt;br /&gt;
   # estimate of contrast&lt;br /&gt;
&lt;br /&gt;
X1 &amp;lt;- model.matrix(~ -1 + diet.f, data=diet)&lt;br /&gt;
   # X matrix using cell means parameterization&lt;br /&gt;
diet.cm1 &amp;lt;- t(diet.helm) %*% solve(t(X1) %*% X1) %*% &lt;br /&gt;
   diet.helm&lt;br /&gt;
&lt;br /&gt;
t(diet.c1) %*% solve(diet.cm1) %*% diet.c1&lt;br /&gt;
&lt;br /&gt;
# how do the explicit contrasts of cell means &lt;br /&gt;
#   compare to R using those contrasts?&lt;br /&gt;
&lt;br /&gt;
contrasts(diet$diet.f) &amp;lt;- contr.helmert  &lt;br /&gt;
#  tell R to use helmert contrasts &lt;br /&gt;
#  default is contr.treatment, &lt;br /&gt;
#    which is drop first level of the factor&lt;br /&gt;
#  contr.SAS is SAS-like (drop last level)&lt;br /&gt;
&lt;br /&gt;
diet.lmh &amp;lt;- lm(longevity ~ diet.f,data=diet)&lt;br /&gt;
coef(diet.lmh)&lt;br /&gt;
# coefficients are not the same as the &lt;br /&gt;
#   hand-computed contrasts!&lt;br /&gt;
&lt;br /&gt;
# the R coefficients are related to the&lt;br /&gt;
#   contrasts among cell means&lt;br /&gt;
&lt;br /&gt;
apply(diet.helm^2,2,sum)&lt;br /&gt;
   # sum of squared coefficients&lt;br /&gt;
   &lt;br /&gt;
coef(diet.lmh)[2:5] * c(2,6,12,20)&lt;br /&gt;
# these are the same as diet.c1&lt;br /&gt;
&lt;br /&gt;
# although R calls them contrasts, they really are not.&lt;br /&gt;
# they are columns of the X matrix for a regression.&lt;br /&gt;
model.matrix(diet.lmh)&lt;br /&gt;
&lt;br /&gt;
# can do C beta from the lm() information&lt;br /&gt;
&lt;br /&gt;
diet.mse &amp;lt;- 4687.7/240   # MSE = est of sigma^2&lt;br /&gt;
diet.clm &amp;lt;- coef(diet.lm)[2:5]&lt;br /&gt;
  # extract coefficients for diet factor&lt;br /&gt;
diet.vclm &amp;lt;- vcov(diet.lm)[2:5,2:5]&lt;br /&gt;
  # and their VC matrix&lt;br /&gt;
diet.mse * t(diet.clm) %*% solve(diet.vclm) %*% &lt;br /&gt;
    diet.clm&lt;br /&gt;
  # SS for diet&lt;br /&gt;
t(diet.clm) %*% solve(diet.vclm) %*% diet.clm/5&lt;br /&gt;
  # F statistic for diet (5 is # rows in C)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
</feed>