units <- yspec::ys_get_unit( yspec::ys_help$spec(), parens =TRUE)
Data sets that come with pmtables; we’ll re-name them for later
data <- pmt_firstdata_pk <- pmt_pkdata_all <- pmt_obs
10.1 Principles
These functions expect that the user passes in all data that is to be summarized and nothing more. We will not filter your data.
10.2 Rename cols
When you select columns to summarize, you can generally pass in alternate (nicer) names that you want to show up in the table. For example, if I have a column called WT in the data frame and I want it to show up as Weight this can be accomplished during the call
Alternatively, you can use the table argument to enter rename info. Note that table is a list that should have names that match up with columns in the data frame and values that are the new names
Calculate the percent of observations or BQL in different sub groups
10.3.1 Stacked by endpoint
The stacked plot creates multiple independent tables to summarize different endpoints; there is no single overall summary for the table because we are summarizing different endpoints
Beginning with version 0.4.1, pmtables can accommodate either BQL or BLQ as the name of the column indicating that observations were below the limit of quantitation. Table notes and output column headers will be adjusted based on the input.
pmtables will summarize continuous data using a built-in function, producing standard summaries (e.g. mean, median, etc). Users can pass a function to replace this default, allowing totally customized summaries.
Custom summary functions are not currently allowed for categorical data.
10.9.1 Continuous long table
You can pass a custom summary function via fun. This function should have a first argument called value and should be able to absorb extra arguments via .... The function should return a data.frame, with a single row and summaries going across in the columns.
For example, we can have pt_cont_long() return the geometric mean and variance by passing the following function
cont_long_custom <-function(value, ...) { value <-na.omit(value) ans <-data.frame(GeoMean =exp(mean(log(value))), Variance =var(value) )mutate(ans, across(everything(), sig))}
Test the function by passing some test data
cont_long_custom(c(1,2,3,4,5))
GeoMean Variance
1 2.61 2.50
Then, pass this as fun
pt_cont_long(data = pmt_first, cols =c("WT", "ALB", "AGE"), fun = cont_long_custom)$data
See pmtables:::cont_long_fun (the default) for an example.
10.9.2 Continuous wide table
You can pass a custom summary function via fun. This function should have a first argument called value and should be able to absorb extra arguments via .... The continuous, wide table must return a data.frame with a single row and a single column named summary
cont_wide_custom <-function(value, ...) { value <-na.omit(value) geo_mean <-sig(exp(mean(log(value)))) variance <-sig(var(value)) n <-length(value) ans <-paste0(geo_mean, " [", variance, "] (", n, ")")data.frame(summary = ans)}
You can test the function by passing some test data
cont_wide_custom(c(1, 3, 5))
summary
1 2.47 [4.00] (3)
Then, pass this as fun
pt_cont_wide(data = pmt_first, cols =c("WT", "ALB", "AGE"), fun = cont_wide_custom)$data