Learn R Programming

⚠️There's a newer version (0.9.8) of this package.Take me there.

tern

[![Check

Copy Link

Version

Install

install.packages('tern')

Monthly Downloads

2,254

Version

0.9.5

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Zhu

Last Published

April 14th, 2025

Functions in tern (0.9.5)

afun_riskdiff

Analysis function to calculate risk difference column values
afun_selected_stats

Get selected statistics names
abnormal_by_worst_grade_worsen

Patient counts for laboratory events (worsen from baseline) by highest grade post-baseline
add_riskdiff

Split function to configure risk difference column
analyze_colvars_functions

Analyze functions on columns
as.rtable

Convert to rtable
append_varlabels

Add variable labels to top left corner in table
analyze_functions

Analyze functions
control_analyze_vars

Control function for descriptive statistics
apply_auto_formatting

Apply automatic formatting
control_annot

Control functions for Kaplan-Meier plot annotation tables
abnormal

Patient counts with abnormal range values
as_factor_keep_attributes

Conversion of a vector to a factor
abnormal_by_baseline

Patient counts with abnormal range values by baseline status
assertions

Additional assertions to use with checkmate
add_rowcounts

Layout-creating function to add row total counts
abnormal_by_marked

Count patients with marked laboratory abnormalities
combination_function

Class for CombinationFunction
check_diff_prop_ci

Check proportion difference arguments
combine_counts

Combine counts
check_same_n

Check element dimension
abnormal_by_worst_grade

Patient counts with the most extreme post-baseline toxicity grade per direction of abnormality
bins_percent_labels

Labels for bins in percent
aesi_label

Labels for adverse event baskets
count_patients_events_in_cols

Count patients and events in columns
combine_groups

Reference and treatment group combination
count_patients_with_event

Count the number of patients with a particular event
combine_levels

Combine factor levels
count_cumulative

Cumulative counts with thresholds
count_missed_doses

Count missed doses
cox_regression

Cox proportional hazards regression
analyze_variables

Analyze variables
cox_regression_inter

Cox regression helper function for interactions
control_incidence_rate

Control function for incidence rate
argument_convention

Standard arguments
combine_vectors

Element-wise combination of two vectors
control_lineplot_vars

Control function for g_lineplot()
arrange_grobs

Arrange multiple grobs
analyze_vars_in_cols

Summarize numeric variables in columns
c_label_n_alt

Content row function to add alt_counts_df row total to labels
decorate_grob

Add titles, footnotes, page Number, and a bounding box to a grid grob
control_logistic

Control function for logistic regression model fitting
compare_variables

Compare variables between groups
d_test_proportion_diff

Description of the difference test between two proportions
day2month

Conversion of days to months
default_stats_formats_labels

Get default statistical methods and their associated formats, labels, and indent modifiers
control_step

Control function for subgroup treatment effect pattern (STEP) calculations
bland_altman

Bland-Altman analysis
c_label_n

Content row function to add row total to labels
decorate_grob_factory

Update page number
desctools_binom

Confidence intervals for a difference of binomials
f_conf_level

Utility function to create label for confidence interval
control_coxph

Control function for Cox-PH model
f_pval

Utility function to create label for p-value
extract_survival_subgroups

Prepare survival data for population subgroups in data frames
extreme_format

Format extreme values
d_onco_rsp_label

Description of standard oncology response
control_coxreg

Control function for Cox regression
format_auto

Format automatically using data significant digits
d_pkparam

Generate PK reference dataset
format_count_fraction

Format count and fraction
control_surv_time

Control function for survfit models for survival time
count_occurrences

Occurrence counts
count_occurrences_by_grade

Occurrence counts by grade
estimate_multinomial_rsp

Estimation of proportions per level of factor
cfun_by_flag

Constructor for content functions given a data frame with flag input
format_fraction_threshold

Format fraction with lower threshold
estimate_proportions

Estimation of proportions
format_extreme_values

Format a single extreme value
control_surv_timepoint

Control function for survfit models for patients' survival rate at time points
count_patients_with_flags

Count the number of patients with particular flags
cut_quantile_bins

Cut numeric vector into empirical quantile bins
fct_collapse_only

Collapse factor levels and keep only those new group levels
d_count_cumulative

Description of cumulative count
fct_discard

Discard specified levels of a factor
format_extreme_values_ci

Format extreme values part of a confidence interval
g_forest

Create a forest plot from an rtable
format_sigfig

Format numeric values by significant figures
count_values_funs

Count specific values
d_count_missed_doses

Description function that calculates labels for s_count_missed_doses()
d_count_abnormal_by_baseline

Description function for s_count_abnormal_by_baseline()
d_proportion

Description of the proportion summary
decorate_grob_set

Decorate set of grobs and add page numbering
default_na_str

Default string replacement for NA values
d_proportion_diff

Description of method used for proportion comparison
groups_list_to_df

Convert list of groups to a data frame
d_rsp_subgroups_colvars

Labels for column variables in binary response by subgroup table
.is_equal_float

Utility function to check if a float value is equal to another float value
draw_grob

Draw grob
empty_vector_if_na

Return an empty numeric if all elements are NA.
ex_data

Simulated CDISC data for examples
h_adlb_abnormal_by_worst_grade

Helper function to prepare ADLB for count_abnormal_by_worst_grade()
h_decompose_gg

ggplot decomposition
g_ipp

Individual patient plots
h_col_indices

Obtain column indices
h_g_ipp

Helper function to create simple line plot over time
h_count_cumulative

Helper function for s_count_cumulative()
h_ggkm

Helper function to create a KM plot
h_format_row

Helper function to format the optional g_lineplot table
explicit_na

Missing data
estimate_coef

Hazard ratio estimation in interactions
h_prop_diff_test

Helper functions to test proportion differences
h_proportions

Helper functions for calculating proportion confidence intervals
fit_survival_step

Subgroup treatment effect pattern (STEP) fit for survival outcome
h_tbl_median_surv

Helper function for survival estimations
forest_viewport

Create a viewport tree for the forest plot
h_grob_median_surv

Helper function to create survival estimation grobs
h_glm_count

Helper functions for Poisson models
d_survival_subgroups_colvars

Labels for column variables in survival duration by subgroup table
h_grob_tbl_at_risk

Helper function to create patient-at-risk grobs
df2gg

Convert data.frame object to ggplot object
format_xx

Format XX as a formatting function
df_explicit_na

Encode categorical missing values in a data frame
h_response_biomarkers_subgroups

Helper functions for tabulating biomarker effects on binary response by subgroup
extract_rsp_subgroups

Prepare response data for population subgroups in data frames
h_split_by_subgroups

Split data frame by subgroups
h_grob_coxph

Helper function to create Cox-PH grobs
h_split_param

Split parameters
h_survival_biomarkers_subgroups

Helper functions for tabulating biomarker effects on survival by subgroup
h_worsen_counter

Helper function to analyze patients for s_count_abnormal_lab_worsen_by_baseline()
extract_by_name

Extract elements by name
formatting_functions

Formatting functions
extract_survival_biomarkers

Prepare survival data estimates for multiple biomarkers in a single data frame
get_covariates

Utility function to return a named list of covariate names
get_smooths

Smooth function with optional grouping
incidence_rate

Incidence rate
h_ancova

Helper function to return results of a linear model
h_response_subgroups

Helper functions for tabulating binary response by subgroup
h_tab_one_biomarker

Helper function for tabulation of a single biomarker result
h_survival_duration_subgroups

Helper functions for tabulating survival duration by subgroup
labels_or_names

Labels or names of list elements
response_subgroups

Tabulate binary response by subgroup
month2day

Conversion of months to days
muffled_car_anova

Muffled car::Anova
rtable2gg

Convert rtable objects to ggplot objects
prune_occurrences

Occurrence table pruning
fit_logistic

Fit for logistic regression
fit_rsp_step

Subgroup treatment effect pattern (STEP) fit for binary (response) outcome
extract_rsp_biomarkers

Prepare response data estimates for multiple biomarkers in a single data frame
fct_explicit_na_if

Insertion of explicit missing values in a factor
fit_coxreg

Fitting functions for Cox proportional hazards regression
range_noinf

Re-implemented range() default S3 method for numerical objects
h_tbl_coxph_pairwise

Helper function for generating a pairwise Cox-PH table
format_count_fraction_fixed_dp

Format count and percentage with fixed single decimal place
stat_propdiff_ci

Proportion difference and confidence interval
labels_use_control

Update labels according to control specifications
strata_normal_quantile

Helper function for the estimation of stratified quantiles
logistic_regression_cols

Logistic regression multivariate column layout function
stack_grobs

Stack multiple grobs
prop_diff

Proportion difference
stat_mean_ci

Confidence interval for mean
summarize_logistic

Multivariate logistic regression table
format_count_fraction_lt10

Format count and fraction with special case for count < 10
prop_diff_test

Difference test for two proportions
summarize_num_patients

Number of patients
split_cols_by_groups

Split columns by groups of levels
summarize_functions

Summarize functions
h_append_grade_groups

Helper function for s_count_occurrences_by_grade()
split_text_grob

Split text according to available text width
to_n

Replicate entries of a vector if required
summarize_change

Summarize the change from baseline or absolute baseline values
format_fraction

Format fraction and percentage
summarize_glm_count

Summarize Poisson negative binomial regression
format_fraction_fixed_dp

Format fraction and percentage with fixed single decimal place
h_xticks

Helper function to calculate x-tick positions
g_km

Kaplan-Meier plot
g_lineplot

Line plot with optional table
imputation_rule

Apply 1/3 or 1/2 imputation rule to data
g_step

Create a STEP graph
h_adlb_worsen

Helper function to prepare ADLB with worst labs
to_string_matrix

Convert table into matrix of strings
g_waterfall

Horizontal waterfall plot
h_adsl_adlb_merge_using_worst_flag

Helper function for deriving analysis datasets for select laboratory tables
h_cox_regression

Helper functions for Cox proportional hazards regression
h_data_plot

Helper function to tidy survival fit data
tidy.step

Custom tidy method for STEP results
try_car_anova

tryCatch around car::Anova
h_grob_y_annot

Helper function to create grid object with y-axis annotation
logistic_summary_by_flag

Logistic regression summary table
h_incidence_rate

Helper functions for incidence rate
h_pkparam_sort

Sort pharmacokinetic data by PARAM variable
h_prop_diff

Helper functions to calculate proportion difference
h_km_layout

Helper function to prepare a KM layout
n_available

Number of available (non-missing entries) in a vector
odds_ratio

Odds ratio estimation
make_names

Make names without dots
reapply_varlabels

Reapply variable labels
summarize_colvars

Summarize variables in columns
h_logistic_regression

Helper functions for multivariate logistic regression
update_weights_strat_wilson

Helper function for the estimation of weights for prop_strat_wilson()
response_biomarkers_subgroups

Tabulate biomarker effects on binary response by subgroup
utils_split_funs

Custom split functions
ungroup_stats

Ungroup non-numeric statistics
rtables_access

Helper functions for accessing information from rtables
h_map_for_count_abnormal

Helper function to create a map data frame for trim_levels_to_map()
tidy_coxreg

Custom tidy methods for Cox regression
univariate

Univariate formula special term
unlist_and_blank_na

Blank for missing input
stat_mean_pval

p-Value of the mean
stat_median_ci

Confidence interval for median
h_odds_ratio

Helper functions for odds ratio estimation
s_cox_multivariate

Multivariate Cox model - summarized results
summarize_patients_exposure_in_cols

Count patients and sum exposure across all patients in columns
sas_na

Convert strings to NA
h_stack_by_baskets

Helper function to create a new SMQ variable in ADAE by stacking SMQ and/or CQ records.
survival_biomarkers_subgroups

Tabulate biomarker effects on survival by subgroup
survival_coxph_pairwise

Pairwise Cox-PH model
score_occurrences

Occurrence table sorting
study_arm

Indicate study arm variable in formula
h_step

Helper functions for subgroup treatment effect pattern (STEP) calculations
summarize_ancova

Summary for analysis of covariance (ANCOVA).
survival_duration_subgroups

Tabulate survival duration by subgroup
survival_time

Survival time analysis
survival_timepoint

Survival time point analysis
tern-package

tern Package
tidy.glm

Custom tidy method for binomial GLM results