
<?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-Twoway</id>
	<title>Anova-Twoway - 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-Twoway"/>
	<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Twoway&amp;action=history"/>
	<updated>2026-07-09T19:27:28Z</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-Twoway&amp;diff=4862&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-Twoway&amp;diff=4862&amp;oldid=prev"/>
		<updated>2016-10-28T05:18:55Z</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;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;!-- diff cache key raj_wiki:diff:1.41:old-2992:rev-4862:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
	<entry>
		<id>https://www.rajkumar.in/index.php?title=Anova-Twoway&amp;diff=2992&amp;oldid=prev</id>
		<title>Raj: Created page with &quot;:Category:R   &lt;source line&gt;   # twoway.r # code for two way ANOVA  food &lt;- read.csv(&#039;food.csv&#039;, as.is=T) food$type.f &lt;- factor(food$type) food$sex.f &lt;- factor(food$sex)  #...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.rajkumar.in/index.php?title=Anova-Twoway&amp;diff=2992&amp;oldid=prev"/>
		<updated>2013-08-06T09:23:37Z</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;   # twoway.r # code for two way ANOVA  food &amp;lt;- read.csv(&amp;#039;food.csv&amp;#039;, as.is=T) food$type.f &amp;lt;- factor(food$type) food$sex.f &amp;lt;- factor(food$sex)  #...&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;
&lt;br /&gt;
&amp;lt;source line&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# twoway.r&lt;br /&gt;
# code for two way ANOVA&lt;br /&gt;
&lt;br /&gt;
food &amp;lt;- read.csv(&amp;#039;food.csv&amp;#039;, as.is=T)&lt;br /&gt;
food$type.f &amp;lt;- factor(food$type)&lt;br /&gt;
food$sex.f &amp;lt;- factor(food$sex)&lt;br /&gt;
&lt;br /&gt;
# can fit using lm, but more helper functions &lt;br /&gt;
#   available with aov()&lt;br /&gt;
diet.aov &amp;lt;- aov(y ~ type.f + sex.f + type.f:sex.f,data=food)&lt;br /&gt;
#   note : specifies the interaction&lt;br /&gt;
#   also have all the usual lm() helper functions&lt;br /&gt;
&lt;br /&gt;
# a shortcut  * specifies all main effects and interaction&lt;br /&gt;
diet.aov &amp;lt;- aov(y ~ type.f*sex.f,data=food)&lt;br /&gt;
#   equivalent to first model&lt;br /&gt;
&lt;br /&gt;
anova(diet.aov)&lt;br /&gt;
#   gives sequential (type I) SS&lt;br /&gt;
#   but same as type III for balanced data&lt;br /&gt;
&lt;br /&gt;
model.tables(diet.aov)&lt;br /&gt;
#   tables of means&lt;br /&gt;
&lt;br /&gt;
rat &amp;lt;- read.csv(&amp;#039;ratweight.csv&amp;#039;,as.is=T)&lt;br /&gt;
rat$amount.f &amp;lt;- factor(rat$amount)&lt;br /&gt;
rat$type.f &amp;lt;- factor(rat$type)&lt;br /&gt;
&lt;br /&gt;
replications(rat)&lt;br /&gt;
#  gives number of replicates for each factor&lt;br /&gt;
&lt;br /&gt;
table(rat$amount,rat$type)&lt;br /&gt;
#  2 x 3 table of counts for each treatment&lt;br /&gt;
&lt;br /&gt;
rat.aov &amp;lt;- aov(gain ~ amount.f*type.f,data=rat)&lt;br /&gt;
#  BEWARE: type I (sequential SS)&lt;br /&gt;
&lt;br /&gt;
# to get type III SS, need to declare othogonal contrasts&lt;br /&gt;
#   can do that factor by factor, but the following does it for all&lt;br /&gt;
options(contrasts=c(&amp;#039;contr.helmert&amp;#039;,&amp;#039;contr.poly&amp;#039;))&lt;br /&gt;
#  first string is the contrast for unordered factors&lt;br /&gt;
#  the second for ordered factors&lt;br /&gt;
&lt;br /&gt;
rat.aov2 &amp;lt;- aov(gain ~ amount.f*type.f,data=rat)&lt;br /&gt;
&lt;br /&gt;
drop1(rat.aov2,~.)&lt;br /&gt;
#  drop each term from full model =&amp;gt; type III SS&lt;br /&gt;
#  second argument specifies all terms&lt;br /&gt;
&lt;br /&gt;
drop1(rat.aov, ~.)&lt;br /&gt;
#  rat.aov() was fit using default contr.treatment&lt;br /&gt;
#  very different and very wrong numbers if&lt;br /&gt;
#   forget to use an orthogonal parameterization&lt;br /&gt;
&lt;br /&gt;
# getting marginal means is gruesome!&lt;br /&gt;
# model.tables() gives you the wrong numbers&lt;br /&gt;
# They are not the lsmeans and not the raw means&lt;br /&gt;
# I haven&amp;#039;t taken the time to figure out what they are&lt;br /&gt;
&lt;br /&gt;
# easiest way I know is to fit a cell means model&lt;br /&gt;
#  and construct your own contrast matrices&lt;br /&gt;
&lt;br /&gt;
rat.aov3 &amp;lt;- aov(gain ~ -1 + amount.f:type.f, data=rat)&lt;br /&gt;
# a cell means model (no intercept, one X column&lt;br /&gt;
#   for each combination of amount and type&lt;br /&gt;
coef(rat.aov3)&lt;br /&gt;
&lt;br /&gt;
# There is at least one R package that tries to &lt;br /&gt;
#  calculate lsmeans automatically, but I know&lt;br /&gt;
#  one case where the computation is wrong.&lt;br /&gt;
#  (but appears correct).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Raj</name></author>
	</entry>
</feed>