| Title: | Nonparametric Tests for Random Effects in Linear and Nonlinear Mixed-Effects Models |
|---|---|
| Description: | Provides nonparametric permutation tests for testing all or any subset of random effects in linear and nonlinear mixed-effects models, without requiring normality or other distributional assumptions on random effects or errors. Three distribution-free variance-component estimators are implemented: Variance Least Squares ('VLS'), Method of Moments ('MM'), and Method of Moments with First-Order Approximation ('MMF'). A permutation procedure is used to obtain finite-sample p-values. Plotting functions support data exploration, model evaluation, and communication of results. Methods are described in Uwimpuhwe, Drikvandi, and Blozis (2026) <doi:10.1002/sim.70605>. |
| Authors: | Germaine Uwimpuhwe [aut, cre], Reza Drikvandi [aut], Shelley A. Blozis [aut] |
| Maintainer: | Germaine Uwimpuhwe <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-07-04 10:36:20 UTC |
| Source: | https://github.com/germaine86/testrenlme |
Estimates the fixed-effects parameter vector by unweighted NLS (first
attempt via nls), or by weighted NLS via
nlminb when weights is supplied or when the
unweighted NLS fails. Used both for initial unweighted estimation and for
GLS re-estimation at the end of VLS using the estimated variance
components.
Beta_hat(data, Expr, start, weights = NULL, group = NULL, verbose = 1)Beta_hat(data, Expr, start, weights = NULL, group = NULL, verbose = 1)
data |
A |
Expr |
A two-sided formula specifying the nonlinear model. |
start |
A named numeric vector of starting values. See the
|
weights |
Either |
group |
Character. Name of the grouping variable, required when
|
verbose |
Integer (0, 1, or 2). Default |
A named numeric vector of estimated fixed effects.
Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) Beta_hat(as.data.frame(Theoph), Expr, start)Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) Beta_hat(as.data.frame(Theoph), Expr, start)
Computes bootstrap standard errors for the fixed effects ,
random effect variance components , and error variance
using one of two bootstrap strategies documented in the literature for
mixed-effects models.
bootstrap_se( Dobj, nboot = 200, type = c("case", "residual"), seed = NULL, verbose = 1 )bootstrap_se( Dobj, nboot = 200, type = c("case", "residual"), seed = NULL, verbose = 1 )
Dobj |
An object of class |
nboot |
Positive integer. Number of bootstrap samples. Default
|
type |
Character. Bootstrap strategy:
|
seed |
Optional integer seed for reproducibility. Default |
verbose |
Integer (0, 1, or 2). Default |
A list of class "Dboot" with components:
BetaMatrix with columns Estimate and SE
for the fixed effects.
DhatMatrix with columns Estimate and SE
for each variance/covariance component (flattened via
row:column naming).
Sigma2Matrix with columns Estimate and SE
for the error variance.
Boot_BetaMatrix of bootstrap fixed-effects estimates
(nboot x length(Beta)).
Boot_DhatArray of bootstrap variance component matrices
(k x k x nboot).
Boot_Sigma2Numeric vector of bootstrap error variance
estimates (length nboot).
typeThe bootstrap strategy used.
nbootNumber of bootstrap samples requested.
nfailNumber of bootstrap samples that failed.
Carpenter, J.R., Goldstein, H. and Rasbash, J. (2003). A novel bootstrap procedure for assessing the relationship between class size and achievement. Journal of the Royal Statistical Society C, 52, 431–443.
Thai, H.T., Mentre, F., Holford, N.H.G., Veyrat-Follet, C. and Comets, E. (2013). A comparison of bootstrap approaches for estimating uncertainty of parameters in linear mixed-effects models. Pharmaceutical Statistics, 12, 129–140.
d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start, method = "VLS") DVLS[c("Dhat", "Sigma2", "Beta")] BootSE <- bootstrap_se(DVLS, nboot = 20, type = "case", seed = NULL, verbose = 1)d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start, method = "VLS") DVLS[c("Dhat", "Sigma2", "Beta")] BootSE <- bootstrap_se(DVLS, nboot = 20, type = "case", seed = NULL, verbose = 1)
Performs a nonparametric permutation test for all random effects or any user-specified subset, using the test statistic of Drikvandi et al. (2013) adapted for nonlinear mixed-effects models in Uwimpuhwe (2026).
Dhypothesis_test( data, Expr, group, random, start = NULL, bi_out = NULL, method = c("VLS", "MM", "MMF"), Dhatt = NULL, Thatt = NULL, MM_base_obj = NULL, nperm = 200, seed = NULL, sig_alpha = 0.05, kappa_max = 10000, RR_catof = "kappa", verbose = 1, perm_freq = 10 )Dhypothesis_test( data, Expr, group, random, start = NULL, bi_out = NULL, method = c("VLS", "MM", "MMF"), Dhatt = NULL, Thatt = NULL, MM_base_obj = NULL, nperm = 200, seed = NULL, sig_alpha = 0.05, kappa_max = 10000, RR_catof = "kappa", verbose = 1, perm_freq = 10 )
data |
A |
Expr |
A two-sided formula specifying the nonlinear model
|
group |
Character. Name of the grouping variable. |
random |
A character vector of two-sided formula strings, one per
parameter in |
start |
A named numeric vector of starting values for all parameters
in |
bi_out |
Optional character vector naming the random effects to
test. If |
method |
Character. One of |
Dhatt |
Optional pre-computed |
Thatt |
Optional pre-computed observed test statistic from
|
MM_base_obj |
Optional pre-computed |
nperm |
Positive integer. Number of permutations |
seed |
Optional integer seed for reproducibility. Default |
sig_alpha |
Significance level for the reject/do-not-reject
decision. Default |
kappa_max |
Condition-number threshold for MM/MMF. Default |
RR_catof |
Exclusion criterion passed to |
verbose |
Integer (0, 1, or 2). Controls message output:
|
perm_freq |
Integer. When |
An object of class "Dtest", a list with components:
DecisionCharacter, "Reject H0" or
"Do not reject H0".
pvalueThe empirical permutation -value.
TobsThe observed test statistic .
TpermNumeric vector of length nperm containing
the permutation statistics .
DhattThe Dmethod object used.
bi_outThe random effects tested.
plotA ggplot2 histogram of the permutation null
distribution with annotated.
Uwimpuhwe, G., Drikvandi, R., and Blozis, S.A. (2026). Testing random effects in nonlinear mixed-effects models. Statistics in Medicine. doi:10.1002/sim.70605
Uwimpuhwe, G., Drikvandi, R. and Blozis, S. A. (in preparation). TestREnlme: An R Package for Testing Random Effects in Nonlinear Mixed-Effects Models. Journal of Statistical Software.
Demidenko, E. (2013). Mixed Models: Theory and Applications with R (2nd ed.). Wiley.
Drikvandi, R., Verbeke, G., Khodadadi, A. and Nia, V. P. (2013). Testing multiple variance components in linear mixed-effects models. Biostatistics, 14 (1), 144–159.
d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start) ## Permutation test (slow -- use nperm = 200 minimum for real use) H <- Dhypothesis_test(d, Expr, group = "Subject", random = random, start = start, Dhatt = DVLS, nperm = 20, seed = 1) H$pvalue H$plotd <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start) ## Permutation test (slow -- use nperm = 200 minimum for real use) H <- Dhypothesis_test(d, Expr, group = "Subject", random = random, start = start, Dhatt = DVLS, nperm = 20, seed = 1) H$pvalue H$plot
Computes the scaled variance covariance matrix and the
error variance using one of three nonparametric
estimators: Variance Least Squares ("VLS"), Method of Moments ("MM"),
or Method of Moments with First-Order Approximation ("MMF").
The method also estimate weighted fixed effects
Dmethod( data, Expr, group, random, start = NULL, method = c("VLS", "MM", "MMF"), MM_base_obj = NULL, kappa_max = 10000, RR_catof = "kappa", Beta_nls = NULL, verbose = 1, is_permuting = FALSE )Dmethod( data, Expr, group, random, start = NULL, method = c("VLS", "MM", "MMF"), MM_base_obj = NULL, kappa_max = 10000, RR_catof = "kappa", Beta_nls = NULL, verbose = 1, is_permuting = FALSE )
data |
A |
Expr |
A two-sided formula specifying the nonlinear model
|
group |
Character. Name of the grouping variable in |
random |
A character vector of two-sided formula strings, one per
parameter in |
start |
A named numeric vector of starting values for all parameters
in |
method |
Character. One of |
MM_base_obj |
An optional pre-computed object of class |
kappa_max |
Positive numeric. Condition-number threshold for
excluding subjects in MM/MMF. Default |
RR_catof |
Exclusion criterion passed to |
Beta_nls |
Optional named numeric vector of pre-computed fixed-effects
estimates. If |
verbose |
Integer (0, 1, or 2). |
is_permuting |
Logical. Internal flag set to |
An object of class "Dmethod", a list with components:
DhatThe estimated scaled covariance matrix of random effects
.
Sigma2The estimated error variance .
BetaThe estimated fixed-effects vector .
methodThe estimation method used.
RPer-subject Jacobian matrices .
YpredPer-subject fitted values under fixed effects only.
residualsPer-subject residuals .
IDconvegenceSubject inclusion/exclusion summary (MM/MMF
only; NULL otherwise).
Additional internal objects are stored as an "internal"
attribute (attr(object, "internal")) and used by package
methods. They are not part of the user interface.
Uwimpuhwe, G., Drikvandi, R., and Blozis, S.A. (2026). Testing random effects in nonlinear mixed-effects models. Statistics in Medicine. doi:10.1002/sim.70605
Uwimpuhwe, G., Drikvandi, R. and Blozis, S. A. (in preparation). TestREnlme: An R Package for Testing Random Effects in Nonlinear Mixed-Effects Models. Journal of Statistical Software.
Demidenko, E. (2013). Mixed Models: Theory and Applications with R (2nd ed.). John Wiley & Sons
Drikvandi, R., Verbeke, G., Khodadadi, A. and Nia, V. P. (2013). Testing multiple variance components in linear mixed-effects models. Biostatistics, 14 (1), 144–159.
d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start) ## method defaults to VLS; explicit: method = "VLS" DVLS[c("Dhat", "Sigma2", "Beta")]d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") DVLS <- Dmethod(d, Expr, group = "Subject", random = random, start = start) ## method defaults to VLS; explicit: method = "VLS" DVLS[c("Dhat", "Sigma2", "Beta")]
Performs the first-stage nonlinear least squares (NLS) fit for each
subject individually, and computes the per-subject Jacobian matrices
and condition numbers . The returned
object can be passed to Dmethod via the MM_base_obj
argument to avoid recomputing the first stage when calling both
method = "MM" and method = "MMF" on the same data.
MM_base( data, Expr, group, random, start = NULL, kappa_max = 10000, RR_catof = "kappa", verbose = 1 )MM_base( data, Expr, group, random, start = NULL, kappa_max = 10000, RR_catof = "kappa", verbose = 1 )
data |
A |
Expr |
A two-sided formula specifying the nonlinear model
|
group |
Character. Name of the grouping (subject) variable. |
random |
A character vector of two-sided formula strings, one per
parameter in |
start |
A named numeric vector of starting values for all parameters
in |
kappa_max |
Positive numeric. Subjects whose per-subject Jacobian
condition number exceeds this threshold are excluded from MM/MMF
second-stage estimation. Default |
RR_catof |
Character. Exclusion criterion: |
verbose |
Integer (0, 1, or 2). |
A list of class "MM_base" with components:
dataThe (re-ordered, group-renumbered) data.frame
used internally.
groupName of the grouping variable.
startThe starting values used.
Beta_nlsNamed numeric vector of pooled (first-pass)
fixed-effects estimates from Beta_hat.
randomThe random formulas, aligned with
start.
re_namesNamed character vector mapping random-effect names to subject-specific parameter names.
TmatrixMatrix of per-subject scaled covariance terms
(one row per subject, k^2 columns).
TiList of per-subject covariance
matrices derived from Tmatrix.
ddiList of per-subject second-stage
deviation outer-product matrices (eq.~8.20).
LamdaMinimum eigenvalue of the standardised scatter matrix, used to bias-correct the MM/MMF variance estimates.
sigma2Pooled residual variance across retained subjects.
Beta_GBNamed numeric vector of non-random-effect fixed-effects estimates.
mTotal number of second-stage fixed-effects
parameters (k * ncol(Q)).
kNumber of random-effects parameters.
id, uid, nud
Subject index vector, unique subject IDs, and number of unique subjects.
IDworksInteger vector of subject IDs retained after filtering.
QSubject-level design matrix.
AaiList with elements Ai (per-subject design
matrices) and a0i (per-subject parameter estimates).
kappaNamed numeric vector of per-subject condition numbers.
IDconvegenceList with elements ID_all,
ID_used, and ID_supressed (itself a list with
highRR and Unconverged).
d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") mb <- MM_base(d, Expr, group = "Subject", random = random, start = start)d <- as.data.frame(Theoph) Expr <- conc ~ Dose * exp(ai2 + ai3 - ai1) * (exp(-Time * exp(ai3)) - exp(-Time * exp(ai2))) / (exp(ai2) - exp(ai3)) start <- c(ai1 = -3.22, ai2 = 0.47, ai3 = -2.45) random <- c("ai1 ~ B1 + bi1", "ai2 ~ B2 + bi2", "ai3 ~ B3 + bi3") mb <- MM_base(d, Expr, group = "Subject", random = random, start = start)
Displays the condition numbers from a "MM_base"
object or the MM_base_obj slot of a "Dmethod" object,
sorted in decreasing order. A horizontal reference line at
kappa_max marks the exclusion threshold.
plot_condition(Dobj, kappa_max = 10000, log_scale = TRUE)plot_condition(Dobj, kappa_max = 10000, log_scale = TRUE)
Dobj |
A |
kappa_max |
Numeric. Exclusion threshold to highlight on the plot.
Default |
log_scale |
Logical. If |
A ggplot2 object.
Draws the model-predicted trajectories on top of the observed data for
each subject. When a "Dmethod" object is supplied, subject-specific
EBLUP-adjusted predictions are used; otherwise only the population
fixed-effects curve is shown.
plot_fitted(Dobj, time, subjects = NULL, overlay = TRUE, ncol = 4)plot_fitted(Dobj, time, subjects = NULL, overlay = TRUE, ncol = 4)
Dobj |
An object of class |
time |
Character. Name of the time variable in |
subjects |
Optional character or integer vector of subject IDs to
plot. If |
overlay |
Logical. If |
ncol |
Integer. Number of columns for the subject facets.
Default |
A ggplot2 object.
Regenerates or customises the permutation histogram stored in a
"Dtest" object. The observed statistic is
shown as a vertical dashed line, and the empirical -value and
rejection decision are annotated on the plot.
plot_perm_hist( Htest, bins = 30, fill = "steelblue", line_col = "red", title = NULL )plot_perm_hist( Htest, bins = 30, fill = "steelblue", line_col = "red", title = NULL )
Htest |
An object of class |
bins |
Integer. Number of histogram bins. Default |
fill |
Character. Fill colour for the histogram bars.
Default |
line_col |
Character. Colour for the |
title |
Character. Plot title. If |
A ggplot2 object.
Produces a spaghetti plot of the raw observed trajectories for all subjects (or a selected subset), with an optional group-level mean profile and subject highlighting.
plot_profiles( data, group, time, response, subjects = NULL, mean_profile = TRUE, highlight = NULL, title = "Individual profiles" )plot_profiles( data, group, time, response, subjects = NULL, mean_profile = TRUE, highlight = NULL, title = "Individual profiles" )
data |
A |
group |
Character. Name of the grouping variable. |
time |
Character. Name of the time variable. |
response |
Character. Name of the response variable. |
subjects |
Optional character or integer vector of subject IDs to
plot. If |
mean_profile |
Logical. Whether to superimpose the group-level mean
trajectory as a bold line. Default |
highlight |
Optional character or integer vector of subject IDs to draw in a contrasting colour (e.g., subjects excluded by the condition-number filter). |
title |
Character. Plot title. Default |
A ggplot2 object.
d <- as.data.frame(Theoph) plot_profiles(d, group = "Subject", time = "Time", response = "conc")d <- as.data.frame(Theoph) plot_profiles(d, group = "Subject", time = "Time", response = "conc")
Produces a residuals-versus-fitted-values scatter plot with a horizontal reference line at zero and a loess smoother to aid detection of systematic misfit or heteroscedasticity.
plot_residuals(Dobj, time, type = c("response", "standardised", "subject"))plot_residuals(Dobj, time, type = c("response", "standardised", "subject"))
Dobj |
An object of class |
time |
Character. Name of the time variable. |
type |
Character. Type of residuals: |
A ggplot2 object.
Produces a side-by-side dot plot (or bar chart) of the estimated
variance components for each random effect,
comparing results from multiple estimation methods.
plot_variance( Dhatt_list, component = c("diagonal", "full"), title = "Variance component estimates" )plot_variance( Dhatt_list, component = c("diagonal", "full"), title = "Variance component estimates" )
Dhatt_list |
A named list of |
component |
Character. |
title |
Character. Plot title. |
A ggplot2 object.
Dmethod objectsBy default all relevant diagnostic plots are produced and arranged in a
grid. Use the which argument to select specific plots.
## S3 method for class 'Dmethod' plot(x, time, which = NULL, ...)## S3 method for class 'Dmethod' plot(x, time, which = NULL, ...)
x |
A |
time |
Character. Name of the time variable (required). |
which |
Integer vector specifying which plots to show:
|
... |
Additional arguments passed to individual plot functions. |
Invisibly returns a list of ggplot2 objects.
Dtest objectsDisplays the permutation null distribution histogram with the observed test statistic annotated.
## S3 method for class 'Dtest' plot(x, ...)## S3 method for class 'Dtest' plot(x, ...)
x |
A |
... |
Additional arguments passed to |
Invisibly returns the ggplot2 object.
Response latency data from a study of quantitative skill acquisition
on a learning task (Blozis 2004). Log-transformed response latencies
are recorded for subjects across trial
blocks, stored in wide format. Used to illustrate fitting a nonlinear
mixed-effects model with a subject-level covariate (working memory)
incorporated through the second-stage model, and to demonstrate
reshaping wide-format longitudinal data into the long format required
by Dmethod and Dhypothesis_test.
SkillAcqSkillAcq
A data frame with 204 rows (one per subject) and 13 columns:
Subject identifier.
Log-transformed response latency at trial block 1.
Log-transformed response latency at trial block 2.
Log-transformed response latency at trial block 3.
Log-transformed response latency at trial block 4.
Log-transformed response latency at trial block 5.
Log-transformed response latency at trial block 6.
Log-transformed response latency at trial block 7.
Log-transformed response latency at trial block 8.
Log-transformed response latency at trial block 9.
Log-transformed response latency at trial block 10.
Log-transformed response latency at trial block 11.
Subject-level working-memory covariate.
SkillAcq is stored in wide format, as commonly encountered in
practice. Before use with Dmethod it must be reshaped to
long format, with one row per subject-trial observation; see
Examples below.
The nonlinear mixed-effects model used for this dataset is
with
where , , and represent,
respectively, the subject-specific initial performance offset, lower
asymptote, and learning rate, each with a regression component on
wm2 and a subject-specific random effect. The questions of
interest are whether all three random effects are necessary, and
whether one or more can be removed to obtain a more parsimonious
model; see Dhypothesis_test.
Blozis, S. A. (2004). Structured latent curve models for the study of change in multivariate repeated measures. Psychological Methods, 9(3), 334–353. https://doi.org/10.1037/1082-989X.9.3.334
Used as a worked example in Uwimpuhwe, G., Drikvandi, R. and Blozis, S. A. (in preparation). TestREnlme: An R Package for Testing Random Effects in Nonlinear Mixed-Effects Models. Journal of Statistical Software.
## Reshape from wide (ly1..ly11) to long format qrt <- data.frame(SkillAcq) qrt1 <- reshape2::melt(qrt, id.vars = c("id", "wm2"), variable.name = "ly", value.name = "Y") qrt1$t <- as.numeric(sub("ly", "", qrt1$ly)) ## Model: Y_ij = ai1 - (ai1 + ai0) * exp(ai2 * t_ij) + e_ij ## with aik = B0k + B1k * wm2_i + bik, k in {0, 1, 2} Expr_learn <- Y ~ ai1 - (ai1 + ai0) * exp(ai2 * t) random_learn <- c("ai0 ~ B00 + B10 * wm2 + bi0", "ai1 ~ B01 + B11 * wm2 + bi1", "ai2 ~ B02 + B12 * wm2 + bi2") ## Estimate variance components (VLS) and test all three random effects DVLS_learn <- Dmethod(qrt1, Expr_learn, group = "id", random = random_learn, start = NULL) DVLS_learn[c("Dhat", "Sigma2", "Beta")] H_learn <- Dhypothesis_test(qrt1, Expr_learn, group = "id", random = random_learn, start = NULL, Dhatt = DVLS_learn, nperm = 200, seed = 1) H_learn$pvalue## Reshape from wide (ly1..ly11) to long format qrt <- data.frame(SkillAcq) qrt1 <- reshape2::melt(qrt, id.vars = c("id", "wm2"), variable.name = "ly", value.name = "Y") qrt1$t <- as.numeric(sub("ly", "", qrt1$ly)) ## Model: Y_ij = ai1 - (ai1 + ai0) * exp(ai2 * t_ij) + e_ij ## with aik = B0k + B1k * wm2_i + bik, k in {0, 1, 2} Expr_learn <- Y ~ ai1 - (ai1 + ai0) * exp(ai2 * t) random_learn <- c("ai0 ~ B00 + B10 * wm2 + bi0", "ai1 ~ B01 + B11 * wm2 + bi1", "ai2 ~ B02 + B12 * wm2 + bi2") ## Estimate variance components (VLS) and test all three random effects DVLS_learn <- Dmethod(qrt1, Expr_learn, group = "id", random = random_learn, start = NULL) DVLS_learn[c("Dhat", "Sigma2", "Beta")] H_learn <- Dhypothesis_test(qrt1, Expr_learn, group = "id", random = random_learn, start = NULL, Dhatt = DVLS_learn, nperm = 200, seed = 1) H_learn$pvalue
Computes
from a fitted Dmethod object.
Tstat(Dobj, bi_out = NULL)Tstat(Dobj, bi_out = NULL)
Dobj |
An object of class |
bi_out |
Optional character vector of random-effect names to test.
If |
A scalar, the value of .
Evaluates the Jacobian of the nonlinear model
function with respect to the random-effects parameters, and computes
fitted values under the fixed-effects-only model.
ZandYPred(data, Expr, group, random, Beta_nls = NULL, start = NULL)ZandYPred(data, Expr, group, random, Beta_nls = NULL, start = NULL)
data |
A |
Expr |
A two-sided formula for the nonlinear model. |
group |
Character name of the grouping variable. |
random |
A named list or vector of one-sided formulas mapping each
parameter to its random-effect expression, e.g.
|
Beta_nls |
Named numeric vector of fixed-effects estimates from
|
start |
A named numeric vector of starting values. See the
|
A list with components:
RNamed list of per-subject Jacobian matrices
.
YpredNamed list of per-subject predicted vectors
.
residualsNamed list of per-subject residual vectors
.