knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

claimr

The goal of claimr is to streamline claim audits

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("mncube/claimr")

Example

#Load claimr
library(claimr)

#Generate sampling frame  with an index id from 1 to N
df_sample_frame_num <- data.frame("sample_frame_sequence_id" = 1:1000,
                                  "score" = rnorm(1000))

#Take a simple random sample from the sampling frame
#And return the output (sample, sample frame, spares) and input in lists
score_audit_num <- rs_singlestage(df = df_sample_frame_num,
                                  seed_number = 100,
                                  audit_review = "Score Audit",
                                  quantity_to_generate = 100,
                                  quantity_of_spares = 3,
                                  frame_low = 1,
                                  frame_high = 1000)

#View some of the samples
head(score_audit_num$output$sample)

#View some of the sampling frame
head(score_audit_num$output$sample_frame)

#View some of the spares
head(score_audit_num$output$spares)

#Compute the relative bias
relative_bias(score_audit_num, score)

Get information for RAT-STATS Unrestricted Variable Appraisals

#Get info
uva_info <- gi_unrestricted_variable_appraisals(samp_obj = score_audit_num,
                                     data_file_format = c("Audited Values"),
                                     audited_values = score,
                                     sample_item_number = sample_frame_sequence_id)
#Look at the data_file
uva_info$audit_review
uva_info$frame_size
uva_info$sample_size
uva_info$data_file_format
head(uva_info$data_file)

#Export data file needed to process "Audited Values" Unrestricted Variable Appraisals in RAT-STATS
rs_uva <- uva_info$data_file
#write.table(rs_uva, sep=",",  col.names=FALSE)

Randomly select items from a two stage sampling process

#In this example let each data frame represents a score sheet (first_set) with
#10 scores (second_set) on each sheet

#Create three separate score sheets 
df1 <- data.frame(page = c(1),
                  score = rnorm(10, 7,2),
                  item = 1:10)
df2 <- data.frame(page = c(2),
                  score = rnorm(10, 6, 1.5),
                  item = 1:10)
df3 <- data.frame(page = c(3),
                  score = rnorm(10, 8, 0.5),
                  item = 1:10)

#Combine the score sheets
df_combined <- rbind(df1, df2, df3)

#Randomly pull observations from the combined score sheet
combined_out <- rs_setsoftwo(df = df_combined,
                       first_set = page,
                       second_set = item,
                       seed_number = NA,
                       audit_review = "",
                       quantity_to_generate = 10,
                       quantity_of_spares = 2,
                       first_set_low = 1,
                       first_set_high = 3,
                       second_set_low = 1,
                       second_set_high = 10)

#Get head of sample
head(combined_out$output$sample)

#Get the mean of the sample
mean(unlist(combined_out$output$sample))

Randomly select items from a three stage sampling process

#In this example let each data frame represents a pre-test or post-test (first_set) and 
#a score sheet (second_set) with 10 scores (third_set) on each sheet

#Create six separate data frames
df1_pre <- data.frame(time = 1,
                      page = c(1),
                      score = rnorm(10, 7,2),
                      item = 1:10)
df2_pre <- data.frame(time = 1,
                      page = c(2),
                      score = rnorm(10, 6, 1.5),
                      item = 1:10)
df3_pre <- data.frame(time = 1,
                      page = c(3),
                      score = rnorm(10, 8, 0.5),
                      item = 1:10)
df1_post <- data.frame(time = 2,
                       page = c(1),
                       score = rnorm(10, 7,2),
                       item = 1:10)
df2_post <- data.frame(time = 2,
                       page = c(2),
                       score = rnorm(10, 6, 1.5),
                       item = 1:10)
df3_post <- data.frame(time = 2,
                       page = c(3),
                       score = rnorm(10, 8, 0.5),
                       item = 1:10)

#Combine the data frames
df_combined <- rbind(df1_pre, df2_pre, df3_pre,
                     df1_post, df2_post, df3_post)

#Randomly pull observations from df_combined
combined_out <- rs_setsofthree(df = df_combined,
                               first_set = time,
                               second_set = page,
                               third_set = item,
                               seed_number = NA,
                               audit_review = "",
                               quantity_to_generate = 10,
                               quantity_of_spares = 2,
                               first_set_low = 1,
                               first_set_high = 2,
                               second_set_low = 1,
                               second_set_high = 3,
                               third_set_low = 1,
                               third_set_high = 10)

#Get head of sample
head(combined_out$output$sample, 10)


mncube/claimr documentation built on Dec. 21, 2021, 8:07 p.m.