The original bread.lm uses the summary.lm function
it seems like a quick fix and I've therefore created
the original bread definition: $(X'X)^-1$
Usage
## S3 method for class 'ols'
bread(x, ...)
Arguments
x
The ols model fit
...
arguments passed to methods.
Value
matrix The bread for the sandwich vcovHC function
Examples
# Generate some data
n <- 500
x1 <- runif(n)*2
x2 <- runif(n)
y <- x1^3 + x2 + rnorm(n)
library(rms)
library(sandwich)
dd <- datadist(x1, x2, y)
org.op <- options(datadist = "dd")
# Main function
f <- ols(y ~ rcs(x1, 3) + x2)
# Check the bread
bread(f)
# Check the HC-matrix
vcovHC(f, type="HC4m")
# Adjust the model so that it uses the HC4m variance
f_rob <- robcov_alt(f, type="HC4m")
# Get the new HC4m-matrix
# - this function just returns the f_rob$var matrix
vcov(f_rob)
# Now check the confidence interval for the function
confint(f_rob)
options(org.op)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Greg)
Loading required package: forestplot
Loading required package: grid
Loading required package: magrittr
Loading required package: Gmisc
Loading required package: Rcpp
Loading required package: htmlTable
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Greg/bread.ols.Rd_%03d_medium.png", width=480, height=480)
> ### Name: bread.ols
> ### Title: Getting the bread for the vcovHC
> ### Aliases: bread.ols
> ### Keywords: internal
>
> ### ** Examples
>
> # Generate some data
> n <- 500
> x1 <- runif(n)*2
> x2 <- runif(n)
> y <- x1^3 + x2 + rnorm(n)
>
> library(rms)
Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2
Attaching package: 'Hmisc'
The following objects are masked from 'package:base':
format.pval, round.POSIXt, trunc.POSIXt, units
Loading required package: SparseM
Attaching package: 'SparseM'
The following object is masked from 'package:base':
backsolve
> library(sandwich)
> dd <- datadist(x1, x2, y)
> org.op <- options(datadist = "dd")
>
> # Main function
> f <- ols(y ~ rcs(x1, 3) + x2)
>
> # Check the bread
> bread(f)
Intercept x1 x1' x2
Intercept 9.207302 -10.674033 11.6339206 -5.2117512
x1 -10.674033 23.196097 -28.7802642 -0.3967190
x1' 11.633921 -28.780264 40.7966078 -0.1788622
x2 -5.211751 -0.396719 -0.1788622 11.3775532
Warning message:
In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
> # Check the HC-matrix
> vcovHC(f, type="HC4m")
Intercept x1 x1' x2
Intercept 0.02159765 -0.02551905 0.028256746 -0.010987209
x1 -0.02551905 0.05257713 -0.063441355 -0.001195910
x1' 0.02825675 -0.06344135 0.087207376 -0.001225887
x2 -0.01098721 -0.00119591 -0.001225887 0.023196936
Warning messages:
1: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
2: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
3: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
4: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
> # Adjust the model so that it uses the HC4m variance
> f_rob <- robcov_alt(f, type="HC4m")
Warning messages:
1: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
2: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
3: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
4: In model.matrix.ols(x) :
You should set the ols(..., x=TRUE) as the fallback may be somewhat unreliable
> # Get the new HC4m-matrix
> # - this function just returns the f_rob$var matrix
> vcov(f_rob)
Intercept x1 x1' x2
Intercept 0.02159765 -0.02551905 0.028256746 -0.010987209
x1 -0.02551905 0.05257713 -0.063441355 -0.001195910
x1' 0.02825675 -0.06344135 0.087207376 -0.001225887
x2 -0.01098721 -0.00119591 -0.001225887 0.023196936
> # Now check the confidence interval for the function
> confint(f_rob)
2.5 % 97.5 %
Intercept -0.2462934 0.3297847
x1 -1.0085903 -0.1097625
x1' 5.0412219 6.1988117
x2 0.8859065 1.4829328
>
> options(org.op)
>
>
>
>
>
> dev.off()
null device
1
>