getRSampleBased:

Usage Arguments Examples

Usage

1
getRSampleBased(model, sampleData, sampleDesign)

Arguments

model
sampleData
sampleDesign

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
##---- 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 (model, sampleData, sampleDesign) 
{
    sampleData <- within(sampleData, {
        sampleWeights <- sampleDesign$weights
        sampleWeights <- sampleWeights/mean(sampleWeights)
    })
    modelfit <- glm(model$formula, model$family, sampleData, 
        sampleWeights)
    prop <- predict(modelfit, type = "response")
    propMean <- weighted.mean(prop, sampleDesign$weights)
    propVar <- weightedVar(prop, sampleDesign$weights)
    sigma <- vcov(modelfit)
    x <- model.matrix(model$formula, sampleData)[, colnames(sigma)]
    z <- model$grad(predict(modelfit, type = "link")) * x
    withBiasAndVar <- !is.null(sigma) && all(!is.na(sigma))
    if (withBiasAndVar) {
        RBias <- getBiasRSampleBased(prop, z, sigma, sampleDesign)
        RVar <- getVarianceRSampleBased(prop, z, sigma, sampleDesign)
        if (RBias > propVar) 
            RBiasFactor <- 0
        else RBiasFactor <- 1 - RBias/propVar
    }
    else {
        RBias <- NA
        RBiasFactor <- NA
        RVar <- NA
    }
    CV <- sqrt(propVar)/propMean
    CVVar <- 0.25 * RVar/propMean^2 + CV^4/nrow(sampleData)
    indicator <- list(type = "R-indicator, sample based", sampleDesign = sampleDesign, 
        prop = prop, propMean = propMean, model = model, modelfit = modelfit, 
        sigma = sigma, z = z, R = 1 - 2 * sqrt(propVar * RBiasFactor), 
        RUnadj = 1 - 2 * sqrt(propVar), RSE = sqrt(RVar), RBiasFactor = RBiasFactor, 
        CV = CV, CVSE = sqrt(CVVar))
    return(indicator)
  }

BERENZ/RISQ documentation built on May 5, 2019, 10:25 a.m.