1 | createWeights(current.targets, bes)
|
current.targets |
|
bes |
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 | ##---- 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 (current.targets, bes)
{
not.there <- names(current.targets)[!names(current.targets) %in%
names(bes)]
if (length(not.there) > 0) {
stop(paste("Var not present in BES", not.there, collapse = ""))
}
vars <- bes[complete.cases(bes[, names(current.targets)]),
]
if (any(!sapply(vars[, names(current.targets)], is.factor))) {
stop("Following vars are not factor:", names(which(!sapply(vars[,
names(current.targets)], is.factor))))
}
testVar <- function(name) {
if (all(sort(levels(vars[[name]])) == sort(names(current.targets[[name]])))) {
return(NULL)
}
else {
stop(paste0("Failed on ", name))
}
}
sapply(names(current.targets), testVar)
library(anesrake)
output <- anesrake(inputter = current.targets, dataframe = vars,
caseid = vars$id, verbose = TRUE, cap = 15, choosemethod = "total",
type = "nolim", pctlim = 0.005, nlim = 5, iterate = TRUE,
force1 = TRUE)
vars$test_weight <- output$weightvec
vars <- vars[, c("id", "test_weight", "region.weighted")]
return(vars)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.