getPartialRConditional:

Usage Arguments Examples

Usage

1
getPartialRConditional(indicator, variable, sampleData, sampleDesign)

Arguments

indicator
variable
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
##---- 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 (indicator, variable, sampleData, sampleDesign) 
{
    stopifnot(variable %in% names(sampleData))
    sampleWeights <- indicator$sampleDesign$weights
    modelVariables <- getVariables(indicator$model$formula, FALSE)
    otherVariables <- modelVariables %sub% variable
    otherCategories <- as.list(sampleData[otherVariables])
    propMeanByOthers <- with(indicator, ave(sampleWeights * prop, 
        otherCategories, FUN = sum)/ave(sampleWeights, otherCategories, 
        FUN = sum))
    zMeanByOthers <- apply(indicator$z, 2, FUN = function(x) return(ave(sampleWeights * 
        x, otherCategories, FUN = sum)/ave(sampleWeights, otherCategories, 
        FUN = sum)))
    categories <- sampleData[[variable]]
    RBiasFactor <- indicator$RBiasFactor
    weights <- sampleWeights/sum(sampleWeights)
    arg <- with(indicator, data.frame(n = sampleWeights, propVar = weights * 
        (prop - propMeanByOthers)^2))
    byCategory <- within(aggregate(arg, list(category = categories), 
        sum), {
        PcUnadj <- sqrt(propVar)
    })
    propVar <- sum(byCategory$propVar)
    Pc <- sqrt(propVar * RBiasFactor)
    PcUnadj <- sqrt(propVar)
    partialIndicator <- list(type = "Conditional partial R-indicator, sample based", 
        variable = variable, Pc = Pc, PcUnadj = PcUnadj, byCategory = byCategory, 
        propMeanByOthers = propMeanByOthers, zMeanByOthers = zMeanByOthers)
    partialIndicator <- getVariancePartialRConditional(partialIndicator, 
        indicator, sampleData, sampleDesign)
    partialIndicator$byCategory <- partialIndicator$byCategory[c("category", 
        "PcUnadj", "PcUnadjSE")]
    return(partialIndicator)
  }

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