fit_trajectory: Apply a model fit to an individual's trajectory

Description Usage Arguments Examples

View source: R/analysis_fit_traj.R

Description

Apply a model fit to an individual's trajectory

Usage

1
2
fit_trajectory(dat, fit, xg = NULL, checkpoints = 365 * c(1:2),
  z_bins = -2)

Arguments

dat

data frame containing variables for one subject to apply a fit to

fit

an object returned from get_fit

xg

grid of x points at which the fit should be evaluated for plotting (if NULL it will be set to an equally-spaced grid of 150 points across x)

checkpoints

x values at which to compute "checkpoints" of the subjects's growth trajectory to compare to other subjects

z_bins

a vector indicating binning of z-scores for the subject's trajectory at each checkpoint with respect to the the WHO growth standard

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
mod <- get_fit(cpp, y_var = "wtkg")
fit <- fit_trajectory(subset(cpp, subjid == 2), mod)
plot(fit$xy$x, fit$xy$y)
lines(fit$fitgrid$x, fit$fitgrid$y)
# there is also a plot method:
plot(fit, x_range = c(0, 2560))

# we can fit the z-scores instead
mod2 <- get_fit(cpp, y_var = "waz")
fit2 <- fit_trajectory(subset(cpp, subjid == 2), mod2)
plot(fit2$xy$x, fit2$xy$z)
lines(fit2$fitgrid$x, fit2$fitgrid$z)
# using the plot method
plot(fit2, x_range = c(0, 2560), center = TRUE)

hafen/hbgd documentation built on March 1, 2020, 5:31 p.m.