plotci: Generic X-Y Plotting with Confidence Intervals

View source: R/plotci.R

plotciR Documentation

Generic X-Y Plotting with Confidence Intervals

Description

Modification to the plot function that adds confidence intervals. The CIs can be plotted using polygons (default) or error bars.

Usage

plotci(x, y, se, level = 0.95, crit.val = NULL, 
       add = FALSE, col = NULL, col.ci = NULL, 
       alpha = NULL, bars = NULL, bw = 0.05, 
       linkinv = NULL, ci = NULL, ...)

Arguments

x

a vector of 'x' values (n by 1). If y is missing, the x input can be a list or matrix containing the x, y, and se arguments.

y

a vector of 'y' values (n by 1).

se

a vector of standard error values (n by 1).

level

confidence level for the intervals (between 0 and 1).

crit.val

an optional critical value for the intervals. If provided, the level input is ignored. See Details.

add

a switch controlling whether a new plot should be created (via a call to plot) or if the plot should be added to the current plot (via a call to lines).

col

a character specifying the color for plotting the lines/points.

col.ci

a character specifying the color for plotting the intervals.

alpha

a scalar between 0 and 1 controlling the transparency of the intervals.

bars

a switch controlling whether the intervals should be plotted as bars or polygons.

bw

a positive scalar controlling the bar width. Ignored if bars = FALSE.

linkinv

an inverse link function for the plotting. If provided, the function plots x versus linkinv(y) and the intervals are similarly transformed.

ci

an optional matrix if dimension n x 2 giving the confidence interval lower and upper bounds: ci = cbind(lwr, upr)

...

extra arguments passed to the plot or lines function.

Details

This function plots x versus y with confidence intervals. Unless ci is provided, the CIs have the form
lwr = y - crit.val * se
upr = y + crit.val * se
where crit.val is the critical value.

If crit.val = NULL, the critival value is determined from the level input as
crit.val <- qnorm(1-(1-level)/2)
where qnorm is the quantile function for the standard normal distribution.

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

See Also

This function is used by plot.ss to plot smoothing spline fits.

Examples

# generate data
set.seed(1)
n <- 100
x <- seq(0, 1, length.out = n)
fx <- 2 + 3 * x + sin(2 * pi * x)
y <- fx + rnorm(n, sd = 0.5)

# fit smooth model
smod <- sm(y ~ x, knots = 10)

# plot fit with 95% CI polygon
plotci(x, smod$fitted.values, smod$se.fit)

# plot fit with 95% CI bars
plotci(x, smod$fitted.values, smod$se.fit, bars = TRUE)

# plot fit +/- 1 SE
plotci(x, smod$fitted.values, smod$se.fit, crit.val = 1, bars = TRUE)


npreg documentation built on May 29, 2024, 4:17 a.m.

Related to plotci in npreg...