presmooth_data: Pre-smooth sparse longitudinal data

Description Usage Arguments Value Examples

View source: R/presmooth_data.R

Description

Pre-smooth sparse longitudinal data

Usage

1
presmooth_data(obs_data, ...)

Arguments

obs_data

data.frame or tibble containing the observed data, with columns id identifying the individual measured, tt identifying the time of the observation, x the value of the surrogate at time tt, and a indicating 1 for treatment arm and 0 for control arm.

...

additional arguments to pass to the function PCA function

Value

list containing matrices X_t and X_c, which are the smoothed surrogate values for the treated and control groups, respectively, for use in downstream analyses

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(dplyr)
library(longsurr)
obs_data <- 
generate_discontinuous_data(n = 50, n_i = 5, delta_s = 0.5, 
k = 1, s_y = 0.1, s_x = 0.1)$obs_ds

head(obs_data)
presmooth_X <- presmooth_data(obs_data)

wide_ds <- full_data %>% 
dplyr::select(id, a, tt, x, y) %>%
tidyr::spread(tt, x) 

y_t <- wide_ds %>%
filter(a == 1) %>%
pull(y)
y_c <- wide_ds %>%
filter(a == 0) %>%
pull(y)
X_t <- presmooth_X$X_t
X_c <- presmooth_X$X_c

estimate_surrogate_value(y_t = y_t, y_c = y_c, 
X_t = X_t, X_c = X_c, method = 'linear')

denisagniel/longsurr documentation built on March 1, 2020, 3:35 a.m.