Skip to content

Instantly share code, notes, and snippets.

View philipp-baumann's full-sized avatar
:atom:
Sensing the environment. WhoeverWhatever-Cares.

Philipp Baumann philipp-baumann

:atom:
Sensing the environment. WhoeverWhatever-Cares.
View GitHub Profile
@philipp-baumann
philipp-baumann / 01_visualize-spectra.R
Last active December 29, 2017 11:47
Visualize spectra
################################################################################
## 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)
@philipp-baumann
philipp-baumann / 02_predict-from-spectra-example.R
Created December 29, 2017 11:55
Predict from spectra and calibrated models
################################################################################
## 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)
################################################################################
## 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")
@philipp-baumann
philipp-baumann / cubist-special-chars-exception.R
Last active January 19, 2019 04:15
Cubist: Special character values in factorial predictors
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)
@philipp-baumann
philipp-baumann / Dockerfile
Created October 6, 2019 16:00
Dockerfile for "A new method for estimating the water retention characteristics and water holding capacity of soils"
# 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'))"
{
"renv": {
"Version": "0.6.0-61"
},
"R": {
"Version": "3.6.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
{
"R": {
"Version": "3.6.1",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
@philipp-baumann
philipp-baumann / _setup-run-all.R
Created October 7, 2019 17:28
Plan and build targets
## 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(
## 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
@philipp-baumann
philipp-baumann / average-spc.R
Created April 15, 2020 08:14
simplerspec: Average spectra in list-column by entries in grouping column
#' @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