knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

stNet

The goal of stNet is to remove the heterogeneity bewteen spatiotemporal data by fusing the spatial and temporal feature with mapping to the desired scale.

Installation

You can install the released version of stNet from CRAN with:

devtools::install_github("WeiquanLuo/stNet")
# install.packages("stNet") # not yet avaliable

Workflow

Workflow for rivertopo{width=100%}

Example

This is a basic example which shows a workflow of using $stNet$ functionality:

library(stNet)
# load data
data(corn_yield_sf); corn_yield_st <- corn_yield_sf # polygon sf object
data(weather_tmin_sf); weather_tmin_st <- weather_tmin_sf # point sf object
data(water_Temperature_sf); water_Temperature_st <- water_Temperature_sf # point sf object

# Visualization the data
plot(sf::st_geometry(corn_yield_st))
plot(sf::st_geometry(weather_tmin_st), col = "blue", add = TRUE)
plot(sf::st_geometry(water_Temperature_st), col = "red", add = TRUE)

Step 1 fuse the spatio heterogeneity: spatio_fuse()

yield_tmin_t <- spatio_fuse(target_stN = corn_yield_st,
                            data_stN = weather_tmin_st,
                            parm_nm = "tmin",
                            crs = 2163)

yield_watertem_t <- spatio_fuse(target_stN = corn_yield_st,
                                data_stN = water_Temperature_st,
                                parm_nm = "watertem",
                                crs = 2163)
yield_watertem_t
yield_watertem_t$target[[1]]
yield_watertem_t$predictor[[1]]

Step 2: fuse temporal heterogeneity: tempo_fuse()

yield_tmin <- tempo_fuse(target_data = yield_tmin_t,
                          date_col = c("Year", "Date"),
                          scaling = c("Year","Month"),
                          aggMethod = c("mean","min"))

yield_watertem <- tempo_fuse(target_data = yield_watertem_t,
                          date_col = c("Year", "Date"),
                          scaling = c("Year","Month"),
                          aggMethod = c("mean","min"))
yield_watertem
yield_watertem$data[[1]]

Step 3: bind multiple homogeneous spatiotemporal data into a single object

If there multiple parameter for the same target varible, we can use cbind_TargetDatas() to join them. For example, joining two objects yield_tmin and yield_tmax by join_by = "Year" with anchoring the target varialbe target = "yield":

bind_data <- cbind_TargetDatas(yield_tmin, yield_watertem, 
                               target = "yield", join_by = "Year"); bind_data; bind_data$data[[1]]

Afterword: Fit Your Model!

After fusing the spatial and temporal heterogeneity of the data, you can use other generic modeling technique to do analysis. For example:

# fitmodel = lm
fitmodel <- function(data){
  model <- lm(yield ~ ., data=data %>% na.omit() %>% dplyr::select(-Year))
  return(model)
}
F_model <- yield_tmin %>%
  dplyr::mutate(model = data %>% purrr::map(fitmodel)) %>% 
  dplyr::mutate(statisics = model %>% purrr::map(.f = function(m) broom::glance(m))) %>%
  tidyr::unnest(statisics); F_model


WeiquanLuo/stNet documentation built on Nov. 24, 2019, 5:11 p.m.