Splitting Strata with Optimall Shiny


The function optimall_shiny(), located within the package optimall, launches a Shiny app that allows users to observe how the stratum sizes, standard deviations, and optimum allocations react to different stratum splits. This vignette demonstrates how to use the application.

Uploading Data

The first step in using optimall_shiny() is uploading data. The data must be in the same format that the rest of optimall’s functions require, meaning that each row must corresponds to one sampling unit. If you have already updated an existing dataset in your R workflow, you will have to save the updated dataframe to a .csv file in order to work with it in optimall_shiny().

Alt text

Splitting Strata

Once the dataset has been uploaded, options for the user to select inputs will appear. Each input correspond to an argument of at least one function in optimall, and the application provides a list of valid options for each one based on the uploaded data. See them below:


optimall_shiny() displays the output dataframe of optimum_allocation() or allocate_wave() based on the current inputs. After a split is confirmed and these inputs are reset, it will show an error in place of this dataframe until valid inputs are selected again. Displayed below this dataframe is a text list of the code that performs each of the confirmed splits in optimall.

Alt text

Confirming Splits

When the user is satisfied with the parameters that are selected, a split can be confirmed by pressing the Confirm Split button at the bottom left of the page. This will split the existing data using the split_strata() parameters specified in the inputs. The inputs that specify arguments for the allocation will not change the splits, they are only included to show how each split may impact the sample allocation.

After Confirm Split is pressed, the code to perform that split will appear in the output at the bottom right of the page. The updated strata will now be in a column called “new_strata”, and the inputs will reset. Using “new_strata” as the column defining the strata, the user can then perform more splits, and the code to perform each one will be added to the list at the bottom right with each confirmation.

Implementing Splits in R

The splits in optimall_shiny() will not be performed on the true dataset in the user’s optimall workflow in R. Instead, the user must return to R if they want to actually transform the data into a working dataframe with the new strata. The code displayed in the app’s output makes this task simple, as it can be copied and pasted into an R script to replicate the splits conducted in the app. Note, however, that the data argument in each split_strata() call needs to be changed to reflect the user’s name for the data.

Error Messages

If any of the selected inputs results in an error in either split_strata() or the selected allocation function, the app will print the error.