plot.ru {rust} | R Documentation |
Plot diagnostics for an ru object
Description
plot
method for class "ru"
. For d = 1
a histogram of
the simulated values is plotted with a the density function superimposed.
The density is normalized crudely using the trapezium rule. For
d = 2
a scatter plot of the simulated values is produced with
density contours superimposed. For d > 2
pairwise plots of the
simulated values are produced.
Usage
## S3 method for class 'ru'
plot(
x,
y,
...,
n = ifelse(x$d == 1, 1001, 101),
prob = c(0.1, 0.25, 0.5, 0.75, 0.95, 0.99),
ru_scale = FALSE,
rows = NULL,
xlabs = NULL,
ylabs = NULL,
var_names = NULL,
points_par = list(col = 8)
)
Arguments
x |
an object of class |
y |
Not used. |
... |
Additional arguments passed on to |
n |
A numeric scalar. Only relevant if
|
prob |
Numeric vector. Only relevant for |
ru_scale |
A logical scalar. Should we plot data and density on the
scale used in the ratio-of-uniforms algorithm ( |
rows |
A numeric scalar. When |
xlabs , ylabs |
Numeric vectors. When |
var_names |
A character (or numeric) vector of length |
points_par |
A list of arguments to pass to
|
Value
No return value, only the plot is produced.
See Also
summary.ru
for summaries of the simulated values
and properties of the ratio-of-uniforms algorithm.
Examples
# Log-normal density ----------------
x <- ru(logf = dlnorm, log = TRUE, d = 1, n = 1000, lower = 0, init = 1)
plot(x)
# Improve appearance using arguments to plot() and hist()
plot(x, breaks = seq(0, ceiling(max(x$sim_vals)), by = 0.25),
xlim = c(0, 10))
# Two-dimensional normal with positive association ----------------
rho <- 0.9
covmat <- matrix(c(1, rho, rho, 1), 2, 2)
log_dmvnorm <- function(x, mean = rep(0, d), sigma = diag(d)) {
x <- matrix(x, ncol = length(x))
d <- ncol(x)
- 0.5 * (x - mean) %*% solve(sigma) %*% t(x - mean)
}
x <- ru(logf = log_dmvnorm, sigma = covmat, d = 2, n = 1000, init = c(0, 0))
plot(x)