dustinfife/flexplot

Visualize error code when reopened file

Opened this issue · 0 comments

Hi

I made lovely plots from a YouTube tutorial (new to R) and when I reopened my file, the script returned an error.

Can you help please, I have been googling for hours?

require(ggplot2)
require(mediation)
library(flexplot)

data= (Data_analysis_moderation)
names(Data_analysis_moderation)

#step two: predict the mediator with the variable of interest

mediate_model = lm(CIT_TEAQGestation_, data=Data_analysis_moderation)
summary(mediate_model)
require(flexplot)
visualize(mediate_model)
#step 3:fit the whole model
full_model = lm(PHQ_Score
CIT_TEAQ + Gestation_, data = Data_analysis_moderation)
summary(full_model)
results = mediate(mediate_model, full_model, treat = 'Gestation_', mediator = "CIT_TEAQ",boot = TRUE, sims=500)
summary(results)

error:

! Can't convert x <haven_labelled> to .

Backtrace:

  1. ├─flexplot::visualize(mediate_model)
  2. └─flexplot:::visualize.lm(mediate_model)
  3. └─flexplot::compare.fits(f, data = data, model1 = object, ...)
  4. └─flexplot::flexplot(...)
    
  5.   └─flexplot:::flexplot_modify_data(...)
    
  6.     └─flexplot:::flexplot_convert_to_categorical(data, axis)
    
  7.       └─base::factor(data[, axis[1]], ordered = T)
    
  8.         ├─base::unique(as.character(y)[ind])
    
  9.         ├─base::as.character(y)
    
  10.         └─vctrs:::as.character.vctrs_vctr(y)
    

Run rlang::last_trace(drop = FALSE) to see 11 hidden frames.