0

3 つの共変量 (X、Y、Z) と 2 つのブレークポイントを持つ変数 V のブレークポイントを推定しようとしています。

応答変数 V = aX + bY + cZ + d

(a,b,c,d) が (0.6,0.2,0.8,0.15)、(1.6,1.2,1.8,1.15)、(3,5,4,2.5) の 3 セットの値を持つデータをシミュレートします。

セグメント化されたパッケージを使用して係数を推定しましたが、次のエラーが発生しました。

Error in segmented.lm(linearFit, seg.Z = ~X + Y + Z, psi = list(X = c(NA),  :   

Bootstrap restart only with a fixed number of breakpoints

ここにデータを含む私のコードがあります

    #trapezoidal data    
    ref=c(rep(1,100),seq(1,10,0.05),rep(10,150),seq(10,0,-0.05),rep(0,200))

    #covariates
    xx=cumsum(ref) 
    yy=diff(xx)
    zz=diff(yy)

    #equalizing lengths of above vectors
    vecL=length(zz)
    xx=xx[1:vecL]
    yy=yy[1:vecL]
    zz=zz[1:vecL]

    #adding noise to covariates
    set.seed(10)
    X=xx + max(xx)/100*rnorm(vecL)
    Y=yy + max(yy)/100*rnorm(vecL)
    Z=zz + max(zz)/100*rnorm(vecL)

    #three segment response variable, total 830 points
    V[1:200]   = 0.6 *X[1:200]+   0.2 *Y[1:200]+   0.8 *Z[1:200]+   0.15 + 0.01*rnorm(200)
    V[201:400] = 1.6 *X[201:400]+ 1.2 *Y[201:400]+ 1.8 *Z[201:400]+ 1.15 + 0.01*rnorm(200)
    V[401:830] = 3.0 *X[401:830]+ 5.0 *Y[401:830]+ 4.0 *Z[401:830]+ 2.50 + 0.01*rnorm(430)

    ##linear model

    linearFit=lm(formula=V~X+Y+Z)
    summary(linearFit)


    ##segmented 

    segFit=segmented(linearFit,seg.Z=~X+Y+Z,psi=list(X=c(NA),Y=c(NA),Z=c(NA)),control=seg.control(display=TRUE, K=4, stop.if.error=FALSE))

そして、これは出力です:

segFit=segmented(linearFit,seg.Z=~X+Y+Z,psi=list(X=c(NA),Y=c(NA),Z=c(NA)),control=seg.control(display=TRUE, K=4, stop.if.error=FALSE))
Error in segmented.lm(linearFit, seg.Z = ~X + Y + Z, psi = list(X = c(NA),  : 
  Bootstrap restart only with a fixed number of breakpoints

psi とコントロールを正しく設定していますか? どんな助けでも大歓迎です。

4

1 に答える 1

0

自動ブレークポイント検出は非常に実験的なようで、ドキュメントはそれを示しています。有限数の開始値を指定することをお勧めします。とにかく、フィッティング関数を次のように実行し始めることができます。

segFit=segmented(linearFit,seg.Z=~X+Y+Z,psi=list(X=c(NA),Y=c(NA),Z=c(NA)),
                 control=seg.control(display=TRUE, K=4, stop.if.error=FALSE, n.boot=0, it.max=50))
#0   287035116.259  (No breakpoint(s)) 
#1   52847700.113  12 
#2   66421579.610  7 
#3   60143023.830  7 
#4   55936266.042  7 
#5   45478319.984  5 
#6   37237514.620  5 
#7   34058342.767  5 
#8   33889551.970  3 
#9   33679837.419  3 
#10  33680392.183  3 
#Error in eval(expr, envir, enclos) : object 'U1.Y' not found

そして、それは私たちにエラーを吐き出します。私の解釈は、ブレークポイントYが見つからなかったというものでした。したがって、ブレークポイントの式から削除しました。

segFit=segmented(linearFit,seg.Z=~X+Z,psi=list(X=c(NA),Z=c(NA)),
                 control=seg.control(display=TRUE, K=4, stop.if.error=FALSE, n.boot=0, it.max=50))
#0   287035116.259  (No breakpoint(s)) 
#1   57518175.693  8 
#2   75024714.551  4 
#3   53678468.904  4 
#4   42978477.989  4 
#5   36762393.424  4 
#6   34564133.079  4 
#7   33672729.061  4 
#8   33672705.918  4 
#Error in eval(expr, envir, enclos) : object 'U1.Z' not found

それはまだ好きではありません。削除しましょうZ:

segFit=segmented(linearFit,seg.Z=~X,psi=list(X=c(NA)),
                 control=seg.control(display=TRUE, K=4, stop.if.error=FALSE, n.boot=0, it.max=50))
#0   287035116.259  (No breakpoint(s)) 
#1   59188023.560  4 
#2   84927431.755  3 
#3   58905175.574  3 
#4   46487759.098  3 
#5   39114874.784  3 
#6   34916433.946  3 
#7   33986478.337  3 
#8   33680464.097  3 
#9   33680464.097  3 

成功!segmented(一点で複数の変数のブレークをうまく処理できるかどうかはわかりません。)

于 2014-09-17T17:54:14.167 に答える