_覓 | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁 |
FrontPage › ChangePoint
|
|
slope螳 覲 讌 谿城.
[edit]
1 覲蟆曙 #library(segmented) options(warn = -1) change_point <- function(y, chart=F, n=10){ #y <- sin(sort(runif(100,0,5)))*10+100 #n=5 #chart=T x <- 1:length(y) #x <- (1:length(y)) * (max(y) - min(y)) / length(y) for(cp_cnt in 1:n){ fit_lm = lm(y ~ x) # intercept-only model fit_tmp = try(segmented(fit_lm, seg.Z = ~x, npsi = cp_cnt),silent=T) if (class(fit_tmp)[1] == "try-error"){ break cp_cnt <- cp_cnt - 1 } else if (length(fit_tmp$psi) == 0){ break cp_cnt <- cp_cnt - 1 } r2 <- cor(y, fitted(fit_tmp))^2 if(r2 >= 0.9){ fit_segmented <- fit_tmp break } fit_segmented <- fit_tmp } if(1==chart){ plot(fit_segmented) points(x,y) lines.segmented(fit_segmented) points.segmented(fit_segmented) } cp <- fit_segmented$psi[,2] return(cp) } set.seed(1024) y <- sin(sort(runif(100,0,5)))*10+100 + sin(sort(runif(50,0,5)))*10+100 cp <- change_point(y, T) 蟆郁骸
[edit]
2 豕蠏 覲蟆曙 #library(segmented) options(warn = -1) recent_change_point <- function(y, chart=F, n=10){ #y <- sin(sort(runif(100,0,5)))*10+100 #n=5 #chart=T x <- 1:length(y) #x <- (1:length(y)) * (max(y) - min(y)) / length(y) for(cp_cnt in 1:n){ fit_lm = lm(y ~ x) # intercept-only model fit_tmp = try(segmented(fit_lm, seg.Z = ~x, npsi = cp_cnt),silent=T) if (class(fit_tmp) == "try-error"){ break cp_cnt <- cp_cnt - 1 } else if (length(fit_tmp$psi) == 0){ break cp_cnt <- cp_cnt - 1 } r2 <- cor(y, fitted(fit_tmp))^2 if(r2 >= 0.9){ fit_segmented <- fit_tmp break } fit_segmented <- fit_tmp } if(1==chart){ plot(fit_segmented) points(x,y) lines.segmented(fit_segmented) points.segmented(fit_segmented) } cp <- fit_segmented$psi[,2] start_x <- round(tail(cp,1), 2) y2 <- y[x >= start_x] x2 <- x[x >= start_x] return(data.frame(x=x2, y=y2)) } set.seed(1024) y <- sin(sort(runif(100,0,5)))*10+100 + sin(sort(runif(50,0,5)))*10+100 x <- 1:length(y) plot(x, y) lines(recent_change_point(y)) 蟆郁骸
鏤
|
覓企 覓殊企 讌碁ゼ 磯 襯企 豺讌 螻 讌襯 螳豢 螳螻 讌企伎 襦 螳 襯 螳豢 螳朱 企 蟾 螻葛 襾碁蟇磯Μ讌 螻 れ願 蠍磯ゼ 螳讌 螳螻 レ覓殊 襷 螳覃 螻 襷讌 豌覈 螳朱 螻褐 蟇一 覃襴 襯伎襷 覓殊企襴 覯 朱 螳讌 螳. 豌讌 願朱 企伎螻 襷覓殊 願朱 伎螳覃 朱 願朱 至 襷 願朱 伎覃 襷覓殊 願朱 覦襯願 蟆企. 願 讌襦 螳 覓殊 譬 伎企. ( <<語>>) |