1 | robR2w(rob.obj, correc = 1.2076)
|
rob.obj |
|
correc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (rob.obj, correc = 1.2076)
{
wt.bisquare = function(u, c = 4.685) {
U <- abs(u/c)
w <- ((1 + U) * (1 - U))^2
w[U > 1] <- 0
w
}
weight.rob = function(rob.obj) {
resid.rob = rob.obj$resid
scale.rob = (rob.obj$scale) * rob.obj$df.residual/length(resid.rob)
resid.rob = resid.rob/scale.rob
weight = wt.bisquare(resid.rob)
}
if (attr(rob.obj, "class") != "lmRob")
stop("This function works only on lmRob objects")
pred = rob.obj$fitted.values
resid = rob.obj$resid
resp = resid + pred
wgt = weight.rob(rob.obj)
scale.rob = rob.obj$scale
resp.mean = sum(wgt * resp)/sum(wgt)
pred.mean = sum(wgt * pred)/sum(wgt)
yMy = sum(wgt * (resp - resp.mean)^2)
rMr = sum(wgt * resid^2)
r2 = (yMy - rMr)/yMy
r2correc = (yMy - rMr)/(yMy - rMr + rMr * correc)
r2adjcor = 1 - (1 - r2correc) * (length(resid) - 1)/(length(resid) -
length(rob.obj$coefficients) - 1)
return(list(robR2w.NoCorrection = r2, robR2w.WithCorrection = r2correc,
robR2w.AdjustedWithCorrection = r2adjcor))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.