Lform: Hypothesis matrix generated by expressions

Description Usage Arguments Details Value See Also Examples

Description

Creates an L matrix using expressions evaluated in 'data' for each column of the L matrix

Usage

1
Lform(fit, form, data = getData(fit))

Arguments

fit

a fitted model with a 'getFix' method.

data

the data frame in which expressions are evaluated.

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.

formula

as an argument of M, a one-sided formula defining a main effect or an interaction term involving factors.

expr

as an argument of M, an expression that can be evaluated in each row of data to form element(s) of the corresponding row of L. formula defining a main effect or an interaction term involving factors.

Details

If Lform is called with only a fit argument, it outputs code consisting of an expression that would, if used as the fmla argument to Lform would generate the full design matrix for the linear model.

If Lform is called with two or three arguments, it generates a hypothesis matrix by evaluating the expressions in form in the environment data. The function M is designed to facilitate the generation of blocks of the hypothesis matrix corresponding to main effects or interaction effects of factors.

Creates a linear hypothesis matrix, i.e. an L matrix, using formulas evaluated in 'data' for each column of the L matrix. This approach lends itself to creating hypotheses and estimates based on data such as partial derivatives with respect to variables evaluated at each data point. An example is the estimation of growth rates in longitudinal models. library(car) library(spida) fit <- lm( income ~ (education + I(education^2) )* type, Prestige) summary(fit) . . . Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 891.3 23889.1 0.037 0.97032 education 210.0 5638.8 0.037 0.97037 I(education^2) 38.3 328.3 0.117 0.90740 typeprof 191523.2 63022.0 3.039 0.00312 ** typewc 25692.3 73888.0 0.348 0.72887 education:typeprof -28133.0 10236.0 -2.748 0.00725 ** education:typewc -4485.4 14007.9 -0.320 0.74956 I(education^2):typeprof 1017.5 451.8 2.252 0.02679 * I(education^2):typewc 170.9 671.6 0.255 0.79967 . . . # estimate the marginal value of occupation for each occupation in the data set L <- list( 'marginal value of education' =Lform( fit, form = list( 0,1,2*education, 0,0, type == 'prof', type == 'wc', 2*education *(type=='prof'), 2* education * (type == 'wc')), data = Prestige)) wald( fit, L ) chat <- coef( wald( fit, L ), se = 2) xyplot( coef +coefp+coefm ~ education | type, cbind(Prestige,chat)[order(Prestige$education),], type = 'l') xyplot( chat~ education | type, Prestige)

Value

hypothesis matrix

See Also

wald,Leff and Lfx for a new improved but experimental version.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
      library(car)
      mod <- lm( income ~ (education + I(education^2) )* type, Prestige)
      summary(mod)

      # estimate the marginal value of an extra year of education for a
      # range of years for each type

      years.type <- expand.grid( education = seq(6,18,2), type = levels(Prestige$type))
      Lf <- Lform( mod,
         list( 0, 1, 2*education, 0, 0, type =="prof", type =="wc",
            2*education*(type =="prof"), 2*education*(type =="wc")),
         years.type)
      Lf
      ww <- wald( mod, Lf)
      ww
      ytderiv <- as.data.frame( ww, se = 2)
      head( ytderiv )
      xyplot( coef ~ education, ytderiv, groups = type, type = 'l',
              auto.key = list(columns = 3, lines = TRUE, points = FALSE)

## End(Not run)

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