赖江山的博客分享 http://blog.sciencenet.cn/u/laijiangshan 生态、统计与R语言

博文

分段回归的代码

已有 5680 次阅读 2019-3-22 19:26 |个人分类:RDA|系统分类:科研笔记| 分段回归的代码

#分段回归的代码

x <- c(1:10, 13:22)

y <- numeric(20)

## Create first segment

y[1:10] <- 20:11 + rnorm(10, 0, 1.5)

## Create second segment

y[11:20] <- seq(11, 15, len=10) + rnorm(10, 0, 1.5)

## Plot it

library(segmented)

lin.mod <- lm(y~x)

#psi starting values for the breakpoints to be estimated

segmented.mod <- segmented(lin.mod, seg.Z = ~x, psi=14)

plot(x,y, pch=16, ylim=c(5,20))

plot(segmented.mod, add=T)




https://wap.sciencenet.cn/blog-267448-1169082.html

上一篇:关于批量读入数据文件并组合为一个文件的代码
下一篇:R语言林学研究当中的应用分析
收藏 IP: 111.196.62.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 02:33

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部