Skip to content

Commit

Permalink
dynamic branching of pest explore
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-messier committed Mar 28, 2024
1 parent 4122234 commit b293b26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions code/03_Pesticide_Analysis/Target_Helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,38 @@ pivot_covariates <- function(data) {

#' fit_lasso
#'
#' @param data
#' @param assume [[1]] is the outcome sf, [[2]] is the covariates sf
#'
#' @return
#' @export
#'
#' @examples
fit_lasso <- function(data) {
fit_lasso <- function(data_outcome, data_covariates) {


# Put together the final dataframe

data_outcome_to_join <- data_outcome |>
st_drop_geometry() |>
select(c("cncntrt","id")) |>
as.data.frame() |>
mutate(id = row_number())


# Subset the outcome and covariates from the data
pest_data <- data |>
select(cncntrt, 40:ncol(data) -1)
data_covariates_to_join <- data_covariates |>
st_drop_geometry() |>
as.data.frame() |>
mutate(id = row_number())

pest_data <- st_drop_geometry(pest_data)
data_fit <- left_join(data_outcome_to_join, data_covariates_to_join, by = "id") |>
select(-"id")


# Fit using the linear_model function in Parsnip
lasso <- linear_reg() %>%
set_engine("glmnet") %>%
lasso <- linear_reg(penalty = 1) %>%
set_engine("glmnet", family = "mgaussian") %>%
set_mode("regression") %>%
fit(log10(cncntrt) ~ ., data = pest_data)
fit(y_outcomes ~ ., data = pest_data)

return(lasso)

Expand Down
Binary file added example_working_target_viz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b293b26

Please sign in to comment.