## ------------------------------------------------------------
## Examples illustrating the four test-data settings:
## (P=1, M=1), (P=1, M>1), (P>1, M=1), and (P>1, M>1)
## ------------------------------------------------------------
set.seed(1)
## training data (fixed across all cases)
dat_train <- generate_clustered_mar(
n = 200, m = 4, d = 1,
x_dist = "uniform", x_params = list(min = 0, max = 10),
target_missing = 0.30,
seed = 1
)
y_grid <- seq(-6, 6, length.out = 201)
## Case 1: P=1, M=1 (one patient, one measurement)
test_11 <- data.frame(
pid = 1,
X1 = 2.5
)
out_11 <- hcp_predict_targets(
dat = dat_train,
test = test_11,
x_cols = "X1",
y_grid = y_grid,
alpha = 0.1,
S = 2, B = 2,
seed = 1
)
out_11$pred
## Case 2: P=1, M>1 (one patient, multiple measurements)
test_1M <- data.frame(
pid = 1,
X1 = c(1, 3, 7, 9)
)
out_1M <- hcp_predict_targets(
dat = dat_train,
test = test_1M,
x_cols = "X1",
y_grid = y_grid,
alpha = 0.1,
S = 2, B = 2,
seed = 1
)
out_1M$pred
## Case 3: P>1, M=1 (multiple patients, one measurement each)
test_P1 <- data.frame(
pid = 1:4,
X1 = c(2, 4, 6, 8)
)
out_P1 <- hcp_predict_targets(
dat = dat_train,
test = test_P1,
x_cols = "X1",
y_grid = y_grid,
alpha = 0.1,
S = 2, B = 2,
seed = 1
)
out_P1$pred
## Case 4: P>1, M>1 (multiple patients, multiple measurements per patient)
test_PM <- data.frame(
pid = c(1,1, 2,2,2, 3,3),
X1 = c(1,6, 2,5,9, 3,8)
)
out_PM <- hcp_predict_targets(
dat = dat_train,
test = test_PM,
x_cols = "X1",
y_grid = y_grid,
alpha = 0.1,
S = 2, B = 2,
seed = 1
)
out_PM$pred
Run the code above in your browser using DataLab