walddf: Wald function producing a data frame for graphing

Description Usage Arguments Value Examples

Description

A version of the wald function that produces a data frame directly, analogously to as.data.frame(wald(...))

Usage

1
2
3
walddf(fit, Llist = "", clevel = 0.95, data = NULL, debug = FALSE,
  full = FALSE, fixed = FALSE, invert = FALSE, method = "svd",
  df = NULL, se = 2, digits = 3, sep = "")

Arguments

fit

a model for which a getFix method exists.

Llist

a hypothesis matrix or a pattern to be matched or a list of these

clevel

level for confidence intervals

data

data frame used as 'data' attribute fot list elements returned only if the corresonding element of Llist has a NULL data attribute

debug

(default FALSE) produce verbose information

full

if TRUE, the hypothesis matrix is the model matrix for fit such that the estimated coefficients are the predicted values for the fixed portion of the model. This is designed to allow the calculation of standard errors for models for which the predict method does not provide them.

fixed

if Llist is a character to be used a regular expression, if fixed is TRUE Llist is interpreted literally, i.e. characters that have a special meaning in regular expressions are interpreted literally.

invert

if Llist is a character to be used a regular expression, invert == TRUE causes the matches to be inverted so that coefficients that do not match will be selected.

method

'svd' (current default) or 'qr' is the method used to find the full rank version of the hypothesis matrix. 'svd' has correctly identified the rank of a large hypothesis matrix where 'qr' has failed.

se

a vector with the multiples of standard error used to generate lower and upper limits. 'names(se)' is appended to 'L' and 'U' to label the variables.

which

selects elements of 'obj' to turn to a data.frame.

Value

A data frame with estimated coefficient, standard error, and, optionally, upper and lower limits and the variables included the 'data' element of 'obj' if present. If length(which) > 1, the returned object is a list of data frames.

Examples

  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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
data(hs)
library( nlme )

###
### Using walddf to create and plot a data frame with predicted values
###
## Not run: 
  fit <- lme(mathach ~ (ses+I(ses^2)) * Sex * Sector, hs, random = ~ 1|school)
  summary(fit)
  pred <- expand.grid( ses = seq(-2,2,.1), Sex = levels(hs$Sex), Sector = levels(hs$Sector))
  head(pred)
  w <- walddf(fit, getX(fit,data=pred)) # attaches data to wald.object so it can included in data frame
  head(w)
  library(latticeExtra)
  xyplot(coef ~ ses | Sector, w, groups = Sex,
     auto.key = T, type = 'l',
     fit = w$coef,
     upper = w$L,
     lower = w$U,
     xlim = c(0,2),
     subscript = T) +
     glayer( gpanel.fit(...))
  wald(fit, 'ses')
  wald( fit, 'Sex')  # sig. overall effect of Sex
  wald( fit, ':Sex') # but no evidence of interaction with ses
  wald( fit, '\\^2') # nor of curvature

  # conditional effect of ses
  head(getX(fit))

  ###
  ###  Effect of ses: Differentiating with respect to ses
  ###

  L <- Lfx(fit, list(
         0,
         1,
         2 * ses,
         0 * M(Sex),
         0 * M(Sector),
         1 * M(Sex),
         2 * ses * M(Sex),
         1 * M(Sector),
         2 * ses * M(Sector),
         0 * M(Sex) * M(Sector),
         1 * M(Sex) * M(Sector),
         2 * ses * M(Sex) * M(Sector)),
         pred)
  head(wald(fit, L), 20)
  w <- walddf(fit, L)
  xyplot(coef ~ ses | Sector, w, groups = Sex,
     auto.key = list(columns = 2, lines = T),
     type = 'l',
     fit = w$coef,
     upper = w$L,
     lower = w$U,
     xlim = c(0,2),
     ylab = 'estimate change in mathach per unit increase in ses',
     subscripts = T) +
     glayer( gpanel.fit(...)) +
     layer(panel.abline(a=0,b=0,lwd = 1, color ='black'))

  ###
  ###  Difference in effect of ses between Sectors
  ###

  pred.d <- expand.grid( ses = seq(-2,2,.1), Sex = levels(hs$Sex), Sector = levels(hs$Sector), Sector0 = levels(hs$Sector))
  pred.d <- subset(pred.d, Sector > Sector0)
  head(pred.d)
  L <- Lfx(fit, list(
         0,
         0,
         0 * ses,
         0 * M(Sex),
         0 * M(Sector),
         0 * M(Sex),
         0 * ses * M(Sex),
         1 * M(Sector) - M(Sector0),
         2 * ses * (M(Sector) - M(Sector0)),
         0 * M(Sex) * M(Sector),
         1 * M(Sex) * (M(Sector) - M(Sector0)),
         2 * ses * M(Sex) * (M(Sector) - M(Sector0))),
         pred.d)
  w <- walddf(fit, L)
  w
  w <- sortdf(w, ~ Sex/ses)
  xyplot(coef  ~ ses | Sex, w,
     type = 'l',
     auto.key = T,
     fit = w$coef,
     lower = w$L2,
     upper = w$U2,
     xlim = c(0,2),
     ylab = 'effect of ses (Public minus Catholic)',
     subscripts = T) +
     layer(gpanel.fit(...)) +
     layer(panel.abline(a=0,b=0,lwd = 1, color ='black'))



## End(Not run)

gmonette/spidanew documentation built on May 17, 2019, 7:27 a.m.