@@ -58,7 +58,7 @@ function parametricbootstrap(
58
58
rng:: AbstractRNG ,
59
59
n:: Integer ,
60
60
morig:: LinearMixedModel{T} ;
61
- β = morig. β ,
61
+ β = coef ( morig) ,
62
62
σ = morig. σ,
63
63
θ = morig. θ,
64
64
use_threads = false ,
@@ -68,6 +68,14 @@ function parametricbootstrap(
68
68
θ = convert (Vector{T},θ)
69
69
βsc, θsc, p, k, m = similar (β), similar (θ), length (β), length (θ), deepcopy (morig)
70
70
y₀ = copy (response (m))
71
+
72
+ β_names = (Symbol .(fixefnames (morig))... , )
73
+ rank = length (β_names)
74
+ # fixef! requires that we take all coefs, even for pivoted terms
75
+ if rank ≠ length (βsc)
76
+ resize! (βsc, rank)
77
+ end
78
+
71
79
# we need to do for in-place operations to work across threads
72
80
m_threads = [m]
73
81
βsc_threads = [βsc]
@@ -93,7 +101,10 @@ function parametricbootstrap(
93
101
(
94
102
objective = mod. objective,
95
103
σ = mod. σ,
96
- β = SVector {p,T} (fixef! (βsc, mod)),
104
+ # fixef! does the pivoted, but not truncated coefs
105
+ # coef does the non-pivoted
106
+ # fixef does either pivoted+truncated or unpivoted
107
+ β = NamedTuple {β_names} (fixef! (βsc, mod)[1 : rank]),
97
108
θ = SVector {k,T} (getθ! (θsc, mod)),
98
109
)
99
110
end
@@ -154,11 +165,22 @@ function simulate!(
154
165
σ = m. σ,
155
166
θ = T[],
156
167
) where {T}
168
+ length (β) == length (fixef (m)) ||
169
+ length (β) == length (coef (m)) ||
170
+ throw (ArgumentError (" You must specify all (non-singular) βs" ))
171
+
157
172
β = convert (Vector{T},β)
158
173
σ = T (σ)
159
174
θ = convert (Vector{T},θ)
160
175
isempty (θ) || setθ! (m, θ)
161
176
177
+ if length (β) ≠ length (coef (m))
178
+ padding = length (coef (m)) - length (β)
179
+ for ii in 1 : padding
180
+ push! (β, - 0.0 )
181
+ end
182
+ end
183
+
162
184
y = randn! (rng, response (m)) # initialize y to standard normal
163
185
164
186
for trm in m. reterms # add the unscaled random effects
@@ -169,7 +191,7 @@ function simulate!(
169
191
m
170
192
end
171
193
172
- function simulate! (m:: LinearMixedModel{T} ; β = m . β , σ = m. σ, θ = T[]) where {T}
194
+ function simulate! (m:: LinearMixedModel{T} ; β = coef (m) , σ = m. σ, θ = T[]) where {T}
173
195
simulate! (Random. GLOBAL_RNG, m, β = β, σ = σ, θ = θ)
174
196
end
175
197
0 commit comments