diff --git a/DESCRIPTION b/DESCRIPTION index 62e4c5c..9848da5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: stRoke Title: Tools for work in clinical stroke research -Version: 0.22.9.3 +Version: 0.22.9.4 Authors@R: person("Andreas Gammelgaard", "Damsbo", , "agdamsbo@clin.au.dk", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7559-1154")) @@ -19,5 +19,7 @@ Language: en-US Config/testthat/edition: 3 Imports: ggplot2, + gtsummary, MASS, + rankinPlot, stats diff --git a/NAMESPACE b/NAMESPACE index baa1609..b914ecf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,8 +4,13 @@ export(age_calc) export(cpr_check) export(cpr_dob) export(cpr_female) +export(generic_stroke) export(plot_olr) export(quantile_cut) import(MASS) import(ggplot2) import(stats) +importFrom(MASS,polr) +importFrom(gtsummary,add_overall) +importFrom(gtsummary,tbl_summary) +importFrom(rankinPlot,grottaBar) diff --git a/R/generic_stroke.R b/R/generic_stroke.R new file mode 100644 index 0000000..7b1d5b2 --- /dev/null +++ b/R/generic_stroke.R @@ -0,0 +1,43 @@ +utils::globalVariables(c("df","group","score","strata")) + +#' Generic stroke study outcome +#' +#' Includes table 1, grotta bars and ordinal logistic regression plot. +#' Please just use this function for illustration purposes. +#' To dos: +#' +#' @param df Data set as data frame +#' @param group Variable to group by +#' @param score Outcome measure variable +#' @param strata Optional variable to stratify by +#' @param variables String of variable names to include in adjusted OLR-analysis +#' +#' @return Returns list with three elements +#' @export +#' +#' @import ggplot2 +#' @importFrom gtsummary tbl_summary +#' @importFrom gtsummary add_overall +#' @importFrom MASS polr +#' @importFrom rankinPlot grottaBar +#' +#' @examples +#' iris$ord<-factor(sample(1:3,size=nrow(iris),replace=TRUE),ordered=TRUE) +#' generic_stroke(df=iris, group = "Species", score = "ord", variables = colnames(iris)[1:3]) +generic_stroke <- function(df, group, score, strata = NULL, variables = NULL) + { + t1<-gtsummary::tbl_summary(data = df[,c(group,variables)], + by = group) |> + gtsummary::add_overall() + + x <- table(df[,c(group, score, strata)]) + f1 <- rankinPlot::grottaBar(x = x, groupName = group, + scoreName = score, + strataName = strata, + colourScheme ="custom") + + df[,score] <- factor(df[,score],ordered = TRUE) + f2 <- plot_olr(MASS::polr(formula(paste0(score,"~.")), data=df[,c(group, score, variables)], Hess=TRUE, method="logistic"), input="model") + + list("Table 1" = t1, "Figure 1" = f1, "Figure 2" = f2) +} diff --git a/docs/404.html b/docs/404.html index 8d28b25..09ea99d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -24,7 +24,7 @@ stRoke - 0.22.9.3 + 0.22.9.4 + + + + + +
+
+
+ +
+

Includes table 1, grotta bars and ordinal logistic regression plot. +Please just use this function for illustration purposes. +To dos:

+
+ +
+

Usage

+
generic_stroke(df, group, score, strata = NULL, variables = NULL)
+
+ +
+

Arguments

+
df
+

Data set as data frame

+ + +
group
+

Variable to group by

+ + +
score
+

Outcome measure variable

+ + +
strata
+

Optional variable to stratify by

+ + +
variables
+

String of variable names to include in adjusted OLR-analysis

+ +
+
+

Value

+ + +

Returns list with three elements

+
+ +
+

Examples

+
iris$ord<-factor(sample(1:3,size=nrow(iris),replace=TRUE),ordered=TRUE) 
+generic_stroke(df=iris, group = "Species", score = "ord", variables = colnames(iris)[1:3])
+#> Waiting for profiling to be done...
+#> $`Table 1`
+#> <div id="evsybsvldj" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
+#>   <style>html {
+#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
+#> }
+#> 
+#> #evsybsvldj .gt_table {
+#>   display: table;
+#>   border-collapse: collapse;
+#>   margin-left: auto;
+#>   margin-right: auto;
+#>   color: #333333;
+#>   font-size: 16px;
+#>   font-weight: normal;
+#>   font-style: normal;
+#>   background-color: #FFFFFF;
+#>   width: auto;
+#>   border-top-style: solid;
+#>   border-top-width: 2px;
+#>   border-top-color: #A8A8A8;
+#>   border-right-style: none;
+#>   border-right-width: 2px;
+#>   border-right-color: #D3D3D3;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #A8A8A8;
+#>   border-left-style: none;
+#>   border-left-width: 2px;
+#>   border-left-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_heading {
+#>   background-color: #FFFFFF;
+#>   text-align: center;
+#>   border-bottom-color: #FFFFFF;
+#>   border-left-style: none;
+#>   border-left-width: 1px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 1px;
+#>   border-right-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_title {
+#>   color: #333333;
+#>   font-size: 125%;
+#>   font-weight: initial;
+#>   padding-top: 4px;
+#>   padding-bottom: 4px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   border-bottom-color: #FFFFFF;
+#>   border-bottom-width: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_subtitle {
+#>   color: #333333;
+#>   font-size: 85%;
+#>   font-weight: initial;
+#>   padding-top: 0;
+#>   padding-bottom: 6px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   border-top-color: #FFFFFF;
+#>   border-top-width: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_bottom_border {
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_col_headings {
+#>   border-top-style: solid;
+#>   border-top-width: 2px;
+#>   border-top-color: #D3D3D3;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   border-left-style: none;
+#>   border-left-width: 1px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 1px;
+#>   border-right-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_col_heading {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: normal;
+#>   text-transform: inherit;
+#>   border-left-style: none;
+#>   border-left-width: 1px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 1px;
+#>   border-right-color: #D3D3D3;
+#>   vertical-align: bottom;
+#>   padding-top: 5px;
+#>   padding-bottom: 6px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   overflow-x: hidden;
+#> }
+#> 
+#> #evsybsvldj .gt_column_spanner_outer {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: normal;
+#>   text-transform: inherit;
+#>   padding-top: 0;
+#>   padding-bottom: 0;
+#>   padding-left: 4px;
+#>   padding-right: 4px;
+#> }
+#> 
+#> #evsybsvldj .gt_column_spanner_outer:first-child {
+#>   padding-left: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_column_spanner_outer:last-child {
+#>   padding-right: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_column_spanner {
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   vertical-align: bottom;
+#>   padding-top: 5px;
+#>   padding-bottom: 5px;
+#>   overflow-x: hidden;
+#>   display: inline-block;
+#>   width: 100%;
+#> }
+#> 
+#> #evsybsvldj .gt_group_heading {
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: initial;
+#>   text-transform: inherit;
+#>   border-top-style: solid;
+#>   border-top-width: 2px;
+#>   border-top-color: #D3D3D3;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   border-left-style: none;
+#>   border-left-width: 1px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 1px;
+#>   border-right-color: #D3D3D3;
+#>   vertical-align: middle;
+#> }
+#> 
+#> #evsybsvldj .gt_empty_group_heading {
+#>   padding: 0.5px;
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: initial;
+#>   border-top-style: solid;
+#>   border-top-width: 2px;
+#>   border-top-color: #D3D3D3;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   vertical-align: middle;
+#> }
+#> 
+#> #evsybsvldj .gt_from_md > :first-child {
+#>   margin-top: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_from_md > :last-child {
+#>   margin-bottom: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_row {
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   margin: 10px;
+#>   border-top-style: solid;
+#>   border-top-width: 1px;
+#>   border-top-color: #D3D3D3;
+#>   border-left-style: none;
+#>   border-left-width: 1px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 1px;
+#>   border-right-color: #D3D3D3;
+#>   vertical-align: middle;
+#>   overflow-x: hidden;
+#> }
+#> 
+#> #evsybsvldj .gt_stub {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: initial;
+#>   text-transform: inherit;
+#>   border-right-style: solid;
+#>   border-right-width: 2px;
+#>   border-right-color: #D3D3D3;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_stub_row_group {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   font-size: 100%;
+#>   font-weight: initial;
+#>   text-transform: inherit;
+#>   border-right-style: solid;
+#>   border-right-width: 2px;
+#>   border-right-color: #D3D3D3;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   vertical-align: top;
+#> }
+#> 
+#> #evsybsvldj .gt_row_group_first td {
+#>   border-top-width: 2px;
+#> }
+#> 
+#> #evsybsvldj .gt_summary_row {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   text-transform: inherit;
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_first_summary_row {
+#>   border-top-style: solid;
+#>   border-top-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_first_summary_row.thick {
+#>   border-top-width: 2px;
+#> }
+#> 
+#> #evsybsvldj .gt_last_summary_row {
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_grand_summary_row {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   text-transform: inherit;
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_first_grand_summary_row {
+#>   padding-top: 8px;
+#>   padding-bottom: 8px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#>   border-top-style: double;
+#>   border-top-width: 6px;
+#>   border-top-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_striped {
+#>   background-color: rgba(128, 128, 128, 0.05);
+#> }
+#> 
+#> #evsybsvldj .gt_table_body {
+#>   border-top-style: solid;
+#>   border-top-width: 2px;
+#>   border-top-color: #D3D3D3;
+#>   border-bottom-style: solid;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_footnotes {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   border-bottom-style: none;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   border-left-style: none;
+#>   border-left-width: 2px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 2px;
+#>   border-right-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_footnote {
+#>   margin: 0px;
+#>   font-size: 90%;
+#>   padding-left: 4px;
+#>   padding-right: 4px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_sourcenotes {
+#>   color: #333333;
+#>   background-color: #FFFFFF;
+#>   border-bottom-style: none;
+#>   border-bottom-width: 2px;
+#>   border-bottom-color: #D3D3D3;
+#>   border-left-style: none;
+#>   border-left-width: 2px;
+#>   border-left-color: #D3D3D3;
+#>   border-right-style: none;
+#>   border-right-width: 2px;
+#>   border-right-color: #D3D3D3;
+#> }
+#> 
+#> #evsybsvldj .gt_sourcenote {
+#>   font-size: 90%;
+#>   padding-top: 4px;
+#>   padding-bottom: 4px;
+#>   padding-left: 5px;
+#>   padding-right: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_left {
+#>   text-align: left;
+#> }
+#> 
+#> #evsybsvldj .gt_center {
+#>   text-align: center;
+#> }
+#> 
+#> #evsybsvldj .gt_right {
+#>   text-align: right;
+#>   font-variant-numeric: tabular-nums;
+#> }
+#> 
+#> #evsybsvldj .gt_font_normal {
+#>   font-weight: normal;
+#> }
+#> 
+#> #evsybsvldj .gt_font_bold {
+#>   font-weight: bold;
+#> }
+#> 
+#> #evsybsvldj .gt_font_italic {
+#>   font-style: italic;
+#> }
+#> 
+#> #evsybsvldj .gt_super {
+#>   font-size: 65%;
+#> }
+#> 
+#> #evsybsvldj .gt_footnote_marks {
+#>   font-style: italic;
+#>   font-weight: normal;
+#>   font-size: 75%;
+#>   vertical-align: 0.4em;
+#> }
+#> 
+#> #evsybsvldj .gt_asterisk {
+#>   font-size: 100%;
+#>   vertical-align: 0;
+#> }
+#> 
+#> #evsybsvldj .gt_indent_1 {
+#>   text-indent: 5px;
+#> }
+#> 
+#> #evsybsvldj .gt_indent_2 {
+#>   text-indent: 10px;
+#> }
+#> 
+#> #evsybsvldj .gt_indent_3 {
+#>   text-indent: 15px;
+#> }
+#> 
+#> #evsybsvldj .gt_indent_4 {
+#>   text-indent: 20px;
+#> }
+#> 
+#> #evsybsvldj .gt_indent_5 {
+#>   text-indent: 25px;
+#> }
+#> </style>
+#>   <table class="gt_table">
+#>   
+#>   <thead class="gt_col_headings">
+#>     <tr>
+#>       <th class="gt_col_heading gt_columns_bottom_border gt_left" rowspan="1" colspan="1" scope="col"><strong>Characteristic</strong></th>
+#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col"><strong>Overall</strong>, N = 150<sup class="gt_footnote_marks">1</sup></th>
+#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col"><strong>setosa</strong>, N = 50<sup class="gt_footnote_marks">1</sup></th>
+#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col"><strong>versicolor</strong>, N = 50<sup class="gt_footnote_marks">1</sup></th>
+#>       <th class="gt_col_heading gt_columns_bottom_border gt_center" rowspan="1" colspan="1" scope="col"><strong>virginica</strong>, N = 50<sup class="gt_footnote_marks">1</sup></th>
+#>     </tr>
+#>   </thead>
+#>   <tbody class="gt_table_body">
+#>     <tr><td class="gt_row gt_left">Sepal.Length</td>
+#> <td class="gt_row gt_center">5.80 (5.10, 6.40)</td>
+#> <td class="gt_row gt_center">5.00 (4.80, 5.20)</td>
+#> <td class="gt_row gt_center">5.90 (5.60, 6.30)</td>
+#> <td class="gt_row gt_center">6.50 (6.23, 6.90)</td></tr>
+#>     <tr><td class="gt_row gt_left">Sepal.Width</td>
+#> <td class="gt_row gt_center">3.00 (2.80, 3.30)</td>
+#> <td class="gt_row gt_center">3.40 (3.20, 3.68)</td>
+#> <td class="gt_row gt_center">2.80 (2.53, 3.00)</td>
+#> <td class="gt_row gt_center">3.00 (2.80, 3.18)</td></tr>
+#>     <tr><td class="gt_row gt_left">Petal.Length</td>
+#> <td class="gt_row gt_center">4.35 (1.60, 5.10)</td>
+#> <td class="gt_row gt_center">1.50 (1.40, 1.58)</td>
+#> <td class="gt_row gt_center">4.35 (4.00, 4.60)</td>
+#> <td class="gt_row gt_center">5.55 (5.10, 5.88)</td></tr>
+#>   </tbody>
+#>   
+#>   <tfoot class="gt_footnotes">
+#>     <tr>
+#>       <td class="gt_footnote" colspan="5"><sup class="gt_footnote_marks">1</sup> Median (IQR)</td>
+#>     </tr>
+#>   </tfoot>
+#> </table>
+#> </div>
+#> 
+#> $`Figure 1`
+
+#> 
+#> $`Figure 2`
+
+#> 
+
+
+
+ + +
+ + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html index b34907b..0a51153 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -10,7 +10,7 @@ stRoke - 0.22.9.3 + 0.22.9.4