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
# Weird behaviour of predict.bam() | |
# packages | |
library("mgcv") | |
# simulate some data | |
set.seed(42) | |
df <- gamSim(1, n = 10000) | |
# fit a bam with and without discrete = TRUE and a gam |
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
#' Create a random effect basis with integers rather than factors | |
#' @import mgcv | |
#' @export | |
smooth.construct.re2.smooth.spec <- function (object, data, knots) { | |
if (!is.null(object$id)) | |
stop("random effects don't work with ids.") | |
if(any(sapply(data, is.numeric))) data <- lapply(data, as.factor) ## <-- All I did was this (and below) | |
form <- as.formula(paste("~", paste(object$term, collapse = ":"), | |
"-1")) | |
object$X <- model.matrix(form, data) |
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
## Can we do better extrapolation than the TPRS example used by Gabriel | |
## Riutort-Mayol et al in their recent paper on low rank approximations to | |
## Gaussian Processes? https://arxiv.org/abs/2004.11408 | |
## Packages | |
library('ggplot2') | |
library('tibble') | |
library('tidyr') | |
library('dplyr') | |
library('mgcv') |
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
## plots and animations of how basis functions are used to make | |
## splines and how these are fitted to data | |
library('ggplot2') | |
library('tibble') | |
library('tidyr') | |
library('dplyr') | |
library('mgcv') | |
library('mvnfast') | |
library('purrr') |
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
## Procuces an animation showing how weighted basis functions combine to produce a sline | |
## - this version is for a cubic regression spline basis | |
## packages required | |
library('ggplot2') | |
library('tibble') | |
library('tidyr') | |
library('dplyr') | |
library('mgcv') | |
library('mvnfast') |
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
Sample | upperDepth | lowerDepth | ageBP | ageError | calUpper | calLower | |
---|---|---|---|---|---|---|---|
SRR-4556 | 20 | 22 | 355 | 35 | 509 | 307 | |
SRR-4557 | 26 | 28 | 465 | 35 | 542 | 480 | |
SRR-4558 | 32 | 34 | 635 | 35 | 671 | 545 | |
SRR-4559 | 38 | 40 | 740 | 35 | 732 | 666 | |
SRR-4560 | 44 | 46 | 865 | 35 | 916 | 691 | |
SRR-4561 | 50 | 52.5 | 870 | 35 | 918 | 692 | |
SRR-4562 | 56 | 58 | 985 | 35 | 967 | 795 | |
SRR-4563 | 100 | 108 | 1270 | 35 | 1284 | 1097 | |
SRR-4564 | 200 | 207 | 2575 | 35 | 2761 | 2558 |
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
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
## leafHeight is in cm.; visited, 1 == TRUE, 0 == FALSE" | |
"leafHeight","visited" | |
67,1 | |
84,1 | |
49,1 | |
70,1 | |
77,1 | |
77,1 | |
66,1 | |
65,1 |
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 5 in line 1.
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
## Subset of data used in Rose et al (2012) Geochimica et Cosmochimica Acta 82, 113–135 doi: http://doi.org/10.1016/j.gca.2010.12.026 | |
SiteCode,Date,SoilType,Region,Hg | |
CHNA,2000,thin,NW,3.84339855275794 | |
CHNA,1990,thin,NW,5.42461797827638 | |
CHNA,1980,thin,NW,8.81972984714937 | |
CHNA,1970,thin,NW,11.4174572948292 | |
CHNA,1960,thin,NW,16.513540420367 | |
CHNA,1950,thin,NW,16.5120469510654 | |
CHNA,1940,thin,NW,11.1888397621818 | |
CHNA,1930,thin,NW,11.6222216338607 |
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
## Compare Brooks et al glmmTMB paper with mgcv | |
## Packages | |
library("glmmTMB") | |
library("mgcv") | |
library("ggplot2") | |
theme_set(theme_bw()) | |
library("ggstance") | |
## Salamander |
NewerOlder