Skip to content

Commit

Permalink
Program
Browse files Browse the repository at this point in the history
  • Loading branch information
aapohiilamo committed Aug 14, 2024
1 parent 3ab69d1 commit 72a0365
Show file tree
Hide file tree
Showing 162 changed files with 14,934 additions and 303 deletions.
432 changes: 432 additions & 0 deletions .Rhistory

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions .Rproj.user/781306AB/jobs/AEF2B074-output.json

This file was deleted.

8 changes: 8 additions & 0 deletions .Rproj.user/781306AB/jobs/B069ADCC-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[1,"==> quarto preview schedule.qmd --to html --no-watch-inputs --no-browse\n\n"]
[1,"\r\n\r\nprocessing file: schedule.qmd\r\n\r | \r | | 0%\r | \r |.......... | 20% \r | \r |..................... | 40% [unnamed-chunk-1]"]
[1,"\r | \r |............................... | 60% \r | \r |.......................................... | 80% [unnamed-chunk-2]"]
[1,"\r | \r |....................................................| 100% \r \r\noutput file: schedule.knit.md\r\n\r\n"]
[1,"pandoc \n to: html\n output-file: schedule.html\n standalone: true\n title-prefix: Demystifying ML Rostock November 5-6\n section-divs: true\n html-math-method: mathjax\n wrap: none\n default-image-extension: png\n css:\n - styles.css\n toc: true\n \nmetadata\n document-css: false\n link-citations: true\n date-format: long\n lang: en\n style: docked\n title: Schedule\n \n"]
[1,"Output created: docs\\schedule.html\n\nPreparing to preview\n"]
[1,"\nWatching files for changes\nBrowse at http://localhost:6805/schedule.html\n"]
[1,"GET: /schedule.html\n"]
12 changes: 6 additions & 6 deletions .Rproj.user/781306AB/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left": {
"splitterpos": 403,
"splitterpos": 287,
"topwindowstate": "NORMAL",
"panelheight": 959,
"windowheight": 997
"panelheight": 680,
"windowheight": 718
},
"right": {
"splitterpos": 607,
"splitterpos": 430,
"topwindowstate": "NORMAL",
"panelheight": 959,
"windowheight": 997
"panelheight": 680,
"windowheight": 718
}
}
4 changes: 2 additions & 2 deletions .Rproj.user/781306AB/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 0,
"TabSet2": 0,
"TabSet1": 1,
"TabSet2": 1,
"TabZoom": {}
}
4 changes: 3 additions & 1 deletion .Rproj.user/781306AB/sources/prop/4213478B
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"source_window_id": "",
"Source": "Source"
"Source": "Source",
"cursorPosition": "20,21",
"scrollLine": "0"
}
11 changes: 11 additions & 0 deletions .Rproj.user/781306AB/sources/prop/4F687EF1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"source_window_id": "",
"Source": "Source",
"rmdVisualMode": "false",
"rmdVisualWrapConfigured": "true",
"docOutlineVisible": "1",
"rmdVisualCollapsedChunks": "",
"cursorPosition": "67,37",
"scrollLine": "0",
"rmdVisualModeLocation": "2778:906"
}
2 changes: 1 addition & 1 deletion .Rproj.user/781306AB/sources/prop/89D31A7C
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"rmdVisualCollapsedChunks": "",
"cursorPosition": "4,0",
"scrollLine": "0",
"rmdVisualModeLocation": "160:0"
"rmdVisualModeLocation": "2:0"
}
4 changes: 2 additions & 2 deletions .Rproj.user/781306AB/sources/prop/AEB9CF09
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "10,75",
"scrollLine": "0"
"cursorPosition": "18,92",
"scrollLine": "24"
}
1 change: 1 addition & 0 deletions .Rproj.user/781306AB/sources/prop/INDEX
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
~%2FOther_projects%2FML_workshop%2F_quarto.yml="4213478B"
~%2FOther_projects%2FML_workshop%2Fcontact.qmd="89D31A7C"
~%2FOther_projects%2FML_workshop%2Findex.qmd="4F687EF1"
~%2FOther_projects%2FML_workshop%2Fschedule.qmd="AEB9CF09"
34 changes: 34 additions & 0 deletions .Rproj.user/781306AB/sources/session-35d87fc4/4590ED4E
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "4590ED4E",
"path": null,
"project_path": null,
"type": "r_dataframe",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1723584378067.0,
"source_on_save": false,
"relative_order": 2,
"properties": {
"expression": "probs_m",
"caption": "probs_m",
"totalObservations": 588,
"displayedObservations": 588,
"variables": 7,
"cacheKey": "1685D8DC",
"object": "probs_m",
"environment": "",
"contentUrl": "grid_resource/gridviewer.html?env=&obj=probs_m&cache_key=1685D8DC&max_display_columns=50",
"preview": 0,
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 4635118810238550016,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1723584378067,
"read_only": false,
"read_only_alternatives": []
}
27 changes: 27 additions & 0 deletions .Rproj.user/781306AB/sources/session-35d87fc4/799D6713
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": "799D6713",
"path": null,
"project_path": null,
"type": "r_source",
"hash": "0",
"contents": "",
"dirty": true,
"created": 1723584319650.0,
"source_on_save": false,
"relative_order": 1,
"properties": {
"tempName": "Untitled1",
"source_window_id": "",
"Source": "Source",
"cursorPosition": "79,20",
"scrollLine": "72"
},
"folds": "",
"lastKnownWriteTime": 4135253754756885857,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1723614768910,
"read_only": false,
"read_only_alternatives": []
}
141 changes: 141 additions & 0 deletions .Rproj.user/781306AB/sources/session-35d87fc4/799D6713-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
## Load packages
library(dtms)
library(ggplot2)
library(tidyverse)
## Define model: Absorbing and transient states, time scale
hrs <- dtms(transient=c("Working","Non-working","Retired"),
absorbing="Dead",
timescale=50:99)

## Quick look at data
head(hrsdata)
#> ID Gender Age State
#> 1 1 1 50 <NA>
#> 2 1 1 51 <NA>
#> 3 1 1 52 <NA>
#> 4 1 1 53 <NA>
#> 5 1 1 54 <NA>
#> 6 1 1 55 <NA>

## Reshape
estdata <- dtms_format(data=hrsdata,
dtms=hrs,
idvar="ID",
timevar="Age",
statevar="State")

## Drop dead-to-dead transitions etc
estdata <- dtms_clean(data=estdata,
dtms=hrs)
#> Dropping 0 rows not in state space
#> Dropping 0 rows not in time range
#> Dropping 98287 rows starting or ending in NA
#> Dropping 51935 rows starting in absorbing state

## Overview
summary(estdata)
#> from to COUNT PROP PROB
#> 1 Non-working Dead 197 0.001974383 0.013936050
#> 2 Non-working Non-working 10635 0.106586622 0.752334465
#> 3 Non-working Retired 1900 0.019042274 0.134408602
#> 4 Non-working Working 1404 0.014071238 0.099320883
#> 5 Retired Dead 2602 0.026077893 0.051556401
#> 6 Retired Non-working 606 0.006073483 0.012007371
#> 7 Retired Retired 46423 0.465262884 0.919831976
#> 8 Retired Working 838 0.008398645 0.016604252
#> 9 Working Dead 306 0.003066808 0.008699855
#> 10 Working Non-working 2066 0.020705967 0.058738237
#> 11 Working Retired 2178 0.021828459 0.061922497
#> 12 Working Working 30623 0.306911343 0.870639411

## Basic censoring
dtms_censoring(data=estdata,
dtms=hrs)
#> Units with left censoring: 2036
#> Units with gaps: 1720
#> Units with right censoring: 1323

## More advanced censoring example
estdata <- dtms_censoring(data=estdata,
dtms=hrs,
add=T,
addtype="obs")
#> Units with left censoring: 2036
#> Units with gaps: 1720
#> Units with right censoring: 1323

estdata |>
subset(subset=to!="Dead",select=c(RIGHT,to)) |>
table() |>
prop.table(margin=1)
#> to
#> RIGHT Non-working Retired Working
#> FALSE 0.13846880 0.51950708 0.34202412
#> TRUE 0.07860922 0.73015873 0.19123205

## Add age squared
estdata$time2 <- estdata$time^2
estdata$time2 <- ifelse(estdata$time > 65, 1, 0)*estdata$time

means <- estdata %>%
group_by(time) %>%
summarize(mean_value = mean(time2))

## Fit model
fit <- dtms_fit(data=estdata,
formula=to~from+time+time2+Gender)

## Transition probabilities by gender

# Men
probs_m <- dtms_transitions(dtms=hrs,
model = fit,
controls = list(Gender=0,
time =50:98,
time2 = means$mean_value),
CI=TRUE)

# Women
probs_w <- dtms_transitions(dtms=hrs,
model = fit,
controls = list(Gender=1,
time =50:98,
time2 =(50:98)^2),
CI=TRUE)

# Overview
summary(probs_m)
#> from to MIN MINtime MAX MAXtime MEDIAN MEAN
#> 1 Non-working Dead 0.0064 50 0.7701 98 0.1080 0.2055
#> 4 Non-working Non-working 0.0000 98 0.8173 54 0.1402 0.3186
#> 7 Non-working Retired 0.0356 50 0.7089 79 0.3904 0.3880
#> 10 Non-working Working 0.0238 98 0.1668 50 0.1008 0.0879
#> 2 Retired Dead 0.0231 58 0.4588 98 0.0364 0.0930
#> 5 Retired Non-working 0.0000 98 0.1627 50 0.0025 0.0324
#> 8 Retired Retired 0.5365 98 0.9492 73 0.8855 0.8381
#> 11 Retired Working 0.0047 98 0.2132 50 0.0121 0.0365
#> 3 Working Dead 0.0013 50 0.4725 98 0.0288 0.0926
#> 6 Working Non-working 0.0000 98 0.0704 58 0.0104 0.0252
#> 9 Working Retired 0.0075 50 0.2443 85 0.1524 0.1375
#> 12 Working Working 0.3990 98 0.9456 50 0.7862 0.7447
summary(probs_w)
#> from to MIN MINtime MAX MAXtime MEDIAN MEAN
#> 1 Non-working Dead 0.0036 50 0.6979 98 0.0743 0.1649
#> 4 Non-working Non-working 0.0000 98 0.8565 54 0.1780 0.3471
#> 7 Non-working Retired 0.0296 50 0.7504 80 0.4309 0.4090
#> 10 Non-working Working 0.0297 98 0.1312 50 0.0822 0.0791
#> 2 Retired Dead 0.0156 57 0.3678 98 0.0253 0.0687
#> 5 Retired Non-working 0.0000 98 0.2013 50 0.0032 0.0404
#> 8 Retired Retired 0.5857 50 0.9600 74 0.9001 0.8567
#> 11 Retired Working 0.0052 98 0.1966 50 0.0115 0.0341
#> 3 Working Dead 0.0009 50 0.3908 98 0.0208 0.0718
#> 6 Working Non-working 0.0000 98 0.0922 58 0.0138 0.0332
#> 9 Working Retired 0.0078 50 0.2633 86 0.1700 0.1488
#> 12 Working Working 0.4542 98 0.9311 50 0.7815 0.7462

# Plotting, men as example
probs_m |> dtms_simplify() |>
ggplot(aes(x=time,y=P,color=to)) +
geom_ribbon(aes(ymin = CIlow, ymax = CIup,fill=to),alpha=0.5) +
geom_line() +
facet_wrap(~from)
34 changes: 34 additions & 0 deletions .Rproj.user/781306AB/sources/session-35d87fc4/9695AB54
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "9695AB54",
"path": null,
"project_path": null,
"type": "r_dataframe",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1723613370447.0,
"source_on_save": false,
"relative_order": 4,
"properties": {
"expression": "spline_basis",
"caption": "spline_basis",
"totalObservations": "31",
"displayedObservations": "31",
"variables": "4",
"cacheKey": "D29D90F4",
"object": "spline_basis",
"environment": "",
"contentUrl": "grid_resource/gridviewer.html?env=&obj=spline_basis&cache_key=D29D90F4&max_display_columns=50",
"preview": "0",
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 4634978072750194688,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1723613370447,
"read_only": false,
"read_only_alternatives": []
}
Empty file.
34 changes: 34 additions & 0 deletions .Rproj.user/781306AB/sources/session-35d87fc4/A8CEBD11
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "A8CEBD11",
"path": null,
"project_path": null,
"type": "r_dataframe",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1723614451718.0,
"source_on_save": false,
"relative_order": 5,
"properties": {
"expression": "estdata",
"caption": "estdata",
"totalObservations": "99778",
"displayedObservations": "99778",
"variables": "10",
"cacheKey": "62C6B3D6",
"object": "estdata",
"environment": "",
"contentUrl": "grid_resource/gridviewer.html?env=&obj=estdata&cache_key=62C6B3D6&max_display_columns=50",
"preview": "0",
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 7957688064806756898,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1723614451718,
"read_only": false,
"read_only_alternatives": []
}
Empty file.
Loading

0 comments on commit 72a0365

Please sign in to comment.