Description Usage Arguments Details Value See Also Examples

`coeftest`

is a generic function for performing
z and (quasi-)t Wald tests of estimated coefficients.
`coefci`

computes the corresponding Wald confidence
intervals.

1 2 3 4 5 6 |

`x` |
an object (for details see below). |

`vcov.` |
a specification of the covariance
matrix of the estimated coefficients. This can be
specified as a matrix or as a function yielding
a matrix when applied to |

`df` |
the degrees of freedom to be used. If this
is a finite positive number a t test with |

`...` |
further arguments passed to the methods
and to |

`save` |
logical. Should the object |

`parm` |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |

`level` |
the confidence level required. |

The generic function `coeftest`

currently has a default
method (which works in particular for `"lm"`

objects) and
dedicated methods for objects of class
`"glm"`

(as computed by `glm`

),
`"mlm"`

(as computed by `lm`

with multivariate responses),
`"survreg"`

(as computed by `survreg`

), and
`"breakpointsfull"`

(as computed by `breakpoints.formula`

).

The default method assumes that a `coef`

methods exists,
such that `coef(x)`

yields the estimated coefficients.

To specify the corresponding covariance matrix `vcov.`

to be used, there
are three possibilities:
1. It is pre-computed and supplied in argument `vcov.`

.
2. A function for extracting the covariance matrix from
`x`

is supplied, e.g., `sandwich`

,
`vcovHC`

, `vcovCL`

,
or `vcovHAC`

from package sandwich.
3. `vcov.`

is set to `NULL`

, then it is assumed that
a `vcov`

method exists, such that `vcov(x)`

yields
a covariance matrix. Illustrations are provided in the examples below.

The degrees of freedom `df`

determine whether a normal
approximation is used or a t distribution with `df`

degrees
of freedom. The default method computes `df.residual(x)`

and if this is `NULL`

, `0`

, or `Inf`

a z test is performed.
The method for `"glm"`

objects always uses `df = Inf`

(i.e., a z test).

The corresponding Wald confidence intervals can be computed either
by applying `coefci`

to the original model or `confint`

to the output of `coeftest`

. See below for examples.

Finally, `nobs`

and `logLik`

methods are provided which work, provided that there are such methods
for the original object `x`

. In that case, `"nobs"`

and
`"logLik"`

attributes are stored in the `coeftest`

output
so that they can be still queried subsequently. If both methods are
available, `AIC`

and `BIC`

can also be applied.

`coeftest`

returns an object of class `"coeftest"`

which
is essentially a coefficient matrix with columns containing the
estimates, associated standard errors, test statistics and p values.
Attributes for a `"method"`

label, and the `"df"`

are
added along with `"nobs"`

and `"logLik"`

(provided that
suitable extractor methods `nobs`

and
`logLik`

are available). Optionally, the full
object `x`

can be `save`

d in an attribute `"object"`

to facilitate further model summaries based on the `coeftest`

result.

`coefci`

returns a matrix (or vector) with columns giving
lower and upper confidence limits for each parameter. These will
be labeled as (1-level)/2 and 1 - (1-level)/2 in percent.

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 | ```
## load data and fit model
data("Mandible", package = "lmtest")
fm <- lm(length ~ age, data = Mandible, subset=(age <= 28))
## the following commands lead to the same tests:
summary(fm)
(ct <- coeftest(fm))
## a z test (instead of a t test) can be performed by
coeftest(fm, df = Inf)
## corresponding confidence intervals
confint(ct)
coefci(fm)
## which in this simple case is equivalent to
confint(fm)
## extract further model information either from
## the original model or from the coeftest output
nobs(fm)
nobs(ct)
logLik(fm)
logLik(ct)
AIC(fm, ct)
BIC(fm, ct)
if(require("sandwich")) {
## a different covariance matrix can be also used:
(ct <- coeftest(fm, df = Inf, vcov = vcovHC))
## the corresponding confidence interval can be computed either as
confint(ct)
## or based on the original model
coefci(fm, df = Inf, vcov = vcovHC)
## note that the degrees of freedom _actually used_ can be extracted
df.residual(ct)
## which differ here from
df.residual(fm)
## vcov can also be supplied as a function with additional arguments
coeftest(fm, df = Inf, vcov = vcovHC, type = "HC0")
## or as a matrix
coeftest(fm, df = Inf, vcov = vcovHC(fm, type = "HC0"))
}
``` |

```
Loading required package: zoo
Attaching package: ‘zoo’
The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
Call:
lm(formula = length ~ age, data = Mandible, subset = (age <=
28))
Residuals:
Min 1Q Median 3Q Max
-9.2013 -1.6592 -0.1217 1.3420 6.4351
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -11.9534 0.9762 -12.24 <2e-16 ***
age 1.7727 0.0477 37.16 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.373 on 156 degrees of freedom
Multiple R-squared: 0.8985, Adjusted R-squared: 0.8978
F-statistic: 1381 on 1 and 156 DF, p-value: < 2.2e-16
t test of coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -11.953366 0.976227 -12.245 < 2.2e-16 ***
age 1.772730 0.047704 37.161 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
z test of coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -11.953366 0.976227 -12.245 < 2.2e-16 ***
age 1.772730 0.047704 37.161 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
2.5 % 97.5 %
(Intercept) -13.88169 -10.02504
age 1.67850 1.86696
2.5 % 97.5 %
(Intercept) -13.88169 -10.02504
age 1.67850 1.86696
2.5 % 97.5 %
(Intercept) -13.88169 -10.02504
age 1.67850 1.86696
[1] 158
[1] 158
'log Lik.' -359.7029 (df=3)
'log Lik.' -359.7029 (df=3)
df AIC
fm 3 725.4059
ct 3 725.4059
df BIC
fm 3 734.5937
ct 3 734.5937
Loading required package: sandwich
z test of coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -11.953366 1.009817 -11.837 < 2.2e-16 ***
age 1.772730 0.054343 32.621 < 2.2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.