Debian Codegraph @

man/augment.sarlm.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/spdep.R
3 \name{augment.sarlm}
4 \alias{augment.sarlm}
5 \title{Augment data with information from a(n) spatialreg object}
6 \usage{
7 \method{augment}{sarlm}(x, data = x$X, ...)
8 }
9 \arguments{
10 \item{x}{An object returned from \code{\link[spatialreg:ML_models]{spatialreg::lagsarlm()}}
11 or \code{\link[spatialreg:ML_models]{spatialreg::errorsarlm()}}.}
12
13 \item{data}{Ignored, but included for internal consistency. See the details
14 below.}
15
16 \item{...}{Additional arguments. Not used. Needed to match generic
17 signature only. \strong{Cautionary note:} Misspelled arguments will be
18 absorbed in \code{...}, where they will be ignored. If the misspelled
19 argument has a default value, the default value will be used.
20 For example, if you pass \code{conf.lvel = 0.9}, all computation will
21 proceed using \code{conf.level = 0.95}. Two exceptions here are:
22 \itemize{
23 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
24 it will be ignored.
25 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
26 will be ignored.
27 }}
28 }
29 \description{
30 Augment accepts a model object and a dataset and adds
31 information about each observation in the dataset. Most commonly, this
32 includes predicted values in the \code{.fitted} column, residuals in the
33 \code{.resid} column, and standard errors for the fitted values in a \code{.se.fit}
34 column. New columns always begin with a \code{.} prefix to avoid overwriting
35 columns in the original dataset.
36
37 Users may pass data to augment via either the \code{data} argument or the
38 \code{newdata} argument. If the user passes data to the \code{data} argument,
39 it \strong{must} be exactly the data that was used to fit the model
40 object. Pass datasets to \code{newdata} to augment data that was not used
41 during model fitting. This still requires that at least all predictor
42 variable columns used to fit the model are present. If the original outcome
43 variable used to fit the model is not included in \code{newdata}, then no
44 \code{.resid} column will be included in the output.
45
46 Augment will often behave differently depending on whether \code{data} or
47 \code{newdata} is given. This is because there is often information
48 associated with training observations (such as influences or related)
49 measures that is not meaningfully defined for new observations.
50
51 For convenience, many augment methods provide default \code{data} arguments,
52 so that \code{augment(fit)} will return the augmented training data. In these
53 cases, augment tries to reconstruct the original data based on the model
54 object with varying degrees of success.
55
56 The augmented dataset is always returned as a \link[tibble:tibble]{tibble::tibble} with the
57 \strong{same number of rows} as the passed dataset. This means that the passed
58 data must be coercible to a tibble. If a predictor enters the model as part
59 of a matrix of covariates, such as when the model formula uses
60 \code{\link[splines:ns]{splines::ns()}}, \code{\link[stats:poly]{stats::poly()}}, or \code{\link[survival:Surv]{survival::Surv()}}, it is represented
61 as a matrix column.
62
63 We are in the process of defining behaviors for models fit with various
64 \code{na.action} arguments, but make no guarantees about behavior when data is
65 missing at this time.
66 }
67 \details{
68 The predict method for sarlm objects assumes that the response is
69 known. See ?predict.sarlm for more discussion. As a result, since the
70 original data can be recovered from the fit object, this method
71 currently does not take in \code{data} or \code{newdata} arguments.
72 }
73 \examples{
74 \dontshow{if (rlang::is_installed(c("spdep", "spatialreg")) && identical(Sys.getenv("NOT_CRAN"), "true")) withAutoprint(\{ # examplesIf}
75
76
77 # load libraries for models and data
78 library(spatialreg)
79 library(spdep)
80
81 # load data
82 data(oldcol, package = "spdep")
83
84 listw <- nb2listw(COL.nb, style = "W")
85
86 # fit model
87 crime_sar <-
88 lagsarlm(CRIME ~ INC + HOVAL,
89 data = COL.OLD,
90 listw = listw,
91 method = "eigen"
92 )
93
94 # summarize model fit with tidiers
95 tidy(crime_sar)
96 tidy(crime_sar, conf.int = TRUE)
97 glance(crime_sar)
98 augment(crime_sar)
99
100 # fit another model
101 crime_sem <- errorsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw)
102
103 # summarize model fit with tidiers
104 tidy(crime_sem)
105 tidy(crime_sem, conf.int = TRUE)
106 glance(crime_sem)
107 augment(crime_sem)
108
109 # fit another model
110 crime_sac <- sacsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw)
111
112 # summarize model fit with tidiers
113 tidy(crime_sac)
114 tidy(crime_sac, conf.int = TRUE)
115 glance(crime_sac)
116 augment(crime_sac)
117 \dontshow{\}) # examplesIf}
118 }
119 \seealso{
120 \code{\link[=augment]{augment()}}
121
122 Other spatialreg tidiers:
123 \code{\link{glance.sarlm}()},
124 \code{\link{tidy.sarlm}()}
125 }
126 \concept{spatialreg tidiers}
127 \value{
128 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
129 \item{.fitted}{Fitted or predicted value.}
130 \item{.resid}{The difference between observed and fitted values.}
131
132 }