ElMaestro
★★★

Denmark,
2017-08-29 12:20
(2403 d 11:59 ago)

Posting: # 17747
Views: 8,648
 

 confint() for difference of effect levels [🇷 for BE/BA]

Hi all,

let us say we have an lm object for a BE analysis in a study where we have n treatments.
Is there a way to use confint() to derive CI's for the difference of the i'th and j'th treatments (where obviously i!=j, and i is within 1..n and j is within 1..n) ?

If not, is there another built-in function that achieves this goal?

Google isn't my friend.:-):-)
Many thanks.

Pass or fail!
ElMaestro
d_labes
★★★

Berlin, Germany,
2017-08-29 14:23
(2403 d 09:56 ago)

@ ElMaestro
Posting: # 17749
Views: 7,864
 

 confint() for difference of effect levels

Dear Öberster Größter Meister,

❝ let us say we have an lm object for a BE analysis in a study where we have n treatments.

Ok. I assume we have.

❝ Is there a way to use confint() to derive CI's for the difference of the i'th and j'th treatments (where obviously i!=j, and i is within 1..n and j is within 1..n) ?

No. confint() gives you confidence intervals for the model parameters only.

❝ If not, is there another built-in function that achieves this goal?

Built in I know of none, if you mean a base R installation. Only from add-on packages.
Have a look at package multcomp.
Or if you prefer using such beasts like "least square means" have a look at package lsmeans.

BTW: All-at-once is not the preferred method of a big regulatory body.
Pairwise lm objects (throwing away the data under those treatments not under consideration) will give you the opportunity to use confint() to derive CI's.

Regards,

Detlew
ElMaestro
★★★

Denmark,
2017-08-29 16:45
(2403 d 07:34 ago)

@ d_labes
Posting: # 17751
Views: 7,938
 

 confint() for difference of effect levels

Hi d_labes,

thanks for your input.

❝ No. confint() gives you confidence intervals for the model parameters only.


Except when we fit the model with intercept, treatment first. Now the SE for whichever treatment is not the intercept, is the SE of the difference (and the other treatment effect is unestimable because of the intercept). The funny logic of linear models. I need to get my head around that aspect.


❝ Or if you prefer using such beasts like "least square means" have a look at package lsmeans.


When we look at treatment effect differences it does not matter how we define the effects by contrast coding. I don't absolutely need an LSMean; I can do with two model effects calcuated in any valid way as long as I can extract their difference.

❝ BTW: All-at-once is not the preferred method of a big regulatory body.


Yes, I have heard of that big regulatory body. But there is a problem. All-at-once is the preferred method of another big regulatory body.:-D:-D:-D:-D


❝ Pairwise lm objects (throwing away the data under those treatments not under consideration) will give you the opportunity to use confint() to derive CI's.

So if we are not considering the big agency, but the other big agency :-), and we are not throwing away treatments when fitting models, how would you approach the CI derivation in R?

Many thanks.

Pass or fail!
ElMaestro
ElMaestro
★★★

Denmark,
2017-08-30 01:18
(2402 d 23:02 ago)

@ ElMaestro
Posting: # 17753
Views: 7,769
 

 Homecooked solution?

Hi all,

since no standard function exists which helps me along, I wrote the stuff below.
The structure of the input file is like in the appendices for Schütz, Labes, Fuglsang's paper in the AAPS Journal.
I am sure the code police will tell me this isn't efficient :-D because the same could be achieved with fewer code lines or some apply family calls. I am sure that is correct. Does the code achieve its goal properly, though? That is a much more interesting question. Not at all throughly tested and certainly not validated.
The purpose is to allow some CI info where we don't ask for "T/R" but perhaps for "R/T" or for "B/D" or "Foo/Bar", whatever.




Extract.Hot.Info=function(TreatmentRatio, Z)
{
  i=regexpr("/", TreatmentRatio)
  T1=substring(TreatmentRatio, 1, i-1)
  T2=substring(TreatmentRatio, i+1, nchar(TreatmentRatio)) ##heck!
  for (i in 1:nrow(Z))
   {
    if (as.character(Z[i,1]) == T1) E1=as.numeric(Z[i,2])
    if (as.character(Z[i,1]) == T2) E2=as.numeric(Z[i,2])
   }
  return(E1-E2)
}

Get.CI.BE=function(FName,  alpha, TreatmentRatio, Stage.Term=F)
{
  A=read.table(FName, header=T) ##Note Var is untransformed
  if (Stage.Term)
   M=lm(log(Var)~factor(Trt)+factor(Seq)+factor(Per)+factor(Subj)+factor(Stg), data=A)
  else
   M=lm(log(Var)~factor(Trt)+factor(Seq)+factor(Per)+factor(Subj), data=A)
 
  df=M$df.residual
  Sc=summary(M)$coefficients
  Trt.Lvls=levels(A$Trt)
  Eff.Lvls=rep(0, length(Trt.Lvls)) ##pseudo effect levels. Usefyl for for extr. of differences
 
  for (i in 1:nrow(Sc))
  for (j in 1:length(Trt.Lvls))
   {
    x=paste("factor(Trt)", as.character(Trt.Lvls[j]), sep="")
    if (rownames(Sc)[i]==x) { Eff.Lvls[j]=Sc[i,1]; SEdiffs=Sc[i,2]}
   }
  Z=data.frame(Trt.Lvls, Eff.Lvls)
  Diff.LogScale=Extract.Hot.Info(TreatmentRatio,Z)
  logL=Diff.LogScale-SEdiffs*qt(p=1-alpha, df=df)
  logU=Diff.LogScale+SEdiffs*qt(p=1-alpha, df=df)
  L=list(PE=exp(Diff.LogScale), Lower=exp(logL), Upper=exp(logU))
  return(L)
}
## call it like Get.CI.BE("Cojones.txt",  0.05, "T/R", F)


Pass or fail!
ElMaestro
mittyri
★★  

Russia,
2017-08-30 10:11
(2402 d 14:08 ago)

@ ElMaestro
Posting: # 17754
Views: 7,710
 

 Restaurant solution

Hi ElMaestro,

❝ When we look at treatment effect differences it does not matter how we define the effects by contrast coding. I don't absolutely need an LSMean; I can do with two model effects calcuated in any valid way as long as I can extract their difference.

Homecook is good, but sometimes you can go to restaurant:-D:

library("lsmeans")
confint(pairs(lsmeans(M, "Trt"), reverse =TRUE), level=1-alpha*2)


I like this package, there is even support for nested structures in latest version.

Kind regards,
Mittyri
ElMaestro
★★★

Denmark,
2017-08-30 11:27
(2402 d 12:53 ago)

@ mittyri
Posting: # 17755
Views: 7,768
 

 Great

Hi Mittyri,


library("lsmeans")

❝ confint(pairs(lsmeans(M, "Trt"), reverse =TRUE), level=1-alpha*2)


Thanks a lot.
This really reminds me of someone who once told me that when I get a good idea then I can be quite certain that somewhere someone else had that same idea already.

Have a good day.

Pass or fail!
ElMaestro
d_labes
★★★

Berlin, Germany,
2017-08-30 21:55
(2402 d 02:24 ago)

@ ElMaestro
Posting: # 17758
Views: 7,663
 

 All-at-once or Two-at-a-time

Dear ElMaestro,

❝ ... Yes, I have heard of that big regulatory body. But there is a problem. All-at-once is the preferred method of another big regulatory body.:-D:-D:-D:-D


If you speak here FDAish have a look at this post.
Unfortunately the reference is no longer found on the Inder-net.

Regards,

Detlew
UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,636 registered users;
81 visitors (0 registered, 81 guests [including 7 identified bots]).
Forum time: 23:20 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

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