码迷,mamicode.com
首页 > 编程语言 > 详细

R语言中的Theil-Sen回归分析

时间:2020-01-13 18:18:00      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:仿真   method   sse   nbsp   cat   des   har   ant   matrix   

原文链接:http://tecdat.cn/?p=10080


 

 Theil-Sen估计器是一种在社会科学中不常用 的简单线性回归估计器  。三个步骤:

  • 在数据中所有点之间绘制一条线
  • 计算每条线的斜率
  • 中位数斜率是 回归斜率

用这种方法计算斜率非常可靠。当误差呈正态分布且没有异常值时,斜率与OLS非常相似。 

有几种获取截距的方法。如果 关心回归中的截距,那么知道 软件在做什么是很合理的。 

当我对异常值和异方差性有担忧时,请在上方针对Theil-Sen进行简单线性回归的评论 。

我进行了一次 模拟,以了解Theil-Sen如何在异方差下与OLS比较。它是更有效的估计器。

library(simglm)
library(ggplot2)
library(dplyr)
library(WRS)

# Hetero
nRep <- 100
n.s <- c(seq(50, 300, 50), 400, 550, 750, 1000)
samp.dat <- sample((1:(nRep*length(n.s))), 25)
lm.coefs.0 <- matrix(ncol = 3, nrow = nRep*length(n.s))
ts.coefs.0 <- matrix(ncol = 3, nrow = nRep*length(n.s))
lmt.coefs.0 <- matrix(ncol = 3, nrow = nRep*length(n.s))
dat.s <- list()



ggplot(dat.frms.0, aes(x = age, y = sim_data)) +
  geom_point(shape = 1, size = .5) +
  geom_smooth(method = "lm", se = FALSE) +
  facet_wrap(~ random.sample, nrow = 5) +
  labs(x = "Predictor", y = "Outcome",
       title = "Random sample of 25 datasets from 15000 datasets for simulation",
       subtitle = "Heteroscedastic relationships")


技术图片

技术图片技术图片?

 
ggplot(coefs.0, aes(x = n, colour = Estimator)) +
  geom_boxplot(
    aes(ymin = q025, lower = q25, middle = q50, upper = q75, ymax = q975), data = summarise(
      group_by(coefs.0, n, Estimator), q025 = quantile(Slope, .025),
      q25 = quantile(Slope, .25), q50 = quantile(Slope, .5),
      q75 = quantile(Slope, .75), q975 = quantile(Slope, .975)), stat = "identity") +
  geom_hline(yintercept = 2, linetype = 2) + scale_y_continuous(breaks = seq(1, 3, .05)) +
  labs(x = "Sample size", y = "Slope",
       title = "Estimation of regression slope in simple linear regression under heteroscedasticity",
       subtitle = "1500 replications - Population slope is 2",
       caption = paste(
         "Boxes are IQR, whiskers are middle 95% of slopes",
         "Both estimators are unbiased in the long run, however, OLS has higher variability",
         sep = "\n"
       ))



技术图片

技术图片技术图片?

 

 

如果您有任何疑问,请在下面发表评论。 

 

 

大数据部落 -中国专业的第三方数据服务提供商,提供定制化的一站式数据挖掘和统计分析咨询服务

统计分析和数据挖掘咨询服务:y0.cn/teradat(咨询服务请联系官网客服

技术图片?技术图片QQ:3025393450

 

技术图片?QQ交流群:186388004 技术图片

【服务场景】  

科研项目; 公司项目外包;线上线下一对一培训;数据爬虫采集;学术研究;报告撰写;市场调查。

【大数据部落】提供定制化的一站式数据挖掘和统计分析咨询

技术图片

 

欢迎关注微信公众号,了解更多数据干货资讯!
 
技术图片技术图片
 

欢迎选修我们的R语言数据分析挖掘必知必会课程!

技术图片

R语言中的Theil-Sen回归分析

标签:仿真   method   sse   nbsp   cat   des   har   ant   matrix   

原文地址:https://www.cnblogs.com/tecdat/p/12188219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!