knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The aim of this document is to illustrate how to calculate zeros and probabilities using the RDBEScore package.
library(RDBEScore)
These should be added to the RDBEScore package which will make this step unnecessary in the future.
# clean the table prefixes of variable names #[makes it easier to handle in other functions] source("R/removePrefixFromVarNames.R") # checks data for some issues related to selection and probabilities, # including some features not yet developed # [stops need to corrected before probabilities are calculated] source("R/runChecksOnSelectionAndProbs.R") # modified/improved version of generateProbs developed during WKRDB-EST 1 # and WKRDB-EST 2 [several new functionalities, warnings, etc] source("R/generateProbs.r") # wrapper to "runChecksOnSelectionAndProbs" and "generateProbs" source("R/applyGenerateProbs.r") source("R/generateZerosUsingSL.r")
First we'll load some example data from the RDBES and check it's valid. It's a good tip to check your RDBESDataObjects are valid after any manipulations you perform.
getwd() # H7 test data load ("data/testDataPreparationFunctions.Rdata") # Number of rows in each non-null table unlist(lapply(myH7RawObject, nrow)) validateRDBESDataObject(myH7RawObject, verbose = TRUE)
First we remove the prefixes and then check the selection and probability values for any issues - there are some things we need to fix.
# clean the prefixes [makes it easier to handle in other functions] myH7RawObject <- removePrefixFromVarNames(myH7RawObject) class(myH7RawObject) # checks data for some issues related to selection and probabilities # note: this function is only exemplified here - # in general only applyGenerateProbs will be used as the wrapper also includes # this function runChecksOnSelectionAndProbs(myH7RawObject, printStopIssue = FALSE)
First, we'll change the selection methods.
# changes to selection methods myH7RawObject$OS$selectMeth<-"SRSWOR" myH7RawObject$SA$stratification<-"N" myH7RawObject$SA$selectMeth<-"SRSWOR" myH7RawObject$BV$selectMeth<-"SRSWOR" runChecksOnSelectionAndProbs(myH7RawObject)
Now the main issues relation to selection methods have been corrected (and documented) but still probabilities cannot be calculated because numTotal are missing.
myH7PrepObject<-applyGenerateProbs (x = myH7RawObject , probType = "both" , overwrite=T , runInitialProbChecks = FALSE)
We'll fix that now.
# changes to numTotal myH7RawObject$OS$numTotal<-c(3,3,3) myH7RawObject$SS$numTotal<-c(1,1,1) myH7RawObject$SA$numTotal<-c(20, 10, 5) myH7RawObject$BV$numTotal<-c(rep(50, 29*5), rep(200, 95*5), rep(200, 39*5)) myH7PrepObject<-applyGenerateProbs (x = myH7RawObject , probType = "both" , overwrite=T , runInitialProbChecks = FALSE)
Generate true zeroes using the data from the SL table.
myH7PrepObject2<-generateZerosUsingSL(myH7PrepObject) # note the solution [dec SAid added to avoid integer that could # duplicate other already existing] myH7PrepObject2$SA
Finally, let's check our object is still valid. (It won't be until Nuno changes his function code :-) )
validateRDBESDataObject(myH7PrepObject2, verbose = TRUE)
#END
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.