R
来自OBHRM百科
R是一个用于统计计算和统计制图的优秀免费工具。与SPSS、SAS等相比,R是属于GNU系统的一个自由、免费、源代码开放的软件。使用R进行统计分析,是免费用正版软件进行统计分析。
目录
R的安装与升级
- R的官方网站:https://www.r-project.org/
- R的安装:您可以从:https://cran.r-project.org/ 下载R软件。如果网络速度慢,官网提供了许多下载R软件的镜像站点,详情请访问:https://cran.r-project.org/mirrors.html 。安装R后,建议同时安装RStudio,官网下载地址:https://www.rstudio.com/products/RStudio/
- R的升级:采用installr包;手工升级。
R常用包
- R包列表:https://cran.r-project.org/web/packages/available_packages_by_name.html
- R常用包
- R多层回归分析包(包名:AutoModel):https://cran.r-project.org/web/packages/AutoModel/index.html
- R中介效应分析包,包括Moderated mediation(包名:mediation):https://cran.r-project.org/web/packages/mediation/index.html
- R调节回归分析包(包名:pequod):https://cran.r-project.org/web/packages/pequod/index.html
- R响应面分析(Response Surface Analysis)包(包名:RSA):https://cran.r-project.org/web/packages/RSA/index.html
- R响应面分析(Response-Surface Analysis)包(包名:rsm):https://cran.r-project.org/web/packages/rsm/index.html
- R结构方程包(包名:sem):https://cran.r-project.org/web/packages/sem/index.html
- R结构方程包(包名:lavaan):https://cran.r-project.org/web/packages/lavaan/index.html
- R结构方程包(包名:OpenMx):https://cran.r-project.org/web/packages/OpenMx/index.html
- R结构方程工具包(包名:semTools):https://cran.r-project.org/web/packages/semTools/index.html
- RMultilevel分析包(包名:multilevel):https://cran.r-project.org/web/packages/multilevel/index.html ,这个包里头还包括AMJ、JAP等文章的数据与分析程序。
- R Multilevel分析包(包名:lme4):https://cran.r-project.org/web/packages/lme4/index.html
- R Multilevel分析(包名:nlme):https://cran.r-project.org/web/packages/nlme/index.html
- R元分析包(包名:metafor):https://cran.r-project.org/web/packages/metafor/index.html
- R菜单式元分析包(包名:MAVIS):https://cran.r-project.org/web/packages/MAVIS/index.html
- R菜单式元分析包(包名:RcmdrPlugin.MA):https://cran.r-project.org/web/packages/RcmdrPlugin.MA/index.html
- R统计效应分析(Power Analysis)包(包名:pwr):https://cran.r-project.org/web/packages/pwr/index.html
- R心理统计包(包名:psych):http://personality-project.org/r/r.guide.html#psych
- R图形与表格辅助工具(包名:sjPlot):https://cran.r-project.org/web/packages/sjPlot/index.html
- R菜单式基本统计包(包名:Rcmdr):https://cran.r-project.org/web/packages/Rcmdr/index.html
- R菜单式数据挖掘包(包名:rattle):https://cran.r-project.org/web/packages/rattle/
- R文献分析包(包名:bibliometrix):https://cran.r-project.org/web/packages/bibliometrix/index.html
- R自动生成APA格式表格的的包1(包名:apa):https://cran.r-project.org/web/packages/apa/index.html
- R自动生成APA格式表格的的包2(包名:apaStyle):https://cran.r-project.org/web/packages/apaStyle/index.html
- R自动生成APA格式表格的的包3(包名:apaTables):https://cran.r-project.org/web/packages/apaTables/index.html
- R自动生成APA格式表格的的包4(包名:psytabs):https://cran.r-project.org/web/packages/psytabs/index.html
- R Task View:https://cran.r-project.org/web/views/
R包的安装与卸载
- 远程安装:在R的控制台,输入install.packages("包的名称")。比如,安装lavaan,就是install.packages("lavaan")。正常情况下,安装会自动完成。如果网络不正常,可能会出现错误,建议改用“本地安装”
- 本地安装:从官方网站下载统计软件包,然后安装:R菜单—程序包—本地安装/install package(s) from local files...。当网络速度不佳时,可以考虑这种安装方式。
- 包的卸载: remove.packages("包的名称")。比如,卸载lavaan,就是remove.packages("lavaan")。
R:数据读取与管理
1、设定工作目录
- 查看当前工作目录,在R控制台输入:getwd()
- 设置工作目录:R菜单-文件-改变工作目录,再选择对应的工作目录就可以。或者在R控制台输入:curwd=setwd("路径"),但是路径中的\要全部替换成\\,比如:curwd=setwd("c:\\program files\\mplus\\mplus examples\\user's guide examples")
2、读取数据
- 从文本文件中读取固定格式数据:如果您的数据还没有输入计算机,建议直接以txt格式输入数据。不需要编制任何软件,可以用Windows系统自带的Edit,或者Editplus、Notepad++输入数据。输入完成后,直接用固定格式读取数据。
- 从文本文件中读取自由格式数据
- 读取CSV格式的数据
- 读取Excel数据
- 读取SPSS、SAS、Stata等的数据文件
4、数据转换: 变量重命名 变量重编码,比如反向计分题目的调整
7、 简单计算
8、保存数据: 保存为文本文件 保存为Excel文件 保存为其他统计软件文件
OBHRM研究常用统计分析:R的应用
1、 信度分析
2、探索性因素分析:不旋转(如,Harman检验) 正交旋转 斜交旋转
3、验证性因素分析: 一阶验证性因素分析 二阶验证性因素分析
5、 相关分析
8、路径分析: 中介变量的路径分析 有调节的中介路径分析
9、结构方程模型: 结构方程模型
自动生成APA样式表格/三横线表格
R推荐图书与资源
- 《Learning Statistics with R》,PDF版免费下载:http://www.compcogscisydney.com/learning-statistics-with-r.html ,同时可以免费下载该书中用过的数据,以及对应R包:lsr(https://cran.r-project.org/web/packages/lsr/index.html )
- 《R实战》(R in Action 中译本),人民邮电出版社,Robert I. Kabacoff 著,高涛,肖楠,陈钢译,2013年