kstephbr: Function which computes the k steps for the weighted HBR fit.

Description Usage Arguments Examples

Description

Function which computes the k steps for the weighted HBR fit.

Usage

1
kstephbr(y, x, ehatk, k, wts2, B, scores = wscores)

Arguments

y
x
ehatk
k
wts2
B
scores

Examples

 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
38
39
40
41
42
43
##---- 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 (y, x, ehatk, k, wts2, B, scores = wscores) 
{
    eps <- 1e-06
    if (k == 1) {
        mat <- hbrrewted(x, y)
        wts2 <- mat[, 1]
        ehatk <- mat[, 2]
        robdis2 <- mat[, 3]
    }
    mstar <- median(ehatk)
    ehatk <- ehatk - mstar
    n <- length(ehatk)
    breaks <- get_breakshbr(ehatk, B)
    gs <- getScoreshbr.brf(ehatk, breaks, scores = scores)
    ind <- c()
    wts <- c()
    for (i in 1:n) {
        if (abs(ehatk[i]) < eps) {
            wts[i] <- 0
            ind <- c(ind, i)
        }
        else {
            wts[i] <- gs$scorevec[i]/ehatk[i]
        }
    }
    wts <- abs(wts/max(wts))
    wts[ind] <- 1
    pwts <- wts2 * wts
    yk <- y - mstar
    fitkp1 <- lm(yk ~ x, weights = pwts)
    if (k == 1) {
        list(fitkp1 = fitkp1, wts2 = wts2, pwts = pwts, robdis2 = robdis2, 
            ehatlts = ehatk)
    }
    else {
        list(fitkp1 = fitkp1, wts2 = wts2, pwts = pwts)
    }
  }

joemckean/rewtedhbr documentation built on May 31, 2019, 1:51 a.m.