Skip to content

Streamlining code: #1

@javirudolph

Description

@javirudolph

Minor suggestion to streamline code in the future.

When fitting the hurdle models starting in

# Fit the global hurdle models

You repeat these models and could write a function instead:

 Glob.Hurd.Aeae <- pscl::hurdle(
      Aeae ~ Precip + TMean + nightlight + Elevation | Precip + TMean + nightlight + Elevation, 
      data = HCM_Full_Aeae, 
      dist = "negbin"
    )

you can transform that to;

hurdle_wrapper_fx <- function(.data, .response) {
  
  model_obj <- pscl::hurdle(
    .response ~ Precip + TMean + nightlight + Elevation | Precip + TMean + nightlight + Elevation, 
    data = .data, 
    dist = "negbin"
  )
  
  # you could add any formatting here if you wanted to make easier tables later
  
  return(model_obj)
}

Just a suggestion for future reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions