用R语言做非参数和半参数回归笔记(共18页).docx
《用R语言做非参数和半参数回归笔记(共18页).docx》由会员分享,可在线阅读,更多相关《用R语言做非参数和半参数回归笔记(共18页).docx(18页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上由詹鹏整理,仅供交流和学习根据南京财经大学统计系孙瑞博副教授的课件修改,在此感谢孙老师的辛勤付出!教材为:Luke Keele: Semiparametric Regression for the Social Sciences. John Wiley & Sons, Ltd. 2008.-第一章 introduction: Global versus Local Statistic一、主要参考书目及说明1、Hardle(1994). Applied Nonparametic Regresstion. 较早的经典书2、Hardle etc (2004). Nonpar
2、ametric and semiparametric models: an introduction. Springer. 结构清晰3、Li and Racine(2007). Nonparametric econometrics: Theory and Practice. Princeton. 较全面和深入的介绍,偏难4、Pagan and Ullah (1999). Nonparametric Econometrics. 经典5、Yatchew(2003). Semiparametric Regression for the Applied Econometrician. 例子不错6、高铁
3、梅(2009). 计量经济分析方法与建模:EVIEWS应用及实例(第二版). 清华大学出版社. (P127/143)7、李雪松(2008). 高级计量经济学. 中国社会科学出版社. (P45 ch3)8、陈强(2010). 高级计量经济学及Stata应用. 高教出版社. (ch23/24)【其他参看原ppt第一章】二、内容简介方法:移动平均(moving average)核光滑(Kernel smoothing)K近邻光滑(K-NN)局部多项式回归(Local Polynormal)Loesss and Lowess样条光滑(Smoothing Spline)B-splineFriedman
4、Supersmoother模型:非参数密度估计非参数回归模型非参数回归模型时间序列的半参数模型Panel data 的半参数模型Quantile Regression三、不同的模型形式1、线性模型linear models2、Nonlinear in variables3、Nonlinear in parameters四、数据转换 Power transformation(对参数方法)In the GLM framework, models are equally prone(倾向于) to some misspecification(不规范) from an incorrect functi
5、onal form.It would be prudent(谨慎的) to test that the effect of any independent variable of a model does not have a nonlinear effect. If it does have a nonlinear effect, analysts in the social science usually rely on Power Transformations to address nonlinearity.ADD: 检验方法见Sanford Weisberg. Applied Lin
6、ear Regression (Third Edition). A John Wiley & Sons, Inc., Publication.(本科的应用回归分析课教材)-第二章Nonparametric Density Estimation非参数密度估计一、三种方法1、直方图 Hiatogram2、Kernel density estimate3、K nearest-neighbors estimate二、Histogram 对直方图的一个数值解释Suppose x1,xN f(x), the density function f(x) is unknown.One can use the
7、following function to estimate f(x)【与x的距离小于h的所有点的个数】三、Kernel density estimateBandwidth: h; Window width: 2h.1、Kernel function的条件The kernel function K(.) is a continuous function, symmetric(对称的) around zero, that integrates(积分) to unity and satisfies additional bounded conditions:(1) K() is symmetric
8、 around 0 and is continuous;(2),;(3) Either(a) K(z)=0 if |z|=z0 for z0Or(b) |z|K(z) 0 as;(4), whereis a constant.2、主要函数形式3、置信区间其中,4、窗宽的选择实际应用中,。其中,s是样本标准差,iqr是样本分位数级差(interquartile range)四、K nearest-neighbors estimate五、R语言部分da - read.table(PSID.txt,header=TRUE)lhwage - da$lhwage#* bandwidth 相等,核函数不同
9、 *den1 -density(lhwage,bw=0.45,kernel=epan)den2 - density(lhwage,bw=0.45,kernel=gauss)den3 - density(lhwage,bw=0.45,kernel=biwe)den4 - density(lhwage,bw=0.45,kernel=rect)plot(den4,lty=4,main= ,xlab=Log Hourly Wage,ylab=Kernel density estimates)lines(den3,lty=3,col = red)lines(den2,lty=2, col=green)l
10、ines(den1,lty=1,col=blue)#* bandwidth 不相等,核函数也不同 *den5 - density(lhwage,bw=0.545,kernel=epan)den6 - density(lhwage,bw=0.246,kernel=gauss)den7 - density(lhwage,bw=0.646,kernel=biwe)den8 - density(lhwage,bw=0.214,kernel=rect)plot(den8,lty=4,main= ,xlab=Log Hourly Wage,ylab=Kernel density estimates)lin
11、es(den7,lty=3,col = red)lines(den6,lty=2, col=green)lines(den5,lty=1,col=blue)-第三章smoothing and local regression一、简单光滑估计法Simple Smoothing1、Local Averaging 局部均值按照x排序,将样本分成若干部分(intervals or “bins”);将每部分x对应的y值的均值作为f(x)的估计。三种不同方法:(1)相同的宽度(equal width bins):uniformly distributed.(2)相同的观察值个数(equal no. of
12、observations bins):k-nearest neighbor.(3)移动平均(moving average)K-NN:等窗宽:2、kernel smoothing 核光滑其中,二、局部多项式估计Local Polynomial Regression1、主要结构局部多项式估计是核光滑的扩展,也是基于局部加权均值构造。local constant regressionlocal linear regressionlowess (Cleveland, 1979)loess (Cleveland, 1988)【本部分可参考:Takezana(2006). Introduction to
13、Nonparametric Regression.(P185 3.7 and P195 3.9)Chambers and Hastie(1993). Statistical models in S. (P312 ch8)】2、方法思路(1)对于每个xi,以该点为中心,按照预定宽度构造一个区间;(2)在每个结点区域内,采用加权最小二乘法(WLS)估计其参数,并用得到的模型估计该结点对应的x值对应y值,作为y|xi的估计值(只要这一个点的估计值);(3)估计下一个点xj;(4)将每个y|xi的估计值连接起来。【R操作library(KernSmooth) #函数locpoly()library(l
14、ocpol) #locpol(); locCteSmootherC()library(locfit) #locfit()#weight funciton: kernel=”tcub”. And “rect”, “trwt”, “tria”, “epan”, “bisq”, “gauss”】3、每个方法对应的估计形式(1)变量个数p=0, local constant regression (kernel smoothing)min(2)变量个数p=1, local linear regressionmin(3)Lowess (Local Weighted scatterplot smoothi
15、ng)p=1:min【还有个加权修正的过程,这里略,详见原书或者PPT】(4)Loess (Local regression)p=1,2:min【还有个加权修正的过程,这里略,详见原书或者PPT】(5)Friedman supersmoothersymmetrick-NN, using local linear fit,varying span, which is determined by local CV,not robust to outliers, fast to computesupsmu( )inR三、模型选择需要选择的内容:(1)窗宽the span;(2)多项式的度the de
16、gree of polynomial for the local regression models;(3)权重函数the weight functions。【其他略】四、R语言部分library(foreign)library(SemiPar)library(mgcv)jacob - read.table(jacob.txt,header=TRUE)#第一部分,简单的光滑估计#1、Kernel Density Estimation#Illustration of Kernel Concepts#Defining the Window Widthattach(jacob)x0 - sort(p
17、erotvote)75diffs - abs(perotvote - x0)which.diff - sort(diffs)120#Applying the Tricube Weight#.Tricube functiontricube - function(z) ifelse (abs(z) 1, (1 - (abs(z)3)3, 0)#.a - seq(0,1, by=.1)tricube(a)#Figure 2.5plot(range(perotvote), c(0,1), xlab=Perot Vote (%), ylab=Tricube Weight, type=n, bty=l)a
18、bline(v=c(x0-which.diff, x0+which.diff), lty=2)abline(v=x0)xwts - seq(x0-which.diff, x0+which.diff, len=250)lines(xwts,tricube(xwts-x0)/which.diff), lty=1, lwd=1)points(x.n, tricube(x.n - x0)/which.diff), cex=1)#2、Kernel Smoothing#Figure 2.6par(mfrow=c(3,1)plot(perotvote, chal.vote, pch=., cex=1.95,
19、xlab=Perot Vote (%), ylab=Challengers Vote Share (%),main=Bandwidth = 4, bty=l)lines(ksmooth(perotvote, chal.vote,bandwidth=4)plot(perotvote, chal.vote, pch=., cex=.65,xlab=Perot Vote (%), ylab=Challengers Vote Share (%),main=Bandwidth = 8, bty=l)lines(ksmooth(perotvote, chal.vote, kernel=box,bandwi
20、dth=8), lty=1)plot(perotvote, chal.vote, pch=., cex=.65,xlab=Perot Vote (%), ylab=Challengers Vote Share (%),main=Bandwidth = 12, bty=l)lines(ksmooth(perotvote, chal.vote, bandwidth=12), lty=1)#* Kernel smoothing中选取box和normal核函数的比较,带宽相等plot(perotvote, chal.vote, pch=., cex=.65, xlab=Perot Vote (%),
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 参数 回归 笔记 18
限制150内