hs_control() records execution and storage controls for hsquared model
calls. The default engine = "fit" fits the validated v0.1 Gaussian
animal model through the HSquared.jl engine (average-information REML);
engine = "validate" parses and validates the contract without fitting,
returning the validated spec invisibly; and engine = "julia" exposes
advanced engine controls.
Usage
hs_control(
engine = c("fit", "validate", "julia"),
backend = c("auto", "cpu", "threads", "cuda", "amdgpu", "metal", "oneapi"),
accelerator = c("auto", "none", "gpu", "cuda", "amdgpu", "metal", "oneapi"),
precision = c("float64", "float32"),
save = c("minimal", "full", "tiny"),
engine_control = list()
)Arguments
- engine
Execution engine.
"fit"(default) fits the v0.1 Gaussian animal model via theHSquared.jlengine; this requires a local Julia, theJuliaCallpackage, and anHSquared.jlcheckout."validate"validates the parser and bridge payload without fitting, then returns the validated spec invisibly (after a confirming message)."julia"exposes the advanced opt-in bridge with explicittargetcontrol.- backend
Planned compute backend. One of
"auto","cpu","threads","cuda","amdgpu","metal", or"oneapi".- accelerator
Planned accelerator preference. One of
"auto","none","gpu","cuda","amdgpu","metal", or"oneapi".- precision
Planned numeric precision. One of
"float64"or"float32".- save
Planned fitted-object storage mode. One of
"minimal","full", or"tiny".- engine_control
A named list for engine-specific controls. The current experimental Julia bridge recognizes
julia_project,initial,iterations,em_warmup,target,variance_components,marginal,max_dense_cells,scale_method,genetic_structure,rank, andexperimental_gllvm.julia_projectis honoured by everytarget; supplying a key a giventargetdoes not honour errors (hsquared#212) rather than being silently ignored. Per-target honoured keys (besidesjulia_project):fit_animal_model(default):initial,max_dense_cells.henderson_mme,metafounder,snp_blup:variance_components.ai_reml:initial,iterations,em_warmup.sparse_reml,two_effect,direct_maternal,genomic,single_step,single_step_construct,metafounder_single_step,relmat,precision:initial,iterations.repeatability:initial,iterations,max_dense_cells,scale_method.multi_effect:initial,iterations,scale_method. Both the default dense route and the opt-inscale_method = "auto"route forwardinitialanditerationsto the Julia fitter.multivariate:initial,iterations,genetic_structure,rank,max_dense_cells.genetic_gllvm:iterations,genetic_structure,rank,experimental_gllvm(initialis not exposed on this route).multivariate_repeatability:initial,iterations,max_dense_cells.random_regression:iterations(noinitial).nongaussian:marginal,iterations,initial(a list withsigma_a2),restart_check.max_dense_cellsboundsnobs^2 + nanimals^2on the engine's dense-validation fitters (hsquared#214, #217): the default Julia targettarget = "fit_animal_model"(viaHSquared.fit_animal_model()/fit_variance_components()) andtarget = "repeatability". Those two requireengine = "julia". The default univariateengine = "fit"path routes to sparse-capableHSquared.fit_ai_reml()and does not use this cap. No dense-cell cap is not a size-free claim: when additive variance is near 0 and the pedigree has more than 512 animals, that default path can stop withconverged = FALSE,optimizer_status = "boundary_score_unresolved", and an inflated residual. Checkfit_diagnostics(). The existing fallback isengine = "julia"withtarget = "sparse_reml"(experimental, opt-in; not a new covered claim). The defaultcbind()path does use the dense-cell cap: it forwardsmax_dense_cellsto the dense multivariate fitter, and a problem above the cap errors instead of allocating (hsquared#280, HSquared.jl#443). A name that is not in the recognised set errors here, rather than being ignored (hsquared#323). It must be a single positive integer; the default,1e6, mirrors the engine's ownDEFAULT_MAX_DENSE_CELLSunchanged. Raise it to fit a larger dense problem at the cost of memory and time, or switch to a sparse route (target = "ai_reml"/"sparse_reml") instead of raising it indefinitely. Exceeding the cap now raises anhsquared_errornaming the observed cell count and the effective cap, rather than a raw Julia trace. Ontarget = "repeatability",max_dense_cellsreaches the point fit only. The opt-in repeatability-coefficient interval is computed by a separate engine entry point that exposes no such control and runs at the engine default (1e6), so raising the cap above1e6returns the point fit with the interval silently absent (NULL) rather than with an error. Tracked on the engine side; not fixed here. This applies toscale_method = "dense"only: the sparse route forms its interval from the fitted components and never reaches that entry point, so it is unaffected bymax_dense_cells.
Start values and limits: unsupplied
initialis a fixed unit start, not data-scaled. Default AI-REML (target = "ai_reml"and the default univariateengine = "fit"path) starts at(sigma_a2 = 1, sigma_e2 = 1), withiterations = 100andtol = 1e-8, and is equivariant to rescalingy. Densetwo_effectstarts at(1, 1, 1)withiterations = 200; denserepeatabilityuses the same unit start and a 200-iteration Nelder-Mead cap. Rescale the response to variance about 1 before those dense routes, or compare againstscale_method = "auto"; otherwise a large-scale trait can reportconverged = TRUEat a wrong optimum. Fitted variances on a rescaledycan be multiplied back: REML variance estimates are equivariant. Checkconvergedafter a dense fit.targetselects which Julia estimator theengine = "julia"bridge runs. Under the defaultengine = "fit"path,targetandvariance_componentsare an error: that path would otherwise ignore them and return an AI-REML fit (hsquared#267). The supported targets are"fit_animal_model","ai_reml","sparse_reml","henderson_mme","repeatability","two_effect","multi_effect","direct_maternal","random_regression","genomic","single_step","single_step_construct","metafounder","metafounder_single_step","snp_blup","relmat","precision","multivariate","multivariate_repeatability","nongaussian", and"genetic_gllvm", described below. Covered opt-in routes (validation scale; not the default path) include"two_effect"(common_env()),"direct_maternal","multi_effect", and"random_regression"atk = 2.marginalapplies only totarget = "nongaussian". Withengine = "julia"and notarget, the bridge defaults totarget = "fit_animal_model": it surfaces the Julia-ownedHSquared.fit_animal_model()dense NelderMead optimizer, honouring theREMLflag. This is not the same estimator as the defaultengine = "fit"path, which runs the validated average-information REML estimator (HSquared.fit_ai_reml(), the same one reached bytarget = "ai_reml"). The two paths target the same Gaussian animal model but differ at the optimizer level, so their estimates can differ slightly. Reach the validated estimator withengine = "fit"(the ordinary path) or withengine = "julia"andtarget = "ai_reml".target = "henderson_mme"is a supplied-variance validation path and requiresvariance_componentswith namedsigma_a2andsigma_e2values.target = "metafounder"is an experimental supplied-variance validation path formetafounder(1 | id, pedigree = ped, group = mf_group, Gamma = Gamma). It builds the Julia-owned animal-onlyA^Gammarelationship;Gammaand the variance components are supplied, not estimated.target = "sparse_reml"is an experimental, opt-in validation path that surfaces the Julia-ownedHSquared.fit_sparse_reml()REML-only sparse optimizer; it acceptsinitial(namedsigma_a2/sigma_e2) anditerations. It is not the default, not production fitting, and not a variance-component estimation claim for the public R interface. It is also the existing fallback when the default AI-REML path stops unconverged on more than 512 animals with additive variance near 0 (converged = FALSE,optimizer_status = "boundary_score_unresolved"). That fallback use does not newly cover this target.target = "ai_reml"exposes the same average-information REML estimator (HSquared.fit_ai_reml()) that the defaultengine = "fit"path uses, with explicitinitialanditerationscontrol. This is the validated v0.1 estimator for the univariate Gaussian animal model; theengine = "fit"default is the ordinary way to reach it.em_warmup(a non-negative integer, default0) optionally runs that many EM-REML warm-start steps before the average-information iterations; it applies to this estimator on both the defaultengine = "fit"path andtarget = "ai_reml".em_warmup = 0(the default) is byte-identical to the previous behaviour. A small positive value (e.g.3) can rescue convergence from poor starting variances; on an identified fit it converges to the same optimum.target = "repeatability"is an experimental, opt-in path for the repeatability (permanent-environment) model. It requiresanimal(1 | id, pedigree = ped) + permanent(1 | id)in the formula and surfaces the Julia-ownedHSquared.fit_repeatability_reml()REML-only optimizer (three-componentinitialwithsigma_a2/sigma_pe2/sigma_e2). It is REML only, not the default, and the additive and permanent-environment variances are identifiable only with repeated records per individual.scale_methodselects the estimator."dense"(the default) is the covered validation-scalefit_repeatability_reml()above, which the engine refuses oncenobs^2 + nanimals^2exceedsmax_dense_cells– a ceiling any field-scale repeated-measures pedigree passes easily.scale_method = "auto"fits the SAME model through the engine's sparse K-effect AI-REML (fit_multi_effect(method = :auto)), expressing it as the animal block plus an identity-relationship permanent-environment block, and so has no dense ceiling. Below the ceiling the two agree to REML tolerance. Two differences are deliberate on the sparse route:initialanditerationsare NOT honoured (the engine picks its own; a supplied value warns), andloglikcarries the REML normalising constant-(n - p)/2 * log(2 * pi)that the dense route omits – so log-likelihoods, AIC, or likelihood-ratio tests must NOT be compared acrossscale_methodon the rawloglik(HSquared.jl #365). Fitdiagnosticsexposeloglik_convention,loglik_full_constant_offset(add tologlikfor the full-constant scale), andloglik_comparable_across_routeswhen the linked engine is new enough; the engine helpercomparable_loglik(fit)does the same conversion.repeatability_interval()IS available on both routes and agrees between them; the sparse one is formed from the fitted components (multi_effect_sum_ratio_interval()) rather than by refitting densely, and both are asymptotic logit-scale delta intervals that are NOT coverage-calibrated.target = "two_effect"is an experimental, opt-in path for two-effect models. It requiresanimal(1 | id, pedigree = ped)plus a second random effect –common_env(1 | group)(an IID common-environment effect) ormaternal_genetic(1 | dam)(a maternal genetic effect carrying the pedigree relationship) – and surfaces the Julia-ownedHSquared.fit_two_effect_reml()REML-only optimizer (three-componentinitialwithsigma_a2/sigma_c2/sigma_e2). It is REML only and not the default. Thecommon_env()leg is covered at validation scale; thematernal_genetic()leg on this same target stays experimental. The covered correlated sibling istarget = "direct_maternal".target = "multi_effect"is an opt-in path foranimal(1 | id, pedigree = ped)plus one or more bare(1 | group)IID intercepts. It is covered at validation scale (the independent generalization of two-effect; not the default path). Random slopes and correlated(x || group)terms remain rejected. The animal-block ratio is narrow-sense h2; other blocks are variance-explained proportions, not heritabilities.initialis a plain numeric vector of length K + 1 (one value per block, in formula order, plus the residual); it anditerationsare forwarded on both the dense and opt-in"auto"routes.target = "direct_maternal"is an opt-in path foranimal(1 | id, pedigree = ped) + maternal_genetic(1 | dam). It estimates the correlated 2x2 direct-maternal genetic covariance and is covered at validation scale (not the default path).heritability()returns the labelled Willham triple (direct h2_d, maternal m2, total h2_T, r_am), never a bare scalar.initialis a list withG_dm(a 2x2 matrix) andsigma_e2(a positive scalar); it anditerationsare honoured.target = "random_regression"is an opt-in reaction-norm path foranimal(rr(covariate, order = k) | id, pedigree = ped). It is covered atk = 2(linear reaction norm).rr_heritability()returns h2(t) as a curve;heritability()errors on this result and namesrr_heritability().k >= 3stays experimental.target = "genomic"is the explicit experimental narrow Gaussian REML genomic route. It acceptsgenomic(1 | id, markers = M), using sample allele frequencies, unweighted VanRaden method 1, and ridge0.01, orgenomic(1 | id, Ginv = Ginv), whose construction method, allele-frequency source, ridge, and scale denominator remain unknown.heritability()returns the genomic variance-component ratio on the declared relationship scale,sigma_g2 / (sigma_g2 + sigma_e2). Because relationship scaling enters through the kernel, this is not generally the fraction of average marginal phenotypic variance and is not pedigree-, founder-base-, population-, or universal narrow-sense heritability. Genomicheritability_interval()andheritability_standard_error()are unavailable. The R capability remains covered at validation scale, experimental, and opt-in; the explicit route does not movepublic_covered_countfrom 7. A fail-closed boundary candidate matched an independent oracle on all 240 sealed holdouts, correcting 30 classifications with no losses, but one cell had a 5.99x p95 runtime ratio against the frozen 3x cap. The seeds are spent, the nine-cell campaign did not run, and the route must remain opt-in pending performance work and a new untouched holdout.target = "single_step"remains an experimental, opt-in path forsingle_step(1 | id, Hinv = Hinv)(a supplied single-step relationship inverse). Both targets surfaceHSquared.fit_ai_reml()and are REML-only; single-step is not a default route.target = "single_step_construct"fitssingle_step(1 | id, pedigree = ped, markers = M)after the engine buildsH^-1from the pedigree and genotyped-subset markers.target = "metafounder_single_step"fitssingle_step(1 | id, pedigree = ped, markers = M, group = mf_group, Gamma = Gamma)through the Julia-owned supplied-GammaH^Gammapath. Both are experimental, opt-in, dense/validation-scale, REML-only, and not comparator-validated;Gammais supplied, not estimated. Both honourinitial(namedsigma_a2/sigma_e2) anditerations.target = "snp_blup"is an experimental, opt-in path for the SNP-BLUP / RR-BLUP marker-effect model. It requiresgenomic(1 | id, markers = M)(a raw marker matrix) and estimates per-marker effects (marker_effects()) and per-individual genomic breeding values.variance_componentsis optional: supply namedsigma_g2(genomic) andsigma_e2(residual) for a supplied-variance solve (HSquared.fit_snp_blup()), or omit them to havehsquared()estimatesigma_g2/sigma_e2by REML from the markers (HSquared.fit_snp_blup_reml()). Not the default.target = "relmat"is an experimental, opt-in path forrelmat(1 | id, K = K)(a supplied dense relationship matrix; the parser marshals the inverse).target = "precision"is the same experimental path forprecision(1 | id, Q = Q)(a supplied precision/inverse). Neither is covered or the default; the supplied matrix is provenance, not an estimate.K/Qmust be square, symmetric, and positive definite, with unique row and column names equal to the ids (any row order; names are matched).relmat()takes the matrixKitself;precision()takes the inverseQ;genomic()takes the inverseGinv, notG. Identical genotypes (monozygotic twins, clones, repeated rows) makeKsingular. Ridge withK + 1e-6 * diag(n); the printed residual is thenE - 1e-6 * Va, so add that shift back before reportingh2 = Va / (Va + Ve)on the kernel. An ACE twin model is not available fromrelmat(). Theanimal(1 | id, pedigree = ped)route rejects selfing (rows with the same known sire and dam) in v0.1, with no argument that reaches the engine'sallow_selfingflag;relmat(1 | id, K = A)with a hand-built orAGHmatrix-built relationship matrixAis the current workaround for a selfing or hermaphroditic pedigree.target = "multivariate"names the experimental multivariate Gaussian animal model. Naming it is optional: acbind()Gaussian response with ananimal()term auto-routes to this target on the default path, and underengine = "julia"with notarget. The t = 2 unstructured capability is covered at validation scale, while remaining experimental. It requires acbind(trait1, trait2, ...)response withanimal(1 | id, pedigree = ped), surfaces the Julia-ownedHSquared.fit_multivariate_reml()REML-only optimizer, and returns G/R covariance matrices, genetic and residual correlations, per-trait heritability, and cross-trait breeding values. Three or more traits and structured covariance are experimental.genetic_structureaccepts"unstructured","diagonal", and a bounded"factor_analytic"opt-in."diagonal"fixes off-diagonal genetic covariances at zero. FA requires exactly four complete Gaussian traits, pedigreeanimal()only, trait intercepts only, unstructured estimated residual covariance, and an explicitengine = "julia",target = "multivariate",genetic_structure = "factor_analytic",rank = 1L, andjulia_projectpath. It reports G, genetic correlations, and specific variances (Psi), with local-identifiability and boundary cautions; no loadings or covariance standard errors.initial = NULLuses Julia's phenotype-scale start; a suppliedinitialmay contain only validatedG0andR0matrices. FAloadingsanduniquenessstarts are rejected rather than silently dropped. This does not activatecov = fa()formula grammar, a default route, or a covered status."lowrank"remains refused on this Gaussian multivariate target.target = "multivariate_repeatability"is the experimentalcbind(...) + permanent(1 | id)route (hsquared#237). Naming it is optional: that formula auto-routes on the default path and underengine = "julia"with notarget. It identifies unstructured trait x traitG0(pedigree) fromP0(iid permanent environment) andR0. It is experimental, REML-only, not covered, and does not changepublic_covered_count(stays 7). R consumesHSquared.fit_multivariate_repeatability_reml(HSquared.jl#398); the result target ismultivariate_repeatability_reml. R will not fall back to animal-onlyfit_multivariate_reml.target = "genetic_gllvm"is a bounded experimental Poisson-log route. It requires exactly three complete traits, one row per pedigree animal (including ancestors), trait intercepts,REML = TRUE, and explicitengine = "julia",julia_project,genetic_structure = "lowrank",rank = 2L, andexperimental_gllvm = TRUE.iterationscontrols the outer optimizer (default 1000). It returns link-scale G, genetic correlations, and trait genetic conditional modes viabreeding_values()(also a pedigree-by-trait matrix infit$result$trait_genetic_modes). Checkfit_diagnostics()before interpretation. Its Laplace objective integrates fixed effects under flat measure; it is available only in diagnostics, andlogLik()/AIC()are unavailable. No heritability, posterior means, loading inference, FA uniqueness, missing records, Bernoulli traits, or automatic rank selection are supplied.target = "nongaussian"is an experimental, opt-in conditional GLMM forpoisson(log)orbinomial(logit)(binary 0/1 orcbind(successes, failures)counts) with one intercept andanimal(1 | id, pedigree = ped). Themarginalcontrol selects a Laplace marginal likelihood approximation ("laplace", default) or a hybrid variational-plus-Laplace objective ("variational"; aliases"la"/"va"). The default Laplace objective integrates the intercept (fixed effects) under a flat measure:V_Ais a REML-like Laplace estimate, not conventional Laplace-ML. At n around 800 it is expected to exceedglmer/pedigreemm/glmmTMBLaplace-MLV_Aby a few percent.logLik()is not comparable withglmer. Thefit_diagnostics()methodrow still reads "Laplace marginal likelihood"; that label is this flat-integrated estimator, not Laplace-ML. It reports the ratified conditional three-field contract: Poisson latent and count-scale observation h2; logit latent, liability, and numerically integrated observation-scale h2 for Bernoulli or common-trial Binomial input. Varying trials return literalNaNwith"varying_trials_no_scalar_estimand", never a trial-count-averaged scalar. The historical engine fieldelboremains for compatibility; with integrated fixed effects this hybrid value has no general lower-bound guarantee. Variational and LaplacelogLik/AICare not comparable with each other or withglmer. This path remains experimental and not coverage-calibrated. The numerical method is unchanged.initial(hsquared#225) is a list withsigma_a2. The engine fits the single variance component with a bracketed Brent search overlog(sigma_a2)onlog(initial$sigma_a2) +/- 6– there is no start value, andinitialsets the centre of the bracket, so supplying it moves the whole search window. Unsupplied, the engine's own hard-codedsigma_a2 = 1.0centres it, giving[exp(-6), exp(6)]; a truesigma_a2outside that window cannot be reached without aninitialon the scale of the data, which is what makesinitialthe retry lever for a boundary refusal.restart_check(hsquared#225, logical, defaultFALSE) opts into the engine's two-start restart (HSquared.jl#327): it refits once from a bumped second start and flagsboundary = TRUEwhen the estimate moves with the start, catching a boundary a single fit can otherwise miss. The result carriesboundary(hsquared#222) next toconverged:TRUEmeans the fittedsigma_a2is a function of the search start, not the data. In practice aboundary = TRUEfit is refused before it reaches the R result at all – the Julia payload builder raises, translated into a classedhsquared_julia_errornaminginitial/restart_checkas the retry levers – soboundaryon a returned fit isFALSE. Read it asfit$result$boundary, or viafit_diagnostics()'ssearch_boundary/search_boundary_conditionrows (hsquared#230); those rows are unrelated to that function'sat_boundaryrows, which flag a variance component at or near zero.