Description Usage Arguments Details See Also Examples
Lfx facilitates generating linear hypothesis matrices for complex models by using M
objects to easily generate portions of the hypothesis matrix.
Lfx(fit) with no other arguments returns a list that is easy to edit to
differentiate with respect to numeric variables.
| 1 2 | 
| fit | a fitted model with a 'getFix' method. | 
| expr.list | a list of expressions with one component for each column (or groups of columns) of the hypothesis matrix corresponding to each term of the model. A term with multiple degrees of freedom can either be generated as separate single terms or with an expression that evaluates to a suitable matrix. | 
| data | the data frame in which expressions are evaluated. | 
| formula | as an argument of  | 
| expr | as an argument of  | 
Creates an L matrix using expressions evaluated in data for each
column or multi-column term of the L matrix. Differentiating with respect
to numeric variables is easy.  Generating pairwise differences between factor levels
requires the intermediate step of creating a data frame (usually with expand.grid,
with crossed factors to be differenced with
differently named versions of themselves.
For example, letting fac be a factor, fac0, the same factor
in a different order
and x a numerical variable:
factor prediction: M(fac)
factor pairwise differences: M(fac) - M(fac0)
interaction terms: M(x) * M(fac0)
zero block of the correct size: 0 * M(fac)
Lfx M M.default M.factor M.formula M.M <.factor >.factor <=.factor =>.factor
| 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 | ##
## The increase in income associated with an additional year of education
##
data(Prestige)   # from library(car)
fit <- lm( income ~ (education+I(education^2)) * type, Prestige)
summary(fit)
Lfx(fit)  # generates expression to cut and paste and differentiate
pred <- expand.grid( education = 3:16, type = levels(Prestige$type))
Lf.ed <- Lfx( fit,
              list( 0,
                    1 + 0* education,
                    2 * M(I(education)),
                    0 * M(type),
                    1 * 1 * M(type),
                    2 * M(I(education)) * M(type)
              ),pred)
zw <- as.data.frame(wald(fit,Lf.ed))
head(zw)
xyplot( coef ~ education , zw, groups = type, type = 'l', auto.key = T)
fit2 <- lm( income ~ (education+I(education^2)) * type*women, Prestige)
pred <- expand.grid( education = 3:16, type = levels(Prestige$type), women=c(0,50,100))
Lfx(fit2)
Lhyp <- Lfx(fit2,
    list( 0,   # differentiated wrt education
          1 * 1,
          1 * M(I(education)),
          0 * M(type),
          0 * women,
          1 * 1 * M(type),
          2 * M(I(education)) * M(type),
          1 * 1 * women,
          2 * M(I(education)) * women,
          0 * M(type) * women,
          1 * 1 * M(type) * women,
          2 * M(I(education)) * M(type) * women
    ),pred)
Lhyp
Lhyp <- as.data.frame( wald(fit2, zw))
summary(fit2)
xyplot( coef ~ education|women , zw, groups = type, type = 'l', auto.key = T,
        ylim = c(-30000,30000))
##
##  Differencing of factor
##
pred <- expand.grid( education = 3:18, women = c(0,50,100),
                     type = levels(Prestige$type),
                     type0 = levels(Prestige$type))
Lfx(fit2)
Lcomp <- Lfx(fit2,
  list( 0,
      0 * education,
      0 * M(I(education^2)),
      1 * M(type) - M(type0),
      0 * women,
      1 * education * (M(type)-M(type0)),
      1 * M(I(education^2)) * (M(type) - M(type0)),
      0 * education * women,
      0 * M(I(education^2)) * women,
      1 * (M(type)-M(type0)) * women,
      1 * education * (M(type) - M(type0)) * women,
      1 * M(I(education^2)) * (M(type) - M(type0)) * women
  ), pred)
zw <- as.data.frame( wald( fit2, Lcomp))
zw
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.