Title: | Fertilizer Response Curve Analysis by Bootstrapping Residuals |
---|---|
Description: | Quantify variability (such as confidence interval) of fertilizer response curves and optimum fertilizer rates using bootstrapping residuals with several popular non-linear and linear models. |
Authors: | Ting Fung (Ralph) Ma [cre, aut], Hannah Francis [aut], Matt Ruark [ctb] |
Maintainer: | Ting Fung (Ralph) Ma <[email protected]> |
License: | GPL-2 |
Version: | 0.5.0 |
Built: | 2024-12-04 07:03:07 UTC |
Source: | CRAN |
Bootstrap confidence intervals of mean
boot.CI(x, alpha = 0.05, CI.type = "all")
boot.CI(x, alpha = 0.05, CI.type = "all")
x |
a vector of observation |
alpha |
significance level (default: 0.05) |
CI.type |
type of CI required (default: "all") |
boot.CI
return list of confidence intervals of mean (CI.percent
: percentile, CI.BC
: bias-corrected and CI.BCa
: bias-corrected and accelerated).
set.seed(12) boot.CI(rnorm(1000, mean=0, sd=1), alpha=0.05, CI.type="per") # example of wrong input for type boot.CI(rnorm(1000, mean=0, sd=1), alpha=0.05, CI.type="all") # require all type
set.seed(12) boot.CI(rnorm(1000, mean=0, sd=1), alpha=0.05, CI.type="per") # example of wrong input for type boot.CI(rnorm(1000, mean=0, sd=1), alpha=0.05, CI.type="all") # require all type
boot.resid.linear.plateau
is the core function to implement bootstrapping residuals on linear plateau models, which assumes
y ~ a + b * (x - c) * (x <= c). Note that this function may take minutes up to days. Parallel computing may be necessary.
We suggest users start with a smaller B
and moderate n.start to see if the bootstrap models can converge.
In general, increasing n.start and plus_minus may help with ease of convergence. For rigorous statistical inference, B should be on the order of a thousand.
boot.resid.linear.plateau( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 100, n.start = 1000, print.progress = TRUE )
boot.resid.linear.plateau( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 100, n.start = 1000, print.progress = TRUE )
mod |
a full model list, probably from |
data |
data frame with two columns ( |
x.range |
vector of data.frame with one column for range of N rate of interested for prediction interval |
B |
bootstrap sample size |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
print.progress |
logical flag whether printing progress |
boot.resid.linear.plateau
returns a list of two elements:
result
: matrix with B rows and columns containing bootstrap sample for parameter (a,b,c
), optimal N and yield (max_x, max_y
), log-likelihood (logLik
) and N values of interest;
x.range
: range of x considered for prediction interval (same as x.range
in vector form)
set.seed(1) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- 100 y <- a + b * (x - c) * (x <= c) + rnorm(length(x), sd=1) d <- cbind(x,y) # a converged example: ans <- f.linear.plateau(d, start=list(a = 7, b = 0.1, c = 150), plus_minus=10, n.start=10, msg=FALSE) ans.boot <- boot.resid.linear.plateau(ans, d, x.range=seq(0,280,by=40), B=9, plus_minus = 1e2, n.start=1000, print.progress=TRUE) # use larger B for inference
set.seed(1) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- 100 y <- a + b * (x - c) * (x <= c) + rnorm(length(x), sd=1) d <- cbind(x,y) # a converged example: ans <- f.linear.plateau(d, start=list(a = 7, b = 0.1, c = 150), plus_minus=10, n.start=10, msg=FALSE) ans.boot <- boot.resid.linear.plateau(ans, d, x.range=seq(0,280,by=40), B=9, plus_minus = 1e2, n.start=1000, print.progress=TRUE) # use larger B for inference
boot.resid.linear.plateau
is the core function to implement bootstrapping residuals on quadratic models, which assumes
y ~ a+b*x+c*x^2. Note that this function may take minutes up to days. Parallel computing may be necessary.
We suggest users start with a smaller B
and moderate n.start to see if the bootstrap models can converge.
In general, increasing n.start and plus_minus may help with ease of convergence. For rigorous statistical inference, B should be on the order of a thousand.
boot.resid.quad( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 10, n.start = 20, print.progress = TRUE )
boot.resid.quad( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 10, n.start = 20, print.progress = TRUE )
mod |
a full model list, probably from |
data |
data frame with two columns ( |
x.range |
vector of data.frame with one column for range of N rate of interested for prediction interval |
B |
bootstrap sample size |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
print.progress |
logical flag whether printing progress |
boot.resid.quad.plateau
returns a list of two elements:
result
: matrix with B rows and columns containing bootstrap sample for parameter (a,b,c
), optimal N and yield (max_x, max_y
), log-likelihood (logLik
) and N values of interest;
x.range
: range of x considered for prediction interval (same as x.range
in vector form)
set.seed(1) x <- rep(1:300, each=5) a <- 8; b <- 0.05; c <- -1e-3 y <- (a + b * x + c *x^2) + rnorm(length(x), sd=0.1) d <- cbind(x,y) ans <- f.quad(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) ans.boot <- boot.resid.quad(ans, d, x.range=seq(0,280,by=40), B=1e1-1, plus_minus = 1e1, n.start=20, print.progress=TRUE) # use larger B for inference
set.seed(1) x <- rep(1:300, each=5) a <- 8; b <- 0.05; c <- -1e-3 y <- (a + b * x + c *x^2) + rnorm(length(x), sd=0.1) d <- cbind(x,y) ans <- f.quad(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) ans.boot <- boot.resid.quad(ans, d, x.range=seq(0,280,by=40), B=1e1-1, plus_minus = 1e1, n.start=20, print.progress=TRUE) # use larger B for inference
boot.resid.quad.plateau
is the core function to implement bootstrapping residuals on quadratic plateau models, which assumes
y = (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c). Note that this function may take minutes up to days. Parallel computing may be necessary.
We suggest users start with a smaller B
and moderate n.start to see if the bootstrap models can converge.
In general, increasing n.start and plus_minus may help with ease of convergence. For rigorous statistical inference, B should be on the order of a thousand.
boot.resid.quad.plateau( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 100, n.start = 5000, print.progress = TRUE )
boot.resid.quad.plateau( mod, data, x.range = data.frame(x = seq(0, 280, by = 40)), B = 100 - 1, plus_minus = 100, n.start = 5000, print.progress = TRUE )
mod |
a full model list, probably from |
data |
data frame with two columns ( |
x.range |
vector of data.frame with one column for range of N rate of interested for prediction interval |
B |
bootstrap sample size |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
print.progress |
logical flag whether printing progress |
boot.resid.quad.plateau
returns a list of two elements:
result
: matrix with B rows and columns containing bootstrap sample for parameter (a,b,c
), optimal N and yield (max_x, max_y
), log-likelihood (logLik
) and N values of interest;
x.range
: range of x considered for prediction interval (same as x.range
in vector form)
set.seed(1) x <- rep(1:300, each=5) a <- 8; b <- 0.05; c <- -1e-4 y <- (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) ans <- f.quad.plateau(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) boot.resid.quad.plateau(ans, d, x.range=seq(0,280,by=40), B=1e1-1, plus_minus = 1e2, n.start=1000, print.progress=TRUE) # use larger B for inference
set.seed(1) x <- rep(1:300, each=5) a <- 8; b <- 0.05; c <- -1e-4 y <- (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) ans <- f.quad.plateau(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) boot.resid.quad.plateau(ans, d, x.range=seq(0,280,by=40), B=1e1-1, plus_minus = 1e2, n.start=1000, print.progress=TRUE) # use larger B for inference
sample1
and sample2
, not necessary with same sample sizeTwo sample bootstrap test for comparing different in sample1
and sample2
, not necessary with same sample size
compare.two.sample(sample1, sample2, fun = mean, R = 1000)
compare.two.sample(sample1, sample2, fun = mean, R = 1000)
sample1 |
first sample |
sample2 |
second sample |
fun |
statistic (univariate) to be compared (default: |
R |
number of resamples (default: |
compare.two.sample
return a list with two components, namely,
p.value
: two tailed p-value for the bootstrap test
object
: a "simpleboot
" object allowing further analysis using other R packages, such as boot
)
set.seed(1203) # compare median of two expontential r.v. compare.two.sample(rexp(100, rate=1), rexp(100, rate=2), fun=median, R=1e3)$p.value f.Q1 <- function(x) quantile(x, probs=0.25) compare.two.sample(rnorm(100, mean=0), rnorm(200, mean=0.5), fun=f.Q1, R=1e3)$p.value
set.seed(1203) # compare median of two expontential r.v. compare.two.sample(rexp(100, rate=1), rexp(100, rate=2), fun=median, R=1e3)$p.value f.Q1 <- function(x) quantile(x, probs=0.25) compare.two.sample(rnorm(100, mean=0), rnorm(200, mean=0.5), fun=f.Q1, R=1e3)$p.value
f.linear.plateau
fits linear plateau model using multiple initial values. The multiple initial values are randomly sampled in a "cube" of parameter space.
More precisely, linear plateau model assumes y ~ a + b * (x - c) * (x <= c).
f.linear.plateau( d, start = list(a = 1, b = 1, c = 1), plus_minus = 100, n.start = 1000, msg = FALSE )
f.linear.plateau( d, start = list(a = 1, b = 1, c = 1), plus_minus = 100, n.start = 1000, msg = FALSE )
d |
data frame with two columns ( |
start |
initial estimate for non-linear least square (default value: |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
msg |
logical flag whether printing progress |
f.linear.plateau
returns a list of two components (if converged): nls.summary
: summary of the fitted model; nls.model
: nls object
set.seed(4) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- 100 y <- a + b * (x - c) * (x <= c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.linear.plateau(d, start=list(a = 7, b = 0.1, c = 150), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)
set.seed(4) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- 100 y <- a + b * (x - c) * (x <= c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.linear.plateau(d, start=list(a = 7, b = 0.1, c = 150), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)
f.quad
fits quadratic model using multiple initial values. The multiple initial values are randomly sampled in a "cube" of parameter space. More precisely, quadratic model assumes
y ~ a+b*x+c*x^2,
f.quad( d, start = list(a = 1, b = 1, c = 1), plus_minus = 1, n.start = 10, msg = FALSE )
f.quad( d, start = list(a = 1, b = 1, c = 1), plus_minus = 1, n.start = 10, msg = FALSE )
d |
data frame with two columns ( |
start |
initial estimate for non-linear least square (default value: |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
msg |
logical flag whether printing progress |
f.quad
returns a list of two components (if converged): nls.summary
: summary of the fitted model; nls.model
: nls object
set.seed(1) x <- rep(1:300, each=2) a <- 8; b <- 0.05; c <- -1e-3 y <- a + b*x + c*x^2 + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.quad(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)
set.seed(1) x <- rep(1:300, each=2) a <- 8; b <- 0.05; c <- -1e-3 y <- a + b*x + c*x^2 + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.quad(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)
f.quad.plateau
fits quadratic plateau model using multiple initial values. The multiple initial values are randomly sampled in a "cube" of parameter space. More precisely, quadratic plateau model assumes
y ~ (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c).
f.quad.plateau( d, start = list(a = 1, b = 1, c = 1), plus_minus = 100, n.start = 1000, msg = FALSE )
f.quad.plateau( d, start = list(a = 1, b = 1, c = 1), plus_minus = 100, n.start = 1000, msg = FALSE )
d |
data frame with two columns ( |
start |
initial estimate for non-linear least square (default value: |
plus_minus |
radius of random initial values (default: |
n.start |
total number of initial points considered (default: |
msg |
logical flag whether printing progress |
f.quad.plateau
returns a list of two components (if converged): nls.summary
: summary of the fitted model; nls.model
: nls object
set.seed(3) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- -1e-4 y <- (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.quad.plateau(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)
set.seed(3) x <- rep(1:300, each=4) a <- 8; b <- 0.05; c <- -1e-4 y <- (a + b * x + c *x^2) * (x <= -0.5*b/c) + (a + -b^2/(4 * c)) * (x > -0.5 * b/c) + rnorm(length(x), sd=0.1) d <- cbind(x,y) # a converged example: ans <- f.quad.plateau(d, start=list(a = 7, b = 0.02, c = 1e-5), plus_minus=10, n.start=10, msg=FALSE) summary(ans$nls.model)