如何用名字打印方差分析
How to Print Anova with names
我正在使用 R 进行方差分析,但是我在打印带有名称的方差 table 时遇到问题。
这是我的输出:
我希望输出是这样的:
示例数据
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
这是我的代码:
library(haven)
ESS8IE <- read_sav("ESS8IE.sav")
View(ESS8IE)
head(ESS8IE)
res.aov <- aov(nwspol ~ as.factor(polintr), data = ESS8IE)
TukeyHSD(res.aov)
我下载了你的文件并像这样读入 R:
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
然后我转换为仅包含感兴趣变量的数据框(因为由于标签重复,R 似乎不想转换整个数据集)
df <- data.frame(nwspol = ESS8IE$nwspol, polintr = ESS8IE$polintr)
然后我 运行 你的 aov
没有 指定 as.factor
:
res.aov <- aov(nwspol ~ polintr, data = df)
这给了我们:
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
由 reprex package (v2.0.1)
创建于 2022-03-04
我正在使用 R 进行方差分析,但是我在打印带有名称的方差 table 时遇到问题。
这是我的输出:
我希望输出是这样的:
示例数据
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
这是我的代码:
library(haven)
ESS8IE <- read_sav("ESS8IE.sav")
View(ESS8IE)
head(ESS8IE)
res.aov <- aov(nwspol ~ as.factor(polintr), data = ESS8IE)
TukeyHSD(res.aov)
我下载了你的文件并像这样读入 R:
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
然后我转换为仅包含感兴趣变量的数据框(因为由于标签重复,R 似乎不想转换整个数据集)
df <- data.frame(nwspol = ESS8IE$nwspol, polintr = ESS8IE$polintr)
然后我 运行 你的 aov
没有 指定 as.factor
:
res.aov <- aov(nwspol ~ polintr, data = df)
这给了我们:
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
由 reprex package (v2.0.1)
创建于 2022-03-04