Learn R Programming

itsadug (version 2.4.1)

inspect_random: Inspection and interpretation of random factor smooths.

Description

Inspection and interpretation of random factor smooths.

Usage

inspect_random(
  model,
  select = 1,
  fun = NULL,
  cond = NULL,
  n.grid = 30,
  print.summary = getOption("itsadug_print"),
  plot = TRUE,
  add = FALSE,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  ylim = NULL,
  h0 = 0,
  v0 = NULL,
  eegAxis = FALSE,
  ...
)

Arguments

model

A gam object, produced by gam or bam.

select

A number, indicating the model term to be selected.

fun

A string or function description to apply to the random effects estimates. When NULL (default), the estimates for the random effects are returned.

cond

A named list of the values to restrict the estimates for the random predictor terms. When NULL (default) all levels are returned.

n.grid

Number of data points estimated for each random smooth.

print.summary

Logical: whether or not to print a summary of the values selected for each predictor. Default set to the print info messages option (see infoMessages).

plot

Logical: whether or not to plot the random effect estimates (TRUE by default).

add

Logical: whether or not to add the random effect estimates to an existing plot (FALSE by default).

main

Changing the main title for the plot, see also title.

xlab

Changing the label for the x axis, defaults to a description of x.

ylab

Changing the label for the y axis, defaults to a description of y.

ylim

Changing the y limits of the plot.

h0

A vector indicating where to add solid horizontal lines for reference. By default 0.

v0

A vector indicating where to add dotted vertical lines for reference. By default no values provided.

eegAxis

Whether or not to reverse the y-axis (plotting negative upwards).

...

other options to pass on to lines, see par

Value

A data frame with estimates for random effects is optionally returned.

See Also

Other Functions for model inspection: dispersion(), fvisgam(), gamtabs(), plot_data(), plot_parametric(), plot_smooth(), plot_topo(), pvisgam()

Examples

Run this code
# NOT RUN {
# load data:
data(simdat)

# }
# NOT RUN {
# Condition as factor, to have a random intercept
# for illustration purposes:
simdat$Condition <- as.factor(simdat$Condition)

# Model with random effect and interactions:
m2 <- bam(Y ~ s(Time) + s(Trial)
+ ti(Time, Trial)
+ s(Condition, bs='re')
+ s(Time, Subject, bs='fs', m=1),
data=simdat)

# extract with wrong select value:
newd <- inspect_random(m2, select=4)
# results in warning, automatically takes select=5
head(newd)
inspect_random(m2, select=5, cond=list(Subject=c('a01','a02','a03')))

# Alternatively, fix random effect of Condition, and plot 
# random effects for subjects with lattice:
newd <- inspect_random(m2, select=5,
    cond=list(Subject=unique(simdat[simdat$Condition==0,'Subject'])),
    plot=FALSE)

# Make lattice plot:
require(lattice)
lattice::xyplot(fit~Time | Subject,
    data=newd, type='l',
    xlab='Time', ylab='Partial effect')

# Using argument 'fun':
inspect_random(m2, select=5, fun=mean, 
    cond=list(Subject=unique(simdat[simdat$Condition==0,'Subject'])))
inspect_random(m2, select=5, fun=mean, 
    cond=list(Subject=unique(simdat[simdat$Condition==2,'Subject'])),
    col='red', add=TRUE)
# }
# NOT RUN {
# see the vignette for examples:
vignette('overview', package='itsadug')
# }

Run the code above in your browser using DataLab