## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(dtametaTMB)


## -----------------------------------------------------------------------------
#| echo: TRUE
data("pap")
papLCA <- fitReitsmaLCA(data=pap,
                        y11=y11,
                        y10=y10,
                        y01=y01,
                        y00=y00,
                        study=id)
papLCA
summary(papLCA)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 8
#| fig.width: 8
plot(papLCA)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 17
#| fig.width: 11
forest(papLCA)


## -----------------------------------------------------------------------------
#| echo: TRUE
papLCA2 <- fitRutterGatsonisLCA(data=pap,
                                y11=y11,
                                y10=y10,
                                y01=y01,
                                y00=y00,
                                study=id)
papLCA2
summary(papLCA2)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 8
#| fig.width: 8
plot(papLCA2,specrange=c(0.3,0.995))


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 17
#| fig.width: 11
forest(papLCA2)


## -----------------------------------------------------------------------------
#| echo: TRUE
pap$type <- factor(pap$type,levels=c("SC","FU"))
papLCA3 <- fitReitsmaSubgroupLCA(data=pap,
                                 y11=y11,
                                 y10=y10,
                                 y01=y01,
                                 y00=y00,
                                 subgroup=type,
                                 study=id)
papLCA3
summary(papLCA3)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 8
#| fig.width: 8
plot(papLCA3,
     nudge_legend = -0.2)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 17
#| fig.width: 13
forest(papLCA3)


## -----------------------------------------------------------------------------
#| echo: TRUE
pap$type <- factor(pap$type,levels=c("SC","FU"))
papLCA4 <- fitRutterGatsonisSubgroupLCA(data=pap,
                                        y11=y11,
                                        y10=y10,
                                        y01=y01,
                                        y00=y00,
                                        subgroup=type,
                                        constrain="shape",
                                        study=id)
papLCA4
summary(papLCA4)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 8
#| fig.width: 8
plot(papLCA4,
     specrange=c(0.3,0.995),
     nudge_legend = -0.2)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 17
#| fig.width: 13
forest(papLCA4)


## -----------------------------------------------------------------------------
#| echo: TRUE
#| fig.height: 6
#| fig.width: 8
data("schuetz")
schuetzLCA <- fitReitsmaLCA(data=schuetz,
                            y11=TP,
                            y10=FP,
                            y01=FN,
                            y00=TN,
                            study=study)
schuetzLCA
summary(schuetzLCA)

schuetzLCA2 <- fitReitsmaSubgroupLCA(data=schuetz,
                                     y11=TP,
                                     y10=FP,
                                     y01=FN,
                                     y00=TN,
                                     subgroup=test,
                                     study=study)
schuetzLCA2
summary(schuetzLCA2)
plot(schuetzLCA2,
     nudge_legend=-0.2,
     size="eb",
     col=c("red","black"))


schuetzLCA3 <- fitReitsmaSubgroupLCA(data=schuetz,
                                     y11=TP,
                                     y10=FP,
                                     y01=FN,
                                     y00=TN,
                                     subgroup=test,
                                     variances="unequal",
                                     prev_variances="unequal",
                                     study=study)
schuetzLCA3
plot(schuetzLCA3,
     nudge_legend=-0.2,
     size="eb",
     col=c("red","black"))


schuetzLCA4 <- fitReitsmaSubgroupLCA(data=schuetz,
                                     y11=TP,
                                     y10=FP,
                                     y01=FN,
                                     y00=TN,
                                     subgroup=test,
                                     variances="unequal",
                                     prev_variances="common",
                                     study=study)

anova(schuetzLCA ,schuetzLCA2)
anova(schuetzLCA2,schuetzLCA3)
anova(schuetzLCA2,schuetzLCA4)

schuetzLCA5 <- fitReitsmaSubgroupLCA(data=schuetz,
                                     y11=TP,
                                     y10=FP,
                                     y01=FN,
                                     y00=TN,
                                     subgroup=test,
                                     variances="unequal",
                                     sensspec_constrain = "sens",
                                     prev_variances="common",
                                     study=study)
schuetzLCA5
anova(schuetzLCA5,schuetzLCA4)

schuetzLCA6 <- fitReitsmaSubgroupLCA(data=schuetz,
                                     y11=TP,
                                     y10=FP,
                                     y01=FN,
                                     y00=TN,
                                     subgroup=test,
                                     variances="unequal",
                                     sensspec_constrain = "spec",
                                     prev_variances="common",
                                     study=study)
schuetzLCA6
anova(schuetzLCA6,schuetzLCA4)

