全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3100 1
2014-03-11
我不知道R里面非参数回归的函数怎么用?求大神指点
举一最简单例子
x<-c(1,2,4,7,11)
y<-c(9,0,3,2,7)
做x对y的一元非参数回归,核估计或局部线性都行。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-12-5 17:23:38
1. 核估计的话:  
x<-c(1,2,4,7,11)
y<-c(9,0,3,2,7)h <- 0.055fx.hat <- function(z, h) {    dnorm((z - x)/h)/h}NWSMOOTH <- function(h, y, x) {    n <- length(y)    s.hat <- rep(0, n)    for (i in 1:n) {        a <- fx.hat(x, h)        s.hat <- sum(y * a/sum(a))    }    return(s.hat)}
   
2. 局部多项式:
x<-c(1,2,4,7,11)
y<-c(9,0,3,2,7)
h <-0.055
LPRSMOOTH <- function(y, x, h) {    n <- length(y)    s.hat <- rep(0, n)    for (i in 1:n) {        weight <- dnorm((x - x)/h)        mod <- lm(y ~ x, weights = weight)        s.hat <- as.numeric(predict(mod, data.frame(x = x)))    }    return(s.hat)}


3. 也可以用现成的函数loess()来做loess回归
loess(y~x,data,span)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群