Introduction

This pinp is not PNAS template started when the introduction to Rcpp by \cite{PeerJ:Rcpp} was converted into this updated Rcpp Introduction vignette. It is based on the pnas_article template of the wonderful rticles package by \cite{CRAN:rticles}. The conversion from markdown to latex is facilitated by rmarkdown \citep{CRAN:rmarkdown} and knitr \citep{CRAN:knitr}. The underlying LaTeX macros are from pnas.org.

The remainder of the document carries over from the corresponding pnas_article template document. but has been edited and updated to our use case. A few specific tips follow. In general, for fine-tuning some knowledge of LaTeX is helpful.

library(DatabaseConnector)
library(CohortMethod)
library(Legend)
library(knitr)
library(xtable)
library(ggplot2)
source("DataPulls.R")
source("PlotsAndTables.R")
options(knitr.kable.NA = '')

# params <- list(databaseId = "MDCR",
#                targetId = 739138,
#                comparatorId =  715259,
#                outcomeId = 18)

useStoredObject <- TRUE

if (!useStoredObject) {
    connectionDetails <- createConnectionDetails(dbms = "postgresql",
                                                 server = "localhost/ohdsi",
                                                 user = "postgres",
                                                 password = Sys.getenv("pwPostgres"),
                                                 schema = "legend")
    connection <- connect(connectionDetails)
    targetName <- getExposureName(connection, params$targetId)
    comparatorName <- getExposureName(connection, params$comparatorId)
    outcomeName <- getOutcomeName(connection, params$outcomeId)
    analyses <- getAnalyses(connection)
    mainResults <- getMainResults(connection,
                                  targetIds = params$targetId,
                                  comparatorIds = params$comparatorId,
                                  outcomeIds = params$outcomeId,
                                  databaseIds = params$databaseId)

    attrition <- getAttrition(connection,
                              targetId = params$targetId,
                              comparatorId = params$comparatorId,
                              outcomeId = params$outcomeId,
                              analysisId = 1,
                              databaseId = params$databaseId)

    balance <- getCovariateBalance(connection,
                                   targetId = params$targetId,
                                   comparatorId = params$comparatorId,
                                   databaseId = params$databaseId)

    ps <- getPs(connection,
                targetId = params$targetId,
                comparatorId = params$comparatorId,
                databaseId = params$databaseId)

    kaplanMeier <- getKaplanMeier(connection,
                                  targetId = params$targetId,
                                  comparatorId = params$comparatorId,
                                  outcomeId = params$outcomeId,
                                  databaseId = params$databaseId,
                                  analysisId = 2)
} else {
    load("paperData.rda")
}

Methods

Results

Table \ref{tab:demographics} \ldots

\clearpage

\begin{figure*} \caption{\textbf{Patient demographics.} Target (T) population is sertaline new-users. Comparative (C) population is dulexotine new-users. We report the standardized difference of population means (StdDiff) before and after stratification for selected base-line patient characteristics.}\label{tab:demographics} \begin{center} \resizebox{0.5\textwidth}{!}{ \begin{tabular}{lrrrrrr} \hline & \multicolumn{3}{c}{Before stratification} & \multicolumn{3}{c}{After stratification} \ \multicolumn{1}{c}{Characteristic} & \multicolumn{1}{c}{T (\%)} & \multicolumn{1}{c}{C (\%)} & \multicolumn{1}{c}{StdDiff} & \multicolumn{1}{c}{T (\%)} & \multicolumn{1}{c}{C (\%)} & \multicolumn{1}{c}{StdDiff} \ \hline

table <- prepareTable1(balance)
table <- table[3:nrow(table),]

print(xtable(table, format = "latex", align = c("l","l","r","r","r","r","r","r")),
      include.rownames = FALSE,
      include.colnames = FALSE,
      hline.after = NULL,
      only.contents = TRUE,
      sanitize.text.function = identity)

\end{tabular} } \end{center} \end{figure*}

\clearpage

plot <- plotPs(ps, targetName, comparatorName)
suppressMessages(ggsave("ps.pdf", plot,
                        width = 5, height = 5, units = "in"))

\begin{figure} \centerline{ \includegraphics[width=0.4\textwidth]{ps} } \caption{\textbf{Preference score distribution for sertaline and dulexotine new-users.} The preference score is a transformation of the propensity score that adjusts for size differences between populations. A higher overlap indicates that subjects in the two populations are more similar in terms of their predicted probability of receiving one treatment over the other. } \end{figure}

More text here.

\begin{figure} \begin{tabular}{lrrrr}

table <- mainResults
table$hr <- sprintf("%.2f (%.2f - %.2f)", mainResults$rr, mainResults$ci95lb, mainResults$ci95ub)
table$p <- sprintf("%.2f", table$p)
table$calHr <- sprintf("%.2f (%.2f - %.2f)", mainResults$calibratedRr, mainResults$calibratedCi95Lb, mainResults$calibratedCi95Ub)
table$calibratedP <- sprintf("%.2f", table$calibratedP)
table <- merge(table, analyses)
table <- table[, c("description", "hr", "p", "calHr", "calibratedP")]

print(xtable(table),
      include.rownames = FALSE,
      include.colnames = FALSE,
      hline.after = NULL,
      only.contents = TRUE,
      sanitize.text.function = identity)

\end{tabular} \end{figure}

Discussion

Appendix

plot <- drawAttritionDiagram(attrition, targetName, comparatorName)
suppressMessages(ggsave("attrition.pdf", plot,
                        width = 6, height = 10, units = "in"))

\begin{figure} \begin{center} \includegraphics[width=0.66\textwidth]{attrition} \end{center} \caption{Attrition diagram for selecting new-users of }\label{fig:attrition} \end{figure}

Inline R Code

The PNAS sample included a fixed PNG image here, but this document prefers to show the results and embedding of R code.

library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
    geom_point(size=3, aes(colour=factor(cyl))) +
    theme(legend.position="none")

Here we use a standard knitr bloc with explicit options for

Digital Figures

Markdown, Pandoc and LaTeX support .eps and .pdf files.

Figures and Tables should be labelled and referenced in the standard way using the \label{} and \ref{} commands.

The R examples above show how to insert a column-wide figure. To insert a figure wider than one column, please use the \begin{figure*}...\end{figure*} environment.

One (roundabout) way of doing this is to not actually plot a figure, but to save it in a file as the following segment shows:

library(ggplot2)
p <- ggplot(data = midwest,
            mapping = aes(x = area,
                          fill = state,
                          color = state)) +
    geom_density(alpha = 0.3)
## save to file
suppressMessages(ggsave("densities.pdf", p))

This file is then included via standard LaTeX commands.

\begin{figure} \begin{center} \includegraphics[width=0.66\textwidth, height=3.5in]{densities} \end{center} \caption{Wide ggplot2 figure}\label{fig} \end{figure}

Typeset Code (But Do Not Run It)

We can also just show code.

xx <- faithful[,"eruptions"]
fit <- density(xx)
plot(fit)

This simply used a pandoc bloc started and ended by three backticks, with r as the language choice. Similarly, many other languages can be typeset directly simply by relying on pandoc.

Single column equations

Authors may use 1- or 2-column equations in their article, according to their preference.

To allow an equation to span both columns, options are to use the \begin{figure*}...\end{figure*} environment mentioned above for figures, or to use the \begin{widetext}...\end{widetext} environment as shown in equation \ref{eqn:example} below.

Please note that this option may run into problems with floats and footnotes, as mentioned in the cuted package documentation. In the case of problems with footnotes, it may be possible to correct the situation using commands \footnotemark and \footnotetext.

\begin{equation} \begin{aligned} (x+y)^3&=(x+y)(x+y)^2\ &=(x+y)(x^2+2xy+y^2) \ &=x^3+3x^2y+3xy^3+x^3. \label{eqn:example} \end{aligned} \end{equation}



OHDSI/Legend documentation built on Dec. 29, 2020, 3:52 a.m.