knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Create random chill and yield data using sample().

chill <- sample(x = 1:50, size = 20, replace = TRUE)
yield <- sample(x = 1000:5000, size = 20, replace = TRUE)

Using chillscatter() create a chill portions (x) and yield (y) scatter plot with associated and estimated densities with loess smooth linear fits density curves. Plot made with the scatter.hist() function in the plyr() package (Wickham 2011) in R (R Core Team 2017).

pasitR::chillscatter(chill, yield)

Use chillkernel() or another type of graphical representation of the same relationship. chillkernel() performs a two-dimensional kernel density estimation for yield and chill using the kde2d() function in the MASS() package (Venables and Ripley 2002). The function produces a matrix of the estimated density (z) of yield (y) and chill (x). As the density function restricts the shape of the kernel to a bivariate normal kernel, it looks slightly different compared to the scatter plot estimates above.

pasitR::chillkernel(chill, yield)

chillkernel() shows a density surface plot of chill portions (x) and yield (y). The legend shows the value for the estimated density (z). The plot is made with the filled.contour() function of the graphics() package.

In chillkernel() the density (z) over the entire plot integrates to one, and therefore represents the relative probability of an observation (yield along y-axis) given a specific chill portion (along x-axis).

Estimated yield given the expected chill

chillkernelslice() calculates the estimated yield given the expected chill, based on a slice of 'z' from the Kernel density calcualted with chillkernel(). The expectedchill parameter is set to 30.

pasitR::chillkernelslice(chill, yield, expectedchill = 30)

chillkernelslice() plots the probabilities (shown along the y-axis) for the expected yield (shown along the x-axis). Since this is a cut through the density kernel chillkernel(), which integrates to 1, the probability values are relative, not absolute measures.

Chill portion intervals

chillviolin() determines different possible chill portion intervals by calculating the optimal interval width for chill portions using the IQR() function in the stats() package, after the Freedman-Diaconis rule (IQR = interquartile range). Optimal interval width for our sample = 2 * interquartile range for our sample / (total number of observations for the interquartile range for our sample)^(1/3)

pasitR::chillviolin(chill, yield)

chillviolin() shows violin plots of chill portions (x) and yield (y) with six different intervals of chill portions. Plot made with ggplot2() (Wickham 2016).

Probability of yield given chill

chillkernelslicerange() The chill portion intervals, optimized interquartile ranges shown in chillviolin() can be used to select a range to slice from the density kernel chillkernel() as was doen for a single chill value in chillkernelslice(). Here we set the maximum chill to 20 and the minimum to 10.

pasitR::chillkernelslicerange(chill, yield, 10, 20)

chillkernelslicerange() plots the probabilities (shown along the y-axis) for the expected yield (shown along the x-axis). As with chillkernelslice() the probability values shown are relative, not absolute measures. They are the result of cuts through the density kernel chillkernel(), which integrates to 1.

References

R Core Team (2017) R: A Language and Environment for Statistical Computing [R Version 3.4.1 (2017-06-30) “Single Candle”] 3.4.1.

Venables, W. N., and B. D. Ripley (2002) Modern Applied Statistics with S. Fourth Edition. New York: Springer.

Wickham, Hadley (2011) Plyr: Tools for Splitting, Applying and Combining Data, Version 1.4. Available Online at Cran. r-Project. Elegant Graphics for Data Analysis. Springer.



CWWhitney/pasitR documentation built on March 30, 2021, 5:36 a.m.