Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
osorensen committed Apr 4, 2024
1 parent 2c93785 commit ec09b03
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion R/gamm4-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ gamm4.wrapup <- function(gobj, ret, final_model) {
sn <- names(gobj$G$random)

if (length(object$family) == 1 &&
object$family[[1]]$family == "gaussian" && object$family[[1]]$link == "identity") {
object$family[[1]]$family == "gaussian" && object$family[[1]]$link == "identity") {
linear <- TRUE
} else {
linear <- FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/summary.galamm.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ print.summary.galamm <- function(
cat("\n")
lme4::.prt.aictab(x$AICtab)
cat("\n")
if(length(x$model$family) == 1) {
if (length(x$model$family) == 1) {
lme4::.prt.resids(residuals(x) / sigma(x), digits = digits)
}

Expand Down
32 changes: 20 additions & 12 deletions data-raw/lifespan.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ set.seed(3)
trajectories <- readRDS("data-raw/trajectories.rds")
epmem_fun <- approxfun(
trajectories$age,
trajectories$epmem_trajectory)
trajectories$epmem_trajectory
)
wmem_fun <- approxfun(
trajectories$age, trajectories$wmem_trajectory)
trajectories$age, trajectories$wmem_trajectory
)
execfun_fun <- approxfun(
trajectories$age, trajectories$execfun_trajectory)
trajectories$age, trajectories$execfun_trajectory
)

n_ids <- 1000
Psi3 <- matrix(c(.08, .05, .05,
.05, .12, .06,
.05, .06, .24), ncol = 3)
Psi3 <- matrix(c(
.08, .05, .05,
.05, .12, .06,
.05, .06, .24
), ncol = 3)
Psi2 <- diag(c(.06, .8, .18))

domains <- c("epmem", "wmem", "execfun")
epmem_tests <- c("CVLTA1", "CVLTA2", "CVLTA3", "CVLTA4", "CVLTA5",
"CVLT5min", "CVLT30min")
epmem_tests <- c(
"CVLTA1", "CVLTA2", "CVLTA3", "CVLTA4", "CVLTA5",
"CVLT5min", "CVLT30min"
)
wmem_tests <- c("DspanBwd", "DspanFwd")
execfun_tests <- c("Stroop1", "Stroop2", "Stroop3", "Stroop4")

Expand All @@ -43,8 +50,10 @@ names(loadings) <- names(item_bias)

lifespan <- tibble(
id = seq_len(n_ids),
age_at_baseline = runif(n_ids, min = min(trajectories$age),
max = max(trajectories$age) - 10),
age_at_baseline = runif(n_ids,
min = min(trajectories$age),
max = max(trajectories$age) - 10
),
timepoints = sample(6, n_ids, replace = TRUE, prob = c(.2, .4, .2, .1, .1, 1))
) %>%
mutate(domain = list(domains)) %>%
Expand Down Expand Up @@ -112,7 +121,7 @@ lifespan <- tibble(
mutate(
retest = as.integer(timepoint > 1),
y = case_when(
domain == "execfun" ~ (y - mean(y)) / sd(y),
domain == "execfun" ~ -(y - mean(y)) / sd(y),
TRUE ~ y
)
) %>%
Expand All @@ -124,4 +133,3 @@ mm <- model.matrix(~ 0 + domain, data = lifespan)
lifespan <- cbind(lifespan, mm)

usethis::use_data(lifespan, overwrite = TRUE)

Binary file modified data/lifespan.rda
Binary file not shown.
14 changes: 2 additions & 12 deletions dev-scripts/lifespan_demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ lmat <- matrix(c(
rep(0, 7), 1, NA, rep(0, 4),
rep(0, 9), 1, NA, NA, NA), ncol = 3)

mod_init <- galamm(
formula = cbind(y, 16 - y) ~ 0 + retest:domain + test +
sl(age, by = domain) + (0 + domain | id),
data = lifespan,
family = c(binomial, gaussian),
family_mapping = ifelse(lifespan$domain == "execfun", 2, 1),
control = galamm_control(
optim_control = list(REPORT = 2, factr = 1e9, trace = 3, maxit = 2))
)

mod <- galamm(
formula = cbind(y, 16 - y) ~ 0 + retest:domain + test +
sl(age, by = domain,
Expand All @@ -30,8 +20,8 @@ mod <- galamm(
theta = mod_init$parameters$parameter_estimates[mod_init$parameters$theta_inds]
),
control = galamm_control(
optim_control = list(REPORT = 2, factr = 1e8, trace = 3, maxit = 10))
optim_control = list(REPORT = 1, trace = 3))
)
beepr::beep()

summary(mod)
plot_smooth(mod, scale = 0, pages = 1)

0 comments on commit ec09b03

Please sign in to comment.