用R进行描述性统计

来自OBHRM百科
Lichaoping讨论 | 贡献2017年3月9日 (四) 17:08的版本 频次分析

跳转至: 导航搜索

频次分析

可以用descr包中的freq()函数来进行频次分析。 脚本与注释

datafilename <- "http://personality-project.org/r/datasets/maps.mixx.epi.bfi.data" # 指定文件名与路径
mydata <-  read.table(datafilename,header=TRUE)                                      # 读取数据到mydata
attach(mydata)                                                                       # 激活mydata
library(descr)                                                                       # 使用descr包中的freq来进行频次分析
freq(epiE)                                                                           # 计算epiE变量的频次,得到频次分析结果和统计图

计算平均数与标准差

脚本与注释

datafilename <- "http://personality-project.org/r/datasets/maps.mixx.epi.bfi.data" # 指定文件名与路径
mydata <-  read.table(datafilename,header=TRUE)                                      # 读取数据到mydata
attach(mydata)                                                                       # 激活mydata
epi <- data.frame(epiE ,epiS ,epiImp ,epilie ,epiNeur)                               # 从mydata中提取数据子集,只包括要分析的变量
library(psych)                                                                       # 使用psych包中的describe计算平均数与标准差
decribe(epi)                                                                         # 描述性统计
describe(epi,fast=TRUE)                                                              # 快速描述性统计,得到核心结果

结果

> describe(epi)   #描述性统计结果。可以把结果复制到Editplus或notepad++,然后复制平均值与标准差两列到论文中
        vars   n  mean   sd median trimmed  mad min max range  skew kurtosis   se
epiE       1 231 13.33 4.14     14   13.49 4.45   1  22    21 -0.33    -0.06 0.27
epiS       2 231  7.58 2.69      8    7.77 2.97   0  13    13 -0.57    -0.02 0.18
epiImp     3 231  4.37 1.88      4    4.36 1.48   0   9     9  0.06    -0.62 0.12
epilie     4 231  2.38 1.50      2    2.27 1.48   0   7     7  0.66     0.24 0.10
epiNeur    5 231 10.41 4.90     10   10.39 4.45   0  23    23  0.06    -0.50 0.32

> describe(epi,fast=TRUE)  #快速描述性统计结果。可以把结果复制到Editplus或notepad++,然后复制平均值与标准差两列到论文中
        vars   n  mean   sd min max range   se
epiE       1 231 13.33 4.14   1  22    21 0.27
epiS       2 231  7.58 2.69   0  13    13 0.18
epiImp     3 231  4.37 1.88   0   9     9 0.12
epilie     4 231  2.38 1.50   0   7     7 0.10
epiNeur    5 231 10.41 4.90   0  23    23 0.32