1 | getVariancePartialRConditional(partialIndicator, indicator, sampleData, sampleDesign)
|
partialIndicator |
|
indicator |
|
sampleData |
|
sampleDesign |
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 | ##---- 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 (partialIndicator, indicator, sampleData, sampleDesign)
{
byCategory <- partialIndicator$byCategory
variable <- partialIndicator$variable
sigma <- indicator$sigma
weights <- sampleDesign$weights
nPopulation <- sum(weights)
propDelta <- indicator$prop - partialIndicator$propMeanByOthers
zDelta <- indicator$z - partialIndicator$zMeanByOthers
variance <- numeric()
for (index in seq(nrow(byCategory))) {
label <- byCategory[index, "category"]
delta <- ifelse(sampleData[[variable]] == label, 1, 0)
zDeltaWeight <- zDelta * delta * weights
propDelta2 <- propDelta * propDelta * delta
A <- matrix(propDelta, nrow = 1) %*% zDeltaWeight
B <- t(zDelta) %*% zDeltaWeight
V1 <- 4 * A %*% sigma %*% t(A)
V2 <- 2 * getTrace(B %*% sigma %*% B %*% sigma)
V3 <- sampleDesign$getVarTotal(sampleDesign, propDelta2)
variance[index] <- 0.25 * (V1 + V2 + V3)/(nPopulation *
sum(propDelta2 * weights))
}
partialIndicator$byCategory <- within(byCategory, PcUnadjSE <- sqrt(variance))
return(partialIndicator)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.