Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an anova table with letters for groupwise significant differences in R->latex?

Is there a package in R that produces tables like this one: enter image description here Basically, given a dataset of factors and variables, produces a nicely-formatted table with pairwise t-tests and letters indicating significance of differences?

Dummy data:

var = c(rnorm(100,mean=1,sd=2),rnorm(30,mean=-1,sd=2),rnorm(50,mean=0,sd=4))
factor = as.factor(c(rep(1,100),rep(2,30),rep(3,50))

How would I take that dummy data and turn it into (one column of) the example table?

like image 380
generic_user Avatar asked Dec 06 '25 10:12

generic_user


1 Answers


Disclaimer


Not an exact answer but it could be good start!!! Use tables package.

library(Hmisc)
library(tables)
stderr <- function(x) sd(x)/sqrt(length(x))
latex(
  object = tabular((Species+1) ~ All(iris)* PlusMinus(mean, stderr, digits=1), data=iris)
 , title = "Test"
 , file=""
 , size = "small"
 , cdot = 3
 , here = TRUE
 , booktabs=TRUE
 , center="centering"
 )

Output


enter image description here


Edited

You can obtain letters using multcompView package.


Code

library(multcompView)

Sepal.Length.fm <- aov(Sepal.Length~Species, data=iris)
Sepal.Length.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Sepal.Length.fm)$"Species"))$"Letters")

Sepal.Width.fm <- aov(Sepal.Width~Species, data=iris)
Sepal.Width.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Sepal.Width.fm)$"Species"))$"Letters")

Petal.Length.fm <- aov(Petal.Length~Species, data=iris)
Petal.Length.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Petal.Length.fm)$"Species"))$"Letters")

Petal.Width.fm <- aov(Petal.Width~Species, data=iris)
Petal.Width.Letters <- data.frame("Letters"=multcompLetters(extract_p(TukeyHSD(Petal.Width.fm)$"Species"))$"Letters")

Letters <- cbind(Sepal.Length.Letters, Sepal.Width.Letters, Petal.Length.Letters, Petal.Width.Letters)

Output

           Letters Letters Letters Letters
versicolor       a       a       a       a
virginica        b       b       b       b
setosa           c       c       c       c
like image 88
MYaseen208 Avatar answered Dec 08 '25 01:12

MYaseen208



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!