Calculating 90% CIs in R vs Python [Software]

posted by Dorota_ – Poland, 2024-11-08 19:35 (573 d 02:30 ago) – Posting: # 24266
Views: 2,848

Hi all,

I want to write a Python code for calculating 90% CIs for point estimates in a 2x2 BE setup. As a reference set I chose the NCAResult4BE dataset from Kyun-SeopBae's BE library. When I run the code:

be2x2(NCAResult4BE, c("Cmax"))

I get the following results:

$Cmax$`90% Confidence Interval of Geometric Mean Ratio (T/R)`
                 Lower Limit Point Estimate Upper Limit
90% CI for Ratio   0.9013625      0.9798396    1.065149


I can easily replicate them using nlme library:

cmax_ = lme(log(Cmax) ~ GRP + PRD + TRT, random = ~1|SUBJ,
            data = data,
            control = lmeControl(opt = "optim"))
cmax = exp(intervals(cmax_, 0.9)$fixed["TRTT",])


The problem starts in Python (3.11) and statsmodels (0.14.4).

model = smf.mixedlm("np.log(Cmax) ~ C(GRP) + C(PRD) + C(TRT, Treatment('R'))",
                    data=NCAdata,
                    groups=NCAdata["SUBJ"],
                    re_formula="~1")
result = model.fit()
conf_ints = result.conf_int(alpha=0.1)
treatment_t_index = conf_ints.index[conf_ints.index.str.contains("T")] conf_int_treatment_t = conf_ints.loc[treatment_t_index] exp_coeff = np.exp(conf_int_treatment_t)
print("Exponentiated 90% Confidence Interval for 'TreatmentT':")
print(exp_coeff)


The results are similar, but not the same:

Exponentiated 90% Confidence Interval for 'TreatmentT':
                                    0         1
C(TRT, Treatment('R'))[T.T]  0.903614  1.062496


Honestly, I have no idea what am I missing. Perhaps someone has stumbled upon a similar issue? Could the rounding be a problem or a model? Is there a way I could fix it?

D.

Complete thread:

UA Flag
Activity
 Admin contact
23,653 posts in 4,991 threads, 1,570 registered users;
149 visitors (0 registered, 149 guests [including 34 identified bots]).
Forum time: 23:05 CEST (Europe/Vienna)

I’m all in favor of the democratic principle
that one idiot is as good as one genius, but I draw the line
when someone takes the next step and concludes
that two idiots are better than one genius.    Leo Szilard

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5