Skip to content

Instantly share code, notes, and snippets.

@fusaroli
Last active December 20, 2019 10:24
Show Gist options
  • Save fusaroli/64d4b4d85221da026cda274647acfb8d to your computer and use it in GitHub Desktop.
Save fusaroli/64d4b4d85221da026cda274647acfb8d to your computer and use it in GitHub Desktop.
Monotonic issue
# Load libraries
library(brms)
library(tidyverse)
# Load data
data <- read_csv("temp_data.csv")
# Define model
SymptomVoice_Age_f <- bf(Outcome ~ 0 + language + language : mo(Symptom) + language : mo(Symptom) : AgeS + (1 | gr(ID, by = language)))
# Define priors
SkepticPrior1 <- c(
prior(normal(0, 1), class=b),
prior(normal(0, .1), class=b, coef = languagedk:moSymptom),
prior(normal(0, .1), class=b, coef = languageus:moSymptom),
prior(normal(0, .1), class=sd)
)
# Run model
m <- brm(SymptomVoice_Age_f,
data = data,
family = gaussian,
prior = SkepticPrior1,
sample_prior = T
)
# Error:
# Error in eval(predvars, data, env) : object 'AgeS' not found
## Pseudo-Fixing it
SymptomVoice_Age_f <- bf(Outcome ~ 0 + language + language : mo(Symptom) + language : mo(Symptom) : data$AgeS + (1 | gr(ID, by = language)))
m <- brm(SymptomVoice_Age_f,
data = data,
family = gaussian,
prior = SkepticPrior1,
sample_prior = T
)
# Hypothesis testing
hypothesis(m,"languagedk:moSymptom > languagedk:moSymptom:data$AgeS", class = "bsp")
# ERROR
#Error: Some parameters cannot be found in the model:
# 'bsp_languagedk:moSymptom:data', 'bsp_AgeS'
## Without the mo() all runs fine
# Define model
SymptomVoice_Age_f2 <- bf(Outcome ~ 0 + language + language : Symptom + language : Symptom : AgeS + (1 | gr(ID, by = language)))
# Define priors
SkepticPrior1 <- c(
prior(normal(0, 1), class=b),
prior(normal(0, .1), class=sd)
)
# Run model
m2 <- brm(SymptomVoice_Age_f2,
data = data,
family = gaussian,
prior = SkepticPrior1,
sample_prior = T
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment