ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:120.06KB ,
资源ID:21080947      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21080947.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(用R语言做非参数文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

用R语言做非参数文档格式.docx

1、Friedman 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

2、functional 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. Appl

3、ied Linear 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 c

4、an use the 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()

5、 is symmetric around 0 and is continuous;(2) ,;(3) Either (a) K(z)=0 if |z|=z0 for z0 Or(b) |z|K(z) 0 as (4) , where is a constant.2、主要函数形式 3、置信区间 其中, 4、窗宽的选择实际应用中,。其中,s是样本标准差,iqr是样本分位数级差(interquartile range) 四、K nearest-neighbors estimate五、R语言部分 da - read.table(PSID.txt,header=TRUE)lhwage - da$lhwa

6、ge #* bandwidth 相等,核函数不同 *den1 - density(lhwage,bw=0.45,kernel=epan)den2 gaussden3 biweden4 rectplot(den4,lty=4,main= ,xlab=Log Hourly Wage,ylab=Kernel density estimateslines(den3,lty=3,col = redlines(den2,lty=2, col=greenlines(den1,lty=1,col=blue#* bandwidth 不相等,核函数也不同 *den5 - density(lhwage,bw=0.5

7、45,kernel=den6 - density(lhwage,bw=0.246,kernel=den7 - density(lhwage,bw=0.646,kernel=den8 - density(lhwage,bw=0.214,kernel=plot(den8,lty=4,main=lines(den7,lty=3,col = lines(den6,lty=2, col=lines(den5,lty=1,col=- 第三章 smoothing and local regression一、简单光滑估计法 Simple Smoothing 1、Local Averaging 局部均值 按照x

8、排序,将样本分成若干部分(intervals or “bins”);将每部分x对应的y值的均值作为f(x)的估计。 三种不同方法:(1)相同的宽度(equal width bins):uniformly distributed. (2)相同的观察值个数(equal no. of observations bins):k-nearest neighbor.(3)移动平均(moving average) K-NN:等窗宽:2、kernel smoothing 核光滑 其中,二、局部多项式估计Local Polynomial Regression1、主要结构 局部多项式估计是核光滑的扩展,也是基于局

9、部加权均值构造。local constant regressionlocal linear regressionlowess (Cleveland, 1979)loess (Cleveland, 1988)【本部分可参考:Takezana(2006). Introduction to Nonparametric Regression.(P185 3.7 and P195 3.9)Chambers and Hastie(1993). Statistical models in S. (P312 ch8)】 2、方法思路 (1)对于每个xi,以该点为中心,按照预定宽度构造一个区间;(2)在每个结点

10、区域内,采用加权最小二乘法(WLS)估计其参数,并用得到的模型估计该结点对应的x值对应y值,作为y|xi的估计值(只要这一个点的估计值);(3)估计下一个点xj;(4)将每个y|xi的估计值连接起来。【R操作 library(KernSmooth) #函数locpoly()library(locpol) #locpol(); locCteSmootherC()library(locfit) #locfit()#weight funciton: kernel=”tcub”. And “rect”, “trwt”, “tria”, “epan”, “bisq”, “gauss”】 3、每个方法对应

11、的估计形式 (1)变量个数p=0, local constant regression (kernel smoothing)min (2)变量个数p=1, local linear regression(3)Lowess (Local Weighted scatterplot smoothing)p=1:【还有个加权修正的过程,这里略,详见原书或者PPT】 (4)Loess (Local regression)p=1,2:(5)Friedman supersmoothersymmetric k-NN, using local linear fit, varying span, which is

12、 determined by local CV, not robust to outliers, fast to computesupsmu( ) in R三、模型选择 需要选择的内容:(1)窗宽the span;(2)多项式的度the degree of polynomial for the local regression models;(3)权重函数the weight functions。【其他略】 四、R语言部分 library(foreign)library(SemiPar)library(mgcv)jacob jacob.txt#第一部分,简单的光滑估计 #1、Kernel De

13、nsity Estimation#Illustration of Kernel Concepts#Defining the Window Widthattach(jacob)x0 - sort(perotvote)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)#

14、Figure 2.5plot(range(perotvote), c(0,1), xlab=Perot Vote (%), ylab=Tricube Weight, type=n, bty=labline(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

15、), cex=1)#2、Kernel SmoothingFigure 2.6par(mfrow=c(3,1)plot(perotvote, chal.vote, pch=., cex=1.95, xlab=Challengers Vote Share (%), main=Bandwidth = 4lines(ksmooth(perotvote, chal.vote, bandwidth=4) , cex=.65, Bandwidth = 8lines(ksmooth(perotvote, chal.vote, kernel=box,bandwidth=8), lty=1) Bandwidth

16、= 1212#* Kernel smoothing中选取box和normal核函数的比较,带宽相等 , cex=.65, xlab=, main=), lty=1)normal), lty=2,col=) #第二部分,LPR模型 #Data Prep For Local Average Regression Step-by-Stepcong - as.data.frame(jacob,2:3)- congorder(cong$perotvote),1:2y - as.matrix(cong$chal.vote)x - as.matrix(cong$perotvote)n - length(y)

17、- x75- abs(x - x0)x.n - xdiffs= which.diffy.n - ydiffs weigh=tricube(x.n-x0)/which.diff)mod which.diff, ydiffs which.diff, pch=16, cex=1, col=gray(.80)points(xdiffs = which.diff, ydiffs = which.diff, cex=.85)abline(mod, lwd=2, col=1)text(27.5, 50, expression(paste(Fitted Value of y at , x0) #这里expre

18、ssion的用法比较有意思 arrows(25, 47, 15, 37, code =2, length = .10)#2、Now Putting It Together For Local Regression Demonstration.#OLS Fit for Comparisonols - lm(chal.vote perotvote, data=jacob)#The loess fitmodel.loess - loess(chal.vote perotvote, data=jacob, span = 0.5)#* 默认设置 degree=2,family=gauss, tricub

19、e加权 *- length(chal.vote)x.loess - seq(min(perotvote), max(perotvote), length=n)y.loess - predict(model.loess, data.frame(perotvote=x.loess) #得到预测值便于比较#The lowess fitmodel.lowess - lowess(chal.vote perotvote, data=jacob, f = 0.5)#* 默认设置 robust linear tricube加权 *x.lowess y.lowess - predict(model.lowes

20、s, data.frame(perotvote=x.lowess) #得到预测值便于比较#Figure 2.8ylab=Challengers Vote Share (%), xlab=Vote for Perot (%)lines(x.loess, y.loess)lines(x.lowess, y.lowess)abline(ols)legend(15,20, c(Loess,Lowess, OLS) , lty=c(1,2,1), bty=, cex=.8)#3、lowess中不同robust的比较 m1.lowess - lowess(perotvote, chal.vote, f = 0.5, iter=0) #* 没有进行第二步的robust加权估计 *m2.lowess - lowess(perotvote, chal.vote, f = 0.5) #* 默认 iter=3,要进行3次robust加权估计 *m0.loess - loess(chal.vote perotvote, data=jacob, span = 0.5, degree=1, family=symm, iter

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1