lmer: Method B (PE catched for imbalanced dataset!!!) and Method C [🇷 for BE/BA]

posted by mittyri – Russia, 2016-11-05 18:38 (2700 d 18:04 ago) – Posting: # 16777
Views: 19,296

Dear Astea!

so many questions ;-)
I'll just put here my code as a solution. Yes, we cannot get SAS results, sorry...
Please let me know if after investigation you still have some questions

library(readxl)
library(lmerTest)
options(contrasts=c("contr.treatment","contr.poly"))
methodC <- function(Dataset){
  muddle.lmer <- (lmer(log(Data)~Sequence+Period+Formulation + (Formulation-1|Subject), data=Dataset))
  cat("\n", "lmer treats Sequence, Period and Formulation as factors, Random is /~Formulation -1|Subject/ (close to Method C), then", "\n")
  FormulationEffect.lmer <- summary(muddle.lmer)$coefficients["FormulationT","Estimate"]   print(FormulationEffect.lmer)
  cat("\n", "PE is", round(exp(as.numeric(FormulationEffect.lmer))*100, digits = 2),
      "\n", "SAS gives 115.66", "\n")
 
  cat("\n", "what about LSMeans?", "\n", "PHX gives for Method C  7.67042954073919 and 7.81589387050252", "\n", "and lmer gives", "\n")
  LSM.lmer <- lmerTest::lsmeans(muddle.lmer, "Formulation")
  print(LSM.lmer$lsmeans.table[c(1,2), c(3,4)])
 
  cat("\n", "\n", "what about CI? SAS gives 107.10-124.89", "\n")
  round(exp(confint(muddle.lmer, "FormulationT", level = 0.90))*100, 2)
}

methodB <- function(Dataset){
  muddle.lmer <- (lmer(log(Data)~Sequence+Period+Formulation + (1|Subject), data=Dataset))
  cat("\n", "lmer treats Sequence, Period and Formulation as factors, Random is /~1|Subject/ (close to Method B), then", "\n")
  FormulationEffect.lmer <- summary(muddle.lmer)$coefficients["FormulationT","Estimate"]   print(FormulationEffect.lmer)
  cat("\n", "PE is", round(exp(as.numeric(FormulationEffect.lmer))*100, digits = 2),
      "\n", "SAS gives 115.73", "\n")
 
  cat("\n", "what about LSMeans?", "\n", "PHX gives for Method B 7.67001367911898 and 7.81610190985527",  "\n", "and lmer gives", "\n")
  LSM.lmer <- lmerTest::lsmeans(muddle.lmer)
  print(LSM.lmer$lsmeans.table[c(7,8), c(3,4)])
 
  cat( "\n", "\n", "what about CI? SAS gives 107.17-124.97", "\n")
  round(exp(confint(muddle.lmer, "FormulationT", level = 0.90))*100, 2)
}

# downloading the reference file from BEBAC; that's the most convenient way to get the file
download.file('http://bebac.at/downloads/Validation Replicate Design EMA.xls', "Dataset.xls", cacheOK = FALSE, mode="wb")
# read it without Perl and Java; thanks, Hadley!
Dataset<-read_excel("Dataset.xls", sheet = 1)
# prepare dataset

Dataset$Formulation<-factor(Dataset$Formulation, levels = c("R", "T")) # for LSMeans in lmer
Dataset$Sequence<-factor(Dataset$Sequence, levels = c("TRTR", "RTRT")) # for LSMeans in lmer
Dataset$Period<-factor(Dataset$Period) # for LSMeans in lmer

methodC(Dataset)
methodB(Dataset)


Kind regards,
Mittyri

Complete thread:

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

With four parameters I can fit an elephant,
and with five I can make him wiggle his trunk.    John von Neumann

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