Care trajectories of patients diagnosed with a serious and chronic condition
data(care)
A data.frame containing three columns:
id id of individuals (2929 different ids)
time number of months since the diagnosis
state new state.
https://larmarange.github.io/analyse-R/data/care_trajectories.RData https://larmarange.github.io/analyse-R/trajectoires-de-soins.html
In this study, patients were followed from the time they were diagnosed with a serious and chronic condition and their care trajectories were tracked monthly from the time of diagnosis. The status variable contains the care status of each individual for each month of follow-up. Trajectories have different lengths.
The four states are:
D: diagnosed, but not in care
C: in care, but not on treatment
T: on treatment, but infection not suppressed
S: on treatment and suppressed infection
data(care)
head(care)
#> id time state
#> 1 3 0 D
#> 2 3 5 D
#> 3 9 0 D
#> 4 9 1 D
#> 5 13 0 D
#> 6 13 7 D
plotData(care)
# Individuals has not the same length. In order to compute the encoding,
# we keep individuals with at least 18 months of history and work
# with the 18 first months.
duration <- compute_duration(care)
idToKeep <- as.numeric(names(duration[duration >= 18]))
care2 <- cut_data(care[care$id %in% idToKeep, ], 18)
head(care2)
#> id time state
#> 1 15 0 D
#> 2 15 4 T
#> 3 15 7 C
#> 4 15 8 D
#> 5 15 15 C
#> 6 15 18 C
# \donttest{
# It is recommended to increase the number of cores to reduce computation time
set.seed(42)
basis <- create.bspline.basis(c(0, 18), nbasis = 10, norder = 4)
fmca <- compute_optimal_encoding(care2, basis, nCores = 2)
#> ######### Compute encoding #########
#> Number of individuals: 1317
#> Number of states: 4
#> Basis type: bspline
#> Number of basis functions: 10
#> Number of cores: 2
#> Method: precompute
#>
| | 0 % elapsed=00s
|===== | 10% elapsed=00s, remaining~00s
|========== | 20% elapsed=00s, remaining~00s
|=============== | 30% elapsed=00s, remaining~00s
|==================== | 40% elapsed=00s, remaining~00s
|========================= | 50% elapsed=00s, remaining~00s
|============================== | 60% elapsed=00s, remaining~00s
|=================================== | 70% elapsed=00s, remaining~00s
|======================================== | 80% elapsed=00s, remaining~00s
|============================================= | 90% elapsed=00s, remaining~00s
|==================================================| 100% elapsed=00s, remaining~00s
#>
#> DONE in 1.48s
#> ---- Compute U matrix:
#>
| | 0 % elapsed=00s
|= | 2 % elapsed=00s, remaining~00s
|== | 4 % elapsed=00s, remaining~00s
|=== | 5 % elapsed=00s, remaining~00s
|==== | 7 % elapsed=00s, remaining~00s
|===== | 9 % elapsed=00s, remaining~00s
|====== | 11% elapsed=00s, remaining~00s
|======= | 13% elapsed=00s, remaining~00s
|======== | 15% elapsed=00s, remaining~00s
|========= | 16% elapsed=00s, remaining~00s
|========== | 18% elapsed=00s, remaining~00s
|========== | 20% elapsed=00s, remaining~00s
|=========== | 22% elapsed=00s, remaining~00s
|============ | 24% elapsed=00s, remaining~00s
|============= | 25% elapsed=00s, remaining~00s
|============== | 27% elapsed=00s, remaining~00s
|=============== | 29% elapsed=00s, remaining~00s
|================ | 31% elapsed=00s, remaining~00s
|================= | 33% elapsed=00s, remaining~00s
|================== | 35% elapsed=00s, remaining~00s
|=================== | 36% elapsed=00s, remaining~00s
|==================== | 38% elapsed=00s, remaining~00s
|==================== | 40% elapsed=00s, remaining~00s
|===================== | 42% elapsed=00s, remaining~00s
|====================== | 44% elapsed=00s, remaining~00s
|======================= | 45% elapsed=00s, remaining~00s
|======================== | 47% elapsed=00s, remaining~00s
|========================= | 49% elapsed=00s, remaining~00s
|========================== | 51% elapsed=00s, remaining~00s
|=========================== | 53% elapsed=00s, remaining~00s
|============================ | 55% elapsed=00s, remaining~00s
|============================= | 56% elapsed=00s, remaining~00s
|============================== | 58% elapsed=00s, remaining~00s
|============================== | 60% elapsed=00s, remaining~00s
|=============================== | 62% elapsed=00s, remaining~00s
|================================ | 64% elapsed=00s, remaining~00s
|================================= | 65% elapsed=00s, remaining~00s
|================================== | 67% elapsed=00s, remaining~00s
|=================================== | 69% elapsed=00s, remaining~00s
|==================================== | 71% elapsed=00s, remaining~00s
|===================================== | 73% elapsed=00s, remaining~00s
|====================================== | 75% elapsed=00s, remaining~00s
|======================================= | 76% elapsed=00s, remaining~00s
|======================================== | 78% elapsed=00s, remaining~00s
|======================================== | 80% elapsed=00s, remaining~00s
|========================================= | 82% elapsed=00s, remaining~00s
|========================================== | 84% elapsed=00s, remaining~00s
|=========================================== | 85% elapsed=00s, remaining~00s
|============================================ | 87% elapsed=00s, remaining~00s
|============================================= | 89% elapsed=00s, remaining~00s
|============================================== | 91% elapsed=00s, remaining~00s
|=============================================== | 93% elapsed=00s, remaining~00s
|================================================ | 95% elapsed=00s, remaining~00s
|================================================= | 96% elapsed=00s, remaining~00s
|==================================================| 98% elapsed=00s, remaining~00s
|==================================================| 100% elapsed=00s, remaining~00s
#>
| | 0 % ~calculating
|= | 1 % ~07s
|== | 2 % ~07s
|== | 3 % ~07s
|=== | 4 % ~07s
|=== | 5 % ~07s
|==== | 6 % ~07s
|==== | 7 % ~07s
|===== | 8 % ~07s
|===== | 9 % ~07s
|====== | 11% ~06s
|====== | 12% ~06s
|======= | 13% ~06s
|======= | 14% ~06s
|======== | 15% ~06s
|======== | 16% ~06s
|========= | 17% ~06s
|========= | 18% ~06s
|========== | 19% ~06s
|========== | 20% ~06s
|=========== | 21% ~06s
|============ | 22% ~06s
|============ | 23% ~06s
|============= | 24% ~06s
|============= | 25% ~06s
|============== | 26% ~06s
|============== | 27% ~06s
|=============== | 28% ~05s
|=============== | 29% ~05s
|================ | 31% ~05s
|================ | 32% ~05s
|================= | 33% ~05s
|================= | 34% ~05s
|================== | 35% ~05s
|================== | 36% ~05s
|=================== | 37% ~05s
|=================== | 38% ~05s
|==================== | 39% ~05s
|==================== | 40% ~05s
|===================== | 41% ~04s
|====================== | 42% ~04s
|====================== | 43% ~04s
|======================= | 44% ~04s
|======================= | 45% ~04s
|======================== | 46% ~04s
|======================== | 47% ~04s
|========================= | 48% ~04s
|========================= | 49% ~04s
|========================== | 51% ~04s
|========================== | 52% ~04s
|=========================== | 53% ~04s
|=========================== | 54% ~04s
|============================ | 55% ~04s
|============================ | 56% ~03s
|============================= | 57% ~03s
|============================= | 58% ~03s
|============================== | 59% ~03s
|============================== | 60% ~03s
|=============================== | 61% ~03s
|================================ | 62% ~03s
|================================ | 63% ~03s
|================================= | 64% ~03s
|================================= | 65% ~03s
|================================== | 66% ~03s
|================================== | 67% ~03s
|=================================== | 68% ~02s
|=================================== | 69% ~02s
|==================================== | 71% ~02s
|==================================== | 72% ~02s
|===================================== | 73% ~02s
|===================================== | 74% ~02s
|====================================== | 75% ~02s
|====================================== | 76% ~02s
|======================================= | 77% ~02s
|======================================= | 78% ~02s
|======================================== | 79% ~02s
|======================================== | 80% ~02s
|========================================= | 81% ~01s
|========================================== | 82% ~01s
|========================================== | 83% ~01s
|=========================================== | 84% ~01s
|=========================================== | 85% ~01s
|============================================ | 86% ~01s
|============================================ | 87% ~01s
|============================================= | 88% ~01s
|============================================= | 89% ~01s
|============================================== | 91% ~01s
|============================================== | 92% ~01s
|=============================================== | 93% ~01s
|=============================================== | 94% ~00s
|================================================ | 95% ~00s
|================================================ | 96% ~00s
|================================================= | 97% ~00s
|================================================= | 98% ~00s
|==================================================| 99% ~00s
|==================================================| 100% elapsed=07s
#>
#> DONE in 7.85s
#> ---- Compute encoding:
#> DONE in 0.01s
#> ---- Compute Bootstrap Encoding:
#> **************************************************
#> DONE in 0.57s
#> Run Time: 10.37s
plotEigenvalues(fmca, cumulative = TRUE, normalize = TRUE)
plot(fmca)
#> Warning: Removed 8 rows containing missing values or values outside the scale range
#> (`geom_line()`).
plot(fmca, addCI = TRUE)
#> Warning: Removed 8 rows containing missing values or values outside the scale range
#> (`geom_line()`).
plotComponent(fmca, addNames = FALSE)
# }