<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Comparing Multiple Means in R	</title>
	<atom:link href="https://www.datanovia.com/en/courses/comparing-multiple-means-in-r/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.datanovia.com/en/courses/comparing-multiple-means-in-r/</link>
	<description>Data Mining and Statistics for Decision Support</description>
	<lastBuildDate>Wed, 23 Dec 2020 02:46:26 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Matt Berry		</title>
		<link>https://www.datanovia.com/en/courses/comparing-multiple-means-in-r/#comment-21435</link>

		<dc:creator><![CDATA[Matt Berry]]></dc:creator>
		<pubDate>Wed, 23 Dec 2020 02:46:26 +0000</pubDate>
		<guid isPermaLink="false">https://www.datanovia.com/en/?post_type=dt_courses&#038;p=10870#comment-21435</guid>

					<description><![CDATA[Having issues with trying to use ggplot to display emmeans pairwise results. I am wanting to see the contrast between all years not just within the same year. 
r script:
library(emmeans)    ### estimated marginal means and p values
library(sjstats)    ### partial eta squared and cohens f effect size
library(lme4)       ### estimated the multi level model (random intercept for participants)
library(lmerTest)   ### gives more comprehsive anova output with p values
library(MuMIn)      ### R2 for the model  
library(tidyverse) 
library(ggpubr) 
library(rstatix)
library(dplyr)
library(readxl)
library(scales)
library(ggsignif)
library(sjPlot)

#load data for One way linear mixed models, repeated measures ##########################
glm_test &#060;- read_excel(&#034;C:/Users/maber/Documents/Clover Valley/CLOVER VALLEY/veg data/LPI/UPL_cover.xlsx&#034;)
view(glm_test)
head(glm_test, 3)
#factor data#############tell it you have factors and what they are called##############
glm_test$year &#060;- factor(glm_test$year,
                        levels = c(1, 2, 3),
                        labels = c(&#034;2018&#034;, &#034;2019&#034;, &#034;2020&#034;))


glm_test$transect &#060;- factor(glm_test$transect,
                            levels = c(1, 2,3),
                            labels = c(&#034;Lower Meadow&#034;, &#034;Middle Meadow&#034;, &#034;Upper Meadow&#034;))

###R knows your factors, the below command brakes down your variables
summary(glm_test)

#run linear model with cover as dependent varible, year as #############################
#independent var. for the plot by stating + (1&#124; plot), This makes it a repeated measures
#we call our linear model lmer1
#set up the model use the following code

lmer2 &#060;- lmer(cover ~ as.factor(year) * as.factor(transect) + (1&#124;plot), 
              data = glm_test)

#linear model dep variable predicted by the indep variable (year)#####################
#run the model with the following code
anova(lmer2)
summary(aov(cover ~ as.factor(year) * as.factor(transect) + Error (plot), 
            data = glm_test))



#post Hoc comparisons###################################################
#emmeans(lmer2, list(pairwise ~ year), adjust = &#034;bonferroni&#034;)

emmeans(lmer2, list(pairwise ~ year), adjust = &#034;tukey&#034;)


# if there was an interaction your code would be this###################

emmeans(lmer2, pairwise ~ year &#124; transect)

tab_model(lmer2)

#Visulize data #########################################################

ggboxplot(glm_test, x = &#034;transect&#034;, y = &#034;cover&#034;, title = &#034;Total % Cover of Upland Species&#034;,
          ylab = &#034; % Cover UPL Species&#034;,
          color = &#034;year&#034;, ggtheme = theme_gray(base_size = 14))+
  scale_x_discrete(labels = label_wrap_gen(7)) + 
  stat_compare_means(comparisons = my_comparisons, label.y = c(65, 75, 80))+
  stat_compare_means(label.y = 82)



The results I want to plot are:
transect = Upper Meadow:
 contrast    estimate   SE df t.ratio p.value
 2018 - 2019   27.500 7.15 38  3.848  0.0013 
 2018 - 2020   20.000 7.15 38  2.798  0.0214 
 2019 - 2020   -7.500 7.15 38 -1.049  0.5509

Link to HTML doc. file:///C:/Users/maber/Documents/Clover%20Valley/CLOVER%20VALLEY/veg%20data/one%20way%20linear%20mixed%20model,%20repeated%20Meas/two-way_liner_mixed_model_repeated_measures.html
data:
plot	transect	year	cover
D11_NORTH	1	1	24
D11_SOUTH	1	1	16
R27_NORTH	1	1	18
R27_SOUTH	1	1	8
R28_NORTH	1	1	64
R28_SOUTH	1	1	54
D11_NORTH	1	2	46
D11_SOUTH	1	2	38
R27_NORTH	1	2	2
R27_SOUTH	1	2	0
R28_NORTH	1	2	20
R28_SOUTH	1	2	34
D11_NORTH	1	3	44
D11_SOUTH	1	3	36
R27_NORTH	1	3	0
R27_SOUTH	1	3	0
R28_NORTH	1	3	26
R28_SOUTH	1	3	38
D13_NORTH	2	1	44
D13_SOUTH	2	1	30
D14_NORTH	2	1	0
D14_SOUTH	2	1	6
R25_NORTH	2	1	14
R25_SOUTH	2	1	2
R26_NORTH	2	1	20
R26_SOUTH	2	1	42
D13_NORTH	2	2	6
D13_SOUTH	2	2	0
D14_NORTH	2	2	2
D14_SOUTH	2	2	0
R25_NORTH	2	2	0
R25_SOUTH	2	2	14
R26_NORTH	2	2	0
R26_SOUTH	2	2	0
D13_NORTH	2	3	2
D13_SOUTH	2	3	8
D14_NORTH	2	3	0
D14_SOUTH	2	3	10
R25_NORTH	2	3	16
R25_SOUTH	2	3	0
R26_NORTH	2	3	18
R26_SOUTH	2	3	0
R21_NORTH	3	1	32
R21_SOUTH	3	1	82
R22_NORTH	3	1	52
R22_SOUTH	3	1	46
R23_NORTH	3	1	64
R23_SOUTH	3	1	68
R24_NORTH	3	1	8
R24_SOUTH	3	1	8
R21_NORTH	3	2	10
R21_SOUTH	3	2	16
R22_NORTH	3	2	10
R22_SOUTH	3	2	22
R23_NORTH	3	2	48
R23_SOUTH	3	2	28
R24_NORTH	3	2	4
R24_SOUTH	3	2	2
R21_NORTH	3	3	6
R21_SOUTH	3	3	10
R22_NORTH	3	3	16
R22_SOUTH	3	3	14
R23_NORTH	3	3	54
R23_SOUTH	3	3	82
R24_NORTH	3	3	16
R24_SOUTH	3	3	2]]></description>
			<content:encoded><![CDATA[<p>Having issues with trying to use ggplot to display emmeans pairwise results. I am wanting to see the contrast between all years not just within the same year.<br />
r script:<br />
library(emmeans)    ### estimated marginal means and p values<br />
library(sjstats)    ### partial eta squared and cohens f effect size<br />
library(lme4)       ### estimated the multi level model (random intercept for participants)<br />
library(lmerTest)   ### gives more comprehsive anova output with p values<br />
library(MuMIn)      ### R2 for the model<br />
library(tidyverse)<br />
library(ggpubr)<br />
library(rstatix)<br />
library(dplyr)<br />
library(readxl)<br />
library(scales)<br />
library(ggsignif)<br />
library(sjPlot)</p>
<p>#load data for One way linear mixed models, repeated measures ##########################<br />
glm_test &lt;- read_excel(&quot;C:/Users/maber/Documents/Clover Valley/CLOVER VALLEY/veg data/LPI/UPL_cover.xlsx&quot;)<br />
view(glm_test)<br />
head(glm_test, 3)<br />
#factor data#############tell it you have factors and what they are called##############<br />
glm_test$year &lt;- factor(glm_test$year,<br />
                        levels = c(1, 2, 3),<br />
                        labels = c(&quot;2018&quot;, &quot;2019&quot;, &quot;2020&quot;))</p>
<p>glm_test$transect &lt;- factor(glm_test$transect,<br />
                            levels = c(1, 2,3),<br />
                            labels = c(&quot;Lower Meadow&quot;, &quot;Middle Meadow&quot;, &quot;Upper Meadow&quot;))</p>
<p>###R knows your factors, the below command brakes down your variables<br />
summary(glm_test)</p>
<p>#run linear model with cover as dependent varible, year as #############################<br />
#independent var. for the plot by stating + (1| plot), This makes it a repeated measures<br />
#we call our linear model lmer1<br />
#set up the model use the following code</p>
<p>lmer2 &lt;- lmer(cover ~ as.factor(year) * as.factor(transect) + (1|plot),<br />
              data = glm_test)</p>
<p>#linear model dep variable predicted by the indep variable (year)#####################<br />
#run the model with the following code<br />
anova(lmer2)<br />
summary(aov(cover ~ as.factor(year) * as.factor(transect) + Error (plot),<br />
            data = glm_test))</p>
<p>#post Hoc comparisons###################################################<br />
#emmeans(lmer2, list(pairwise ~ year), adjust = &quot;bonferroni&quot;)</p>
<p>emmeans(lmer2, list(pairwise ~ year), adjust = &quot;tukey&quot;)</p>
<p># if there was an interaction your code would be this###################</p>
<p>emmeans(lmer2, pairwise ~ year | transect)</p>
<p>tab_model(lmer2)</p>
<p>#Visulize data #########################################################</p>
<p>ggboxplot(glm_test, x = &quot;transect&quot;, y = &quot;cover&quot;, title = &quot;Total % Cover of Upland Species&quot;,<br />
          ylab = &quot; % Cover UPL Species&quot;,<br />
          color = &quot;year&quot;, ggtheme = theme_gray(base_size = 14))+<br />
  scale_x_discrete(labels = label_wrap_gen(7)) +<br />
  stat_compare_means(comparisons = my_comparisons, label.y = c(65, 75, 80))+<br />
  stat_compare_means(label.y = 82)</p>
<p>The results I want to plot are:<br />
transect = Upper Meadow:<br />
 contrast    estimate   SE df t.ratio p.value<br />
 2018 &#8211; 2019   27.500 7.15 38  3.848  0.0013<br />
 2018 &#8211; 2020   20.000 7.15 38  2.798  0.0214<br />
 2019 &#8211; 2020   -7.500 7.15 38 -1.049  0.5509</p>
<p>Link to HTML doc. file:///C:/Users/maber/Documents/Clover%20Valley/CLOVER%20VALLEY/veg%20data/one%20way%20linear%20mixed%20model,%20repeated%20Meas/two-way_liner_mixed_model_repeated_measures.html<br />
data:<br />
plot	transect	year	cover<br />
D11_NORTH	1	1	24<br />
D11_SOUTH	1	1	16<br />
R27_NORTH	1	1	18<br />
R27_SOUTH	1	1	8<br />
R28_NORTH	1	1	64<br />
R28_SOUTH	1	1	54<br />
D11_NORTH	1	2	46<br />
D11_SOUTH	1	2	38<br />
R27_NORTH	1	2	2<br />
R27_SOUTH	1	2	0<br />
R28_NORTH	1	2	20<br />
R28_SOUTH	1	2	34<br />
D11_NORTH	1	3	44<br />
D11_SOUTH	1	3	36<br />
R27_NORTH	1	3	0<br />
R27_SOUTH	1	3	0<br />
R28_NORTH	1	3	26<br />
R28_SOUTH	1	3	38<br />
D13_NORTH	2	1	44<br />
D13_SOUTH	2	1	30<br />
D14_NORTH	2	1	0<br />
D14_SOUTH	2	1	6<br />
R25_NORTH	2	1	14<br />
R25_SOUTH	2	1	2<br />
R26_NORTH	2	1	20<br />
R26_SOUTH	2	1	42<br />
D13_NORTH	2	2	6<br />
D13_SOUTH	2	2	0<br />
D14_NORTH	2	2	2<br />
D14_SOUTH	2	2	0<br />
R25_NORTH	2	2	0<br />
R25_SOUTH	2	2	14<br />
R26_NORTH	2	2	0<br />
R26_SOUTH	2	2	0<br />
D13_NORTH	2	3	2<br />
D13_SOUTH	2	3	8<br />
D14_NORTH	2	3	0<br />
D14_SOUTH	2	3	10<br />
R25_NORTH	2	3	16<br />
R25_SOUTH	2	3	0<br />
R26_NORTH	2	3	18<br />
R26_SOUTH	2	3	0<br />
R21_NORTH	3	1	32<br />
R21_SOUTH	3	1	82<br />
R22_NORTH	3	1	52<br />
R22_SOUTH	3	1	46<br />
R23_NORTH	3	1	64<br />
R23_SOUTH	3	1	68<br />
R24_NORTH	3	1	8<br />
R24_SOUTH	3	1	8<br />
R21_NORTH	3	2	10<br />
R21_SOUTH	3	2	16<br />
R22_NORTH	3	2	10<br />
R22_SOUTH	3	2	22<br />
R23_NORTH	3	2	48<br />
R23_SOUTH	3	2	28<br />
R24_NORTH	3	2	4<br />
R24_SOUTH	3	2	2<br />
R21_NORTH	3	3	6<br />
R21_SOUTH	3	3	10<br />
R22_NORTH	3	3	16<br />
R22_SOUTH	3	3	14<br />
R23_NORTH	3	3	54<br />
R23_SOUTH	3	3	82<br />
R24_NORTH	3	3	16<br />
R24_SOUTH	3	3	2</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 111/160 objects using Memcached
Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 33/54 queries in 0.580 seconds using APC

Served from: www.datanovia.com @ 2025-07-22 21:54:01 by W3 Total Cache
-->