Gaussian Quadrature rules provide sets of x values, called abscissae , and corresponding weights, w, to approximate an integral with respect to a weight function , $g(x)$ . For a kth order rule the approximation is
\[\int f(x)g(x)\,dx \approx \sum_{i=1}^k w_i f(x_i)\]
For the Gauss-Hermite rule the weight function is
\[g(x) = e^{-x^2}\]
and the domain of integration is $(-\infty, \infty)$ . A slight variation of this is the normalized Gauss-Hermite rule for which the weight function is the standard normal density
\[g(z) = \phi(z) = \frac{e^{-z^2/2}}{\sqrt{2\pi}}\]
Thus, the expected value of $f(z)$ , where $\mathcal{Z}\sim\mathscr{N}(0,1)$ , is approximated as
\[\mathbb{E}[f]=\int_{-\infty}^{\infty} f(z) \phi(z)\,dz\approx\sum_{i=1}^k w_i\,f(z_i) .\]
Naturally, there is a caveat. For the approximation to be accurate the function $f(z)$ must behave like a low-order polynomial over the range of interest. More formally, a kth order rule is exact when f is a polynomial of order 2k-1 or less.
In the Golub-Welsch algorithm the abscissae for a particular Gaussian quadrature rule are determined as the eigenvalues of a symmetric tri-diagonal matrix and the weights are derived from the squares of the first row of the matrix of eigenvectors. For a kth order normalized Gauss-Hermite rule the tridiagonal matrix has zeros on the diagonal and the square roots of 1:k-1 on the super- and sub-diagonal, e.g.
using DataFrames, LinearAlgebra, Gadfly
sym3 = SymTridiagonal(zeros(3), sqrt.(1:2))
ev = eigen(sym3);
ev.values3-element Vector{Float64}:
-1.7320508075688739
1.1102230246251565e-15
1.7320508075688774abs2.(ev.vectors[1,:])3-element Vector{Float64}:
0.16666666666666743
0.6666666666666657
0.16666666666666677As a function of k this can be written as
function gausshermitenorm(k)
ev = eigen(SymTridiagonal(zeros(k), sqrt.(1:k-1)))
ev.values, abs2.(ev.vectors[1,:])
end;gausshermitenorm (generic function with 1 method)providing
gausshermitenorm(3)([-1.7320508075688739, 1.1102230246251565e-15, 1.7320508075688774], [0.16666666666666743, 0.6666666666666657, 0.16666666666666677])The weights and positions are often shown as a lollipop plot . For the 9th order rule these are
gh9=gausshermitenorm(9)
plot(x=gh9[1], y=gh9[2], Geom.hair, Geom.point, Guide.ylabel("Weight"), Guide.xlabel(""))
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
4.5127458633997832.2345844007746478e-5
3.2054290028564690.002789141321231774
2.0768479786778320.04991640676521808
1.02325566378913550.244097502894938
0.00.4063492063492072
-1.0232556637891310.24409750289493937
-2.0768479786778260.04991640676521781
-3.2054290028564650.002789141321231766
-4.5127458633997782.234584400774634e-5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0.0
0.1
0.2
0.3
0.4
0.5
0.00
0.02
0.04
0.06
0.08
0.10
0.12
0.14
0.16
0.18
0.20
0.22
0.24
0.26
0.28
0.30
0.32
0.34
0.36
0.38
0.40
0.42
0.44
0.46
0.48
0.50
0.000
0.002
0.004
0.006
0.008
0.010
0.012
0.014
0.016
0.018
0.020
0.022
0.024
0.026
0.028
0.030
0.032
0.034
0.036
0.038
0.040
0.042
0.044
0.046
0.048
0.050
0.052
0.054
0.056
0.058
0.060
0.062
0.064
0.066
0.068
0.070
0.072
0.074
0.076
0.078
0.080
0.082
0.084
0.086
0.088
0.090
0.092
0.094
0.096
0.098
0.100
0.102
0.104
0.106
0.108
0.110
0.112
0.114
0.116
0.118
0.120
0.122
0.124
0.126
0.128
0.130
0.132
0.134
0.136
0.138
0.140
0.142
0.144
0.146
0.148
0.150
0.152
0.154
0.156
0.158
0.160
0.162
0.164
0.166
0.168
0.170
0.172
0.174
0.176
0.178
0.180
0.182
0.184
0.186
0.188
0.190
0.192
0.194
0.196
0.198
0.200
0.202
0.204
0.206
0.208
0.210
0.212
0.214
0.216
0.218
0.220
0.222
0.224
0.226
0.228
0.230
0.232
0.234
0.236
0.238
0.240
0.242
0.244
0.246
0.248
0.250
0.252
0.254
0.256
0.258
0.260
0.262
0.264
0.266
0.268
0.270
0.272
0.274
0.276
0.278
0.280
0.282
0.284
0.286
0.288
0.290
0.292
0.294
0.296
0.298
0.300
0.302
0.304
0.306
0.308
0.310
0.312
0.314
0.316
0.318
0.320
0.322
0.324
0.326
0.328
0.330
0.332
0.334
0.336
0.338
0.340
0.342
0.344
0.346
0.348
0.350
0.352
0.354
0.356
0.358
0.360
0.362
0.364
0.366
0.368
0.370
0.372
0.374
0.376
0.378
0.380
0.382
0.384
0.386
0.388
0.390
0.392
0.394
0.396
0.398
0.400
0.402
0.404
0.406
0.408
0.410
0.412
0.414
0.416
0.418
0.420
0.422
0.424
0.426
0.428
0.430
0.432
0.434
0.436
0.438
0.440
0.442
0.444
0.446
0.448
0.450
0.452
0.454
0.456
0.458
0.460
0.462
0.464
0.466
0.468
0.470
0.472
0.474
0.476
0.478
0.480
0.482
0.484
0.486
0.488
0.490
0.492
0.494
0.496
0.498
0.500
0.0
0.5
Weight
Notice that the magnitudes of the weights drop quite dramatically away from zero, even on a logarithmic scale
plot(
x=gh9[1], y=gh9[2], Geom.hair, Geom.point,
Scale.y_log2, Guide.ylabel("Weight (log scale)"),
Guide.xlabel(""),
)
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
4.512745863399783-15.449633937746196
3.205429002856469-8.485963249444321
2.076847978677832-4.324342104304117
1.0232556637891355-2.0344705583898297
0.0-1.2992080183872758
-1.023255663789131-2.0344705583898217
-2.076847978677826-4.324342104304124
-3.205429002856465-8.485963249444326
-4.512745863399778-15.449633937746205
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
2-20
2-15
2-10
2-5
20
2-20
2-19
2-18
2-17
2-16
2-15
2-14
2-13
2-12
2-11
2-10
2-9
2-8
2-7
2-6
2-5
2-4
2-3
2-2
2-1
20
2-20.0
2-19.9
2-19.8
2-19.7
2-19.6
2-19.5
2-19.4
2-19.3
2-19.2
2-19.1
2-19.0
2-18.9
2-18.8
2-18.7
2-18.6
2-18.5
2-18.4
2-18.3
2-18.2
2-18.1
2-18.0
2-17.9
2-17.8
2-17.7
2-17.6
2-17.5
2-17.4
2-17.3
2-17.2
2-17.1
2-17.0
2-16.9
2-16.8
2-16.7
2-16.6
2-16.5
2-16.4
2-16.3
2-16.2
2-16.1
2-16.0
2-15.9
2-15.8
2-15.7
2-15.6
2-15.5
2-15.4
2-15.3
2-15.2
2-15.1
2-15.0
2-14.9
2-14.8
2-14.7
2-14.6
2-14.5
2-14.4
2-14.3
2-14.2
2-14.1
2-14.0
2-13.9
2-13.8
2-13.7
2-13.6
2-13.5
2-13.4
2-13.3
2-13.2
2-13.1
2-13.0
2-12.9
2-12.8
2-12.7
2-12.6
2-12.5
2-12.4
2-12.3
2-12.2
2-12.1
2-12.0
2-11.9
2-11.8
2-11.7
2-11.6
2-11.5
2-11.4
2-11.3
2-11.2
2-11.1
2-11.0
2-10.9
2-10.8
2-10.7
2-10.6
2-10.5
2-10.4
2-10.3
2-10.2
2-10.1
2-10.0
2-9.9
2-9.8
2-9.7
2-9.6
2-9.5
2-9.4
2-9.3
2-9.2
2-9.1
2-9.0
2-8.9
2-8.8
2-8.7
2-8.6
2-8.5
2-8.4
2-8.3
2-8.2
2-8.1
2-8.0
2-7.9
2-7.8
2-7.7
2-7.6
2-7.5
2-7.4
2-7.3
2-7.2
2-7.1
2-7.0
2-6.9
2-6.8
2-6.7
2-6.6
2-6.5
2-6.4
2-6.3
2-6.2
2-6.1
2-6.0
2-5.9
2-5.8
2-5.7
2-5.6
2-5.5
2-5.4
2-5.3
2-5.2
2-5.1
2-5.0
2-4.9
2-4.8
2-4.7
2-4.6
2-4.5
2-4.4
2-4.3
2-4.2
2-4.1
2-4.0
2-3.9
2-3.8
2-3.7
2-3.6
2-3.5
2-3.4
2-3.3
2-3.2
2-3.1
2-3.0
2-2.9
2-2.8
2-2.7
2-2.6
2-2.5
2-2.4
2-2.3
2-2.2
2-2.1
2-2.0
2-1.9
2-1.8
2-1.7
2-1.6
2-1.5
2-1.4
2-1.3
2-1.2
2-1.1
2-1.0
2-0.9
2-0.8
2-0.7
2-0.6
2-0.5
2-0.4
2-0.3
2-0.2
2-0.1
20.0
2-20
20
Weight (log scale)
The definition of MixedModels.GHnorm is similar to the gausshermitenorm function with some extra provisions for ensuring symmetry of the abscissae and the weights and for caching values once they have been calculated.
GHnorm(k::Int)Return the (unique) GaussHermiteNormalized{k} object.
The function values are stored (memoized) when first evaluated. Subsequent evaluations for the same k have very low overhead.
source using MixedModels
GHnorm(3)MixedModels.GaussHermiteNormalized{3}([-1.7320508075688772, 0.0, 1.7320508075688772], [0.16666666666666666, 0.6666666666666666, 0.16666666666666666])By the properties of the normal distribution, when $\mathcal{X}\sim\mathscr{N}(\mu, \sigma^2)$
\[\mathbb{E}[g(x)] \approx \sum_{i=1}^k g(\mu + \sigma z_i)\,w_i\]
For example, $\mathbb{E}[\mathcal{X}^2]$ where $\mathcal{X}\sim\mathcal{N}(2, 3^2)$ is
μ = 2; σ = 3; ghn3 = GHnorm(3);
sum(@. ghn3.w * abs2(μ + σ * ghn3.z)) # should be μ² + σ² = 1313.0(In general a dot, '.', after the function name in a function call, as in abs2.(...), or before an operator creates a fused vectorized evaluation in Julia. The macro @. has the effect of vectorizing all operations in the subsequent expression.)
A binary response is a "Yes"/"No" type of answer. For example, in a 1989 fertility survey of women in Bangladesh (reported in Huq, N. M. and Cleland, J., 1990 ) one response of interest was whether the woman used artificial contraception. Several covariates were recorded including the woman's age (centered at the mean), the number of live children the woman has had (in 4 categories: 0, 1, 2, and 3 or more), whether she lived in an urban setting, and the district in which she lived. The version of the data used here is that used in review of multilevel modeling software conducted by the Center for Multilevel Modelling, currently at University of Bristol (http://www.bristol.ac.uk/cmm/learning/mmsoftware/data-rev.html). These data are available as the :contra dataset.
contra = DataFrame(MixedModels.dataset(:contra))
describe(contra)1 dist D01 D61 0 String 2 urban N Y 0 String 3 livch 0 3+ 0 String 4 age 0.00204757 -13.56 -1.56 19.44 0 Float64 5 use N Y 0 String
A smoothed scatterplot of contraception use versus age
plot(contra, x=:age, y=:use, Geom.smooth, Guide.xlabel("Centered age (yr)"),
Guide.ylabel("Contraception use"))
Centered age (yr)
-20
-10
0
10
20
-20
-18
-16
-14
-12
-10
-8
-6
-4
-2
0
2
4
6
8
10
12
14
16
18
20
-20.0
-19.8
-19.6
-19.4
-19.2
-19.0
-18.8
-18.6
-18.4
-18.2
-18.0
-17.8
-17.6
-17.4
-17.2
-17.0
-16.8
-16.6
-16.4
-16.2
-16.0
-15.8
-15.6
-15.4
-15.2
-15.0
-14.8
-14.6
-14.4
-14.2
-14.0
-13.8
-13.6
-13.4
-13.2
-13.0
-12.8
-12.6
-12.4
-12.2
-12.0
-11.8
-11.6
-11.4
-11.2
-11.0
-10.8
-10.6
-10.4
-10.2
-10.0
-9.8
-9.6
-9.4
-9.2
-9.0
-8.8
-8.6
-8.4
-8.2
-8.0
-7.8
-7.6
-7.4
-7.2
-7.0
-6.8
-6.6
-6.4
-6.2
-6.0
-5.8
-5.6
-5.4
-5.2
-5.0
-4.8
-4.6
-4.4
-4.2
-4.0
-3.8
-3.6
-3.4
-3.2
-3.0
-2.8
-2.6
-2.4
-2.2
-2.0
-1.8
-1.6
-1.4
-1.2
-1.0
-0.8
-0.6
-0.4
-0.2
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
4.2
4.4
4.6
4.8
5.0
5.2
5.4
5.6
5.8
6.0
6.2
6.4
6.6
6.8
7.0
7.2
7.4
7.6
7.8
8.0
8.2
8.4
8.6
8.8
9.0
9.2
9.4
9.6
9.8
10.0
10.2
10.4
10.6
10.8
11.0
11.2
11.4
11.6
11.8
12.0
12.2
12.4
12.6
12.8
13.0
13.2
13.4
13.6
13.8
14.0
14.2
14.4
14.6
14.8
15.0
15.2
15.4
15.6
15.8
16.0
16.2
16.4
16.6
16.8
17.0
17.2
17.4
17.6
17.8
18.0
18.2
18.4
18.6
18.8
19.0
19.2
19.4
19.6
19.8
20.0
-20
0
20
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
N
Y
Contraception use
shows that the proportion of women using artificial contraception is approximately quadratic in age.
A model with fixed-effects for age, age squared, number of live children and urban location and with random effects for district, is fit as
const form1 = @formula use ~ 1 + age + abs2(age) + livch + urban + (1|dist);
m1 = fit(MixedModel, form1, contra, Bernoulli(), fast=true)Generalized Linear Mixed Model fit by maximum likelihood (nAGQ = 1)
use ~ 1 + age + :(abs2(age)) + livch + urban + (1 | dist)
Distribution: Bernoulli{Float64}
Link: LogitLink()
logLik deviance AIC AICc BIC
-1186.3922 2372.7844 2388.7844 2388.8592 2433.3231
Variance components:
Column VarianceStd.Dev.
dist (Intercept) 0.22533 0.47469
Number of obs: 1934; levels of grouping factors: 60
Fixed-effects parameters:
──────────────────────────────────────────────────────
Coef. Std. Error z Pr(>|z|)
──────────────────────────────────────────────────────
(Intercept) -1.01528 0.173972 -5.84 <1e-08
age 0.00351074 0.00921014 0.38 0.7031
abs2(age) -0.0044865 0.000722797 -6.21 <1e-09
livch: 1 0.801876 0.161867 4.95 <1e-06
livch: 2 0.901014 0.184771 4.88 <1e-05
livch: 3+ 0.899415 0.1854 4.85 <1e-05
urban: Y 0.684404 0.119684 5.72 <1e-07
──────────────────────────────────────────────────────For a model such as m1, which has a single, scalar random-effects term, the unscaled conditional density of the spherical random effects variable, $\mathcal{U}$ , given the observed data, $\mathcal{Y}=\mathbf{y}_0$ , can be expressed as a product of scalar density functions, $f_i(u_i),\; i=1,\dots,q$ . In the PIRLS algorithm, which determines the conditional mode vector, $\tilde{\mathbf{u}}$ , the optimization is performed on the deviance scale ,
\[D(\mathbf{u})=-2\sum_{i=1}^q \log(f_i(u_i))\]
The objective, $D$ , consists of two parts: the sum of the (squared) deviance residuals , measuring fidelity to the data, and the squared length of $\mathbf{u}$ , which is the penalty. In the PIRLS algorithm, only the sum of these components is needed. To use Gauss-Hermite quadrature the contributions of each of the $u_i,\;i=1,\dots,q$ should be separately evaluated.
const devc0 = map!(abs2, m1.devc0, m1.u[1]); # start with uᵢ²
const devresid = m1.resp.devresid; # n-dimensional vector of deviance residuals
const refs = only(m1.LMM.reterms).refs; # n-dimensional vector of indices in 1:q
for (dr, i) in zip(devresid, refs)
devc0[i] += dr
end
show(devc0)[121.29247990015143, 22.022573370710067, 2.9189004524855235, 30.787717763292576, 47.54204967093912, 69.55502456202477, 23.404687150479827, 46.27907378867114, 24.45278089007126, 7.759490551598567, 9.77366225581456, 42.75903574934856, 27.552494318037308, 156.42045124992165, 26.19246852580294, 27.4162491656178, 24.538088886864443, 57.56615452803383, 31.179403716190123, 22.3415587728768, 27.47809480259192, 19.988456589334945, 16.010854738874336, 9.761478962403158, 83.86349398054233, 15.568769290218775, 42.75968309810438, 51.46851371624581, 32.73334457583006, 70.41572374106235, 39.6858696785426, 27.544104056087072, 14.697567276334153, 53.047353874299375, 64.84964757020208, 19.7438806576064, 19.415516116790887, 11.24228565929631, 37.416774805234695, 54.26508057255895, 39.58249522765603, 17.39840470258463, 60.22781269420124, 28.819185776235816, 42.444255022821466, 112.99129190868078, 17.297702165403734, 51.577343050081375, 2.187213814535444, 22.96155934060964, 47.414475694845, 87.23162381920278, 25.923443742638362, 9.470291285204864, 61.175862929322456, 27.10281808865993, 48.016174453118644, 8.4602026082129, 30.365222014103303, 47.374159422974834]One thing to notice is that, even on the deviance scale, the contributions of different districts can be of different magnitudes. This is primarily due to different sample sizes in the different districts.
using FreqTables
freqtable(contra, :dist)'1×60 Named LinearAlgebra.Adjoint{Int64, Vector{Int64}}
' ╲ dist │ D01 D02 D03 D04 D05 D06 … D56 D57 D58 D59 D60 D61
─────────┼──────────────────────────────────────────────────────────────
1 │ 117 20 2 30 39 65 … 45 27 33 10 32 42Because the first district has one of the largest sample sizes and the third district has the smallest sample size, these two will be used for illustration. For a range of $u$ values, evaluate the individual components of the deviance and store them in a matrix.
const devc = m1.devc;
const xvals = -5.0:2.0^(-4):5.0;
const uv = vec(m1.u[1]);
const u₀ = vec(m1.u₀[1]);
results = zeros(length(devc0), length(xvals))
for (j, u) in enumerate(xvals)
fill!(devc, abs2(u))
fill!(uv, u)
MixedModels.updateη!(m1)
for (dr, i) in zip(devresid, refs)
devc[i] += dr
end
copyto!(view(results, :, j), devc)
endA plot of the deviance contribution versus $u_1$
plot(x=xvals, y=view(results, 1, :), Geom.line, Guide.xlabel("u₁"),
Guide.ylabel("Deviance contribution"))
u₁
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0
100
200
300
400
500
0
20
40
60
80
100
120
140
160
180
200
220
240
260
280
300
320
340
360
380
400
420
440
460
480
500
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
174
176
178
180
182
184
186
188
190
192
194
196
198
200
202
204
206
208
210
212
214
216
218
220
222
224
226
228
230
232
234
236
238
240
242
244
246
248
250
252
254
256
258
260
262
264
266
268
270
272
274
276
278
280
282
284
286
288
290
292
294
296
298
300
302
304
306
308
310
312
314
316
318
320
322
324
326
328
330
332
334
336
338
340
342
344
346
348
350
352
354
356
358
360
362
364
366
368
370
372
374
376
378
380
382
384
386
388
390
392
394
396
398
400
402
404
406
408
410
412
414
416
418
420
422
424
426
428
430
432
434
436
438
440
442
444
446
448
450
452
454
456
458
460
462
464
466
468
470
472
474
476
478
480
482
484
486
488
490
492
494
496
498
500
0
500
Deviance contribution
shows that the deviance contribution is very close to a quadratic. This is also true for $u_3$
plot(x=xvals, y=view(results, 3, :), Geom.line, Guide.xlabel("u₃"),
Guide.ylabel("Deviance contribution"))
u₃
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0
10
20
30
40
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
4.2
4.4
4.6
4.8
5.0
5.2
5.4
5.6
5.8
6.0
6.2
6.4
6.6
6.8
7.0
7.2
7.4
7.6
7.8
8.0
8.2
8.4
8.6
8.8
9.0
9.2
9.4
9.6
9.8
10.0
10.2
10.4
10.6
10.8
11.0
11.2
11.4
11.6
11.8
12.0
12.2
12.4
12.6
12.8
13.0
13.2
13.4
13.6
13.8
14.0
14.2
14.4
14.6
14.8
15.0
15.2
15.4
15.6
15.8
16.0
16.2
16.4
16.6
16.8
17.0
17.2
17.4
17.6
17.8
18.0
18.2
18.4
18.6
18.8
19.0
19.2
19.4
19.6
19.8
20.0
20.2
20.4
20.6
20.8
21.0
21.2
21.4
21.6
21.8
22.0
22.2
22.4
22.6
22.8
23.0
23.2
23.4
23.6
23.8
24.0
24.2
24.4
24.6
24.8
25.0
25.2
25.4
25.6
25.8
26.0
26.2
26.4
26.6
26.8
27.0
27.2
27.4
27.6
27.8
28.0
28.2
28.4
28.6
28.8
29.0
29.2
29.4
29.6
29.8
30.0
30.2
30.4
30.6
30.8
31.0
31.2
31.4
31.6
31.8
32.0
32.2
32.4
32.6
32.8
33.0
33.2
33.4
33.6
33.8
34.0
34.2
34.4
34.6
34.8
35.0
35.2
35.4
35.6
35.8
36.0
36.2
36.4
36.6
36.8
37.0
37.2
37.4
37.6
37.8
38.0
38.2
38.4
38.6
38.8
39.0
39.2
39.4
39.6
39.8
40.0
0
50
Deviance contribution
The PIRLS algorithm provides the locations of the minima of these scalar functions, stored as
m1.u₀[1]1×60 Matrix{Float64}:
-1.58477 -0.0727267 0.449058 0.341589 … -0.767069 -0.902922 -1.06625the minima themselves, evaluated as devc0 above, and a horizontal scale, which is the inverse of diagonal of the Cholesky factor. As shown below, this is an estimate of the conditional standard deviations of the components of $\mathcal{U}$ .
using MixedModels: block
const s = inv.(m1.LMM.L[block(1,1)].diag);
s'1×60 adjoint(::Vector{Float64}) with eltype Float64:
0.406888 0.713511 0.952164 0.627134 … 0.839678 0.654964 0.603258The curves can be put on a common scale, corresponding to the standard normal, as
for (j, z) in enumerate(xvals)
@. uv = u₀ + z * s
MixedModels.updateη!(m1)
@. devc = abs2(uv) - devc0
for (dr, i) in zip(devresid, refs)
devc[i] += dr
end
copyto!(view(results, :, j), devc)
endplot(x=xvals, y=view(results, 1, :), Geom.line,
Guide.xlabel("Scaled and shifted u₁"),
Guide.ylabel("Shifted deviance contribution"))
Scaled and shifted u₁
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0
10
20
30
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3.0
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5.0
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
6.0
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
7.0
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
8.0
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
9.0
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9
10.0
10.1
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
11.0
11.1
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
12.0
12.1
12.2
12.3
12.4
12.5
12.6
12.7
12.8
12.9
13.0
13.1
13.2
13.3
13.4
13.5
13.6
13.7
13.8
13.9
14.0
14.1
14.2
14.3
14.4
14.5
14.6
14.7
14.8
14.9
15.0
15.1
15.2
15.3
15.4
15.5
15.6
15.7
15.8
15.9
16.0
16.1
16.2
16.3
16.4
16.5
16.6
16.7
16.8
16.9
17.0
17.1
17.2
17.3
17.4
17.5
17.6
17.7
17.8
17.9
18.0
18.1
18.2
18.3
18.4
18.5
18.6
18.7
18.8
18.9
19.0
19.1
19.2
19.3
19.4
19.5
19.6
19.7
19.8
19.9
20.0
20.1
20.2
20.3
20.4
20.5
20.6
20.7
20.8
20.9
21.0
21.1
21.2
21.3
21.4
21.5
21.6
21.7
21.8
21.9
22.0
22.1
22.2
22.3
22.4
22.5
22.6
22.7
22.8
22.9
23.0
23.1
23.2
23.3
23.4
23.5
23.6
23.7
23.8
23.9
24.0
24.1
24.2
24.3
24.4
24.5
24.6
24.7
24.8
24.9
25.0
25.1
25.2
25.3
25.4
25.5
25.6
25.7
25.8
25.9
26.0
26.1
26.2
26.3
26.4
26.5
26.6
26.7
26.8
26.9
27.0
27.1
27.2
27.3
27.4
27.5
27.6
27.7
27.8
27.9
28.0
28.1
28.2
28.3
28.4
28.5
28.6
28.7
28.8
28.9
29.0
29.1
29.2
29.3
29.4
29.5
29.6
29.7
29.8
29.9
30.0
0
30
Shifted deviance contribution
plot(x=xvals, y=view(results, 3, :), Geom.line,
Guide.xlabel("Scaled and shifted u₃"),
Guide.ylabel("Shifted deviance contribution"))
Scaled and shifted u₃
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0
5
10
15
20
25
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3.0
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
4.0
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5.0
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
6.0
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
7.0
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
8.0
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
9.0
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9
10.0
10.1
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
11.0
11.1
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
12.0
12.1
12.2
12.3
12.4
12.5
12.6
12.7
12.8
12.9
13.0
13.1
13.2
13.3
13.4
13.5
13.6
13.7
13.8
13.9
14.0
14.1
14.2
14.3
14.4
14.5
14.6
14.7
14.8
14.9
15.0
15.1
15.2
15.3
15.4
15.5
15.6
15.7
15.8
15.9
16.0
16.1
16.2
16.3
16.4
16.5
16.6
16.7
16.8
16.9
17.0
17.1
17.2
17.3
17.4
17.5
17.6
17.7
17.8
17.9
18.0
18.1
18.2
18.3
18.4
18.5
18.6
18.7
18.8
18.9
19.0
19.1
19.2
19.3
19.4
19.5
19.6
19.7
19.8
19.9
20.0
20.1
20.2
20.3
20.4
20.5
20.6
20.7
20.8
20.9
21.0
21.1
21.2
21.3
21.4
21.5
21.6
21.7
21.8
21.9
22.0
22.1
22.2
22.3
22.4
22.5
22.6
22.7
22.8
22.9
23.0
23.1
23.2
23.3
23.4
23.5
23.6
23.7
23.8
23.9
24.0
24.1
24.2
24.3
24.4
24.5
24.6
24.7
24.8
24.9
25.0
0
25
Shifted deviance contribution
On the original density scale these become
for (j, z) in enumerate(xvals)
@. uv = u₀ + z * s
MixedModels.updateη!(m1)
@. devc = abs2(uv) - devc0
for (dr, i) in zip(devresid, refs)
devc[i] += dr
end
copyto!(view(results, :, j), @. exp(-devc/2))
endplot(x=xvals, y=view(results, 1, :), Geom.line,
Guide.xlabel("Scaled and shifted u₁"),
Guide.ylabel("Conditional density"))
Scaled and shifted u₁
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0.0
0.5
1.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0.035
0.040
0.045
0.050
0.055
0.060
0.065
0.070
0.075
0.080
0.085
0.090
0.095
0.100
0.105
0.110
0.115
0.120
0.125
0.130
0.135
0.140
0.145
0.150
0.155
0.160
0.165
0.170
0.175
0.180
0.185
0.190
0.195
0.200
0.205
0.210
0.215
0.220
0.225
0.230
0.235
0.240
0.245
0.250
0.255
0.260
0.265
0.270
0.275
0.280
0.285
0.290
0.295
0.300
0.305
0.310
0.315
0.320
0.325
0.330
0.335
0.340
0.345
0.350
0.355
0.360
0.365
0.370
0.375
0.380
0.385
0.390
0.395
0.400
0.405
0.410
0.415
0.420
0.425
0.430
0.435
0.440
0.445
0.450
0.455
0.460
0.465
0.470
0.475
0.480
0.485
0.490
0.495
0.500
0.505
0.510
0.515
0.520
0.525
0.530
0.535
0.540
0.545
0.550
0.555
0.560
0.565
0.570
0.575
0.580
0.585
0.590
0.595
0.600
0.605
0.610
0.615
0.620
0.625
0.630
0.635
0.640
0.645
0.650
0.655
0.660
0.665
0.670
0.675
0.680
0.685
0.690
0.695
0.700
0.705
0.710
0.715
0.720
0.725
0.730
0.735
0.740
0.745
0.750
0.755
0.760
0.765
0.770
0.775
0.780
0.785
0.790
0.795
0.800
0.805
0.810
0.815
0.820
0.825
0.830
0.835
0.840
0.845
0.850
0.855
0.860
0.865
0.870
0.875
0.880
0.885
0.890
0.895
0.900
0.905
0.910
0.915
0.920
0.925
0.930
0.935
0.940
0.945
0.950
0.955
0.960
0.965
0.970
0.975
0.980
0.985
0.990
0.995
1.000
0
1
Conditional density
plot(x=xvals, y=view(results, 3, :), Geom.line,
Guide.xlabel("Scaled and shifted u₃"),
Guide.ylabel("Conditional density"))
Scaled and shifted u₃
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0.0
0.5
1.0
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0.035
0.040
0.045
0.050
0.055
0.060
0.065
0.070
0.075
0.080
0.085
0.090
0.095
0.100
0.105
0.110
0.115
0.120
0.125
0.130
0.135
0.140
0.145
0.150
0.155
0.160
0.165
0.170
0.175
0.180
0.185
0.190
0.195
0.200
0.205
0.210
0.215
0.220
0.225
0.230
0.235
0.240
0.245
0.250
0.255
0.260
0.265
0.270
0.275
0.280
0.285
0.290
0.295
0.300
0.305
0.310
0.315
0.320
0.325
0.330
0.335
0.340
0.345
0.350
0.355
0.360
0.365
0.370
0.375
0.380
0.385
0.390
0.395
0.400
0.405
0.410
0.415
0.420
0.425
0.430
0.435
0.440
0.445
0.450
0.455
0.460
0.465
0.470
0.475
0.480
0.485
0.490
0.495
0.500
0.505
0.510
0.515
0.520
0.525
0.530
0.535
0.540
0.545
0.550
0.555
0.560
0.565
0.570
0.575
0.580
0.585
0.590
0.595
0.600
0.605
0.610
0.615
0.620
0.625
0.630
0.635
0.640
0.645
0.650
0.655
0.660
0.665
0.670
0.675
0.680
0.685
0.690
0.695
0.700
0.705
0.710
0.715
0.720
0.725
0.730
0.735
0.740
0.745
0.750
0.755
0.760
0.765
0.770
0.775
0.780
0.785
0.790
0.795
0.800
0.805
0.810
0.815
0.820
0.825
0.830
0.835
0.840
0.845
0.850
0.855
0.860
0.865
0.870
0.875
0.880
0.885
0.890
0.895
0.900
0.905
0.910
0.915
0.920
0.925
0.930
0.935
0.940
0.945
0.950
0.955
0.960
0.965
0.970
0.975
0.980
0.985
0.990
0.995
1.000
0
1
Conditional density
and the function to be integrated with the normalized Gauss-Hermite rule is
for (j, z) in enumerate(xvals)
@. uv = u₀ + z * s
MixedModels.updateη!(m1)
@. devc = abs2(uv) - devc0
for (dr, i) in zip(devresid, refs)
devc[i] += dr
end
copyto!(view(results, :, j), @. exp((abs2(z) - devc)/2))
endplot(x=xvals, y=view(results, 1, :), Geom.line,
Guide.xlabel("Scaled and shifted u₁"), Guide.ylabel("Kernel ratio"))
Scaled and shifted u₁
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0
1
2
3
4
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
0.00
0.02
0.04
0.06
0.08
0.10
0.12
0.14
0.16
0.18
0.20
0.22
0.24
0.26
0.28
0.30
0.32
0.34
0.36
0.38
0.40
0.42
0.44
0.46
0.48
0.50
0.52
0.54
0.56
0.58
0.60
0.62
0.64
0.66
0.68
0.70
0.72
0.74
0.76
0.78
0.80
0.82
0.84
0.86
0.88
0.90
0.92
0.94
0.96
0.98
1.00
1.02
1.04
1.06
1.08
1.10
1.12
1.14
1.16
1.18
1.20
1.22
1.24
1.26
1.28
1.30
1.32
1.34
1.36
1.38
1.40
1.42
1.44
1.46
1.48
1.50
1.52
1.54
1.56
1.58
1.60
1.62
1.64
1.66
1.68
1.70
1.72
1.74
1.76
1.78
1.80
1.82
1.84
1.86
1.88
1.90
1.92
1.94
1.96
1.98
2.00
2.02
2.04
2.06
2.08
2.10
2.12
2.14
2.16
2.18
2.20
2.22
2.24
2.26
2.28
2.30
2.32
2.34
2.36
2.38
2.40
2.42
2.44
2.46
2.48
2.50
2.52
2.54
2.56
2.58
2.60
2.62
2.64
2.66
2.68
2.70
2.72
2.74
2.76
2.78
2.80
2.82
2.84
2.86
2.88
2.90
2.92
2.94
2.96
2.98
3.00
3.02
3.04
3.06
3.08
3.10
3.12
3.14
3.16
3.18
3.20
3.22
3.24
3.26
3.28
3.30
3.32
3.34
3.36
3.38
3.40
3.42
3.44
3.46
3.48
3.50
3.52
3.54
3.56
3.58
3.60
3.62
3.64
3.66
3.68
3.70
3.72
3.74
3.76
3.78
3.80
3.82
3.84
3.86
3.88
3.90
3.92
3.94
3.96
3.98
4.00
0
5
Kernel ratio
plot(x=xvals, y=view(results, 3, :), Geom.line,
Guide.xlabel("Scaled and shifted u₃"), Guide.ylabel("Kernel ratio"))
Scaled and shifted u₃
-5
0
5
-5.0
-4.5
-4.0
-3.5
-3.0
-2.5
-2.0
-1.5
-1.0
-0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
4.5
5.0
-5.00
-4.95
-4.90
-4.85
-4.80
-4.75
-4.70
-4.65
-4.60
-4.55
-4.50
-4.45
-4.40
-4.35
-4.30
-4.25
-4.20
-4.15
-4.10
-4.05
-4.00
-3.95
-3.90
-3.85
-3.80
-3.75
-3.70
-3.65
-3.60
-3.55
-3.50
-3.45
-3.40
-3.35
-3.30
-3.25
-3.20
-3.15
-3.10
-3.05
-3.00
-2.95
-2.90
-2.85
-2.80
-2.75
-2.70
-2.65
-2.60
-2.55
-2.50
-2.45
-2.40
-2.35
-2.30
-2.25
-2.20
-2.15
-2.10
-2.05
-2.00
-1.95
-1.90
-1.85
-1.80
-1.75
-1.70
-1.65
-1.60
-1.55
-1.50
-1.45
-1.40
-1.35
-1.30
-1.25
-1.20
-1.15
-1.10
-1.05
-1.00
-0.95
-0.90
-0.85
-0.80
-0.75
-0.70
-0.65
-0.60
-0.55
-0.50
-0.45
-0.40
-0.35
-0.30
-0.25
-0.20
-0.15
-0.10
-0.05
0.00
0.05
0.10
0.15
0.20
0.25
0.30
0.35
0.40
0.45
0.50
0.55
0.60
0.65
0.70
0.75
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
1.35
1.40
1.45
1.50
1.55
1.60
1.65
1.70
1.75
1.80
1.85
1.90
1.95
2.00
2.05
2.10
2.15
2.20
2.25
2.30
2.35
2.40
2.45
2.50
2.55
2.60
2.65
2.70
2.75
2.80
2.85
2.90
2.95
3.00
3.05
3.10
3.15
3.20
3.25
3.30
3.35
3.40
3.45
3.50
3.55
3.60
3.65
3.70
3.75
3.80
3.85
3.90
3.95
4.00
4.05
4.10
4.15
4.20
4.25
4.30
4.35
4.40
4.45
4.50
4.55
4.60
4.65
4.70
4.75
4.80
4.85
4.90
4.95
5.00
-5
0
5
h,j,k,l,arrows,drag to pan
i,o,+,-,scroll,shift-drag to zoom
r,dbl-click to reset
c for coordinates
? for help
?
0.9
1.0
1.1
1.2
1.3
0.88
0.90
0.92
0.94
0.96
0.98
1.00
1.02
1.04
1.06
1.08
1.10
1.12
1.14
1.16
1.18
1.20
1.22
1.24
1.26
1.28
1.30
0.900
0.902
0.904
0.906
0.908
0.910
0.912
0.914
0.916
0.918
0.920
0.922
0.924
0.926
0.928
0.930
0.932
0.934
0.936
0.938
0.940
0.942
0.944
0.946
0.948
0.950
0.952
0.954
0.956
0.958
0.960
0.962
0.964
0.966
0.968
0.970
0.972
0.974
0.976
0.978
0.980
0.982
0.984
0.986
0.988
0.990
0.992
0.994
0.996
0.998
1.000
1.002
1.004
1.006
1.008
1.010
1.012
1.014
1.016
1.018
1.020
1.022
1.024
1.026
1.028
1.030
1.032
1.034
1.036
1.038
1.040
1.042
1.044
1.046
1.048
1.050
1.052
1.054
1.056
1.058
1.060
1.062
1.064
1.066
1.068
1.070
1.072
1.074
1.076
1.078
1.080
1.082
1.084
1.086
1.088
1.090
1.092
1.094
1.096
1.098
1.100
1.102
1.104
1.106
1.108
1.110
1.112
1.114
1.116
1.118
1.120
1.122
1.124
1.126
1.128
1.130
1.132
1.134
1.136
1.138
1.140
1.142
1.144
1.146
1.148
1.150
1.152
1.154
1.156
1.158
1.160
1.162
1.164
1.166
1.168
1.170
1.172
1.174
1.176
1.178
1.180
1.182
1.184
1.186
1.188
1.190
1.192
1.194
1.196
1.198
1.200
1.202
1.204
1.206
1.208
1.210
1.212
1.214
1.216
1.218
1.220
1.222
1.224
1.226
1.228
1.230
1.232
1.234
1.236
1.238
1.240
1.242
1.244
1.246
1.248
1.250
1.252
1.254
1.256
1.258
1.260
1.262
1.264
1.266
1.268
1.270
1.272
1.274
1.276
1.278
1.280
1.282
1.284
1.286
1.288
1.290
1.292
1.294
1.296
1.298
1.300
0.9
1.0
1.1
1.2
1.3
Kernel ratio