Example data
Within metalite.sl, we utilized the ADSL datasets from the metalite
package to create an illustrative dataset. The metadata structure
remains consistent across all analysis examples within metalite.sl. To
calculate treatment compliance percent and treatment compliance range,
we utilized adex dataset. Additional information can be accessed on the
metalite
package website.
Analysis preparation
The function prepare_trt_compliance()
is written to
prepare data for treatment compliance analysis.The function takes four
arguments:
meta is metadata object created by metalite and it contains data from
ADSL. Analysis, Population, and Parameter arguments are used to subset
and process the meta data. They have default values, which rely on the
meta data object.
The function assign default value Analysis to
trt_compliance
, Population to the population value
associated with the trt_compliance
analysis in meta plan,
and parameter to the parameter(s) associated with the
trt_compliance
analysis in meta$plan.
However, the user can also manually specify the analysis, population,
and parameter values when calling the function, if they want to override
the default values.
In the body of the function, it calls another function
prepare_sl_summary with the same meta, analysis, population, and
parameter arguments. prepare_sl_summary
takes the meta
data, subsets it based on the analysis, population, and parameter
values, and then calculates and returns a summary of the relevant
data.
The result of prepare_sl_summary is then returned as the result of
prepare_trt_compliance.
The resulting output of the function
prepare_trt_compliance()
comprises a collection of raw
datasets for analysis and reporting.
outdata <- prepare_trt_compliance(meta)
Click to show the output
outdata
#> List of 14
#> $ meta :List of 7
#> $ population : chr "apat"
#> $ observation : chr "apat"
#> $ parameter : chr "CMPLRNG;CMPLPCT"
#> $ n :'data.frame': 1 obs. of 6 variables:
#> $ order : NULL
#> $ group : chr "TRTA"
#> $ reference_group: NULL
#> $ char_n :List of 2
#> $ char_var : chr [1:2] "CMPLRNG" "CMPLPCT"
#> $ char_prop :List of 2
#> $ var_type :List of 2
#> $ group_label : Factor w/ 3 levels "Placebo","Low Dose",..: 1 3 2
#> $ analysis : chr "trt_compliance"
parameter
: parameter name
outdata$parameter
#> [1] "CMPLRNG;CMPLPCT"
n
: number of participants in population
outdata$n
#> name n_1 n_2 n_3 n_9999 var_label
#> 1 Participants in population 85 84 83 252 -----
The resulting dataset contains frequently used statistics, with
variables indexed according to the order specified in
outdata$group
.
outdata$group
#> [1] "TRTA"
char_n
: number of participants completed vs not
completed in each parameter
outdata$char_n
#> [[1]]
#> name Placebo Low Dose High Dose Total var_label
#> 1 0% to <=20% 1 1 1 3 Treatment Compliance Range
#> 2 >20% to <=40% 0 0 1 1 Treatment Compliance Range
#> 3 >80% 84 83 81 248 Treatment Compliance Range
#>
#> [[2]]
#> name Placebo Low Dose High Dose Total
#> 1 Mean 99.0 99.0 98.1 98.7
#> 2 SD 9.4 9.5 12.2 10.4
#> 3 SE 1.0 1.0 1.3 0.7
#> 4 Median 100.0 100.0 100.0 100.0
#> 5 Min 12.9 13.2 8.9 8.9
#> 6 Max 100.0 100.0 100.0 100.0
#> 7 Q1 to Q3 100 to 100 100 to 100 100 to 100 100 to 100
#> 8 Range 12.93 to 100 13.25 to 100 8.88 to 100 8.88 to 100
#> var_label
#> 1 Treatment Compliance Percent
#> 2 Treatment Compliance Percent
#> 3 Treatment Compliance Percent
#> 4 Treatment Compliance Percent
#> 5 Treatment Compliance Percent
#> 6 Treatment Compliance Percent
#> 7 Treatment Compliance Percent
#> 8 Treatment Compliance Percent
char_var
: name of parameter
outdata$char_var
#> [1] "CMPLRNG" "CMPLPCT"
char_prop
: proportion of subject with treatment
compliance
outdata$char_prop
#> [[1]]
#> name Placebo Low Dose High Dose Total
#> 1 0% to <=20% 1.176471 1.190476 1.204819 1.1904762
#> 2 >20% to <=40% 0.000000 0.000000 1.204819 0.3968254
#> 3 >80% 98.823529 98.809524 97.590361 98.4126984
#> var_label
#> 1 Treatment Compliance Range
#> 2 Treatment Compliance Range
#> 3 Treatment Compliance Range
#>
#> [[2]]
#> name Placebo Low Dose High Dose Total var_label
#> 1 Mean NA NA NA NA Treatment Compliance Percent
#> 2 SD NA NA NA NA Treatment Compliance Percent
#> 3 SE NA NA NA NA Treatment Compliance Percent
#> 4 Median NA NA NA NA Treatment Compliance Percent
#> 5 Min NA NA NA NA Treatment Compliance Percent
#> 6 Max NA NA NA NA Treatment Compliance Percent
#> 7 Q1 to Q3 NA NA NA NA Treatment Compliance Percent
#> 8 Range NA NA NA NA Treatment Compliance Percent
Additional statistics
By using the display
argument, we can choose specific
statistics to include.
tbl <- outdata |> format_trt_compliance(display_stat = c("mean", "sd", "median", "range"), display_col = c("n", "prop", "total"))
Click to show the output
tbl$tbl
#> name n_1 p_1 n_2 p_2
#> 1 Participants in population 85 <NA> 84 <NA>
#> 2 0% to <=20% 1 (1.2) 1 (1.2)
#> 3 >20% to <=40% 0 (0.0) 0 (0.0)
#> 4 >80% 84 (98.8) 83 (98.8)
#> 5 Mean 99.0 <NA> 99.0 <NA>
#> 6 SD 9.4 <NA> 9.5 <NA>
#> 7 Median 100.0 <NA> 100.0 <NA>
#> 8 Range 12.93 to 100 <NA> 13.25 to 100 <NA>
#> n_3 p_3 n_9999 p_9999 var_label
#> 1 83 <NA> 252 <NA> -----
#> 2 1 (1.2) 3 (1.2) Treatment Compliance Range
#> 3 1 (1.2) 1 (0.4) Treatment Compliance Range
#> 4 81 (97.6) 248 (98.4) Treatment Compliance Range
#> 5 98.1 <NA> 98.7 <NA> Treatment Compliance Percent
#> 6 12.2 <NA> 10.4 <NA> Treatment Compliance Percent
#> 7 100.0 <NA> 100.0 <NA> Treatment Compliance Percent
#> 8 8.88 to 100 <NA> 8.88 to 100 <NA> Treatment Compliance Percent
RTF tables
The last step is to prepare the RTF table using
rtf_trt_compliance
.
outdata |>
format_trt_compliance() |>
rtf_trt_compliance(
"Source: [CDISCpilot: adam-adsl]",
path_outtable = "outtable/treatment0compliance.rtf"
)
#> The output is saved in/rtmp/Rtmp7YMja5/Rbuild3605e43666ac3c/metalite.sl/vignettes/outtable/treatment0compliance.rtf