Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create function for residuals vs actual plot ts_skedacity_scatter_plot() #180

Closed
spsanderson opened this issue Dec 8, 2021 · 2 comments
Closed
Assignees
Labels

Comments

@spsanderson
Copy link
Owner

This plot should show the residuals on the y axis and the actual values on the x axis to check for hetero/homoskedacity

@spsanderson spsanderson added this to the healthyR.ts 0.1.7 milestone Dec 8, 2021
@spsanderson spsanderson self-assigned this Dec 8, 2021
@spsanderson
Copy link
Owner Author

set a parameter .interactive to default to TRUE for a plotly plot.

@spsanderson
Copy link
Owner Author

spsanderson commented Dec 9, 2021

ts_skedacity_scatter_plot <- function(.calibration_tbl, .model_id = NULL
                              , .interactive = FALSE){
  
  # * Tidyeval ----
  calibration_tbl  <- .calibration_tbl
  model_id         <- .model_id
  interactive_bool <- .interactive
  
  # * Checks ----
  if(!modeltime::is_calibrated(calibration_tbl)){
    stop(call. = FALSE, "You must supply a calibrated modeltime table.")
  }
  
  # Calibration Tibble filter
  if(is.null(model_id)){
    calibration_tbl <- calibration_tbl
  } else {
    calibration_tbl <- calibration_tbl %>%
      dplyr::filter(.model_id == model_id)
  }
  
  g <- calibration_tbl %>% 
    dplyr::ungroup() %>% 
    dplyr::select(-.model, -.type) %>% 
    tidyr::unnest(.calibration_data) %>% 
    ggplot2::ggplot(
      mapping = ggplot2::aes(
        x = .prediction
        , y = .residuals
        , fill = .model_desc
      )
    ) + 
    ggplot2::geom_point(alpha = 0.312) + 
    ggplot2::geom_smooth(alpha = 0.312, size = .5) +
    ggplot2::facet_wrap(
      ~ .model_desc
      , scales = "free"
    ) + 
    tidyquant::scale_color_tq() + 
    ggplot2::theme_minimal() +
    ggplot2::theme(legend.position = "none") +
    ggplot2::labs(
      title = "Skedacity Scatter Plot"
      , x = "Predictions"
      , y = "Residuals"
    )
  
  if(interactive_bool){
    g <- plotly::ggplotly(g)
  }
  
  return(g)
  
}

@spsanderson spsanderson changed the title Create function for residuals vs actual plot ts_residual_scatter_plot() Create function for residuals vs actual plot ts_skedacity_scatter_plot() Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant