This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
## Task: Example script to visualize spectra in simplerspec framework | |
################################################################################ | |
# Remove all R objects from memory | |
rm(list = ls()) | |
# Load packages | |
pkgs <- c("tidyverse", "simplerspec") | |
lapply(pkgs, library, character.only = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
## Task: Example script to predict spectra in simplerspec framework | |
################################################################################ | |
# Remove all R objects from memory | |
rm(list = ls()) | |
# Load packages | |
pkgs <- c("tidyverse", "simplerspec") | |
lapply(pkgs, library, character.only = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
## Task: Select reference samples for soil refence analyses by using | |
## Kennard-Stones | |
## sampling algorithm on preprocessed spectra in PCA space | |
################################################################################ | |
# Load packages | |
library("tidyverse") | |
library("simplerspec") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkgs <- c("mlbench", "Cubist") | |
lapply(pkgs, library, character.only = TRUE) | |
# Example data set | |
data(BostonHousing) | |
# Test with only 2 factorial predictors | |
boston_housing <- BostonHousing[, c("crim", "zn", "medv")] | |
# Convert numeric `crim` and `zn` to factors | |
boston_housing$zn <- as.factor(boston_housing$zn) | |
boston_housing$crim <- as.factor(boston_housing$crim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pull docker image (includes RStudio server) | |
FROM rocker/rstudio:3.6.0 | |
RUN apt-get update \ | |
&& apt-get install -y --no-install-recommends \ | |
libz-dev \ | |
libxml2-dev | |
ENV RENV_VERSION 0.7.0-111 | |
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"renv": { | |
"Version": "0.6.0-61" | |
}, | |
"R": { | |
"Version": "3.6.1", | |
"Repositories": [ | |
{ | |
"Name": "CRAN", | |
"URL": "https://cloud.r-project.org" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"R": { | |
"Version": "3.6.1", | |
"Repositories": [ | |
{ | |
"Name": "CRAN", | |
"URL": "https://cloud.r-project.org" | |
} | |
] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Load packages | |
pkgs <- c("here", "drake", "tidyverse", "data.table", | |
"simplerspec", "caret", "Cubist", "rsample", "nls.multstart", | |
"broom", # modeling | |
"future", "future.apply", "doParallel", "doFuture", # asynchronous computation | |
"gghighlight", "grid", "gridExtra", "cowplot", # graphics | |
"xtable") # tables | |
purrr::walk(pkgs, library, character.only = TRUE) | |
funs <- list( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Wrangle results of nested group k-fold cross-validation ===================== | |
# Add additional grouping IDs | |
cubist_nested_results_ids <- cubist_nested_add_ids( | |
object = cubist_nested_results_repgroupcv, x_vars = "spc_pre", | |
id_cols = c("site_id", "depth_cm"), | |
y_vars = param_names, | |
custom_spc_averaging = FALSE) | |
# Get predicted and observed values for each outer resample assessment set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @title Average spectra in list-column by entries in grouping column | |
#' @description Average spectra in list-column of spectra tibble (`spc_tbl`) by | |
#' groups given in group column. | |
#' @param spc_tbl Tibble data frame containing at least the grouping column | |
#' given in argument `by` and input spectra given in list-column `column_in`. | |
#' @param by Character vector of length 1L or name/symbol that specifies the | |
#' column by which groups of spectra are averaged. Default is `"sample_id"`. | |
#' @param column_in Character vector of length 1L or or name/symbol that | |
#' specifies the list-column that contains the inputs spectra to be averaged. | |
#' Default is `"spc_rs"`, which are resampled spectra (i.e., resulting after |
OlderNewer