Calculate a subject level rate from numerator and denominator data
This function takes in a list of data frames including dfSUBJ, dfNumerator, and dfDenominator, and calculates a subject level rate based on the specified numerator and denominator methods (either "Count" or "Sum"). If the method is "Count", the function simply counts the number of rows in the provided data frame. If the numerator method is "Sum", the function takes the sum of the values in the specified column (strNumeratorCol or strDenominatorCol). The function returns a data frame with the calculated input rate for each subject.
The data requirements for the function are as follows:
dfSubjects: A data frame with columns for SubjectID and any other relevant subject information
dfNumerator: A data frame with a column for SubjectID and
strNumeratorColifstrNumeratorMethodis "Sum"dfDenominator: A data frame with a column for SubjectID and
strDenominatorColifstrDenominatorMethodis "Sum"
All other columns are dropped from the output data frame. Note that if no values for a subject are found in dfNumerator/dfDenominator numerator and denominator values are filled with 0 in the output data frame.
Arguments
- dfSubjects
data.framewith columns for SubjectID and any other relevant subject information- dfNumerator
data.framewith a column for SubjectID andstrNumeratorColifstrNumeratorMethodis "Sum"- dfDenominator
data.framewith a column for SubjectID andstrDenominatorColifstrDenominatorMethodis "Sum"- strGroupCol
characterColumn name indfSubjectsto use for grouping. Default: "GroupID"- strGroupLevel
charactervalue for the group level. Default: NULL which is parsed tostrGroupCol- strSubjectCol
characterColumn name indfSubjectsto use for subject ID. Default: "SubjectID"- strNumeratorMethod
characterMethod to calculate numerator. Default: "Count"- strDenominatorMethod
characterMethod to calculate denominator. Default: "Count"- strNumeratorCol
characterColumn name indfNumeratorto use for numerator calculation. Default: NULL- strDenominatorCol
characterColumn name indfDenominatorto use for denominator calculation. Default: NULL
Value
data.frame with the following specification:
| Column Name | Description | Type |
| SubjectID | The subject ID | Character |
| GroupID | The group ID | Character |
| GroupLevel | The group type | Character |
| Numerator | The calculated numerator value | Numeric |
| Denominator | The calculated denominator value | Numeric |
| Metric | The calculated input rate/metric | Numeric |
Examples
# Run for AE KRI
dfInput <- Input_Rate(
dfSubjects = gsm.core::lSource$Raw_SUBJ,
dfNumerator = gsm.core::lSource$Raw_AE,
dfDenominator = gsm.core::lSource$Raw_SUBJ,
strSubjectCol = "subjid",
strGroupCol = "invid",
strGroupLevel = "Site",
strNumeratorMethod = "Count",
strDenominatorMethod = "Sum",
strDenominatorCol = "timeontreatment"
)