Мне любопытно о двух различиях о dfbeta и dfbetas - PullRequest
0 голосов
/ 13 мая 2019

Я пытаюсь сделать код про dfbetas.но я не знаю разностного кода dfbeta и dfbetas в R. и я не знаю, почему эти два результата отличаются.

y= c(56.25, 75, 115.625, 68.75, 96.875, 168.750,  84.375,  171.875, 109.375, 103.125)
x1=c(106.329, 144.726, 136.287, 154.430, 385.232, 585.544, 489.451, 445.992, 270.886, 163.291)
x2=c(90.756,  203.361, 672.269, 183.193, 140.336, 146.218, 184.874, 537.815, 309.244, 190.756)
x3=c(94.650,  131.687, 123.457, 113.169, 117.284, 152.263, 121.399, 150.206, 185.185, 139.918)
x4=c(162.791, 255.814, 191.860, 133.721, 174.419, 273.256, 255.814, 552.326, 534.884, 360.465)
x5=c(114.337, 112.632, 153.684, 116.842,  87.368,  94.737,  95.789, 113.684, 108.421, 106.321)
x=cbind(1,x1,x2,x3,x4,x5)

dfbetas.js=function(x){
  n=length(y);p=ncol(x)-1
  b=solve(t(x)%*%x)%*%(t(x)%*%y)
  C=solve(t(x)%*%x)
  sigma.hat.mi=c()
for(i in 1:n){
  SSE.mi=y[-i]-(x[-i,]%*%solve(t(x[-i,])%*%x[-i,])%*%t(x[-i,])%*%y[-i])
  sigma.hat.mi[i]=sqrt(sum(SSE.mi^2)/(n-p-2))
}
  dfbetas.self=matrix(NA,nrow=n,ncol=length(b))
  for(j in 1:length(b)){
    for(i in 1:n){
      b.mi=solve(t(x[-i,])%*%x[-i,])%*%(t(x[-i,])%*%y[-i])
      dfbetas.self[i,j]=(b[j]-b.mi[j])/(sigma.hat.mi[i]*sqrt(C[j,j]))
    }
  }
  print(dfbetas.self)
}
dfbetas.js(x)
dfbeta(lm(y~x1+x2+x3+x4+x5)) #dfbeta
influence.measures(lm(y~x1+x2+x3+x4+x5)) #dfbetas
              [,1]         [,2]         [,3]         [,4]        [,5]         [,6]
 [1,] -0.063429091  0.076679024 -0.170191979 -0.186020166  0.17467690  0.142290356
 [2,] -0.011974248  0.033364876 -0.005307696 -0.021199012  0.01534060  0.012888825
 [3,]  0.034969383  0.002144448 -0.082245088 -0.061036473  0.11308539 -0.018509577
 [4,]  0.005045504  0.003298807  0.009567908 -0.008031121  0.01493122 -0.008276116
 [5,]  1.219911819 -0.826663377  1.102479573  0.203811009 -0.83042581 -1.227683030
 [6,] -8.945000499 10.367169645 -7.000656833  5.343176070 -2.29457385  7.026734861
 [7,]  0.016874636 -1.157231530  0.361551135  0.994036945 -0.51006636 -0.321541196
 [8,]  0.311744572  0.428829147  0.326751233 -1.469807152  1.50839649 -0.027441010
 [9,]  0.416989589  0.515381241  0.134030842 -1.295376051  0.04478046  0.030603256
[10,]  0.170904382 -0.305169737  0.033076869  0.002570310  0.11207452 -0.141871843
   (Intercept)            x1            x2           x3           x4          x5
1   -14.209832  0.0091554553 -0.0283346416 -0.145449237  0.027449269  0.28589138
2    -2.691794  0.0039974772 -0.0008867021 -0.016632601  0.002418972  0.02598556
3     7.867826  0.0002571492 -0.0137516537 -0.047929972  0.017847118 -0.03734981
4     1.135377  0.0003956355  0.0016000395 -0.006307579  0.002356816 -0.01670272
5   261.324953 -0.0943808849  0.1755097168  0.152381077 -0.124780900 -2.35865178
6  -461.474371  0.2850560932 -0.2684010308  0.962094342 -0.083035555  3.25121671
7     1.932217 -0.0706227547  0.0307658836  0.397260124 -0.040967834 -0.33020470
8    58.207111  0.0426740977  0.0453390642 -0.957830052  0.197554757 -0.04595178
9    69.262180  0.0456249556  0.0165445082 -0.750961658  0.005217403  0.04558938
10   34.516659 -0.0328488309  0.0049645297  0.001811807  0.015877323 -0.25697856
Influence measures of


    lm(formula = y ~ x1 + x2 + x3 + x4 + x5) :
     dfb.1_   dfb.x1   dfb.x2   dfb.x3  dfb.x4   dfb.x5   dffit    cov.r   cook.d   hat inf
1  -0.06343  0.07668 -0.17019 -0.18602  0.1747  0.14229  0.2940 1.81e+01 0.018982 0.711   *
2  -0.01197  0.03336 -0.00531 -0.02120  0.0153  0.01289 -0.0645 7.04e+00 0.000920 0.225   *
3   0.03497  0.00214 -0.08225 -0.06104  0.1131 -0.01851 -0.3249 6.90e+01 0.023392 0.920   *
4   0.00505  0.00330  0.00957 -0.00803  0.0149 -0.00828 -0.0544 7.52e+00 0.000656 0.265   *
5   1.21991 -0.82666  1.10248  0.20381 -0.8304 -1.22768  1.4539 2.33e+01 0.424495 0.869   *
6  -8.94500 10.36717 -7.00066  5.34318 -2.2946  7.02673 15.4185 6.27e-07 2.769152 0.814   *
7   0.01687 -1.15723  0.36155  0.99404 -0.5101 -0.32154 -2.2132 2.61e-03 0.281056 0.362   *
8   0.31174  0.42883  0.32675 -1.46981  1.5084 -0.02744  2.6441 3.59e+00 1.066710 0.836   *
9   0.41699  0.51538  0.13403 -1.29538  0.0448  0.03060 -2.3676 4.66e-01 0.676846 0.690   *
10  0.17090 -0.30517  0.03308  0.00257  0.1121 -0.14187  0.5719 2.18e+00 0.058389 0.308
...