Pearson's Chi-squared test with Yates' continuity correction
data: table(Mobility, Group)
X-squared = 4.4013, df = 1, p-value = 0.03591
Multivariate analysis
Characteristic
OR1
95% CI1
p-value
Group
0.005
3D Replica
—
—
Control
3.83
1.47, 10.9
time
<0.001
3 m
—
—
6 m
0.13
0.04, 0.36
12 m
0.06
0.01, 0.20
Sex
0.27
Female
—
—
Male
1.74
0.65, 4.69
1 OR = Odds Ratio, CI = Confidence Interval
“Bleeding on probing”
Bleeding
3D Replica
Control
0 - Normal
97.2%
86.4%
1 - Abnormal
2.8%
13.6%
Total
100.0%
100.0%
Univariate analysis
Pearson's Chi-squared test with Yates' continuity correction
data: table(Bleeding, Group)
X-squared = 4.1536, df = 1, p-value = 0.04155
Multivariate analysis
Call:
glm(formula = as.factor(Bleeding) ~ Group + time + Sex, family = binomial,
data = clinical_long)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -5.3124 1.1350 -4.680 2.86e-06 ***
GroupControl 2.2568 0.8454 2.670 0.00760 **
time6 m 0.3651 0.8598 0.425 0.67108
time12 m 0.3651 0.8598 0.425 0.67108
SexMale 2.1755 0.7470 2.912 0.00359 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 76.745 on 137 degrees of freedom
Residual deviance: 60.781 on 133 degrees of freedom
AIC: 70.781
Number of Fisher Scoring iterations: 6
Pocket
Pocket
3D Replica
Control
0 - Normal
97.2%
86.4%
1 - Abnormal
2.8%
13.6%
Total
100.0%
100.0%
Univariate analysis
Pearson's Chi-squared test with Yates' continuity correction
data: table(Pocket, Group)
X-squared = 4.1536, df = 1, p-value = 0.04155
Multivariate analysis
Call:
glm(formula = as.factor(Pocket) ~ Group + time + Sex, family = binomial,
data = clinical_long)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -5.3124 1.1350 -4.680 2.86e-06 ***
GroupControl 2.2568 0.8454 2.670 0.00760 **
time6 m 0.3651 0.8598 0.425 0.67108
time12 m 0.3651 0.8598 0.425 0.67108
SexMale 2.1755 0.7470 2.912 0.00359 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 76.745 on 137 degrees of freedom
Residual deviance: 60.781 on 133 degrees of freedom
AIC: 70.781
Number of Fisher Scoring iterations: 6
Modelling
Mobility model
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula:
Mobility ~ Group * time + `Age (surgery)` + Sex + `Total surgery time (min)` +
`Extra- alveolar time (s)` + `Moores Stage` + `Donor fitting times` +
(1 | id)
Data: clinical_long
REML criterion at convergence: 132.9
Scaled residuals:
Min 1Q Median 3Q Max
-1.64797 -0.74486 -0.00841 0.42711 2.27320
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.01223 0.1106
Residual 0.09386 0.3064
Number of obs: 138, groups: id, 46
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.449475 0.345442 35.529098 1.301 0.201580
GroupControl 0.121499 0.106828 94.193338 1.137 0.258284
time6 m -0.375000 0.088442 87.999998 -4.240 5.50e-05 ***
time12 m -0.416667 0.088442 87.999998 -4.711 9.14e-06 ***
`Age (surgery)` 0.001424 0.022670 34.000000 0.063 0.950298
SexMale 0.059302 0.071419 34.000000 0.830 0.412142
`Total surgery time (min)` 0.004275 0.002148 34.000000 1.990 0.054665 .
`Extra- alveolar time (s)` -0.001300 0.001105 34.000000 -1.177 0.247511
`Moores Stage`4 -0.310120 0.081033 34.000000 -3.827 0.000530 ***
`Moores Stage`5 -0.389971 0.103990 34.000000 -3.750 0.000659 ***
`Donor fitting times`2 -0.008938 0.082902 34.000000 -0.108 0.914779
`Donor fitting times`3 -0.052546 0.112550 34.000000 -0.467 0.643570
`Donor fitting times`4 1.022147 0.293722 34.000000 3.480 0.001396 **
`Donor fitting times`5 -0.252938 0.305483 34.000000 -0.828 0.413448
GroupControl:time6 m 0.011364 0.127888 87.999998 0.089 0.929398
GroupControl:time12 m -0.037879 0.127888 87.999998 -0.296 0.767784
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Bleeding
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula:
Bleeding ~ Group * time + `Age (surgery)` + Sex + `Total surgery time (min)` +
`Extra- alveolar time (s)` + `Moores Stage` + `Donor fitting times` +
(1 | id)
Data: clinical_long
REML criterion at convergence: -96.6
Scaled residuals:
Min 1Q Median 3Q Max
-7.1625 -0.1608 -0.0532 0.0618 4.0847
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.03597 0.18965
Residual 0.00726 0.08521
Number of obs: 138, groups: id, 46
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) -0.2297298 0.3211929 34.1332598 -0.715 0.47933
GroupControl 0.0729192 0.0753630 39.5737721 0.968 0.33913
time6 m 0.0416667 0.0245969 88.0000023 1.694 0.09381 .
time12 m 0.0416667 0.0245969 88.0000023 1.694 0.09381 .
`Age (surgery)` 0.0069052 0.0212915 33.9999907 0.324 0.74768
SexMale 0.1251724 0.0670775 33.9999938 1.866 0.07068 .
`Total surgery time (min)` 0.0048846 0.0020176 33.9999939 2.421 0.02097 *
`Extra- alveolar time (s)` -0.0001918 0.0010374 33.9999940 -0.185 0.85443
`Moores Stage`4 -0.1765400 0.0761072 33.9999935 -2.320 0.02650 *
`Moores Stage`5 -0.1841585 0.0976680 33.9999930 -1.886 0.06792 .
`Donor fitting times`2 -0.1392278 0.0778619 33.9999939 -1.788 0.08267 .
`Donor fitting times`3 -0.1129832 0.1057078 33.9999938 -1.069 0.29268
`Donor fitting times`4 0.9337009 0.2758663 33.9999939 3.385 0.00181 **
`Donor fitting times`5 -0.3075329 0.2869123 33.9999941 -1.072 0.29133
GroupControl:time6 m -0.0416667 0.0355671 88.0000023 -1.171 0.24456
GroupControl:time12 m -0.0416667 0.0355671 88.0000023 -1.171 0.24456
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
We fitted a linear mixed model (estimated using REML and nloptwrap optimizer)
to predict Bleeding with Group, time, Age (surgery), Sex, Total surgery time
(min), Extra- alveolar time (s), Moores Stage and Donor fitting times (formula:
Bleeding ~ Group * time + `Age (surgery)` + Sex + `Total surgery time (min)` +
`Extra- alveolar time (s)` + `Moores Stage` + `Donor fitting times`). The model
included id as random effect (formula: ~1 | id). The model's total explanatory
power is substantial (conditional R2 = 0.91) and the part related to the fixed
effects alone (marginal R2) is of 0.48. The model's intercept, corresponding to
Group = 3D Replica, time = 3 m, Age (surgery) = 0, Sex = Female, Total surgery
time (min) = 0, Extra- alveolar time (s) = 0, Moores Stage = 3 and Donor
fitting times = 1, is at -0.23 (95% CI [-0.87, 0.41], t(120) = -0.72, p =
0.476). Within this model:
- The effect of Group [Control] is statistically non-significant and positive
(beta = 0.07, 95% CI [-0.08, 0.22], t(120) = 0.97, p = 0.335; Std. beta = 0.27,
95% CI [-0.28, 0.82])
- The effect of time [6 m] is statistically non-significant and positive (beta
= 0.04, 95% CI [-7.03e-03, 0.09], t(120) = 1.69, p = 0.093; Std. beta = 0.15,
95% CI [-0.03, 0.33])
- The effect of time [12 m] is statistically non-significant and positive (beta
= 0.04, 95% CI [-7.03e-03, 0.09], t(120) = 1.69, p = 0.093; Std. beta = 0.15,
95% CI [-0.03, 0.33])
- The effect of Age (surgery) is statistically non-significant and positive
(beta = 6.91e-03, 95% CI [-0.04, 0.05], t(120) = 0.32, p = 0.746; Std. beta =
0.05, 95% CI [-0.23, 0.33])
- The effect of Sex [Male] is statistically non-significant and positive (beta
= 0.13, 95% CI [-7.64e-03, 0.26], t(120) = 1.87, p = 0.064; Std. beta = 0.46,
95% CI [-0.03, 0.95])
- The effect of Total surgery time (min) is statistically significant and
positive (beta = 4.88e-03, 95% CI [8.90e-04, 8.88e-03], t(120) = 2.42, p =
0.017; Std. beta = 0.34, 95% CI [0.06, 0.61])
- The effect of Extra- alveolar time (s) is statistically non-significant and
negative (beta = -1.92e-04, 95% CI [-2.25e-03, 1.86e-03], t(120) = -0.18, p =
0.854; Std. beta = -0.03, 95% CI [-0.38, 0.31])
- The effect of Moores Stage [4] is statistically significant and negative
(beta = -0.18, 95% CI [-0.33, -0.03], t(120) = -2.32, p = 0.022; Std. beta =
-0.65, 95% CI [-1.20, -0.10])
- The effect of Moores Stage [5] is statistically non-significant and negative
(beta = -0.18, 95% CI [-0.38, 9.22e-03], t(120) = -1.89, p = 0.062; Std. beta =
-0.68, 95% CI [-1.39, 0.03])
- The effect of Donor fitting times [2] is statistically non-significant and
negative (beta = -0.14, 95% CI [-0.29, 0.01], t(120) = -1.79, p = 0.076; Std.
beta = -0.51, 95% CI [-1.08, 0.05])
- The effect of Donor fitting times [3] is statistically non-significant and
negative (beta = -0.11, 95% CI [-0.32, 0.10], t(120) = -1.07, p = 0.287; Std.
beta = -0.42, 95% CI [-1.19, 0.35])
- The effect of Donor fitting times [4] is statistically significant and
positive (beta = 0.93, 95% CI [0.39, 1.48], t(120) = 3.38, p < .001; Std. beta
= 3.43, 95% CI [1.43, 5.44])
- The effect of Donor fitting times [5] is statistically non-significant and
negative (beta = -0.31, 95% CI [-0.88, 0.26], t(120) = -1.07, p = 0.286; Std.
beta = -1.13, 95% CI [-3.22, 0.96])
- The effect of Group [Control] × time [6 m] is statistically non-significant
and negative (beta = -0.04, 95% CI [-0.11, 0.03], t(120) = -1.17, p = 0.244;
Std. beta = -0.15, 95% CI [-0.41, 0.11])
- The effect of Group [Control] × time [12 m] is statistically non-significant
and negative (beta = -0.04, 95% CI [-0.11, 0.03], t(120) = -1.17, p = 0.244;
Std. beta = -0.15, 95% CI [-0.41, 0.11])
Standardized parameters were obtained by fitting the model on a standardized
version of the dataset. 95% Confidence Intervals (CIs) and p-values were
computed using a Wald t-distribution approximation.
Pocket
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula:
Pocket ~ Group * time + `Age (surgery)` + Sex + `Total surgery time (min)` +
`Extra- alveolar time (s)` + `Moores Stage` + `Donor fitting times` +
(1 | id)
Data: clinical_long
REML criterion at convergence: -96.6
Scaled residuals:
Min 1Q Median 3Q Max
-7.1625 -0.1608 -0.0532 0.0618 4.0847
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 0.03597 0.18965
Residual 0.00726 0.08521
Number of obs: 138, groups: id, 46
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) -0.2297298 0.3211929 34.1332598 -0.715 0.47933
GroupControl 0.0729192 0.0753630 39.5737721 0.968 0.33913
time6 m 0.0416667 0.0245969 88.0000023 1.694 0.09381 .
time12 m 0.0416667 0.0245969 88.0000023 1.694 0.09381 .
`Age (surgery)` 0.0069052 0.0212915 33.9999907 0.324 0.74768
SexMale 0.1251724 0.0670775 33.9999938 1.866 0.07068 .
`Total surgery time (min)` 0.0048846 0.0020176 33.9999939 2.421 0.02097 *
`Extra- alveolar time (s)` -0.0001918 0.0010374 33.9999940 -0.185 0.85443
`Moores Stage`4 -0.1765400 0.0761072 33.9999935 -2.320 0.02650 *
`Moores Stage`5 -0.1841585 0.0976680 33.9999930 -1.886 0.06792 .
`Donor fitting times`2 -0.1392278 0.0778619 33.9999939 -1.788 0.08267 .
`Donor fitting times`3 -0.1129832 0.1057078 33.9999938 -1.069 0.29268
`Donor fitting times`4 0.9337009 0.2758663 33.9999939 3.385 0.00181 **
`Donor fitting times`5 -0.3075329 0.2869123 33.9999941 -1.072 0.29133
GroupControl:time6 m -0.0416667 0.0355671 88.0000023 -1.171 0.24456
GroupControl:time12 m -0.0416667 0.0355671 88.0000023 -1.171 0.24456
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
All regression plots
All Regression tables
Characteristic
Mobility
Bleeding on probing
Pocket
Beta
95% CI1
p-value
Beta
95% CI1
p-value
Beta
95% CI1
p-value
Group
3D Replica
—
—
—
—
—
—
Control
0.12
-0.09, 0.33
0.3
0.07
-0.08, 0.23
0.3
0.07
-0.08, 0.23
0.3
time
3 m
—
—
—
—
—
—
6 m
-0.38
-0.55, -0.20
<0.001
0.04
-0.01, 0.09
0.094
0.04
-0.01, 0.09
0.094
12 m
-0.42
-0.59, -0.24
<0.001
0.04
-0.01, 0.09
0.094
0.04
-0.01, 0.09
0.094
Age (surgery)
0.00
-0.04, 0.05
>0.9
0.01
-0.04, 0.05
0.7
0.01
-0.04, 0.05
0.7
Sex
Female
—
—
—
—
—
—
Male
0.06
-0.09, 0.20
0.4
0.13
-0.01, 0.26
0.071
0.13
-0.01, 0.26
0.071
Total surgery time (min)
0.00
0.00, 0.01
0.055
0.00
0.00, 0.01
0.021
0.00
0.00, 0.01
0.021
Extra- alveolar time (s)
0.00
0.00, 0.00
0.2
0.00
0.00, 0.00
0.9
0.00
0.00, 0.00
0.9
Moores Stage
3
—
—
—
—
—
—
4
-0.31
-0.47, -0.15
<0.001
-0.18
-0.33, -0.02
0.027
-0.18
-0.33, -0.02
0.027
5
-0.39
-0.60, -0.18
<0.001
-0.18
-0.38, 0.01
0.068
-0.18
-0.38, 0.01
0.068
Donor fitting times
1
—
—
—
—
—
—
2
-0.01
-0.18, 0.16
>0.9
-0.14
-0.30, 0.02
0.083
-0.14
-0.30, 0.02
0.083
3
-0.05
-0.28, 0.18
0.6
-0.11
-0.33, 0.10
0.3
-0.11
-0.33, 0.10
0.3
4
1.0
0.43, 1.6
0.001
0.93
0.37, 1.5
0.002
0.93
0.37, 1.5
0.002
5
-0.25
-0.87, 0.37
0.4
-0.31
-0.89, 0.28
0.3
-0.31
-0.89, 0.28
0.3
Group * time
Control * 6 m
0.01
-0.24, 0.27
>0.9
-0.04
-0.11, 0.03
0.2
-0.04
-0.11, 0.03
0.2
Control * 12 m
-0.04
-0.29, 0.22
0.8
-0.04
-0.11, 0.03
0.2
-0.04
-0.11, 0.03
0.2
1 CI = Confidence Interval
Tidymodels
Truth
Prediction 3D Replica Control
3D Replica 11 7
Control 4 13
# A tibble: 2 × 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 accuracy binary 0.686
2 kap binary 0.374
Source Code
---title: "03 Clinical Results Miks"author: "SUE"date: 04/18/2024date-modified: last-modifiedformat: html: toc: truetoc-expand: 3code-fold: truecode-tools: trueeditor: visualexecute: echo: false cache: true warning: false message: false---# Packages```{r}pacman::p_load(tidyverse, # tools for data science visdat, #NAs janitor, # for data cleaning and tables here, # for reproducible research gtsummary, # for tables countrycode, # to normalize country data scales, viridis, DataExplorer, patchwork, parsnip, # for data modelling skimr, irr, # for agreement lubridate )# FOR EDA try DataExplorer, SmartEDA o dllokr, check https://www.youtube.com/watch?v=sKrWYE63Vk4&t=7s```Packages for the modeling```{r}pacman::p_load(lme4, # for the GLM tidymodels, lmerTest, easystats, # check https://easystats.github.io/easystats/ sjPlot # for the plots )```# Dataset```{r}clinical <-read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSeWp8I-NzTi_NjOVfzAv1UOZjmzUROiikQ6r3HUORR9903EQ58ujw5buFJZG1PYI75rC1kf0TocxCa/pub?gid=1775358060&single=true&output=csv") ``````{r}clinical <- clinical |> janitor::remove_empty(which =c("rows", "cols")) ``````{r}theme_set(theme_minimal())```# EDA```{r}# clinical |> # group_by(Group) |> # DataExplorer::create_report( output_dir = here("eda_reports"), # output_file = "eda_clinical.html", # report_title = "Data Profiling Clinical Report")``````{r}# skimr::skim(clinical)```### Add the clinical data 2```{r}clinical2 <-read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSeWp8I-NzTi_NjOVfzAv1UOZjmzUROiikQ6r3HUORR9903EQ58ujw5buFJZG1PYI75rC1kf0TocxCa/pub?gid=45470096&single=true&output=csv")```### Join```{r}clinical <- clinical |>left_join(clinical2, by ="id") |>rename("Group"="Group.x", "Moores Stage"="STAGE OF DEVELOP" ) |>select(-c(Group.y, GENDER))``````{r}rm(clinical2)```## EDA Descriptive Table### Table 1```{r}clinical |>select(-c(id, matches("Bleeding|Periodontal|Mobility"), "DONOR TOOTH- recipient region")) |> gtsummary::tbl_summary(by ="Group") |>modify_caption("**Descriptive Table**")```## ## Group variables```{r}clinical_long <- clinical |>pivot_longer(cols =c(starts_with("Mobility"), starts_with("Bleeding on probing"), starts_with("Periodontal pocket")),names_to =c(".value", "time"),names_pattern ="(.*?)(\\d+ m)" ) |>mutate(time =as.factor(time), time =fct_relevel(time, "3 m", "6 m", "12 m"))```Cleaning```{r}# Cleaning up the column namesclinical_long <- clinical_long |>rename_with(~str_trim(.), .cols =everything()) |>mutate(Mobility =as.factor(Mobility)) # Ensure mobility is treated as a categorical variable``````{r}# head(clinical_long)```### Mobility plot```{r}clinical_long |>ggplot(aes(x = time, fill = Mobility)) +geom_bar(position ="fill") +labs(title ="Change in Mobility Over Time",x ="Time (months)",y ="Proportion",fill ="Mobility Status") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")``````{r}p1 <- clinical_long |>ggplot(aes(x = time, fill = Mobility)) +geom_bar(position ="fill") +labs(title ="Change in Mobility Over Time",x ="Time (months)",y ="Proportion",fill ="Mobility Status") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")```### Bleeding plot```{r}clinical_long |>ggplot(aes(x = time, fill =`Bleeding on probing`)) +geom_bar(position ="fill") +labs(title ="Change in Bleeding on probing Over Time",x ="Time (months)",y ="Proportion",fill ="Bleeding on probing") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")``````{r}p2 <- clinical_long |>ggplot(aes(x = time, fill =`Bleeding on probing`)) +geom_bar(position ="fill") +labs(title ="Change in Bleeding on probing Over Time",x ="Time (months)",y ="Proportion",fill ="Bleeding on probing") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")```### Periodontal pocket plot```{r}clinical_long |>ggplot(aes(x = time, fill =`Periodontal pocket`)) +geom_bar(position ="fill") +labs(title ="Change in Periodontal pocket Over Time",x ="Time (months)",y ="Proportion",fill ="Periodontal pocket") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")``````{r}p3 <- clinical_long |>ggplot(aes(x = time, fill =`Periodontal pocket`)) +geom_bar(position ="fill") +labs(title ="Change in Periodontal pocket Over Time",x ="Time (months)",y ="Proportion",fill ="Periodontal pocket") +facet_wrap(~ Group) +# Remove this line if no faceting by group is desiredtheme_minimal() +scale_fill_viridis_d(option ="viridis", direction =-1) +scale_y_continuous(labels =label_percent()) +theme(legend.position ="bottom")``````{r}# p1 / p2 / p3``````{r}ggsave(here("figures", "changes_time.pdf"), width =15, height =25, units =c("cm"), dpi =300)``````{r}rm(p1, p2, p3)```# Regression models## Mobility```{r}clinical_long |>tabyl(Mobility, Group) |># Adjust Group to your actual grouping variableadorn_totals("row") |>adorn_percentages("col") |>adorn_pct_formatting(digits =1) |># adorn_ns(position = "front") |> knitr::kable()```### Univariate analysis```{r}clinical_long |>with(chisq.test(table(Mobility, Group)))```### Multivariate analysis```{r}# mobility_model <- glmer(Mobility ~ Group + time + Sex , (1|id), # # family = binomial(link = "logit"), # # data = clinical_long)mobility_model <-glm(Mobility ~ Group + time + Sex , family = binomial, data = clinical_long)``````{r}# summary(mobility_model)``````{r}gtsummary::tbl_regression(mobility_model,exponentiate = T,pvalue_fun =~style_pvalue(.x, digits =2)) |>add_global_p() |>bold_p(t =0.10) |>bold_labels() |>italicize_levels()``````{r}rm(mobility_model)```## "Bleeding on probing"```{r}clinical_long <- clinical_long |>rename("Bleeding"=`Bleeding on probing`)``````{r}clinical_long |>tabyl(Bleeding, Group) |># Adjust Group to your actual grouping variableadorn_totals("row") |>adorn_percentages("col") |>adorn_pct_formatting(digits =1) |># adorn_ns(position = "front") |> knitr::kable()```### Univariate analysis```{r}clinical_long |>with(chisq.test(table(Bleeding, Group)))```### Multivariate analysis```{r}# bleeding_model <- glmer("Bleeding on probing" ~ Group + time + Sex , (1|id), # # family = binomial(link = "logit"), # # data = clinical_long) bleeding_model <-glm(as.factor(Bleeding) ~ Group + time + Sex , family = binomial, data = clinical_long)``````{r}summary(bleeding_model)``````{r}# gtsummary::tbl_regression(bleeding_model, # exponentiate = T, # pvalue_fun = ~ style_pvalue(.x, digits = 2)) |># add_global_p() |> # bold_p(t = 0.10) |> # bold_labels() |> # italicize_levels()``````{r}rm(bleeding_model)```## Pocket```{r}clinical_long <- clinical_long |>rename("Pocket"=`Periodontal pocket`)``````{r}clinical_long |>tabyl(Pocket, Group) |># Adjust Group to your actual grouping variableadorn_totals("row") |>adorn_percentages("col") |>adorn_pct_formatting(digits =1) |># adorn_ns(position = "front") |> knitr::kable()```### Univariate analysis```{r}clinical_long |>with(chisq.test(table(Pocket, Group)))```### Multivariate analysis```{r}# Pocket_model <- glmer(Pocket ~ Group + time + Sex , (1|id), # # family = binomial(link = "logit"), # # data = clinical_long) Pocket_model <-glm(as.factor(Pocket) ~ Group + time + Sex , family = binomial, data = clinical_long)``````{r}summary(Pocket_model)``````{r}# gtsummary::tbl_regression(Pocket_model, # exponentiate = T, # pvalue_fun = ~ style_pvalue(.x, digits = 2)) |># add_global_p() |> # bold_p(t = 0.10) |> # bold_labels() |> # italicize_levels()``````{r}rm(Pocket_model)```# Modelling```{r}# Data Preparationclinical_long <- clinical_long %>%mutate(Sex =as.factor(Sex),Group =as.factor(Group),`Donor fitting times`=as.factor(`Donor fitting times`),`Moores Stage`=as.factor(`Moores Stage`),`time`=factor(time, levels =c("3 m", "6 m", "12 m")))``````{r}# Recoding outcome variablesclinical_long <- clinical_long %>%mutate(Mobility =as.numeric(gsub(" - .*", "", Mobility)),Bleeding =as.numeric(gsub(" - .*", "", Bleeding)),Pocket =as.numeric(gsub(" - .*", "", Pocket)))```## Mobility model```{r}# Model for Mobilitymodel_mobility <-lmer(Mobility ~ Group * time +`Age (surgery)`+ Sex +`Total surgery time (min)`+`Extra- alveolar time (s)`+`Moores Stage`+`Donor fitting times`+ (1| id), data = clinical_long)``````{r}summary(model_mobility)``````{r}t1 <- model_mobility |> gtsummary::tbl_regression()``````{r}# report(model_mobility)``````{r}plot_model(model_mobility, type ="pred", terms =c("Group", "time"), show.values =TRUE)``````{r}p1 <-plot_model(model_mobility, type ="pred", terms =c("Group", "time"), show.values =TRUE)```## Bleeding```{r}# Model for Bleedingmodel_bleeding <-lmer(Bleeding ~ Group * time +`Age (surgery)`+ Sex +`Total surgery time (min)`+`Extra- alveolar time (s)`+`Moores Stage`+`Donor fitting times`+ (1| id), data = clinical_long)``````{r}summary(model_bleeding)``````{r}t2 <- model_bleeding |> gtsummary::tbl_regression()``````{r}report(model_bleeding)``````{r}plot_model(model_bleeding, type ="pred", terms =c("Group", "time"), show.values =TRUE)``````{r}p2 <-plot_model(model_bleeding, type ="pred", terms =c("Group", "time"), show.values =TRUE)```## Pocket```{r}# Model for Pocketmodel_pocket <-lmer(Pocket ~ Group * time +`Age (surgery)`+ Sex +`Total surgery time (min)`+`Extra- alveolar time (s)`+`Moores Stage`+`Donor fitting times`+ (1| id), data = clinical_long)``````{r}summary(model_pocket)``````{r}t3 <- model_pocket |> gtsummary::tbl_regression()``````{r}# report(model_pocket)``````{r}plot_model(model_pocket, type ="pred", terms =c("Group", "time"), show.values =TRUE)``````{r}p3 <-plot_model(model_pocket, type ="pred", terms =c("Group", "time"), show.values =TRUE)```## All regression plots```{r}p1 / p2 / p3``````{r}ggsave(here("figures", "regression_models.pdf"), height =19, width =13, units =c("cm"), dpi =300)``````{r}rm(p1, p2, p3)```## All Regression tables```{r}tbl_merge(tbls =list(t1, t2, t3), tab_spanner =c("**Mobility**", "**Bleeding on probing**", "**Pocket**"))``````{r}tbl_merge(tbls =list(t1, t2, t3), tab_spanner =c("**Mobility**", "**Bleeding on probing**", "**Pocket**")) |>as_gt() |> gt::gtsave(here("figures", "tabl_4.html"))``````{r}rm(model_bleeding, model_mobility, model_pocket, t1, t2, t3)```# Tidymodels```{r}# Split data into training and testing setsset.seed(123)data_split <-initial_split(clinical_long, prop =0.75)train_data <-training(data_split)test_data <-testing(data_split)``````{r}# Define recipe for preprocessingclinical_recipe <-recipe(Group ~ Mobility + Bleeding + Pocket +`Age (surgery)`+ Sex +`Total surgery time (min)`+`Extra- alveolar time (s)`+`Moores Stage`+`Donor fitting times`+ time, data = train_data) %>%step_dummy(all_nominal_predictors()) %>%step_normalize(all_numeric_predictors())``````{r}# Define the logistic regression modellog_reg_model <-logistic_reg() %>%set_engine("glm")``````{r}# Create the workflowclinical_workflow <-workflow() %>%add_model(log_reg_model) %>%add_recipe(clinical_recipe)``````{r}# Train the modelclinical_fit <- clinical_workflow %>%fit(data = train_data)``````{r}# Make predictions on the test datatest_predictions <- clinical_fit %>%predict(new_data = test_data) %>%bind_cols(test_data)``````{r}# Evaluate the modeltest_predictions %>%conf_mat(truth = Group, estimate = .pred_class)``````{r}test_predictions %>%metrics(truth = Group, estimate = .pred_class)```