Skip to content

Commit

Permalink
Try a simpler test example
Browse files Browse the repository at this point in the history
  • Loading branch information
haziqj committed May 29, 2024
1 parent 6b9a5d1 commit d9a70f3
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions tests/testthat/test-models.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,64 @@
test_that("CFA", {
INLA::inla.setOption(num.threads = "1:1")

mod <- "
eta1 =~ y1 + y2 + y3
eta2 =~ y4 + y5 + y6
"
dat <- lavaan::simulateData(mod, sample.nobs = 100)
expect_no_error({
fit <- icfa(
model = mod,
data = dat,
meanstructure = FALSE,
verbose = FALSE,
npost = 10
)
})
})
test_that("Fake test", {
require(INLA)


n = 100; a = 1; b = 1; tau = 100
z = rnorm(n)
eta = a + b*z

test_that("SEM", {
INLA::inla.setOption(num.threads = "1:1")
scale = exp(rnorm(n))
prec = scale*tau
y = rnorm(n, mean = eta, sd = 1/sqrt(prec))

data = list(y=y, z=z)
formula = y ~ 1+z

mod <- "
eta1 =~ y1 + y2 + y3
eta2 =~ y4 + y5 + y6
eta2 ~ 0.3*eta1
y1 ~~ 0.5*y4
"
dat <- lavaan::simulateData(mod, sample.nobs = 100)
expect_no_error({
fit <- isem(
model = mod,
data = dat,
meanstructure = FALSE,
verbose = FALSE,
npost = 10
)
result = inla(formula, family = "gaussian", data = data)
})


})

# test_that("CFA", {
# INLA::inla.setOption(num.threads = "1:1")
#
# mod <- "
# eta1 =~ y1 + y2 + y3
# eta2 =~ y4 + y5 + y6
# "
# dat <- lavaan::simulateData(mod, sample.nobs = 100)
# expect_no_error({
# fit <- icfa(
# model = mod,
# data = dat,
# meanstructure = FALSE,
# verbose = FALSE,
# npost = 10
# )
# })
# })
#
# test_that("SEM", {
# INLA::inla.setOption(num.threads = "1:1")
#
# mod <- "
# eta1 =~ y1 + y2 + y3
# eta2 =~ y4 + y5 + y6
# eta2 ~ 0.3*eta1
# y1 ~~ 0.5*y4
# "
# dat <- lavaan::simulateData(mod, sample.nobs = 100)
# expect_no_error({
# fit <- isem(
# model = mod,
# data = dat,
# meanstructure = FALSE,
# verbose = FALSE,
# npost = 10
# )
# })
# })



0 comments on commit d9a70f3

Please sign in to comment.