Advertisement

# Ellipse BRMS NL Attempt

Dec 1st, 2019
14
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ### Object position BRMS model
2. # Load in results and libraries
3. library(brms)
4. library(loo)
5. mc.cores=2
6.
7. # Set dictionary with dataset.txt
8. data <- read.table("dataset.txt", header = T)
9.
10. # BRMS: Non-linear model - Ellipse
11. # Define Priors
12. prior1 <- prior(normal(0, 1, lb = 0), nlpar = "a") +
13.   prior(lognormal(0, 2), nlpar = "b")
14.
15. priors <- c(set_prior("normal(0,2)", nlpar = "a", lb = 0),
16.             set_prior("normal(0,2)", nlpar = "b", lb = 0))
17.
18. nlModel <- brm(bf(Distance ~ sqrt(a ^ 2 * sin(Angle)^2 + b^2 * cos(Angle)^2),
19.                a ~ 1, b ~ 1,
20.                nl = TRUE), data = data, prior = priors, cores = 2, chains = 2)
21. marginal_effects(nlModel)
22. pp_check(nlModel)
23. plot(nlModel)
24.
25. # BRMS: Linear model - One category per angle
26. data\$anglesF <- as.factor(data\$Angle)
27. lModel <- mComplex <- brm(Distance ~-1+anglesF +(1|Part), data = data, chains = 2, iter=2000, cores = 2)
28. marginal_effects(lModel)
29. pp_check(lModel)
30.
31. # Compare models with loo
32. loo(nlModel,lModel)
Advertisement
RAW Paste Data Copied
Advertisement