# Using {ordinalsimr}

    library(ordinalsimr)

# Shiny App

The {ordinalsimr} package wraps a Shiny application and supporting functions for running simulation studies on several pre-selected statistical tests applicable to ordinal data. The Shiny app is particularly suited for calculating Power and Type II error for a proposed 2-group comparison of an ordinal endpoint. Available parameters to manipulate before running the tests include:

- Number of simulations to run (integer)
- The sample size (integer)
- The distribution ratio between group 1 and group 2 (ratio of form X:X)
- Group 1 and Group 2 distribution probabilities for levels of the ordinal outcome

In addition to these parameters for running the simulation, the following can be adjusted in the Distributions page

- Setting the alpha significance level/p-value threshold
- Setting the confidence intervals for the Power/T2 Error calculations
- Setting the confidence intervals (separately) for the Type I Error in Group 1 and Group 2

Bug reports and feature requests can be submitted as issues at https://github.com/NeuroShepherd/ordinalsimr/issues

## Using Downloaded Data

Data downloaded after running a simulation is stored as a `.rds` file, and can be loaded into your R session using `readRDS()`. The data is structured as a named list with 3 elements at the top level, and several sub-elements. A summary of the available information is available in the code below.

    output <- readRDS("data-2025-01-19-d8621b-1.rds")
    output$comparison_data$distribution_statistics
    #> # A tibble: 36 × 10
    #> # Groups:   Sample Size [6]
    #>    `Sample Size` test   lower_power_bound upper_power_bound power `Power 95% CI`
    #>            <int> <chr>              <dbl>             <dbl> <dbl> <chr>
    #>  1            30 Wilco…             0.452             0.736  0.6  [0.452, 0.736]
    #>  2            30 Fisher             0.337             0.626  0.48 [0.337, 0.626]
    #>  3            30 Chi S…             0.374             0.663  0.52 [0.374, 0.663]
    #>  4            30 Chi S…             0.374             0.663  0.52 [0.374, 0.663]
    #>  5            30 Prop.…             0.472             0.753  0.62 [0.472, 0.753]
    #>  6            30 Coin …             0.472             0.753  0.62 [0.472, 0.753]
    #>  7            31 Wilco…             0.512             0.788  0.66 [0.512, 0.788]
    #>  8            31 Fisher             0.337             0.626  0.48 [0.337, 0.626]
    #>  9            31 Chi S…             0.374             0.663  0.52 [0.374, 0.663]
    #> 10            31 Chi S…             0.374             0.663  0.52 [0.374, 0.663]
    #> # ℹ 26 more rows
    #> # ℹ 4 more variables: lower_t2error_bound <dbl>, upper_t2error_bound <dbl>,
    #> #   t2_error <dbl>, `TII Error 95% CI` <chr>
    str(output, max.level = 2)
    #> List of 3
    #>  $ comparison_data:List of 3
    #>   ..$ run_info               : tibble [300 × 13] (S3: tbl_df/tbl/data.frame)
    #>   ..$ distribution_statistics: gropd_df [36 × 10] (S3: grouped_df/tbl_df/tbl/data.frame)
    #>   .. ..- attr(*, "groups")= tibble [6 × 2] (S3: tbl_df/tbl/data.frame)
    #>   .. .. ..- attr(*, ".drop")= logi TRUE
    #>   ..$ distribution_plot      :List of 11
    #>   .. ..- attr(*, "class")= chr [1:2] "gg" "ggplot"
    #>  $ group1_data    :List of 2
    #>   ..$ run_info      : tibble [300 × 13] (S3: tbl_df/tbl/data.frame)
    #>   ..$ group1_t1error: gropd_df [36 × 6] (S3: grouped_df/tbl_df/tbl/data.frame)
    #>   .. ..- attr(*, "groups")= tibble [6 × 2] (S3: tbl_df/tbl/data.frame)
    #>   .. .. ..- attr(*, ".drop")= logi TRUE
    #>  $ group2_data    :List of 2
    #>   ..$ run_info      : tibble [300 × 13] (S3: tbl_df/tbl/data.frame)
    #>   ..$ group2_t1error: gropd_df [36 × 6] (S3: grouped_df/tbl_df/tbl/data.frame)
    #>   .. ..- attr(*, "groups")= tibble [6 × 2] (S3: tbl_df/tbl/data.frame)
    #>   .. .. ..- attr(*, ".drop")= logi TRUE

- Top level items
  - `comparison_data` are results from comparing Group 1 against Group 2 in the statistical tests (for TII error and power)
  - `group1_data` are results from comparing Group 1 data against itself (for TI error of this group)
  - `group2_data` are results from comparing Group 2 data against itself (for TI error of this group)
- Second level items
  - `run_info` are tables of detailed metainformation about the parameters used for each run
  - `distribution_statistics` are tables of computed TII error, power, and associated confidence intervals
  - `group1_t1error` and `group2_t1error` are tables of TI error and associated confidence intervals