R语言讲义(包括各种回归)

上传人:宝路 文档编号:48452528 上传时间:2018-07-15 格式:PPTX 页数:191 大小:3.55MB
返回 下载 相关 举报
R语言讲义(包括各种回归)_第1页
第1页 / 共191页
R语言讲义(包括各种回归)_第2页
第2页 / 共191页
R语言讲义(包括各种回归)_第3页
第3页 / 共191页
R语言讲义(包括各种回归)_第4页
第4页 / 共191页
R语言讲义(包括各种回归)_第5页
第5页 / 共191页
点击查看更多>>
资源描述

《R语言讲义(包括各种回归)》由会员分享,可在线阅读,更多相关《R语言讲义(包括各种回归)(191页珍藏版)》请在金锄头文库上搜索。

1、R 语言讲义 免费(没有权力和铜臭) 资源公开, 可改变代码(不是黑盒子,也不是 吝啬鬼, 透明是防止“腐败”的最好方式) 容易学习。可编程以实行复杂的课题 可扩展: 通过数千个网上提供的适用于不同 领域、不同目的、不同方法的软件包来实 现你的目标。也可以把你的方法贡献出来 功能强大(绘图功能, 优秀的内在帮助系统, R社区的支持,不断更新,不断修正) 没有任何一个商业软件有如此多和如此新 的算法 世界应用统计学家大都把自己的方法首先以R来 实现,并尽量放到R 网站上 一年多,R网站的软件包数量增加了两倍,从近 1000个到近3000多个。大都都有关于计算、演 示和输入输出方法的函数和例子数据

2、 除非得到巨额资助(或者永远使用盗版软件), 没 有理由在公立学校教授商业软件 绝大多数美国统计研究生都会的语言(Berkeley 统计和应用数学本科都开设R语言课) 我的很大一部分数据分析知识的来源就是R. 我都能学会, 并且到处宣传和普及, 相信你们会 做得更好!点击CRAN得到一批镜像网站下载R(http:/www.r- project.org/)点击镜像网站比如Berkeley选择这个,下载安装文件选择这个,下载软件包选择 basePackages (每个都有大量数据和可以读写修改的 函数/程序) base The R Base Package boot Bootstrap R (S-

3、Plus) Functions (Canty) class Functions for Classification cluster Cluster Analysis Extended Rousseeuw et al. concord Concordance and reliability datasets The R Datasets Package exactRankTests Exact Distributions for Rank and Permutation Tests foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata

4、, Systat, dBase, . graphics The R Graphics Package grDevices The R Graphics Devices and Support for Colours and Fonts grid The Grid Graphics Package KernSmooth Functions for kernel smoothing for Wand all(x!=0);any(x0);(1:10)x0 diff(x) diff(x,lag=2) x=matrix(1:20,4,5);x x=matrix(1:20,4,5,byrow=T);x t

5、(x) x=matrix(sample(1:100,20),4,5) 2*x x+5 y=matrix(sample(1:100,20),5,4) x+t(y) (z=x%*%y) z1=solve(z) # solve(a,b)可以解ax=b方程 z1%*%z round(z1%*%z,14)矩阵 nrow(x); ncol(x);dim(x)#行列数目 x=matrix(rnorm(24),4,6) xc(2,1),#第2和第1行 x,c(1,3) #第1和第3列 x2,1 #第2,1元素 xx,10,1 #第1列大于0的元素 sum(x,10) #第1列大于0的元素的个数 sum(x,1

6、0yfit=predict(d,data=(w$gawks=(xfit) plot(log(w$ac)w$gawks);lines(yfitxfit,col=“red“)library(mfp) w=read.csv(“f:/2010stat/ac.csv“) d=mfp(log(ac)fp(gawks,select=0.05),data=w,verbose=T)M=2 P1=-2 P2=0Null model Straight line model Best-fitting FP1 model Best-fitting FP2 modelsummary(d)par(mfrow=c(2,2)

7、plot(mfp(log(ac)fp(gawks),w)xfit=(w$gawks);yfit=predict(d,data=(w$gawks=(xfit) plot(log(w$ac)w$gawks);lines(yfitxfit,col=“red“)变量选择:library(MMIX)library(MMIX) X1-c(-0.2,-2.4,-0.7,1.2,0.0,-1.1,-2.1,-0.3,2.0,-1.7,1.4,-1.3,-3.4,0.4,-1.3, -4.8) X2- c(-3, 2, 1, -2, -2, -4, 0, 1, 1, -1, -1, -4, 0, 2, 0, -

8、4) X3-c(2,1,0,-2,1,-2, 0, -1, -4, 1, -3, -3, -3, -1, 0, 2)#Linear model Y1- c(8.7, 6, 9.1, 10.4, 7.6 ,10.4, 7.9, 11.9, 18, 10.5, 16.5, 8.8, 7.7,13.5, 8.2, 0.8) data1-data.frame(Y1,X1,X2,X3) pairs(data1) #Logistic model Y2-c(1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1) data2-data.frame(Y2,X1,X2,X3

9、) pairs(data2)#varSelec data1bis-varSelec(data=data1,family=gaussian(“identity“),maxVar=2) data2bis-varSelec(data=data2,family=binomial(“logit“),maxVar=2)最终得到两个简化的数据集:选X1,X3选X2#bootFreq #Stepwise selection method bootStep1- bootFreq(data=data1,family=gaussian(“identity“),nboot=50,method=2, criterion

10、=“bic“,trace=0) bootStep1 summary(bootStep1) plot(bootStep1)This function analyses the stability of the stepwise selection and mixing methods using a bootstrap procedure.bootStep2-bootFreq(data=data2,family=binomial(“logit“),method=2, criterion=“bic“,nboot=20,trace=0) bootStep2 summary(bootStep2) pl

11、ot(bootStep2)Adaptative Regression by Mixing with model Screening Apply ARMS for linear and logistic models.#ARMS method armsResult1-arms(data=data1,family=gaussian(“identity“),nbest=5,nsample=10, criterion=“both“,weight=“aic“) armsResult1 summary(armsResult1) plot(armsResult1)armsResult2-arms(data=

12、data2,family=binomial(“logit“),nbest=5,nsample=10, criterion=“both“,weight=“aic“) armsResult2 summary(armsResult2) plot(armsResult2)#Root Mean Square Error by cross-validation #Stepwise selection with BIC pmseStepBic-pmseCV(data=data1,method=2,np=1,random=FALSE,direction=“both“, criterion=“bic“,trac

13、e=0) pmseStepBic #BMA pmseBMA-pmseCV(data=data1,method=3,np=1,random=FALSE) pmseBMAModel performance indicators PMSE and AUC#Area Under ROC Curve by cross-validation aucStepBic-aucCV(data=data2,method=2,np=1,random=FALSE,direction=“both“, criterion=“bic“,trace=0) aucStepBicaucBMA-aucCV(data=data2,me

14、thod=3,np=1,random=FALSE) aucBMAConditional logistic regression 参见ppt: logisticRegressionManitoba-Nov2010.pdf“Prospective” modelConditional likelihoodExponential movement kernels (Forester et al 2009)library(TwoStepCLogit) data(bison)dyad - bison$Cluster stratum - bison$Strata Y - bison$Y x1 - bison

15、$biomass x2 - bison$water x3 - bison$biomass2bison.data - cbind(dyad,stratum,Y,x1,x2,x3) # Conditional logistic regression # There are 10 observations per stratum, with # 2 cases and 8 controls in each stratum# Model 1: all three covariates x1, x2, x3 # Random effects in front of x1 and x3 # Main di

16、agonal covariance structure for D Fit1 - Ts.estim(bison.data, Proposed.model=c(1,2,3),random=c(1,3), All.m.1=FALSE, D=“UN(1)“) Fit1 # Model 2: only covariates x1, x3 # Random effects in front of x1 and x3 # Unstructured covariance structure for D Fit2 - Ts.estim(bison.data, Proposed.model=c(1,3),random=c(1,2), All.m.1=FALSE, D=“UN“) Fit2Bayesian Methods for Tree Based ModelsBayesia

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号