~ubuntu-branches/debian/sid/r-cran-emmeans/sid

« back to all changes in this revision

Viewing changes to man/emtrends.Rd

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2018-03-04 19:13:28 UTC
  • Revision ID: package-import@ubuntu.com-20180304191328-szjtzuij7pz3rgob
Tags: upstream-1.1.2
ImportĀ upstreamĀ versionĀ 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
% Generated by roxygen2: do not edit by hand
 
2
% Please edit documentation in R/emtrends.R
 
3
\name{emtrends}
 
4
\alias{emtrends}
 
5
\title{Estimated marginal means of linear trends}
 
6
\usage{
 
7
emtrends(model, specs, var, delta.var = 0.01 * rng, data,
 
8
  transform = c("none", "response"), ...)
 
9
}
 
10
\arguments{
 
11
\item{model}{A supported model object (\emph{not} a reference grid)}
 
12
 
 
13
\item{specs}{Specifications for what marginal trends are desired -- as in
 
14
\code{\link{emmeans}}}
 
15
 
 
16
\item{var}{Character value giving the name of a variable with respect to 
 
17
which a difference quotient of the linear predictors is computed. In order
 
18
for this to be useful, \code{var} should be a numeric predictor that
 
19
interacts with at least one factor in \code{specs}. Then instead of
 
20
computing EMMs, we compute and compare the slopes of the \code{var} trend
 
21
over levels of the specified other predictor(s). As in EMMs, marginal
 
22
averages are computed for the predictors in \code{specs} and \code{by}.
 
23
See also the \dQuote{Generalizations} section below.}
 
24
 
 
25
\item{delta.var}{The value of \emph{h} to use in forming the difference
 
26
quotient \eqn{(f(x+h) - f(x))/h}. Changing it (especially changing its
 
27
sign) may be necessary to avoid numerical problems such as logs of negative
 
28
numbers. The default value is 1/100 of the range of \code{var} over the
 
29
dataset.}
 
30
 
 
31
\item{data}{As in \code{\link{ref_grid}}, you may use this argument to supply
 
32
the dataset used in fitting the model, for situations where it is not
 
33
possible to reconstruct the data. Otherwise, leave it missing.}
 
34
 
 
35
\item{transform}{If \code{object} has a response
 
36
transformation or link function, then specifying 
 
37
\code{transform = "response"} will cause
 
38
\code{emtrends} to calculate the trends after back-transforming to the
 
39
response scale. This is done using the chain rule, and standard errors are
 
40
estimated via the delta method. With \code{transform = "none"} (the
 
41
default), the trends are calculated on the scale of the linear predictor,
 
42
without back-transforming it. This argument works similarly to the
 
43
\code{transform} argument in \code{\link{ref_grid}}, in that the returned
 
44
object is re-gridded to the new scale (see also \code{\link{regrid}}).}
 
45
 
 
46
\item{...}{Additional arguments passed to other methods or to 
 
47
\code{\link{ref_grid}}}
 
48
}
 
49
\value{
 
50
An \code{emmGrid} or \code{emm_list} object, according to \code{specs}.
 
51
See \code{\link{emmeans}} for more details on when a list is returned.
 
52
}
 
53
\description{
 
54
The \code{emtrends} function is useful when a fitted model involves a
 
55
numerical predictor \eqn{x}  interacting with another predictor \code{a}
 
56
(typically a factor). Such models specify that \eqn{x} has a different trend
 
57
depending on \eqn{a}; thus, it may be of interest to estimate and compare
 
58
those trends. Analogous to the \code{\link{emmeans}} setting, we construct a
 
59
reference grid of these predicted trends, and then possibly average them over
 
60
some of the predictors in the grid.
 
61
}
 
62
\section{Generalizations}{
 
63
 
 
64
Instead of a single predictor, the user may specify some monotone function of
 
65
one variable, e.g., \code{var = "log(dose)"}. If so, the chain rule is
 
66
applied. Note that, in this example, if \code{model} contains
 
67
\code{log(dose)} as a predictor, we will be comparing the slopes estimated by
 
68
that model, whereas specifying \code{var = "dose"} would perform a
 
69
transformation of those slopes, making the predicted trends vary depending on
 
70
\code{dose}.
 
71
}
 
72
 
 
73
\examples{
 
74
fiber.lm <- lm(strength ~ diameter*machine, data=fiber)
 
75
# Obtain slopes for each machine ...
 
76
( fiber.emt <- emtrends(fiber.lm, "machine", var = "diameter") )
 
77
# ... and pairwise comparisons thereof
 
78
pairs(fiber.emt)
 
79
 
 
80
# Suppose we want trends relative to sqrt(diameter)...
 
81
emtrends(fiber.lm, ~ machine | diameter, var = "sqrt(diameter)", 
 
82
         at = list(diameter = c(20, 30)))
 
83
 
 
84
}
 
85
\seealso{
 
86
\code{link{emmeans}}, \code{\link{ref_grid}}
 
87
}