NIEHS / PrestoGP

Penalized Regression on Spatiotemporal Outcomes using Gaussian Processes a.k.a. PrestoGP
https://niehs.github.io/PrestoGP/
0 stars 0 forks source link

Test PrestoGP task #5

Closed kyle-messier closed 7 months ago

sigmafelix commented 8 months ago

An example in the package file does not run well due to the ill-formatted bundled data. Below is my modified example:

library(PrestoGP)
library(tidytable)
library(tictoc)
data("US_ST_NO2_Data")

## the data bundled in the package is stored as a "one-column" data.frame
usst = tidytable::separate(US_ST_NO2_Data, names(US_ST_NO2_Data)[1], strsplit(names(US_ST_NO2_Data), "\\.")[[1]], sep="\\,", convert = TRUE)

# Modified from the package example
usst <-
  usst |>
  mutate(date = as.POSIXct(date, format = "%m/%d/%Y")) |>
  filter(date <= as.POSIXct("2018/07/31"))

lat       <- usst$Latitude  # Latitude
lon       <- usst$Longitude # Longitude
logNO2    <-  log(usst$Y)   # ozone data
time      <- usst$YearFrac  # time in fractional years
N         <- length(logNO2)
locs = cbind(lon,lat,time)         # Coordinates in R3 (x,y,t)
X.Design <- usst[,7:145]    #Design matrix
X.Design <- scale(X.Design)
X <- X.Design

model <- PrestoGP::SpatiotemporalModel()
tic()
model <- prestogp_fit(model, logNO2, X, locs, parallel = FALSE, optim.method = "SANN")
toc()
# 26686 obs., July 2018 data
# 142.284 sec elapsed (0.2.0.9003)
# 205.717 sec elapsed (0.2.0.9012)

# Multivariate: error
# Yext <- cbind(logNO2, rgamma(length(logNO2), 2, 0.02))
# model <- MultivariateVecchiaModel()
# tic()
# model <- prestogp_fit(model, Yext, X, locs, parallel = FALSE, optim.method = "SANN")
# toc()
ericbair-sciome commented 8 months ago

The examples (and documentation generally) for PrestoGP are severely outdated. I will work on updating all of this soon.