movStats | R Documentation |
Moving Estimates Using Overlapping Windows
movStats(
formula,
stat = NULL,
discrete = FALSE,
space = c("n", "x"),
eps = if (space == "n") 15,
varyeps = FALSE,
nignore = 10,
xinc = NULL,
xlim = NULL,
times = NULL,
tunits = "year",
msmooth = c("smoothed", "raw", "both"),
tsmooth = c("supsmu", "lowess"),
bass = 8,
span = 1/4,
maxdim = 6,
penalty = NULL,
trans = function(x) x,
itrans = function(x) x,
loess = FALSE,
ols = FALSE,
qreg = FALSE,
lrm = FALSE,
orm = FALSE,
hare = FALSE,
lrm_args = NULL,
family = "logistic",
k = 5,
tau = (1:3)/4,
melt = FALSE,
data = environment(formula),
pr = c("none", "kable", "plain", "margin")
)
formula |
a formula with the analysis variable on the left and the x-variable on the right, following by optional stratification variables |
stat |
function of one argument that returns a named list of computed values. Defaults to computing mean and quartiles + N except when y is binary in which case it computes moving proportions. If y has two columns the default statistics are Kaplan-Meier estimates of cumulative incidence at a vector of |
discrete |
set to |
space |
defines whether intervals used fixed width or fixed sample size |
eps |
tolerance for window (half width of window). For |
varyeps |
applies to |
nignore |
see description, default is to exclude |
xinc |
increment in x to evaluate stats, default is xlim range/100 for |
xlim |
2-vector of limits to evaluate if |
times |
vector of times for evaluating one minus Kaplan-Meier estimates |
tunits |
time units when |
msmooth |
set to |
tsmooth |
defaults to the super-smoother |
bass |
the |
span |
the |
maxdim |
passed to |
penalty |
passed to |
trans |
transformation to apply to x |
itrans |
inverse transformation |
loess |
set to TRUE to also compute loess estimates |
ols |
set to TRUE to include rcspline estimate of mean using ols |
qreg |
set to TRUE to include quantile regression estimates w rcspline |
lrm |
set to TRUE to include logistic regression estimates w rcspline |
orm |
set to TRUE to include ordinal logistic regression estimates w rcspline (mean + quantiles in |
hare |
set to TRUE to include hazard regression estimtes of incidence at |
lrm_args |
a |
family |
link function for ordinal regression (see |
k |
number of knots to use for ols and/or qreg rcspline |
tau |
quantile numbers to estimate with quantile regression |
melt |
set to TRUE to melt data table and derive Type and Statistic |
data |
data.table or data.frame, default is calling frame |
pr |
defaults to no printing of window information. Use |
Function to compute moving averages and other statistics as a function
of a continuous variable, possibly stratified by other variables.
Estimates are made by creating overlapping moving windows and
computing the statistics defined in the stat function for each window.
The default method, space='n'
creates varying-width intervals each having a sample size of 2*eps +1
, and the smooth estimates are made every xinc
observations. Outer intervals are not symmetric in sample size (but the mean x in those intervals will reflect that) unless eps=nignore
, as outer intervals are centered at observations nignore
and n - nignore + 1
where the default for nignore
is 10. The mean x-variable within each windows is taken to represent that window. If trans
and itrans
are given, x means are computed on the trans(x)
scale and then itrans
'd. For space='x'
, by default estimates are made on to the nignore
smallest to the nignore
largest
observed values of the x variable to avoid extrapolation and to
help getting the moving statistics off on an adequate start for
the left tail. Also by default the moving estimates are smoothed using supsmu
.
When melt=TRUE
you can feed the result into ggplot
like this:
ggplot(w, aes(x=age, y=crea, col=Type)) + geom_line() +
facet_wrap(~ Statistic)
See here for several examples.
a data table, with attribute infon
which is a data frame with rows corresponding to strata and columns N
, Wmean
, Wmin
, Wmax
if stat
computed N
. These summarize the number of observations used in the windows. If varyeps=TRUE
there is an additional column eps
with the computed per-stratum eps
. When space='n'
and xinc
is not given, the computed xinc
also appears as a column. An additional attribute info
is a kable
object ready for printing to describe the window characteristics.
Frank Harrell
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.