check code for Type III in R [🇷 for BE/BA]

posted by WHM – Korea, 2015-02-16 08:54 (3328 d 15:28 ago) – Posting: # 14425
Views: 5,633

Dear R users

I've used SAS proc glm or WNL for BE.
Recently, I've tried to get type III anova table (because of my manager who loves R). I've noticed that it is difficult to manage type III ANOVA Table.
I read prior posts and compared SAS proc glm, proc mixed and WNL, so I've known some problems and solutions. I've tried drop1() mentioned prior posts but it did now show all SAS showed.
firstly, I(actually my manager) want to take basic code using lm() for unbalanced data which is 2x2x2 crossover design.
I used two lm() models. one is treatment(TRT) behind period(PRD), the other is period(PRD) behind treatment(TRT).
so here is my code for type III anova table and sas results(WNL is also same result).
Can I use this code for type III anova table in 2x2x2 crossover design ?

----R code--------------------------------------------
lm.test1<-lm(log(Cmax)~TRT+PRD+SEQ+SID:SEQ, data=df)
lm.test2<-lm(log(Cmax)~PRD+TRT+SEQ+SID:SEQ, data=df)
anova.F<-anova(lm.test1)
# trt result to lm.test1 to make type III
anova.F[1,]<-anova(lm.test2)[2,]
#Tests of Hypotheses Using the Type III MS for subject(sequence) as an Error Term
anova.F[3,4]<-anova.F[3,3]/anova.F[4,3] 
anova.F[3,5]<-pf(anova.F[3,4],anova.F[3,1],anova.F[4,1],lower.tail =F)


----R result--------------------------------------------
Analysis of Variance Table

Response: log(Cmax)
          Df  Sum Sq Mean Sq F value    Pr(>F)   
TRT        1  0.1181 0.11805  1.3950    0.2436   
PRD        1  0.0765 0.07649  0.9039    0.3467   
SEQ        1  0.5889 0.58890  1.6448    0.2061   
SEQ:SID   46 16.4697 0.35804  4.2308 1.458e-06 ***
Residuals 46  3.8928 0.08463                     


----SAS result(proc glm)--------------------------------------------

Source DF Type III SS Mean Square F Value Pr > F
SEQ 1 0.58889907 0.58889907 6.96 0.0113
SID(SEQ) 46 16.46968620 0.35803666 4.23 <.0001
PRD 1 0.07648993 0.07648993 0.90 0.3467
TRT 1 0.11805116 0.11805116 1.39 0.2436

Tests of Hypotheses Using the Type III MS for subject(sequence) as an Error Term
Source DF Type III SS Mean Square F Value Pr > F
SEQ 1 0.58889907 0.58889907 1.64 0.2061


Best regards
WHM

Complete thread:

UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,636 registered users;
75 visitors (0 registered, 75 guests [including 8 identified bots]).
Forum time: 00:22 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