Skip to content

Commit

Permalink
olm hard code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-messier committed Apr 26, 2024
1 parent 2678cea commit fb9757d
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 665 deletions.
355 changes: 1 addition & 354 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,357 +1,3 @@
g1
tar_visnetwork(targets_only = T)
tar_make()
tar_make()
tar_visnetwork(targets_only = T)
library(parsnip)
?fit
sf_outcomes
pest_data <- data.frame(
y1 = rnorm(100), # Example response variable 1
y2 = rnorm(100), # Example response variable 2
x1 = rnorm(100), # Example predictor variable 1
x2 = rnorm(100) # Example predictor variable 2
)
# Fit using the linear_model function in Parsnip
lasso <- linear_reg() %>%
set_engine("glmnet", family = "mgaussian") %>%
set_mode("regression") %>%
fit(cbind(y1, y2) ~ ., data = pest_data)
pest_data <- data.frame(
y1 = rnorm(100), # Example response variable 1
y2 = rnorm(100), # Example response variable 2
x1 = rnorm(100), # Example predictor variable 1
x2 = rnorm(100) # Example predictor variable 2
)
pest_data
a <- cbind(y1, y2)
y1 = rnorm(100), # Example response variable 1
y1 = rnorm(100)
y2 = rnorm(100)
a <- cbind(y1, y2)
dim(a)
a
?glmnet
df
pest_data <- df |>
select(c("cncntrt","Year","left_cns"))
df
df
pest_data <- df |>
select(c("cncntrt","Year","lft_cns"))
pest_data
# Fit using the linear_model function in Parsnip
lasso <- linear_reg() %>%
set_engine("glmnet", family = "gaussian") %>%
set_mode("regression") %>%
fit(cncntrt ~ ., data = pest_data)
pest_data <- data.frame(
y1 = rnorm(100), # Example response variable 1
y2 = rnorm(100), # Example response variable 2
x1 = rnorm(100), # Example predictor variable 1
x2 = rnorm(100) # Example predictor variable 2
)
# Fit using the linear_model function in Parsnip
lasso <- linear_reg() %>%
set_engine("glmnet", family = "mgaussian") %>%
set_mode("regression") %>%
fit(cbind(y1, y2) ~ ., data = pest_data)
# Fit using the linear_model function in Parsnip
lasso <- linear_reg(penalty = 1) %>%
set_engine("glmnet", family = "mgaussian") %>%
set_mode("regression") %>%
fit(cbind(y1, y2) ~ ., data = pest_data)
lasso
lasso$fit
lasso$fit$beta
data_partitioned <- tar_read(sf_pesticide_partition_cleaned)
data_partitioned[[1]]
data_partitioned[[2]]
data_partitioned[[2]][,l10n_info()]
data_partitioned[[2]][,1:10]
data_partitioned[[2]][,1:5]
data_partitioned[[1]]
data_outcome <- data_partitioned[[1]] |>
st_drop_geometry()
data_outcome
data_model <- left_join(data_outcome, data_covariates, by = "id")
data_covariates <- data_partitioned[[2]] |>
st_drop_geometry()
data_model <- left_join(data_outcome, data_covariates, by = "id")
data_model
data_model[,1:5]
data_model[,1:10]
data <- left_join(data_outcome, data_covariates, by = "id")
data
data_covariates
colnames(data_covariates)
colnames(data_covariates)[1:20]
data_outcome
data_outcome_to_join <- data_outcome |>
st_drop_geometry() |>
filter("cncntrt","id") |>
as.data.frame() |>
mutate(id = row_number())
data_outcome_to_join <- data_outcome |>
st_drop_geometry() |>
select(c("cncntrt","id")) |>
as.data.frame() |>
mutate(id = row_number())
data_outcome_to_join
data_outcome_to_join |> head()
data_covariates
colnames(data_covariates)[1:10]
colnames(data_covariates)[1790:1803]
data_covariates_to_join <- data_covariates |>
st_drop_geometry() |>
select(-"geometry") |>
as.data.frame() |>
mutate(id = row_number())
data_covariates <- sf_pesticide_partition_cleaned[[2]]
data_covariates_to_join <- data_covariates |>
st_drop_geometry() |>
select(-"geometry") |>
as.data.frame() |>
mutate(id = row_number())
data_covariates_to_join <- data_covariates |>
st_drop_geometry() |>
as.data.frame() |>
mutate(id = row_number())
View(data_covariates_to_join)
data_fit <- left_join(data_outcome_to_join, data_covariates_to_join, by = "id")
View(data_fit)
data_fit <- left_join(data_outcome_to_join, data_covariates_to_join, by = "id") |>
select(-"id")
View(data_fit)
hist(data_fit$cncntrt)
summary(data_fit$cncntrt)
data_outcome
data_outcome[data_outcome$cncntrt==0,]
d1 <- tar_read(readQS)
d1
d1[d1$cncntrt==0,]
p1<-d1[d1$cncntrt==0,]
p1$X
p1$Y
p1[c("X","Y")]
p1
azo <- st_read("/Volumes/SET/Projects/PrestoGP_Pesticides/input/data_process/data_AZO_watershed_huc_join.shp")
azo
azo.idx <- azo[azo$cncntrt==0,]
azo.idx
azo.initial <- load("/Volumes/SET/Projects/PrestoGP_Pesticides/input/data_process/data_AZO_year_avg.RData")
azo.initial
azo.initial[[1]]
load("/Volumes/SET/Projects/PrestoGP_Pesticides/input/data_process/data_AZO_year_avg.RData")
data.AZO.year.avg
data.AZO.year.avg[data.AZO.year.avg$concentration==0,]
sf_pesticide_partition_cleaned[[3]]
sf_pesticide_partition_cleaned[[3]]$wll_dpt
knitr::opts_chunk$set(echo = TRUE)
library(dataRetrieval)
install.packages("dataRetrieval")
library(dataRetrieval)
library(dplyr)
library(beepr)
install.packages("beepr")
library(dataRetrieval)
library(dplyr)
library(beepr)
library(lubridate)
library(tidyverse)
library(data.table)
param.chlorotriazines <- c("39632", "04040", "04038", "04039", "38535", "04035")
startDate <- "2000-01-01"
endDate <- "2022-12-31"
state.list <- state.abb[c(-2, -11)]
state.fun.AZO <- function(x) {
print(x)
temp <- whatWQPdata(
statecode = state.list[x],
parameterCd = param.chlorotriazines
)
temp <- temp[temp$MonitoringLocationTypeName == "Well", ]
if (nrow(temp) > 0) {
site.info <- str_subset(temp$MonitoringLocationIdentifier, "(?<=USGS-)\\d+") %>%
str_extract("(?<=USGS-)\\d+") %>%
readNWISsite() %>%
select(c(site_no, well_depth_va))
site.info$MonitoringLocationIdentifier <- paste0("USGS-", site.info$site_no)
data.chlorotriazines <- readWQPqw(temp$MonitoringLocationIdentifier, param.chlorotriazines,
startDate = startDate, endDate = endDate
)
result <- left_join(data.chlorotriazines, temp, by = "MonitoringLocationIdentifier") %>%
left_join(site.info, by = "MonitoringLocationIdentifier")
return(result)
}
}
data.AZO <- lapply(1:48, state.fun.AZO)
sum(is.na(sf_pesticide_partition_cleaned[[3]]$wll_dpt))
dim(d1)
dim(d1,1)
dim(d1)[1]
dim(d1)[1]-6
tar_make()
p1 <- tar_read(plot_pesticide_maps_57fe39ed)
p1
sf_pesticide_partition_cleaned <- tar_read(sf_pesticide_partition_cleaned)
sf_pesticide_partition_cleaned[[1]]
ggplot(sf_pesticide_partition_cleaned,aes(cncntrt)) + geom_density()
ggplot(sf_pesticide_partition_cleaned |> as.data.frame(),aes(cncntrt)) + geom_density()
ggplot(sf_pesticide_partition_cleaned |> as.data.frame(),aes(cncntrt)) + geom_density() + scale_x_log10()
library(PrestoGP)
?VecchiaModel
?check_input
?PrestoGP::check_input
?PrestoGP::prestogp_fit
?MultivariateVecchiaModel
tar_make()
tar_make()
sf_pesticide_dummies_cv <- tar_read(sf_pesticide_dummies_cv)
sf_pesticide_dummies_cv[[1]]
sf_pesticide_dummies_cv
length(sf_pesticide_dummies_cv)
sf_pesticide_dummies_cv[[1]]
tar_make()
sf_pesticide_dummies_cv[[1]]
sf_pesticide_dummies_cv[[1]]$kfolds
?tar_group_by
tar_make()
tar_make()
sf_pesticide_for_fit <- tar_read(sf_pesticide_for_fit)
sf_pesticide_for_fit
sf_pesticide_for_fit[,1:10]
head(sf_pesticide_for_fit)
View(sf_pesticide_for_fit)
tar_make()
lasso.fit <- tar_read(lasso_fit_by_chem_4eeee620)
lasso.fit$censor_probs
?glmnet
lasso.fit$fit$beta
plot(lasso.fit$fit)
plot(lasso.fit$fit$beta)
plot(lasso.fit$fit)
lasso.fit$lvl
glmnet::plot(lasso.fit$fit)
tar_visnetwork(targets_only = T)
tar_make()
lasso.fit <- tar_read(lasso_fit_by_chem_4eeee620)
autoplot(lasso.fit)
autoplot(lasso.fit$fit)
lasso.fit
autoplot(lasso.fit)
autoplot(lasso.fit$spec)
lasso.fit$fit
tar_make()
f2 <- tar_read(lasso_fit_by_kfold_2808dfa1)
f2
f2[[1]]
f2[[2]]
f2[[3]]
f2[[4]]
plot(f2)
plot(f2[[2]])
f2
autoplot(f2)
autoplot(f2$fit)
tar_make()
f1 <- tar_read(lasso_fit_by_kfold_68b90cee)
f1
autoplot(f1)
autoplot(f1$fit)
plot(f1$fit)
tar_visnetwork(targets_only = T)
?tar_visnetwork
tar_mermaid(targets_only = T)
tm <- tar_mermaid(targets_only = T)
tm
tar_visnetwork(targets_only = T)
tar_visnetwork()
tar_make()
m1 <- tar_read(plot_covariate_maps_97adc691)
m1
1259*24
1259*24/2
=======
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ ifelse(.x$lft_cns == 0, .x$cncntrt, 1e-9))) |>
pull(data)
# 2) A list of LOD, each element is a vector of the limit of detection
# use dplyr to create a separate list by each ChmlNm and create an LOD. The
# LOD should be the cnctrnt
pesticide_lod <- data_analysis |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ .x$cnctrnt)) |>
pull(data)
# 2) A list of LOD, each element is a vector of the limit of detection
# use dplyr to create a separate list by each ChmlNm and create an LOD. The
# LOD should be the cnctrnt
pesticide_lod <- data_analysis |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ .x$cncntrt)) |>
pull(data)
pesticide_outcomes[[1]][1:10]
pesticide_lod[[1]][1:10]
#2a) Create a list of the of the lft_cns variable by ChmclNm
pesticide_lft_cns <- data_analysis |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ .x$lft_cns)) |>
pull(data)
pesticide_lft_cns[[1]][1:10]
cbind(pesticide_lft_cns[[1]][1:10],pesticide_outcomes[[1]][1:10],pesticide_lod[[1]][1:10])
# 4) A list of X's, each element is a matrix of the covariates
# For now, we will use the covariates in the data_analysis
pesticide_covariates <- data_analysis |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ .x %>% select(-cncntrt, -lft_cns))) |>
pull(data)
pesticide_covariates[[1]]
pesticide_covariates[[2]]
pesticide_covariates[[3]]
pesticide_covariates[[4]]
ls
pesticide_covariates[[3]]
data_analysis
data_analysis[[1]][,1:20]
data_analysis[[1]][,1:10]
data_analysis[,1:10]
# 5) A list of locs, each element is a matrix of the locations
# For now, we will use the locations in the data_analysis - it includes x, y, and time
# Because the locations are from the sf geometry object we need to use the original data
# We get the geometry from the sf object and then add the time (column name is Year)
pesticide_locs <- data_analysis |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, ~ st_coordinates(.x |> select(geometry)))) |>
pull(data)
# 5) A list of locs, each element is a matrix of the locations
# For now, we will use the locations in the data_analysis - it includes x, y, and time
# Because the locations are from the sf geometry object we need to use the original data
# We get the geometry from the sf object and then add the time (column name is Year)
data_analysis <- splits |>
analysis() |>
group_by(ChmclNm) |>
nest() |>
mutate(geometry = st_as_text(geometry)) |>
sf::st_drop_geometry()
# 5) A list of locs, each element is a matrix of the locations
# For now, we will use the locations in the data_analysis - it includes x, y, and time
# Because the locations are from the sf geometry object we need to use the original data
# We get the geometry from the sf object and then add the time (column name is Year)
data_analysis <- splits |>
analysis() |>
group_by(ChmclNm) |>
nest() |>
mutate(data = map(data, st_coordinates())) |>
sf::st_drop_geometry()
data_analysis <- splits |>
analysis() |>
group_by(ChmclNm)
data_analysis <- splits |>
analysis()
data_analysis
Expand Down Expand Up @@ -863,3 +509,4 @@ library(yardstick)
library(data.table)
tar_visnetwork(targets_only = T)
getwd()
getwd()
Loading

0 comments on commit fb9757d

Please sign in to comment.