Description Usage Arguments Value Examples
creates a weighting function from a sampling frame
1 2 3 | map_to_weighting(sampling.frame, data.stratum.column,
sampling.frame.population.column = "population",
sampling.frame.stratum.column = "stratum", data = NULL)
|
data.stratum.column |
data column name that holds the record's strata names |
sampling.frame.population.column |
sampling frame name of column holding population counts. defaults to "population" |
sampling.frame.stratum.column |
sampling frame name of column holding stratum names. defaults to "stratum". Stratum names must match exactly values in: |
data |
optional but recommended: you can provide an example data frame of data supposed to match the sampling frame to check if the provided variable names match and whether all strata in the data appear in the sampling frame. |
sampling.frame.file |
data frame containing the sampling frame. should contain columns "stratum" and "population", otherwise column names must be specified. |
returns a new function that takes a data frame as input returns a vector of weights corresponding to each row in the data frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Not run: # load data and sampling frames:
mydata<-read.csv("mydata.csv")
mysamplingframe<-read.csv("mysamplingframe.csv")
# create weighting function:
weighting<-weighting_fun_from_samplingframe(sampling.frame = mysamplingframe,
data.stratum.column = "strata_names",
sampling.frame.population.column = "pop",
sampling.frame.stratum.column = "strat_name")
# use weighting function:
mydata$weights<-weighting(mydata)
# this also works on subsets of the data:
mydata_subset<-mydata[1:100,]
subset_weights<- weighting(mydata)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.