两个样本T测试绘图问题

时间:2015-10-29 17:19:17

标签: r

我一直在使用CVS文件作为数据框来进行一些T测试分析,并希望绘制结果。但是,我一直收到错误消息。有没有人有任何想法,为什么它不起作用?

> test1<- t.test(Cetinje$Ocjena.govora.Ocjena.govora..Pitanje.8.~ Cetinje$Pol.Identitet,alternative="two.sided",conf.level=0.95)
> test1

    Welch Two Sample t-test

data:  Cetinje$Ocjena.govora.Ocjena.govora..Pitanje.8. by Cetinje$Pol.Identitet
t = -3.665, df = 25.134, p-value = 0.001157
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.6018368 -0.4494452
sample estimates:
mean in group 1 mean in group 2 
       2.307692        3.333333 

plot(test1)

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

2 个答案:

答案 0 :(得分:0)

boxplot(Cetinje$Ocjena.govora.Ocjena.govora..Pitanje.8.~ Cetinje$Pol.Identitet)

答案 1 :(得分:0)

正如提到的另一个答案,您只需使用boxplot功能。您还可以通过简单的技巧标记显着差异:

# Significance thresholds
alpha = c(0.05, 0.01, 0.001)
symbols = c('***', '**', '*', '')
which_symbol = as.numeric(cut(test1$p.value, c(0, rev(alpha), 1)))

boxplot(Cetinje$Ocjena.govora.Ocjena.govora..Pitanje.8.~ Cetinje$Pol.Identitet)

ypos = max(Cetinje$Ocjena.govora.Ocjena.govora..Pitanje.8.[Cetinje$Pol.Identitet == levels(Cetinje$Pol.Identitet)[2]])
text(x = 2, y = ypos, symbols[which_symbol], cex = 1.5, adj = c(0.5, 0))

顺便提一下,代码表明好的变量名称是必不可少的;倒数第二行几乎不可读。通过更好的变量名称可以大大改善它。