“用R进行单因素方差分析”的版本间的差异

来自OBHRM百科
跳转至: 导航搜索
(创建页面,内容为“==脚本与注释== <pre>datafilename="http://personality-project.org/r/datasets/R.appendix1.data" # 数据文件所在位置 mydata=read.table(datafilename,header=...”)
 
 
第7行: 第7行:
 
print(model.tables(aovresult,"means"),digits=3) # 显示平均值、样本数量等
 
print(model.tables(aovresult,"means"),digits=3) # 显示平均值、样本数量等
 
boxplot(Alertness~group,data=mydata)            # 画图</pre>
 
boxplot(Alertness~group,data=mydata)            # 画图</pre>
 +
 +
==结果==
 +
<pre>> summary(aovresult)                              # 显示单因素方程分析总体结果
 +
            Df Sum Sq Mean Sq F value  Pr(>F) 
 +
group        2  426.2  213.12  8.789 0.00298 **
 +
Residuals  15  363.8  24.25                 
 +
---
 +
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
> print(model.tables(aovresult,"means"),digits=3) # 显示平均值、样本数量等
 +
Tables of means
 +
Grand mean
 +
       
 +
27.66667
 +
 +
group
 +
      a    b    c
 +
    32.5 28.2 19.2
 +
rep  6.0  8.0  4.0</pre>

2017年3月8日 (三) 17:12的最新版本

脚本与注释

datafilename="http://personality-project.org/r/datasets/R.appendix1.data"  # 数据文件所在位置
mydata=read.table(datafilename,header=T)   #读取数据文件
names(mydata) <-c("group", "Alertness")    # 给变量命名,一个命名为group,另一个为Alertness
aovresult <- aov(Alertness~group,data=mydata)   # 进行单因素方差分析,结果保存到avoresult
summary(aovresult)                              # 显示单因素方程分析总体结果
print(model.tables(aovresult,"means"),digits=3) # 显示平均值、样本数量等
boxplot(Alertness~group,data=mydata)            # 画图

结果

> summary(aovresult)                              # 显示单因素方程分析总体结果
            Df Sum Sq Mean Sq F value  Pr(>F)   
group        2  426.2  213.12   8.789 0.00298 **
Residuals   15  363.8   24.25                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> print(model.tables(aovresult,"means"),digits=3) # 显示平均值、样本数量等
Tables of means
Grand mean
         
27.66667 

 group 
       a    b    c
    32.5 28.2 19.2
rep  6.0  8.0  4.0