knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(survival)
library(myReportRx)
library(tidyverse)

# This will select pander tables for Word documents and kable + kableExtra for pdf/html documents and leave as is for chunk execution in Rstudio
if (is.null(knitr::pandoc_to())){options('doc_type'='tblOnly')} else {if (knitr::pandoc_to("docx")) {options('doc_type'='doc')} else (options('doc_type'='pdf'))}

# Uncomment to create the packages.bib file of R packages used
#knitr::write_bib((.packages(all.available=T)),file ='packages.bib')

Introduction {-}

This is an rMarkdown document to produce Word and Pdf files from the reportRx package [@R-reportRx].

First, make some changes to the lung data.

data(lung)
lung <- lung %>%
  mutate(
    Status=factor(status-1),
    Sex = factor(sex,labels = c('Male','Female')),
    AgeGroup = cut(age, breaks=seq(0,100,10)),
    OneLevelFactor = factor(x='one level')
  ) %>%
  arrange(Status)

lung$x_null = rnorm(nrow(lung))
lung$x_pred = c(rnorm(sum(lung$Status==0),0,1),
                rnorm(sum(lung$Status==1),1,1))
set.seed(1)
test_data = tibble(
  y= rnorm(1000),
  x0= geoR::rboxcox(1000, lambda=.5, mean=10, sd=2),
  x1= x0+y
)

Numbered Heading

Test covsum

rm_covsum(data=lung,
       covs=c('Status','Sex','age','AgeGroup','meal.cal','OneLevelFactor')
)
rm_covsum(data=lung,
       covs=c('Status','age','AgeGroup','meal.cal','OneLevelFactor'),
       maincov = 'Sex')

Test plotunivariate

Figure \@ref(fig:test-plotunivariate) shows the bivariate relationships between the response and covariates. Figure referencing works only when a figure caption is provided in the chunk options. Note that underscores and not allowed in the chunk names, only hyphens.

plot_univariate(data=lung,
                covs=c('Sex','age','AgeGroup','meal.cal','OneLevelFactor'),
                response = 'Status',
                response_title = 'Test Response Title',
                showN=T
)

Tests for uvsum

Test logistic

Tables \@ref(tab:test-uv-logistic-1), \@ref(tab:test-uv-logistic-2) and \@ref(tab:test-uv-logistic-3) display the logistic regression results with different confidence interval widths. If the document in knit to pdf, the chank-lable option will not be used, instead the name of the chunk will be used in cross-referening. For Word tables the chunk label needs to be added into the function call.

rm_uvsum(response = 'Status',
      covs=c('age','Sex','wt.loss'),
      data=lung,
      type='logistic',
      chunk_label = 'test-uv-logistic-1' )
rm_uvsum(response = 'Status',
      covs=c('age'),
      data=lung,
      type='logistic',
      CIwidth=.9,
      chunk_label='test-uv-logistic-2')
rm_uvsum(response = 'Status',
      covs=c('age'),
      data=lung,
      type='logistic',
      CIwidth=.99,
      chunk_label='test-uv-logistic-3')
rm_uvsum(response = 'Status',
      covs=c('age:Sex'),
      data=lung,
      type='logistic',
      CIwidth=.99,
      chunk_label='test-uv-logistic-3')

Test Linear

rm_uvsum(response = 'wt.loss',
      covs=c('Status','Sex','ph.ecog','meal.cal','age'),
      data=lung,
      CIwidth=.95)
rm_uvsum(response = 'wt.loss',
      covs=c('age'),
      data=lung,
      CIwidth=.90)

Test coxph

rm_uvsum(response = c('time','status'),
      covs=c('Sex','ph.ecog','meal.cal','age'),
      data=lung,
      CIwidth=.95)
rm_uvsum(response = c('time','status'),
      covs=c('Sex','ph.ecog','meal.cal','age'),
      data=lung,
      CIwidth=.90)

\newpage

Unnumbered Heading {-}

Test mvsum

m = glm(Status~wt.loss+Sex+AgeGroup,
        data=lung,
        family='binomial')
rm_mvsum(m,data = lung,HolmGlobalp = T)

This type of interaction works ok

m = glm(Status~wt.loss*Sex+AgeGroup,
        data=lung,
        family='binomial')
rm_mvsum(m,data = lung,HolmGlobalp = T)

But this one fails

m = glm(Status~wt.loss:Sex+AgeGroup,
        data=lung,
        family='binomial')
rm_mvsum(m,data = lung,HolmGlobalp = T)

References

\newpage

Appendix

Other results can go here.

Test crr

rm_uvsum(response = c('time','status'),
      covs=c('Sex','ph.ecog','meal.cal','age'),
      data=lung,
      type='crr',
      CIwidth=.90)

rm_uvsum(response = c('time','status'),
      covs=c('age'),
      data=lung,
      type='crr')

Test boxcox

rm_uvsum(response = 'y',
      covs=c('x0','x1'),
      data=test_data,
      type='boxcox',
      CIwidth=.90)


Avery-Lisa/myReportRx documentation built on May 23, 2021, 2:30 a.m.