plot_fit: Visualization of estimated mean trajectories and nonlinear...

View source: R/plot-fit.R

plot_fitR Documentation

Visualization of estimated mean trajectories and nonlinear functions from a PLSMM

Description

This function plots the observed data, the estimated mean trajectories, and the estimated nonlinear functions from the output of plsmm_lasso.

Usage

plot_fit(
  x,
  y,
  series,
  t,
  name_group_var,
  plsmm_output,
  predicted = FALSE,
  show_obs = FALSE
)

Arguments

x

A matrix of predictors.

y

A continuous vector of response variable.

series

A variable representing different series or groups in the data modeled as a random intercept.

t

A numeric vector indicating the time points.

name_group_var

A character string specifying the name of the grouping variable.

plsmm_output

Output object obtained from the plsmm_lasso function.

predicted

Logical indicating whether to plot predicted values. If FALSE only the observed time points are used.

show_obs

Logical. If TRUE the observed time points are used for the position scale of the x-axis.

Details

If predicted is TRUE the function uses the model from plsmm_output to predict unobserved time points on a continuous grid of time.

Value

Two plots:

  • The first plot shows the observed data and the estimated mean trajectories.

  • The second plot shows the estimated nonlinear functions.

Examples


set.seed(123)
data_sim <- simulate_group_inter(
  N = 50, n_mvnorm = 3, grouped = TRUE,
  timepoints = 3:5, nonpara_inter = TRUE,
  sample_from = seq(0, 52, 13),
  cos = FALSE, A_vec = c(1, 1.5)
)
sim <- data_sim$sim
x <- as.matrix(sim[, -1:-3])
y <- sim$y
series <- sim$series
t <- sim$t
bases <- create_bases(t)
lambda <- 0.0046
gamma <- 0.00000001
plsmm_output <- plsmm_lasso(x, y, series, t,
  name_group_var = "group", bases$bases,
  gamma = gamma, lambda = lambda, timexgroup = TRUE,
  criterion = "BIC"
)
plot_fit(x, y, series, t, name_group_var = "group", plsmm_output)


plsmmLasso documentation built on June 22, 2024, 9:35 a.m.