SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The...

28
SAS PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: [email protected] non-linear mixed models maximum likelihood repeated measurements on each subject (i) response vector i y random effect vector i u any distribution ( ) i i 1 py u, β ( ) i 2 qu β multivariate normal i u likelihood ( ) ( ) ( ) i i i 1 i 2 i i u py u, qu du β =∏ β β multidimensional integral evaluated by Gaussian quadrature (default) likelihood maximised numerically; default Quasi-Newton 1

Transcript of SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The...

Page 1: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

SAS PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004

E-mail: [email protected]

• non-linear mixed models • maximum likelihood • repeated measurements on each subject (i) • response vector iy • random effect vector iu• any distribution ( )i i 1p y u ,β

( )i 2q u β• multivariate normal iu

• likelihood ( ) ( ) ( )

i

i i 1 i 2 ii

u

p y u , q u duβ = ∏ β β∫

• multidimensional integral evaluated by Gaussian quadrature (default) • likelihood maximised numerically; default Quasi-Newton

1

Page 2: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

• multi-level models

e.g i = batch ( )2i ww ~ N 0,σ ; i = 1,...,b

j = sample ( )2ij uu ~ N 0,σ ; j = 1,...,s

k = sub-sample response vector ( )ij ij i ijy : p y w ,u

likelihood

( ) ( ) ( )i ij

ij i ij u ij ij w i ii w j u

p y | w ,u q u du q w dw⎡ ⎤= ∏ ∫ ∏ ∫⎢ ⎥⎣ ⎦

effectively a 2-D integral

2

Page 3: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

SAS NLMIXED does not (yet) take advantage of this factorisation; it allows only one RANDOM statement Specifying, subject = batch(i) random effect ( )

( )

TTi i i1 is T T Ti i1 is

v w ,u ,...,u

y y ,..., y

=

=

likelihood = ( ) ( )

ii i i i

i vp y | v q v dv∏ ∫

an (s + 1) – D integral feasible for s reasonably low.

3

Page 4: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

3 illustrations of NLMIXED

• Normal Bi-exponential model • Binary 3-level non-linear model • Repeated ordinal data proportional odds model with subject effects

4

Page 5: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Indomethicin Kenetics; Pinheiro & Bates (P&B) §6.2

0.0

0.5

1.0

1.5

2.0

2.5

3.0

0 1 2 3 4 5 6 7 8 0.0

0.5

1.0

1.5

2.0

2.5

3.0

0 1 2 3 4 5 6 7 8 0.0

0.5

1.0

1.5

2.0

2.5

3.0

0 1 2 3 4 5 6 7 8

Indo

met

hici

n co

ncen

tratio

n (m

cg/m

l) Subject 2 Subject 3 Subject 1

0.0

0.5

1.0

1.5

2.0

2.5

3.0

0 1 2 3 4 5 6 7 8

0.0

0.5

1.0

1.5

2.0

2.5

3.0

0.5

1.0

1.5

2.0

2.5

3.0

Subject 5Subject 4 Subject 6

T

0 1 2 3 4 5 6 7 80.0

0 1 2 3 4 5 6 7 8

ime since drug administration (hr)

5

Page 6: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Normal Bi-exponential model; random coefficients

( ) ( )( ) ( )

ij 1 1i 2 2i j

3 3i 4 4i j ij

y b exp exp b t

b exp exp b t

⎡ ⎤= β + − β +⎣ ⎦⎡ ⎤+ β + − β + + ε⎣ ⎦

( )2 4β > β i = 1,..., 6 subjects

jt ; 11 times for each subject Normal theory:

( )2ij ~ N 0,ε σ

( ) ( )T1i 2i 3i 4ib ,b ,b ,b ~ N 0,ψ

6

Page 7: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Fitting: maximum likelihood P&B fit NLME models using linear approximations NLMIXED uses adaptive Gaussian quadrature - more computationally intensive - by using a lot of quadrature points can get accurate

approximation to m.l.e.

7

Page 8: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

P&B select model with

21

212 1 2 2

23

ss s s0 0 s0 0 0 0

⎛ ⎞⎜ ⎟ρ⎜ ⎟Ψ =⎜ ⎟⎜ ⎟⎝ ⎠

SAS NLMIXED code proc nlmixed gconv=1e-13 data=a ; parms beta1=2.8 beta2=0.89 beta3=0.61 beta4=-1.1 s1=1 s2=1 s3=1 rho12=0 sigma=0.2; bounds s1>0, s2>0, s3>0, rho12>-1, rho12<1, sigma>0; model conc~normal((beta1+b1)*exp(-exp(beta2+b2)*time) +(beta3+b3)*exp(-exp(beta4)*time) , sigma**2); random b1 b2 b3 ~ normal( [0,0,0], [s1**2,rho12*s1*s2,s2**2,0,0,s3**2]) subject=subject; run;

8

Page 9: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Results

P & B NLMIXED (21 points)

ˆlog L 57.532

58.4741β 2.8045 2.81002β 0.8502 0.98163β 0.5887 0.76044β –1.1029 –0.8810

1s 0.6950 0.79592s 0.1707 0.15993s 0.1834 0.227212ρ 0.905 1.000

σ 0.07823 0.07750

9

Page 10: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

set ( )12 1i 2iCorr b ,b 1ρ = =

⇒ 2i 1i 2 1b b s /s=

21

21 2 2

23

ss s s0 0 s0 0 0 0

⎛ ⎞⎜ ⎟⎜ ⎟Ψ =⎜ ⎟⎜ ⎟⎝ ⎠

proc nlmixed gconv=1e-13 data=a ; parms beta1=2.8100 beta2=0.9816 beta3=0.7604 beta4=-0.8810 s1=0.7959 s2=0.1599 s3=0.2272 sigma=0.07750; bounds s1>0, s2>0, s3>0, sigma>0; model conc~normal((beta1+b1)*exp(-exp(beta2+b1*s2/s1)*time) +(beta3+b3)*exp(-exp(beta4)*time) , sigma**2); random b1 b3 ~ normal( [0,0], [s1**2,0,s3**2]) subject=subject;

run; 10

Page 11: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Quadrature Points 5 Parameter Estimates Standard Parameter Estimate Error beta1 2.8097 0.3525 beta2 0.9815 0.1267 beta3 0.7603 0.1577 beta4 -0.8812 0.1466 s1 0.7949 0.2823 s2 0.1595 0.08139 s3 0.2271 0.07194 sigma 0.07750 0.007452

11

Page 12: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

BINARY MULTI-LEVEL MODEL

Hyper pigmentation

3 levels : 33 panellists (k) 2 armpits (j) 15 visits (i)

response variable: = presence of hyperpigmentation ijky ~ Binary ( )ijkp

Explanatory variables Group : at panellist level, coded 0,1 Armpit : Left/Right, coded 0/1 Product : at armpit level, coded 0,1 Visit : 1...15

12

Page 13: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Model

( )ijklogit p = fixed effects + k jkw u+

( ) ( )2 2k w jk uw ~ N 0, ,u ~ N 0, ; j=1,2 σ σ

13

Page 14: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

MLwiN: RIGLS, 1st order MQL

14

Page 15: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

NLMIXED:

Subject – panellist (k)

Random effects ( )k 1k 2kw ,u ,u ~ N 0,ψ

2w

2u

2u

0 00 00 0

⎛ ⎞σ⎜ ⎟ψ = σ⎜ ⎟⎜ ⎟σ⎝ ⎠

- require 3-D integrals

OR reduce to 2-D

jk k jkv w u= + , j = 1,2 2 2 2

1k w u w2 2 2

2k w w u

v 0~ N ,

v 0⎡ ⎤⎛ ⎞σ + σ σ⎛ ⎞ ⎛ ⎞⎢ ⎥⎜ ⎟⎜ ⎟ ⎜ ⎟ σ σ + σ⎢ ⎥⎝ ⎠⎝ ⎠ ⎝ ⎠⎣ ⎦

15

Page 16: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

proc nlmixed gconv=1e-13 data=hyper; ods output ParameterEstimates=p1; parms beta1=0.8998 beta2=1.6507 beta3=0.6764 beta4=-0.2457 beta5=0.0038 varw=10 varu=1; eta=beta1+beta2*vgroup+beta3*vr+beta4*vprod+beta5*visit +vl*left+vr*right; model y~binary(1/(1+exp(-eta))); random left right ~ normal([0,0], [varw+varu, varw, varw+varu]) subject=panel; run; Quadrature Points 9

-2 Log Likelihood 372.3

Parameter Estimates

NLMIXED MLwiN Standard Standard Parameter Estimate Error Estimate Error beta1 2.1769 1.1540 0.804 0.655 beta2 4.3457 1.8518 1.748 0.878 beta3 1.5174 0.4905 0.587 0.655 beta4 -0.1010 0.4925 -0.120 0.265 beta5 0.01206 0.03425 0.005 0.021 varw 14.3174 6.1330 5.875 1.564 varu 0.7399 0.6977 1.007 0.543

16

Page 17: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

proc nlmixed qpoints=41 gconv=1e-13 data=hyper; ods output ParameterEstimates=p2; parms /data=p1; eta=beta1+beta2*vgroup+beta3*vr+beta4*vprod+beta5*visit +vl*left+vr*right; model y~binary(1/(1+exp(-eta))); random left right ~ normal([0,0], [varw+varu, varw, varw+varu]) subject=panel; run; Quadrature Points 9 41 81 -2 Log Likelihood 372.3 372.4 372.4 Parameter Estimates qpoints=9 qpoints=41 qpoints=81 qpoints=9 qpoints=41 qpoints=81 Standard Standard Standard Parameter Estimate Estimate Estimate Error Error Error beta1 2.1769 2.2111 2.2093 1.1540 1.1894 1.1869 beta2 4.3457 4.2191 4.2210 1.8518 1.7747 1.7769 beta3 1.5174 1.5266 1.5258 0.4905 0.4961 0.4957 beta4 -0.1010 -0.09601 -0.09625 0.4925 0.4971 0.4970 beta5 0.01206 0.01212 0.01211 0.03425 0.03432 0.03432 varw 14.3174 15.0614 15.0132 6.1330 7.0415 6.9230 varu 0.7399 0.7595 0.7590 0.6977 0.7074 0.7069

17

Page 18: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

fitted logits and probabilities at visit 15 group arm product logit( ) p p 0 L 0 2.39 0.916 0 L 1 2.29 0.908 0 R 0 3.92 0.980 0 R 1 3.82 0.979 1 L 0 6.61 0.999 1 L 1 6.52 0.999 1 R 0 8.14 1.000 1 R 1 8.04 1.000

18

Page 19: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

visit → ∞ ⇒ p → 1 model visit as non-linear logistic

( ) 6visitijk 5logit p linear effects + e random effects−β= β +

19

Page 20: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

proc nlmixed qmax=51 gconv=1e-13 data=hyper; parms beta1=2.2 beta2=4.2 beta3=1.5 beta4=-0.1 beta5=-0.25 beta6=0.1 varw=15 varu=0.76; eta=beta1+beta2*vgroup+beta3*vr+beta4*vprod+beta5*exp(-beta6*visit) +vl*left+vr*right; model y~binary(1/(1+exp(-eta))); random left right ~ normal([0,0], [varw+varu, varw, varw+varu]) subject=panel; run; Quadrature Points 31 81 -2 Log Likelihood 367.1 367.1 Parameter Estimates qpoints=31 qpoints=81 qpoints=31 qpoints=81 Standard Standard Parameter Estimate Estimate Error Error beta1 2.4620 2.4627 1.1802 1.1823 beta2 4.3064 4.2942 1.8205 1.8107 beta3 1.5534 1.5537 0.5072 0.5078 beta4 -0.09512 -0.09494 0.5081 0.5084 beta5 -7.7700 -7.7740 15.9468 15.9528 beta6 1.7710 1.7712 1.9938 1.9935 varw 15.5627 15.5843 7.2089 7.2089 varu 0.8136 0.8143 0.7451 0.7452 20

Page 21: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

fitted logits and probabilities linear logistic exponential logistic at visit 15 as visit → ∞

ˆ ˆ group arm product logit( ) logit( ) p p p p

0 L 0 2.39 0.916 2.46 0.921 0 L 1 2.29 0.908 2.37 0.914 0 R 0 3.92 0.980 4.02 0.982 0 R 1 3.82 0.979 3.92 0.981 1 L 0 6.61 0.999 6.76 0.999 1 L 1 6.52 0.999 6.66 0.999 1 R 0 8.14 1.000 8.31 1.000 1 R 1 8.04 1.000 8.22 1.000

21

Page 22: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Proportional odds model

- for ordinal response at time t for subject i Pr (response is category j)

( )j it it ip P Y j z ,s= = – it covariates at time t for subject i z – i subject effect (random) s

– j = 1,...,k (categories)

22

Page 23: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

( )j itQ P Y j = ≤

p p ... = jp1 2+ + +

1p Q , p Q Q , ... , p 1 Q

(j = 1,...,k–1) k⇒ 1 1 2 2 1 k −= = − = −

Proportional Odds

( ) Tj j it i (j = 1,....,k–1) logit Q z s= α + β +

( )2 2 2

i s ss ~ N 0, ; e δσ σ =

j 'sα are cut-points.

23

Page 24: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

( ) itjni i it i j

t jP Y y z ,s p= = ∏∏

where 1 if response is in category j for subject i itjn = at time t 0 otherwise likelihood

( ) itj

i

nj i i

i s t j, , p q(s )dsβ α δ = ∏ ∫ ∏∏

24

Page 25: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Trial of Eliprodil in Severe Head Injury (Bolland, 2003) 440 patients 3 times (day 21, 90, 180) 3 ordinal responses on Glasgow outcome scale (GOS) j = 1 good recovery j = 2 moderate disability j = 3 severe disability or worse

covariates:

- days = log(log(day))

gcsind01 = 0, Glasgow coma score 51, Glasgow coma score > 5

≤⎧⎨⎩

proportional odds model: ( )j j 1 2 ilogit Q days gcsind01+s= α + β × + β ×

25

Page 26: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

• initial values; fit proportional odds model ignoring subject effects using GENMOD proc genmod data=hidata7 ; model gos3cat= lldays gcsind01/ d=multinomial ; run; Analysis Of Parameter Estimates Standard Wald 95% Parameter DF Estimate Error Confidence Limits Intercept1 1 -5.9031 0.4298 -6.7455 -5.0608 Intercept2 1 -5.4047 0.4242 -6.2361 -4.5733 lldays 1 3.1446 0.2774 2.6009 3.6884 gcsind01 1 1.3696 0.1273 1.1201 1.6191 Scale 0 1.0000 0.0000 1.0000 1.0000 NOTE: The scale parameter was held fixed.

26

Page 27: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

• Proportional odds subject effect model using general log-likelihood

proc nlmixed qpoints=63 gconv=1e-14 data=hidata7; ods output ParameterEstimates=parm1; parms a1=-5.9031 a2=-5.4047 b1=3.1446 b2=1.3696 delta=2; p1=1/(1+exp(-a1-b1*lldays-b2*gcsind01+s)); q2=1/(1+exp(-a2-b1*lldays-b2*gcsind01+s)); p2=q2-p1; p3=1-q2; logl=n1*log(p1)+n2*log(p2)+n3*log(p3); model gos3cat~general(logl); random s~normal(0,exp(2*delta)) subject=patid; run; Quadrature Points 63 127 -2 Log Likelihood 1553.7 1553.7 Parameter Estimates qpoints=63 qpoints=127 qpoints=63 qpoints=127 Standard Standard Parameter Estimate Estimate Error Error a1 -24.7754 -24.7768 2.2173 2.2181 a2 -22.4901 -22.4913 2.0387 2.0394 b1 13.0560 13.0568 1.1516 1.1520 b2 5.8335 5.8337 0.9357 0.9358 delta 1.9463 1.9464 0.1043 0.1043 27

Page 28: SAS PROC NLMIXED - University of Glasgow :: Glasgow ... PROC NLMIXED Mike Patefield – The University of Reading – 12 May 2004 E-mail: w.m.patefield@reading.ac.uk • non-linear

Further Applications of NLMIXED • non-linear structural relationships (Patefield, 2002) • non-linear factor analysis • multilevel Poisson modelling Checking • ensure identifiability by examining eigenvalues of Hessian matrix

28