plot_hyreg2: plot function to visualize the classification based on the...

View source: R/plot_hyreg2.R

plot_hyreg2R Documentation

plot function to visualize the classification based on the model estimated using hyreg2 or hyreg2_het

Description

This function can be used to visualize the classification based on the model for different variables. ggplot2::ggplot() is used.

Usage

plot_hyreg2(
  data,
  x,
  y,
  id_col,
  id_df_model,
  type_to_plot = NULL,
  colors = NULL
)

Arguments

data

a dataframe, which was used to estimate the model using hyreg2() or hyreg2_het()

x

charachter string, column of data to be plotted in x-axis

y

charachter string, column of data to be plotted in y-axis

id_col

charachter sting, grouping variable, same as was given in model. if model was estimated without grouping, see Details

id_df_model

dataframe of two columns indicating which group belongs to which class, first column named as input id_col, second column named "mod_comp". this input can be generated using the give_id() function, see Details.

type_to_plot

list of two charachter elements. First: columnname of column containing indicator for type of data, Second: value of column type, that should be used for the plot, see details of hyreg2() inputs type and type_cont,type_dich

colors

charachter vector, colors to be used in ggplot, default NULL - than colors are choosen automatically

Details

id_col_df has to be provided anyway, even if the model was estimated without grouping variable. Since there might be no grouping varibale in the data, we recommend to create a new column called "observation" in data using the rownames/observationnumbers as charachter values and use this column as input for id_col in plot_hyreg2, additionally you can then use id_df_model = give_id(data,model,"observation"), see example

Value

ggplot object visualizing x against y by classes from the model

Author(s)

Svenja Elkenkamp & John Grosser

Examples

# estimate a model using simulated_data_rnorm

formula <- y ~  -1 + x1 + x2 + x3 | id
k <- 2
stv <- setNames(c(0.2,0.2,0.2,1,1),c(colnames(simulated_data_norm)[3:5],c("sigma","theta")))
control <- list(iter.max = 1000, verbose = 4)

hyflex_mod <- hyreg2(formula = formula,
                    data =  simulated_data_norm,
                    type =  simulated_data_norm$type,
                    stv = stv,
                    k = k,
                    type_cont = "TTO",
                    type_dich = "DCE_A",
                    opt_method = "L-BFGS-B",
                    control = control,
                    latent = "cont",
                    id_col = "id"
)
# plotting the variables id against y
plot_hyreg2(data = simulated_data_norm,
          x = "id",
          y = "y",
          id_col = "id",
          id_df_model = give_id(data = simulated_data_norm,
                                model = hyflex_mod,
                                id = "id"))



hyreg2 documentation built on Nov. 5, 2025, 7:38 p.m.

Related to plot_hyreg2 in hyreg2...