diff --git a/Comp/r-sas_ci_for_poissonrate.qmd b/Comp/r-sas_ci_for_poissonrate.qmd index ffecf3085..b26f08004 100644 --- a/Comp/r-sas_ci_for_poissonrate.qmd +++ b/Comp/r-sas_ci_for_poissonrate.qmd @@ -4,11 +4,15 @@ title: "Confidence Intervals Poisson Exposure Adjusted Incidence Rates (EAIR)" # Introduction -A unified family of methods covering the single rate and all contrasts for independent Poisson rates was described by Laud^1, with the addition of a bias correction for the OR case^2. +A unified family of methods covering the single rate and all contrasts for independent Poisson rates was described by Laud\^1, with the addition of a bias correction for the OR case\^2. # Summary -This page is a placeholder whilst further content is being developed. To date, using the {ratesci} R package developed by Pete Laud compared to using the [SAS macro](https://github.com/PeteLaud/ratesci-sas/blob/main/scoreci.sas) also developed by Pete Laud achieved a full match in results. In one scenario the SAS macro returned an error (whereas R returned valid results), however this was due to the way different computer environments handle floating point rounding. It was fixed by updating rows 449 and 450 of the SAS macro from using 1E-15 (15 decimals) to be 1E-9 (9 decimals). +This page is a placeholder whilst further content is being developed. + +In many cases, using the {ratesci} R package developed by Pete Laud compared to using the [SAS macro](https://github.com/PeteLaud/ratesci-sas/blob/main/scoreci.sas) also developed by Pete Laud achieved a full match in results. + +In one scenario the SAS macro returned an error (whereas R returned valid results), however this was due to the way different computer environments handle floating point rounding. It was fixed by updating rows 449 and 450 of the SAS macro from using 1E-15 (15 decimals) to be 1E-9 (9 decimals). ``` %else %if "&distrib." = "poi" %then %do; @@ -20,6 +24,8 @@ This page is a placeholder whilst further content is being developed. To date, u ``` +In a few other scenarios, particularly when results crossed the cut point (eg. 0.000499 vs 0.000500), even using the same rounding method across SAS & R (eg. both using round to even or using round up), led to different results to the third decimal. It is believe this was just due to large decimal rounding eg. above to 9 or 15 decimals or Floating point errors, however more research is needed. + # References 1\) Laud, P. J. [Equal-tailed confidence intervals for comparison of rates](https://doi.org/10.1002/pst.1813).*Pharmaceutical Statistics***16**, 334–348 (2017). diff --git a/Comp/r-sas_ci_for_prop_stratified.qmd b/Comp/r-sas_ci_for_prop_stratified.qmd new file mode 100644 index 000000000..17701f83d --- /dev/null +++ b/Comp/r-sas_ci_for_prop_stratified.qmd @@ -0,0 +1,28 @@ +--- +title: "Confidence Intervals - proportions for stratified designs" +--- + +# Introduction + +As documented [here](Confidence%20limits%20using%20the%20Miettinen-Nurminen%20stratified%20method%20as%20de...%20-%20SAS%20Support%20Communities), there is requirement to use methods other than the wald method, for CI's for proportions. In certain cases, for example, when you have a baseline imbalance of stratification factors, the stratified Miettinen-Nurminen 1985 method is recommended. + +# Packages + +There are two identified R packages that can do this: + +- [{ratesci}](petelaud/ratesci:%20Confidence%20intervals%20and%20tests%20for%20comparison%20of%20rates) +- [{cicalc}](Stratified%20Miettinen-Nurminen%20Confidence%20Interval%20for%20Difference%20in%20Proportions%20—%20ci_prop_diff_mn_strata%20•%20cicalc) + +There are two available macros to use in SAS: + +- [scoreci](https://psiaims.github.io/CAMIS/SAS/Score%20confidence%20intervals%20and%20tests%20for%20a%20single%20binomial%20or%20Poisson%20rate,%20or%20for%20comparisons%20of%20independent%20rates,%20with%20or%20without%20stratification.%20%E2%80%94%20scoreci%20%E2%80%A2%20ratesci) + +- [PharmaSUG paper](https://pharmasug.org/proceedings/2025/SA/PharmaSUG-2025-SA-198.pdf) + +This page is a placeholder whilst further content is being developed. See the individual R and SAS pages for guidance on using each macro. Note that SAS Proc freq should not be used for stratified Miettinen-Nurminen 1985 method, as it's actually performing an unstratified approach. + + +Generally, the 4 methods agreed. The scoreci macro calculates the confidence intervals iteratively using MLE, however, the PharmaSUG paper's method calculates confidence intervals using weighted difference of rates. When the sample size within strata were small this led to small numeric discrepancies. + +cicalc in R vs scoreci sas macro reached agreement in the examples tested. + diff --git a/SAS/ci_for_prop_stratified.qmd b/SAS/ci_for_prop_stratified.qmd index d3ac9cf4c..da2ce3e08 100644 --- a/SAS/ci_for_prop_stratified.qmd +++ b/SAS/ci_for_prop_stratified.qmd @@ -6,7 +6,7 @@ title: "Confidence Intervals - proportions for stratified designs" As documented [here](Confidence%20limits%20using%20the%20Miettinen-Nurminen%20stratified%20method%20as%20de...%20-%20SAS%20Support%20Communities), there is requirement to use methods other than the wald method, for CI's for proportions. In certain cases, for example, when you have a baseline imbalance of stratification factors, the stratified Miettinen-Nurminen 1985 method is reccommended. -You may think that SAS can do this method using the following code. However, this is performing an unstratified miettinen-nurminen method. The output would contain the risk differences calculated for each strata seperately and then a common risk difference (however this is not a stratified approach). See [SAS](https://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_freq_details63.htm) for more detail of SAS's calculations and . +You may think that SAS can do this method using the following code. However, this is performing an unstratified miettinen-nurminen method. The output would contain the risk differences calculated for each strata separately and then a common risk difference (however this is not a stratified approach). See [SAS](https://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_freq_details63.htm) for more detail of SAS's calculations. ``` sas proc freq data = xxxx; @@ -18,12 +18,10 @@ run; There are two available macros to use in SAS: -- [{ratesci}](Score confidence intervals and tests for a single binomial or Poisson rate, or for comparisons of independent rates, with or without stratification. — scoreci • ratesci) -- [cytel](A%20SAS%20Macro%20Calculating%20Confidence%20Intervals%20of%20the%20Difference%20in%20Binomial%20Proportions%20from%20Stratified%20Analysis%20using%20the%20Miettinen%20&%20Nurminen%20Method%20with%20Cochran-Mantel-Haenszel%20Weights) +- [scoreci](Score%20confidence%20intervals%20and%20tests%20for%20a%20single%20binomial%20or%20Poisson%20rate,%20or%20for%20comparisons%20of%20independent%20rates,%20with%20or%20without%20stratification.%20—%20scoreci%20•%20ratesci) +- [PharmaSUG paper](https://pharmasug.org/proceedings/2025/SA/PharmaSUG-2025-SA-198.pdf) -This page is a placeholder whilst further content is being developed. - -To date the cytel macro has been been extensively tested by CAMIS project (please contact us if you'd like to help with this research!). However, the ratesci macro has been tested against {cicalc} and {ratesci} r packages and found to have agreement. +The scoreci macro calculates the confidence intervals iteratively using MLE, however, the PharmaSUG paper's method calculates confidence intervals using weighted difference of rates. Therefore, the results can have very small differences (observed at the 2nd and 3rd decimal place), but these only arose when the sample size within each strata was very small. In most cases, the 2 macros aligned numerically. ``` NOTE that: skew = FALSE option, indicates no skewness correction which gives us the miettinen-nurminen method. @@ -37,10 +35,10 @@ etc. %SCORECI(DS=, - CONTRAST = RD, - SKEW = FALSE, - LEVEL = 0.95, - STRATIFY = TRUE, - OUTPUT = TRUE, - WEIGHT = 1); + CONTRAST = RD, + SKEW = FALSE, + LEVEL = 0.95, + STRATIFY = TRUE, + OUTPUT = TRUE, + WEIGHT = 1); ```