欢迎来到天天文库
浏览记录
ID:22583919
大小:780.14 KB
页数:42页
时间:2018-10-30
《r软件基础介绍》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、分析步骤数据集建立!形制作回归分析模型检验与预测模型诊断一、数据集建立与梗概1.数据读入〉Iibrary(AER)>data(Journals)〉journaI二read,csv(‘d:/journal,csv,head二T)2.数据集梗概(1)names(journal)⑵str(journal)(3)head(journal)(4)taiI(journal)⑸summary(journals)I形制作1.plot函数plot(x,y,…)说明:x表示横轴变量,y表示纵轴变量;data指定分析变量所在的数据框,如果没有该选项,则分析变
2、量已经存在于内存中,或者通过使用attach和detach来实现数据框的调入。Type的取值主要有"p"、"I"、ViIViViViViIViViViViIViViVi11r11b、c、b、0、h、s、Somain:作标题;sub:作副标题;xlab:x轴标签.ylab:y轴标签;col:指定颜色。2.实例>journaIs二Journals[,c("subs11,"price11)]〉journaIs$citeprice二journaIs$price/journaIs$citations>pIot(Iog(subs)~Iog(cit
3、eprice),data二journaIs)>plot(log(subs)〜Iog(citeprice),data=journaIs,col=,green1,main=,pricevssubs1)4、RUE,singular,ok二TRUE,contrasts二NULL,offset,…)formula:指定用于回归分析的模型,因变量在左,自变量在右,中间用分开,解释变量之间用‘+’连接。默认回归模型包括截距项,如果取消,则使用‘+0’或者‘_1’表示。subset:用于对部分观测的数据框进行分析weights:表示指定权重变量,执行WLSdata:指定分析数据所在的数据框2.示例>jour_Im=Im(Iog(subs)~log(citeprice),data二journaIs)>cps_Im二Im(Iog(wage)〜exper5、ience+l(experience"2)+education+ethnicity,data=CPS1988说明:I函数表示变量为新产生变量作为解释变量1.回归分析结果的提取FunctionDescriptionprint()simpleprinteddisplaysummary0standardregressionoutputcoef()extractingtheregressioncoefficientsresid()extractingresidualsfitted()extractingfittedvaluesanova0com6、parisonofnestedmodeIspredict0predictionsfornewdataPIot()diagnosticplotsconfint0confidenceintervalsforcoefficientsdeviance()residualsumofsquaresvcov0variance—covariancematrixIogLik()log-1ikeIihoodAICOinformationcriteriaincludingAIC,BIC/SBCcoeftest()extractingtheregression7、output>coeftest(jour_lm)EstimateStd.Errortvalue(Intercept)4.7662120.05590985.249<2.2e-16***log(citeprice)-0.5330530.035613-14.968<2.2e—16*林Signif.codes:00.0010.010.050.1门1四、模型检验与预测1.回归系数单参数检验系数显著性检验与联合检验可以通过coeftest0或者summary0获取.2.联合为零显著性检验通过anova()获取.3.一般参数约束检验Rp=r,使用下列8、曲数:Iinear,hypothesis(model,hypothesis,matrix=,rhs=)其中:modeI为某个回归模型,hypothesis.matrix为约束矩阵/?,rhs为/。例如下列语
4、RUE,singular,ok二TRUE,contrasts二NULL,offset,…)formula:指定用于回归分析的模型,因变量在左,自变量在右,中间用分开,解释变量之间用‘+’连接。默认回归模型包括截距项,如果取消,则使用‘+0’或者‘_1’表示。subset:用于对部分观测的数据框进行分析weights:表示指定权重变量,执行WLSdata:指定分析数据所在的数据框2.示例>jour_Im=Im(Iog(subs)~log(citeprice),data二journaIs)>cps_Im二Im(Iog(wage)〜exper
5、ience+l(experience"2)+education+ethnicity,data=CPS1988说明:I函数表示变量为新产生变量作为解释变量1.回归分析结果的提取FunctionDescriptionprint()simpleprinteddisplaysummary0standardregressionoutputcoef()extractingtheregressioncoefficientsresid()extractingresidualsfitted()extractingfittedvaluesanova0com
6、parisonofnestedmodeIspredict0predictionsfornewdataPIot()diagnosticplotsconfint0confidenceintervalsforcoefficientsdeviance()residualsumofsquaresvcov0variance—covariancematrixIogLik()log-1ikeIihoodAICOinformationcriteriaincludingAIC,BIC/SBCcoeftest()extractingtheregression
7、output>coeftest(jour_lm)EstimateStd.Errortvalue(Intercept)4.7662120.05590985.249<2.2e-16***log(citeprice)-0.5330530.035613-14.968<2.2e—16*林Signif.codes:00.0010.010.050.1门1四、模型检验与预测1.回归系数单参数检验系数显著性检验与联合检验可以通过coeftest0或者summary0获取.2.联合为零显著性检验通过anova()获取.3.一般参数约束检验Rp=r,使用下列
8、曲数:Iinear,hypothesis(model,hypothesis,matrix=,rhs=)其中:modeI为某个回归模型,hypothesis.matrix为约束矩阵/?,rhs为/。例如下列语
此文档下载收益归作者所有