Home > Net >  How to Print Anova with names
How to Print Anova with names

Time:03-05

I'm doing anova analysis using R, But I'm having trouble printing anova table with names.

Here's the dataset

Here's my output:
Here's my output

I want output to be like this:
I want output to be like this

Sample data

name    cntry   nwspol  polintr
ESS8e02_2   IE  60  3   
ESS8e02_2   IE  30  3   
ESS8e02_2   IE  150 2   
ESS8e02_2   IE  120 3   
ESS8e02_2   IE  60  3   
ESS8e02_2   IE  90  3   
ESS8e02_2   IE  180 2   
ESS8e02_2   IE  140 4   
ESS8e02_2   IE  30  3   
ESS8e02_2   IE  60  2   
ESS8e02_2   IE  120 2   
ESS8e02_2   IE  80  2   
ESS8e02_2   IE  30  2   
ESS8e02_2   IE  10  4   

here's my code:

library(haven)

ESS8IE <- read_sav("ESS8IE.sav")

View(ESS8IE)

head(ESS8IE)

res.aov <- aov(nwspol ~ as.factor(polintr), data = ESS8IE)

TukeyHSD(res.aov)

CodePudding user response:

I downloaded your file and read it into R like this:

library(memisc)

ESS8IE <- as.data.set(spss.system.file(path.expand("~/ESS8IE.sav")))
#> File character set is 'UTF-8'.
#> Converting character set to the local 'iso8859-1'.
#> Warning: 6 variables have duplicated labels:
#>   edlvdru, isco08, edlvpdru, isco08p, edlvfdru, edlvmdru

Then I converted to a data frame with just the variables of interest (since R doesn't seem to want to convert the whole data set because of the duplicated labels)

df     <- data.frame(nwspol = ESS8IE$nwspol, polintr = ESS8IE$polintr)

Then I ran your aov without specifying as.factor:

res.aov <- aov(nwspol ~ polintr, data = df)

Which gives us:

TukeyHSD(res.aov)
#>   Tukey multiple comparisons of means
#>     95% family-wise confidence level
#> 
#> Fit: aov(formula = nwspol ~ polintr, data = df)
#> 
#> $polintr
#>                                              diff       lwr        upr
#> Quite interested-Very interested        -28.39317 -38.09591 -18.690420
#> Hardly interested-Very interested       -48.52669 -58.58877 -38.464596
#> Not at all interested-Very interested   -59.00698 -69.04518 -48.968790
#> Hardly interested-Quite interested      -20.13352 -27.39256 -12.874473
#> Not at all interested-Quite interested  -30.61382 -37.83971 -23.387930
#> Not at all interested-Hardly interested -10.48030 -18.18197  -2.778625
#>                                             p adj
#> Quite interested-Very interested        0.0000000
#> Hardly interested-Very interested       0.0000000
#> Not at all interested-Very interested   0.0000000
#> Hardly interested-Quite interested      0.0000000
#> Not at all interested-Quite interested  0.0000000
#> Not at all interested-Hardly interested 0.0026808

Created on 2022-03-04 by the reprex package (v2.0.1)

  • Related