Skip to content

Commit c888204

Browse files
add CIs
1 parent b78a9d1 commit c888204

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

R/buildmxPedigrees.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,12 @@ buildFamilyGroups <- function(
287287
#' @param model_name Name of the overall pedigree model.
288288
#' @param vars A named list or vector of initial variance component values.
289289
#' @param group_models A list of OpenMx models for each family group.
290+
#' @param ci Logical. If TRUE, include confidence interval computations for the variance components. Default is FALSE
290291
#' @return An OpenMx pedigree model combining variance components and family groups.
291292
#' @export
292293

293-
buildPedigreeMx <- function(model_name, vars, group_models) {
294+
buildPedigreeMx <- function(model_name, vars, group_models,
295+
ci = FALSE) {
294296
if (!requireNamespace("OpenMx", quietly = TRUE)) {
295297
stop("OpenMx package is required for buildPedigreeMx function. Please install it.")
296298
}
@@ -335,7 +337,12 @@ buildPedigreeMx <- function(model_name, vars, group_models) {
335337
Ver = isTRUE(flags$Ver)
336338
),
337339
group_models,
338-
OpenMx::mxFitFunctionMultigroup(group_names)
340+
OpenMx::mxFitFunctionMultigroup(group_names),
341+
ci = if (ci & any(flags$Vad, flags$Vdd, flags$Vcn, flags$Vce, flags$Vmt, flags$Vam, flags$Ver)) {
342+
OpenMx::mxCI(c("vad", "vdd", "vcn", "vce", "vmt", "vam", "ver")[c(flags$Vad, flags$Vdd, flags$Vcn, flags$Vce, flags$Vmt, flags$Vam, flags$Ver)])
343+
} else {
344+
NULL
345+
}
339346
)
340347
}
341348

vignettes/articles/v61_pedigree_model_fitting.Rmd

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,24 @@ group_models_mace <- lapply(seq_len(n_families), function(i) {
156156
multi_model_ace <- buildPedigreeMx(
157157
model_name = "MultiPedigreeModel",
158158
vars = start_vars,
159-
group_models = group_models_ace
159+
group_models = group_models_ace,
160+
ci = TRUE
160161
)
161162
162163
multi_model_mace <- buildPedigreeMx(
163164
model_name = "MultiPedigreeModel",
164165
vars = start_vars,
165-
group_models = group_models_mace
166+
group_models = group_models_mace,
167+
ci = TRUE
166168
)
167169
```
168170
```{r, include = FALSE}
169171
fitted_multi_ace <- NULL # ensure variable exists for later use
170172
fitted_multi_mace <- NULL # ensure variable exists for later use
171173
```
172174
```{r, eval = run_models}
173-
fitted_multi_ace <- mxRun(multi_model_ace, intervals= TRUE)
175+
fitted_multi_ace <- mxRun(multi_model_ace,
176+
intervals= TRUE)
174177
saveRDS(fitted_multi_ace, "inst/extdata/fitted_multi_ace.rds")
175178
176179
fitted_multi_mace <- mxRun(multi_model_mace, intervals= TRUE)
@@ -220,3 +223,12 @@ cat("Common nuclear (Vcn):", fitted_multi_mace$ModelOne$Vcn$values/total_var_ma
220223
cat("Mitochondrial (Vmt):", fitted_multi_mace$ModelOne$Vmt$values/total_var_mace, "\n")
221224
cat("Unique environ. (Ver):", fitted_multi_mace$ModelOne$Ver$values/total_var_mace, "\n")
222225
```
226+
Now we can compare the ACE and MACE models to see if including the mitochondrial component changes our estimates of heritability and environmental contributions. This can provide insights into the role of mitochondrial inheritance in the trait of interest (LRS) in these squirrels.
227+
228+
```{r, eval = has_openmx && !is.null(fitted_multi_ace) && !is.null(fitted_multi_mace)}
229+
230+
mxCompare(fitted_multi_mace, fitted_multi_ace)
231+
232+
fitted_multi_ace_ci <- omxRunCI(fitted_multi_ace, verbose = 0, optimizer = "SLSQP")
233+
234+
```

0 commit comments

Comments
 (0)