Christensen
Christensen
Christensen
Education:
Engineer from DTU in 2008 Statistics and Data Analysis
Research interests:
Sensometrics
Likelihood methods
Mixed effects models
Computational statistics
Applied statistics (food science, biology, . . . )
R-packages:
sensR with Per Bruun Brockhoff
ordinal
binomTools with Merete Kjr Hansen
Psychoco 2012
1 / 64
Outline
2 / 64
Psychoco 2012
4 / 64
Outline
Psychoco 2012
Psychoco 2012
3 / 64
Replicated
Regression analysis
X
X
X
X
X
X
X
X
X
X
Psychoco 2012
5 / 64
Sample size
Simulation
X
X
X
X
X
X
X
X
Likelihood CI
Power
X
X
X
(X)
X
(X)
X
X
X
X
X
X
Psychoco 2012
6 / 64
Psychoco 2012
8 / 64
plot
ROC
AUC
lla
ne
ou
rescale
psyfun
psyinv
pc2pd
pd2pc
isc
e
Illu
str
ati
on
Tr
an
sfo
r
findcr
clm2twoAC
SDT
samdiffSim
discrimSim
a1
a2
X
X
X
X
X
X
ma
tio
n
Sa
mp
le
siz
e
Po
we
r&
d 0,
CI
,t
est
s
Similarity test
discrimPwr
d.primePwr
discrimSS
d.primeSS
twoACpwr
Difference test
discrim
AnotA
samediff
twoAC
betabin
d 0 estimation
Vignettes:
X
X
X
X
X
X
isc
rim
in
at
Development on R-Forge:
https://r-forge.r-project.org/projects/sensr/
Duo-Trio, Triangle
2-AFC, 3-AFC
A-not A
Same-Different
2-AC
A-not A w. Sureness
io
n
7 / 64
Psychometric functions
1.0
f3-AFC (d 0 ) =
0.9
2AFC
3AFC
0.8
Duotrio
pc
d0 = X
0.5
0.4
d'
Psychoco 2012
(z d 0 )(z ) dz = (d 0 / 2)
psyphy: mafc(m=3): F () = m1 (1
only depends on no. alternatives.
(z d 0 )(z )2 dz
Family objects:
twoAFC(), threeAFC(), duotrio(), triangle()
Problem: d 0 0
0.3
ftriangle (d ) = 2
pc = fpsy (d 0 )
Triangle
n h
i
h
io
p
p
z 3 + d 0 2/3 + z 3 d 0 2/3 (z ) dz
0
y binom(pc , n)
0.7
0.6
f2-AFC (d 0 ) =
A GLM:
9 / 64
1
m )()
Psychoco 2012
10 / 64
Outline
Development on R-Forge:
https://r-forge.r-project.org/projects/ordinal/
Vignettes:
Analysis if ordinal data with cumulative link models (32 pages)
Psychoco 2012
11 / 64
Psychoco 2012
12 / 64
Introduction
Introduction
(preference, grades)
Objective:
How does perceived bitternes depend on temperature and contact?
CLM:
ij = P (Yi j ) = F (j x T
i )
Intuitively:
A logistic regression model for J 2 (ordered) categories
Psychoco 2012
13 / 64
temperature
contact
judges
predictor
predictor
random
2
Si = + x T
i + i , i N (0, )
= + (tempi ) + i
warm
j 1 Si < j Y = j
cold
cold
1
Psychoco 2012
= + (tempi ) + i
14 / 64
Psychoco 2012
2
Si = + x T
i + i , i N (0, )
warm
Values
1, 2, 3 ,4, 5
less more
cold, warm
no, yes
1, . . . , 9
Type
response
Temperature and contact between juice and skins can be controlled when
cruching grapes during wine production.
Variables
bitterness
15 / 64
P (Yi j ) = F (j x T
i )
Psychoco 2012
15 / 64
Introduction
Introduction
> data(wine)
> fm1 <- clm(rating ~ contact + temp, data=wine, link="probit")
> summary(fm1)
formula: rating ~ contact + temp
data:
wine
link
threshold nobs logLik AIC
niter max.grad cond.H
probit flexible 72
-85.76 183.52 5(0) 1.53e-13 2.2e+01
formula:
link: threshold:
fm2 rating ~ contact
probit flexible
fm1 rating ~ contact + temp probit flexible
Coefficients:
Estimate Std. Error z value Pr(>|z|)
contactyes
0.8677
0.2669
3.251 0.00115 **
tempwarm
1.4994
0.2918
5.139 2.77e-07 ***
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
no.par
AIC
logLik LR.stat df Pr(>Chisq)
fm2
5 210.05 -100.026
fm1
6 183.52 -85.761 28.529 1 9.231e-08 ***
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Threshold coefficients:
Estimate Std. Error z value
1|2 -0.7733
0.2829 -2.734
2|3
0.7360
0.2499
2.945
3|4
2.0447
0.3218
6.353
4|5
2.9413
0.3873
7.595
16 / 64
convergence
slice
drop.coef
C:
Psychoco 2012
18 / 64
lla
ne
ou
clm
clmmC
clm.fit
clm.control
clmm.control
Convergence assessment
isc
e
M
Fit
tin
g
Psychoco 2012
17 / 64
clm2
clmm2C
clm2.control
clmm2.control
Di
str
ibu
tio
ns
Psychoco 2012
im
pl.
Fo
rm
er
[pdqrg]gumbelC
[pdg]lgammaC
gnormC
glogisC
gcauchyC
Implementations in C
Psychoco 2012
19 / 64
Overview
Overview
Inference
Checking
coef
fitted
logLik
nobs
vcov
AIC, BIC
extractAIC
anova
drop1
add1
confint
profile
predict
step, stepAIC
slice
convergence
print
summary
model.frame
model.matrix
update
F (j x T
i )
Extended CLM:
T
g(j ) w T
i j x i
exp(z T
i )
threshold effects
nominal effects
scale effects
random
F (j X Z b )
Psychoco 2012
20 / 64
Y:
P (Yi j ) = F (j (tempi ))
warm
P(Y = 2|cold)
require symmetry?
P(Y = 2|cold)
require equidistance?
cold
cold
P (Yi j ) = F (j (tempi ))
j ordered, but otherwise not
restricted
require equidistance?
21 / 64
warm
Psychoco 2012
Psychoco 2012
22 / 64
Psychoco 2012
22 / 64
Overview
Coefficients:
Estimate Std. Error z value Pr(>|z|)
contactyes
0.8571
0.2645
3.241 0.00119 **
tempwarm
1.4891
0.2882
5.166 2.39e-07 ***
--Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
formula:
link: threshold:
fm.equi rating ~ contact + temp probit equidistant
fm.flex rating ~ contact + temp probit flexible
fm.equi
fm.flex
Threshold coefficients:
Estimate Std. Error z value
threshold.1 -0.5865
0.2326 -2.522
spacing
1.2415
0.1284
9.668
Psychoco 2012
23 / 64
contact:no
contact:yes
3|4
2|3
1|2
Nominal effects:
ij = F (j 1 (tempi )2j (contacti ))
This is:
partial proportional odds
Threshold
Psychoco 2012
24 / 64
ij = F (j 1 (tempi )2 (contacti ))
4|5
no.par
AIC logLik LR.stat df Pr(>Chisq)
4 182.47 -87.237
6 183.52 -85.761 2.9515 2
0.2286
Overview
Treatment coding:
j : for contact: no
2j : contact: yes no
Psychoco 2012
25 / 64
Psychoco 2012
26 / 64
Overview
Outline
5
Si = + 1 (tempi ) + 2 (contacti ) + i ,
i N (0, (tempi ))
warm
(Cox, 1995)
ij = F
j 1 (tempi ) 2 (contacti )
1 (tempi )
cold
1
Psychoco 2012
29 / 64
ML estimation of CLMs
Conventional approaches:
`(, ; y ) =
n
X
30 / 64
wi log i
i=1
i = ij i,j 1
Psychoco 2012
ij = F (j x T
i )
Approach in ordinal:
Accurately
Reliably
Fast
Psychoco 2012
31 / 64
Psychoco 2012
32 / 64
Solve for = [ T , T ]T :
XTW X = XW z
Psychoco 2012
33 / 64
Psychoco 2012
34 / 64
From:
ij = F (j x T
i )
To:
k = F (B k + o k )
ik = ik x T
i
ik = F (ik )
k = 1, 2
k = F (k )
Why?
k = Ak X + o k
k = B k + o k
Psychoco 2012
35 / 64
Psychoco 2012
36 / 64
Generating matrices in R
Initialize environment:
> rho <- new.env(parent = parent.frame())
(i+1) = (i) h
Generate Ak :
> A1 <- A[, -(ntheta + 1), drop = FALSE]
> A2 <- A[, -1, drop = FALSE]
Psychoco 2012
37 / 64
`(; y ) =
wi log i
i=1
38 / 64
g (; y ) = C T $
= F (1 ) F (2 )
T
C T = BT
1 11 B 2 12
k = B k + o k
are n n diagonal
Psychoco 2012
The gradient
(default: = 106 )
H ( (i) )h = g ( (i) )
39 / 64
Psychoco 2012
40 / 64
The Hessian
T
T
H (; y ) = B T
1 21 B 1 B 2 22 B 2 C 3 C
How does this estimation routine handle the extended model framework?
are n n diagonal
Psychoco 2012
41 / 64
Structured thresholds
Psychoco 2012
42 / 64
Nominal effects
T
ij = j w T
i j x i
ij = g(j ) x T
i
nqs
nq
ns
Step 3: Redefine B k = [D k , X ]
Result:
The model can still be written as: k = B k + o k
Result:
Psychoco 2012
43 / 64
Psychoco 2012
44 / 64
Scale effects
Outline
g = [C 2 , C 3 ]T $
D ET
H =
E F
Result:
The log-likelihood, the gradient and the Hessian are slightly more
complicated
The algorithm changes slightly
Psychoco 2012
45 / 64
Relative loglikelihood
link
threshold nobs logLik AIC
niter max.grad
probit flexible 72
-85.76 183.52 5(0) 1.59e-13
Coefficients:
tempwarm contactyes
1.4994
0.8677
4|5
2.9413
1.344388
1.344382
2.503099
1|2
Psychoco 2012
46 / 64
Threshold coefficients:
1|2
2|3
3|4
-0.7733 0.7360 2.0447
1e11
3e11
5e11
Hessian:
ii = exp(Z )i
Relative loglikelihood
Gradient:
1e11
k = (B k + o k ),
3e11
In matrices:
j x T
i
T
exp(z i )
5e11
ij =
2.503102
2.503105
tempwarm
47 / 64
Psychoco 2012
48 / 64
> convergence(fm1)
> data(iris)
> iris.polr <- polr(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris)
1|2
2|3
3|4
4|5
tempwarm
contactyes
2.825
Psychoco 2012
49 / 64
Psychoco 2012
51 / 64
> data(iris)
> iris.polr <- polr(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris)
> data(iris)
> iris.polr <- polr(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris)
> set.seed(1)
> iris.polr <- polr(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris, start = runif(6), Hess=TRUE)
> set.seed(1)
> iris.polr <- polr(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris, start = runif(6), Hess=TRUE)
and so does:
> iris.clm <- clm(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data=iris)
Psychoco 2012
51 / 64
Psychoco 2012
51 / 64
polr
0.0e+00
clm:
clm
2.0e05 1.0e05
polr:
Relative loglikelihood
setosa|versicolor
Psychoco 2012
53 / 64
Psychoco 2012
54 / 64
> convergence(iris.clm)
nobs logLik niter max.grad cond.H logLik.Error
150 -5.95 18(0) 1.56e-07 4.0e+07 <1e-10
setosa|versicolor
versicolor|virginica
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
setosa|versicolor
versicolor|virginica
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Psychoco 2012
55 / 64
Psychoco 2012
56 / 64
Outline
ij = F (j 1 (tempi ) 2 (contacti ))
warm
ij = F (j 1 (tempi ) 2 (contacti )
cold
1
Psychoco 2012
57 / 64
ij = F (j 1 (tempi ) 2 (contacti ))
warm
cold
ij = F (j 1 (tempi ) 2 (contacti )
cold
Psychoco 2012
58 / 64
ij = F (j 1 (tempi ) 2 (contacti ))
warm
Psychoco 2012
58 / 64
ij = F (j 1 (tempi ) 2 (contacti )
b(judgei )), b N (0, b2 )
Psychoco 2012
58 / 64
ij = F (j 1 (tempi ) 2 (contacti ))
ij = F (j 1 (tempi ) 2 (contacti ))
warm
warm
ij = F (j 1 (tempi ) 2 (contacti )
ij = F (j 1 (tempi ) 2 (contacti )
cold
1
Psychoco 2012
cold
58 / 64
Psychoco 2012
58 / 64
k = F (B k Z v o k )
V N (0, )
`(, ; y ) = log
Rr
p (y |v )p (v ) dv
Integration methods:
Random effects:
Var Std.Dev
judge 1.288
1.135
Number of groups: judge 9
Laplace approximation (Tierney and Kadane, 1986; Pinheiro and Bates, 1995;
Coefficients:
Estimate Std. Error z value Pr(>|z|)
tempwarm
3.0619
0.5951
5.145 2.67e-07 ***
contactyes
1.8334
0.5124
3.578 0.000346 ***
.....
Joe, 2008)
60 / 64
Psychoco 2012
61 / 64
References
References
Agresti, A. (2002). Categorical Data Analysis (Second ed.). Wiley.
Bates, D. and M. Maechler (2012). Matrix: Sparse and Dense Matrix Classes and Methods. R package version 1.0-3.
1 random term:
Cox, C. (1995). Location-scale cumulative odds models for ordinal data: A generalized non-linear model approach. Statistics in
medicine 14, 11911203.
implemented in C
Eld
en, L., L. Wittmeyer-Koch, and H. B. Nielsen (2004). Introduction to Numerical Computation analysis and MATLAB
illustrations. Studentlitteratur.
Fahrmeir, L. and G. Tutz (2001). Multivariate Statistical Modelling Based on Generalized Linear Models (Second ed.). Springer
series in statistics. Springer-Verlag New York, Inc.
Greene, W. H. and D. A. Hensher (2010). Modeling Ordered Choices: A Primer. Cambridge University Press.
2 random terms:
Hedeker, D. and R. D. Gibbons (1994). A random-effects ordinal regression model for multilevel analysis. Biometrics 50,
933944.
Joe, H. (2008). Accuracy of laplace approximation for discrete response mixed models. Comput. Stat. Data Anal. 52 (12),
50665074.
exclusively in R
Liu, Q. and D. A. Pierce (1994). A note on gauss-hermite quadrature. Biometrika 81 (3), 624629.
Marschner, I. C. (2011, December). glm2: Fitting Generalized Linear Models with Convergence Problems. The R Journal 3 (2),
1215.
Laplace
Peterson, B. and F. E. Harrell Jr. (1990). Partial proportional odds models for ordinal response variables. Applied Statistics 39,
205217.
Pinheiro, J. C. and D. M. Bates (1995). Approximations to the nonlinear mixed-effects model. Jounal of Computational and
Graphical Statistics 4 (1), 1235.
Randall, J. (1989). The analysis of sensory data by generalised linear model. Biometrical journal 7, 781793.
Tierney, L. and J. B. Kadane (1986). Accurate approximations for posterior moments and marginal densities. Journal of the
American Statistical Association 81 (393), 8286.
Venables, W. N. and B. D. Ripley (2002). Modern Applied Statistics with S (Fourth ed.). New York: Springer. ISBN
0-387-95457-0.
Yee, T. W. (2010, 1). The vgam package for categorical data analysis. Journal of Statistical Software 32 (10), 134.
Psychoco 2012
62 / 64
Psychoco 2012
64 / 64
Psychoco 2012
63 / 64