Learn R Programming

hyreg2 (version 1.1.0)

plot_hyreg2: plot function for hyreg2

Description

Function to visualize model results by hyreg2 or hygre2_het

Usage

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

Value

ggplot object visualizing x against y by classes

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 on x-axis

y

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

id_col

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

class_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_class() 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

Author

Svenja Elkenkamp & John Grosser

Details

id_col must 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 use class_df_model = give_class(data,model,"observation"), see example

Examples

Run this code
# 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",
          class_df_model = give_class(data = simulated_data_norm,
                                model = hyflex_mod,
                                id = "id"))


Run the code above in your browser using DataLab