Description Usage Arguments Value Author(s) See Also Examples

View source: R/fitted.bayesx.R

Extractor functions to the fitted values/model residuals of the estimated model with
`bayesx`

and fitted model term partial effects/residuals.

1 2 3 4 5 |

`object` |
an object of class |

`model` |
for which model the fitted values/residuals should be provided, either an integer or
a character, e.g. |

`term` |
if not |

`...` |
not used. |

For `fitted.bayesx`

, either the fitted linear predictor and mean or if e.g.
`term = "sx(x)"`

, an object with class `"xx.bayesx"`

, where `"xx"`

is depending of
the type of the term. In principle the returned term object is simply a `data.frame`

containing the covariate(s) and its effects, depending on the estimation method, e.g. for MCMC
estimated models, mean/median fitted values and other quantities are returned. Several additional
informations on the term are provided in the `attributes`

of the object. For all types
of terms plotting functions are provided, see function `plot.bayesx`

.

Using `residuals.bayesx`

will either return the mean model residuals or the mean partial
residuals of a term specified in argument `term`

.

Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ```
## Not run:
## generate some data
set.seed(121)
n <- 500
## regressors
dat <- data.frame(x = runif(n, -3, 3), z = runif(n, 0, 1),
w = runif(n, 0, 3))
## generate response
dat$y <- with(dat, 1.5 + sin(x) + z -3 * w + rnorm(n, sd = 0.6))
## estimate model
b1 <- bayesx(y ~ sx(x) + z + w, data = dat)
## extract fitted values
fit <- fitted(b1)
hist(fit, freq = FALSE)
## now extract 1st model term
## and plot it
fx <- fitted(b1, term = "sx(x)")
plot(fx)
## extract model residuals
hist(residuals(b1))
## extract partial residuals for sx(x)
pres <- residuals(b1, term = "sx(x)")
plot(fx, ylim = range(pres[, 2]))
points(pres)
## End(Not run)
## now another example with
## use of read.bayesx.output
## load example data from
## package R2BayesX
dir <- file.path(find.package("R2BayesX"), "examples", "ex01")
b2 <- read.bayesx.output(dir)
## extract fitted values
hist(fitted(b2))
## extract model term of x
## and plot it
fx <- fitted(b2, term = "sx(x)")
plot(fx)
## have a look at the attributes
names(attributes(fx))
## extract the sampling path of the variance
spv <- attr(fx, "variance.sample")
plot(spv, type = "l")
## Not run:
## combine model objects
b <- c(b1, b2)
## extract fitted terms for second model
fit <- fitted(b, model = 2, term = 1:2)
names(fit)
plot(fit["sx(id)"])
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.