Compute analysis of variance tables for a fitted model object or a likelihood ratio test for two fitted model objects.

# S3 method for splm
anova(object, ..., test = TRUE, Terms, L)

# S3 method for spautor
anova(object, ..., test = TRUE, Terms, L)

# S3 method for spglm
anova(object, ..., test = TRUE, Terms, L)

# S3 method for spgautor
anova(object, ..., test = TRUE, Terms, L)

# S3 method for anova.splm
tidy(x, ...)

# S3 method for anova.spautor
tidy(x, ...)

# S3 method for anova.spglm
tidy(x, ...)

# S3 method for anova.spgautor
tidy(x, ...)

Arguments

object

A fitted model object from splm(), spautor(), spglm(), or spgautor().

...

An additional fitted model object.

test

A logical value indicating whether p-values from asymptotic Chi-squared hypothesis tests should be returned. Defaults to TRUE.

Terms

An optional character or integer vector that specifies terms in the model used to jointly compute test statistics and p-values (if test = TRUE) against a null hypothesis of zero. Terms is only used when a single fitted model object is passed to the function. If Terms is a character vector, it should contain the names of the fixed effect terms. If Terms is an integer vector, it should correspond to the order (starting at one) of the names of the fixed effect terms. The easiest way to obtain the names of all possible terms is to run tidy(anova(object))$effects (the integer representation matches the positions of this vector).

L

An optional numeric matrix or list specifying linear combinations of the coefficients in the model used to compute test statistics and p-values (if test = TRUE) for coefficient constraints corresponding to a null hypothesis of zero. L is only used when a single fitted model object is passed to the function. If L is a numeric matrix, its rows indicate coefficient constraints and its columns represent coefficients. Then a single hypothesis test is conducted against a null hypothesis of zero. If L is a list, each list element is a numeric matrix specified as above. Then separate hypothesis tests are conducted. The easiest way to obtain all possible coefficients is to run tidy(object)$term.

x

An object from anova(object).

Value

When one fitted model object is present, anova()

returns a data frame with degrees of freedom (Df), test statistics (Chi2), and p-values (Pr(>Chi2) if test = TRUE) corresponding to asymptotic Chi-squared hypothesis tests for each model term.

When two fitted model objects are present, anova() returns a data frame with the difference in degrees of freedom between the full and reduced model (Df), a test statistic (Chi2), and a p-value corresponding to the likelihood ratio test (Pr(>Chi2) if test = TRUE).

Whether one or two fitted model objects are provided, tidy() can be used to obtain tidy tibbles of the anova(object) output.

Details

When one fitted model object is present, anova() performs a general linear hypothesis test corresponding to some hypothesis specified by a matrix of constraints. If Terms and L are not specified, each model term is tested against zero (which correspond to type III or marginal hypothesis tests from classical ANOVA). If Terms is specified and L is not specified, all terms are tested jointly against zero. When L is specified, the linear combinations of terms specified by L are jointly tested against zero.

When two fitted model objects are present, one must be a "reduced" model nested in a "full" model. Then anova() performs a likelihood ratio test.

Examples

# one-model anova
spmod <- splm(z ~ water + tarp,
  data = caribou,
  spcov_type = "exponential", xcoord = x, ycoord = y
)
anova(spmod)
#> Analysis of Variance Table
#> 
#> Response: z
#>             Df    Chi2 Pr(>Chi2)    
#> (Intercept)  1 43.4600 4.327e-11 ***
#> water        1  1.6603 0.1975631    
#> tarp         2 15.4071 0.0004512 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tidy(anova(spmod))
#> # A tibble: 3 × 4
#>   effects        df statistic  p.value
#>   <chr>       <int>     <dbl>    <dbl>
#> 1 (Intercept)     1     43.5  4.33e-11
#> 2 water           1      1.66 1.98e- 1
#> 3 tarp            2     15.4  4.51e- 4
# see terms
tidy(anova(spmod))$effects
#> [1] "(Intercept)" "water"       "tarp"       
tidy(anova(spmod, Terms = c("water", "tarp")))
#> # A tibble: 1 × 4
#>   effects        df statistic  p.value
#>   <chr>       <int>     <dbl>    <dbl>
#> 1 water, tarp     3      17.1 0.000685
# same as
tidy(anova(spmod, Terms = c(2, 3)))
#> # A tibble: 1 × 4
#>   effects        df statistic  p.value
#>   <chr>       <int>     <dbl>    <dbl>
#> 1 water, tarp     3      17.1 0.000685
# likelihood ratio test
lmod <- splm(z ~ water + tarp,
  data = caribou,
  spcov_type = "none"
)
tidy(anova(spmod, lmod))
#> # A tibble: 1 × 5
#>   full  reduced    df statistic p.value
#>   <chr> <chr>   <int>     <dbl>   <dbl>
#> 1 spmod lmod        2      4.17   0.124