Title: | FAB Confidence Intervals |
Version: | 0.2 |
Description: | Frequentist assisted by Bayes (FAB) confidence interval construction. See 'Adaptive multigroup confidence intervals with constant coverage' by Yu and Hoff <doi:10.1093/biomet/asy009> and 'Exact adaptive confidence intervals for linear regression coefficients' by Hoff and Yu <doi:10.1214/18-EJS1517>. |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | MASS |
Date: | 2021-01-07 |
Author: | Peter Hoff and Chaoyu Yu |
Maintainer: | Peter Hoff <peter.hoff@duke.edu> |
RoxygenNote: | 5.0.1 |
NeedsCompilation: | no |
Packaged: | 2021-01-07 14:09:43 UTC; pdhoff |
Repository: | CRAN |
Date/Publication: | 2021-01-07 15:10:02 UTC |
Empirical Bayes estimation of hyperparameters
Description
Compute emprirical Bayes estimates of the error variance and distribution of the regression coefficients.
Usage
ebayes_est(y, X, emu = FALSE, dof = min(50, round(0.5 * (dim(X)[1] -
dim(X)[2]))))
Arguments
y |
a numeric vector of data |
X |
a design matrix |
emu |
(logical) estimate mean of coefficient (TRUE) or assume it is zero (FALSE)? |
dof |
degrees of freedom to use for the t-quantiles (the remainder go to adaptive estimation of the prior) |
Details
This function computes the adaptive FAB confidence interval for each coefficient in a linear regression model.
Value
A list (s,sigma2,tau2,mu) where
s an estimate of the error standard deviation
sigma2 an estimate of the error variance, independent of s
tau2 an estimate of the coefficient variance, independent of s
mu an estimate of the coefficient mean, independent of s
Author(s)
Peter Hoff
FAB regression coefficient intervals
Description
Compute the adaptive FAB t-intervals for the coefficients of a regression model.
Usage
fabregCI(y, X, alpha = 0.05, dof = min(50, round(0.5 * (dim(X)[1] -
dim(X)[2]))), verbose = TRUE)
Arguments
y |
a numeric vector of data |
X |
a design matrix |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
dof |
degrees of freedom to use for the t-quantiles (the remainder go to adaptive estimation of the prior) |
verbose |
logical, print progress or not |
Details
This function computes the adaptive FAB confidence interval for each coefficient in a linear regression model.
Value
A matrix where each row corresponds to the interval and OLS estimate of a coefficient.
Author(s)
Peter Hoff
FAB t-interval
Description
Computation of a 1-alpha FAB t-interval
Usage
fabtCI(y, psi = c(0, 100, 1, 2), alpha = 0.05)
Arguments
y |
a numeric vector with at least two non-missing values |
psi |
a length-four vector of hyperparameters for the prior |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
Details
A FAB interval is the "frequentist" interval procedure
that is Bayes optimal: It minimizes the prior expected
interval width among all interval procedures with
exact 1-alpha frequentist coverage. This function computes
the FAB t-interval for the mean of a normal population with an
unknown variance, given a user-specified prior distribution
determined by psi
. The prior is that the population mean
and variance are independently distributed as normal and
inverse-gamma random variables.
Referring to the elements of psi
as mu, t2, s20, nu0, the prior is determined as follows:
mu is the prior expectation of the mean
t2 is the prior variance of the mean
the population variance is inverse-gamma(nu0/2,nu0 s20/2)
Author(s)
Peter Hoff
Examples
y<-rnorm(10)
fabtCI(y,c(0,10,1,5))
fabtCI(y,c(0,1/10,1,5))
fabtCI(y,c(2,10,1,5))
fabtCI(y,c(0,1/10,1,5))
FAB t-interval with z-optimal w-function
Description
Computation of a 1-alpha FAB t-interval using the w-function of the optimal FAB z-interval
Usage
fabtwzCI(y, s2, df, muw, t2w, s2w, alpha = 0.05)
Arguments
y |
a numeric vector with at least two non-missing values |
s2 |
a variance estimate |
df |
degrees of freedom corresponding to |
muw |
prior expectation of the mean |
t2w |
prior variance of the mean |
s2w |
assumed population variance |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
Details
Internal function for multifabCIhom. It's similar to fabtCI, the difference being that fabtwzCI uses the w-function that leads to the optimal CI if the sampling variance were known.
Author(s)
Chaoyu Yu
Examples
y<-rnorm(10)
fabtwzCI(y,10,9,1,5,10)
fabtwzCI(y,1/10,9,1,5,1/10)
fabtwzCI(y,10,1,9,5,10)
fabtwzCI(y,1/10,9,1,5,1/10)
z-optimal FAB t-interval
Description
Computation of a 1-alpha FAB t-interval using z-optimal spending function
Usage
fabtzCI(y, s, dof, alpha = 0.05, psi = list(mu = 0, tau2 = 1e+05, sigma2 =
1))
Arguments
y |
a numeric scalar, a normally distributed statistic |
s |
a numeric scalar, the standard error of y |
dof |
positive integer, degrees of freedom for s |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
psi |
a list of parameters for the spending function, including
|
Examples
n<-10
y<-rnorm(n)
fabtzCI(mean(y),sqrt(var(y)/n),n-1)
t.test(y)$conf.int
FAB z-interval
Description
Computation of a 1-alpha FAB z-interval
Usage
fabzCI(y, mu, t2, s2, alpha = 0.05)
Arguments
y |
a numeric scalar |
mu |
a numeric scalar |
t2 |
a positive numeric scalar |
s2 |
a positive numeric scalar |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
Details
A FAB interval is the "frequentist" interval procedure
that is Bayes optimal: It minimizes the prior expected
interval width among all interval procedures with
exact 1-alpha frequentist coverage. This function computes
the FAB z-interval for the mean of a normal population with an
known variance, given a user-specified prior distribution
determined by psi
. The prior is that the population mean
is normally distributed.
Referring to the elements of psi
as mu, t2, s2, the prior and population variance are
determined as follows:
mu is the prior expectation of the mean
t2 is the prior variance of the mean
s2 is the population variance
Author(s)
Peter Hoff
Examples
y<-0
fabzCI(y,0,10,1)
fabzCI(y,0,1/10,1)
fabzCI(y,2,10,1)
fabzCI(y,0,1/10,1)
Hierarchical heteroscedastic model estimates
Description
Estimate across-group heterogeneity of means and variances
Usage
hhetmodel(y, g)
Arguments
y |
a numeric vector of data |
g |
a group membership vector, of the same length as y |
Details
This function estimates parameters in a hierarchical model for normally distributed groups, where the across-group model for means is normal and the across group model for variances is inverse-gamma.
Value
A vector (mu,t2,s20,nu0), where
mu is the mean of the group means
t2 is the variance of the group means
the the distribution of group variances is inverse-gamma(nu0/2,nu0 s20/2)
Author(s)
Peter Hoff
Hierarchical homoscedastic model estimates
Description
Estimate across-group heterogeneity of means
Usage
hhommodel(y, g, group, p1)
Arguments
y |
a numeric vector of data |
g |
a group membership vector, of the same length as y |
group |
the index of the group |
p1 |
number of groups used to pool sample variance |
Details
This function estimates parameters in a hierarchical model for normally distributed groups, where the across-group model for means is normal and the variance is the same across groups.
Value
A vector (s2,df,muw,t2w,s2w), where
s2 is the pooled variance
df is the degree of freedom of the t-quantiles
muw is the estimate mean of the group means
t2w is the estimate variance of the group means
s2w is the estimate within-group variance
Author(s)
Chaoyu Yu
Multigroup FAB t-intervals
Description
Computation of 1-alpha FAB t-intervals for heteroscedastic multigroup data.
Usage
multifabCI(y, g, alpha = 0.05)
Arguments
y |
a numeric vector of data |
g |
a group membership vector, of the same length as y |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
Details
For each group j, this function computes an estimate of the parameters in a hierarchical model for means and variances from data other than group j, and uses this information to construct a FAB t-interval for group j. These intervals have 1-alpha frequentist coverage, assuming within-group normality.
Author(s)
Peter Hoff
Examples
## -- simulated data
p<-10 ; n<-10
y<-rnorm(n*p) ; g<-rep(1:p,n)
## -- more interesting data takes longer
# data(radon) ; y<-radon[,2] ; g<-radon[,1]
## -- FAB t-intervals
FCI<-multifabCI(y,g)
## -- UMAU t-intervals
ybar<-tapply(y,g,mean) ; ssd<-tapply(y,g,sd) ; n<-table(g)
qtn<-cbind( qt(.025,n-1), qt(.975,n-1) )
UCI<-sweep(sweep(qtn,1,ssd/sqrt(n),"*"),1,ybar,"+")
mean( (UCI[,2]-UCI[,1])/(FCI[,2]-FCI[,1]) , na.rm=TRUE)
Multigroup FAB t-intervals for the homoscedastic model
Description
Computation of 1-alpha FAB t-intervals for homoscedastic multigroup data.
Usage
multifabCIhom(y, g, alpha = 0.05, prop = 0.5)
Arguments
y |
a numeric vector of data |
g |
a group membership vector, of the same length as y |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
prop |
the proportion of groups to obtain the sample variance estimate |
Details
For each group j, this function computes an estimate of the parameters in a hierarchical model for means using data from other groups, and uses this information to construct a FAB t-interval for group j. These intervals have 1-alpha frequentist coverage, assuming within-group normality and that the within group variance is the same across groups.
Author(s)
Chaoyu Yu
Examples
## -- simulate the data
mu = 0; sigma2 = 10; tau2 = 1; p =100;
theta = rnorm(p,mu,sqrt(tau2))
ns = round(runif(p,2,18))
Y=c()
for(i in 1:p){
d2 = rnorm(ns[i],theta[i],sqrt(sigma2))
d1 = rep(i,ns[i])
d = cbind(d1,d2)
Y = rbind(Y,d)}
y = Y[,2]
g = Y[,1]
## -- FAB t-intervals
FCI = multifabCIhom(y,g)
## -- UMAU t-intervals
ybar<-tapply(y,g,mean) ; ssd<-tapply(y,g,sd) ; n<-table(g)
qtn<-cbind( qt(.025,n-1), qt(.975,n-1) )
UCI<-sweep(sweep(qtn,1,ssd/sqrt(n),"*"),1,ybar,"+")
mean( (UCI[,2]-UCI[,1])/(FCI[,2]-FCI[,1]) , na.rm=TRUE)
Prior predictive acceptance probability
Description
Compute prior probability of falling into an acceptance region
Usage
pppaccept(w, theta, mu, t2, s20, nu0, n, alpha)
Arguments
w |
the weight in [0,1] determining acceptance region endpoints |
theta |
value of theta being tested |
mu |
prior mean of theta |
t2 |
prior variance of theta |
s20 |
prior parameter for population variance |
nu0 |
prior parameter for population variance |
n |
sample size |
alpha |
level of test |
Details
Internal function for fabtCI. This function computes the prior probability that the value theta will fall in the acceptance region of a biased level-alpha test, under a specified prior predictive distribution.
Author(s)
Peter Hoff
Minnesota Radon Dataset
Description
Radon levels in 919 homes from 85 Minnesota counties
Usage
data(radon)
Format
A numeric matrix
Source
http://www.stat.columbia.edu/~gelman/arm/software/
Bayes-optimal spending function
Description
Compute Bayes optimal spending function
Usage
sfabz(theta, psi, alpha = 0.05)
Arguments
theta |
value of theta being tested |
psi |
a list of parameters for the spending function, including
|
alpha |
level of test |
Details
This function computes the value of s that minimizes the acceptance probability of a biased level-alpha test for a normal population with known variance, under a specified prior predictive distribution.
Author(s)
Peter Hoff
UMAU regression coefficient intervals
Description
Compute the usual t-intervals for the coefficients of a regression model
Usage
umauregCI(y, X, alpha = 0.05)
Arguments
y |
a numeric vector of data |
X |
a design matrix |
alpha |
the type I error rate, so 1-alpha is the coverage rate |
Details
This function computes the 'usual' uniformly most accurate unbiased confidence interval for each coefficient in a linear regression model.
Value
A matrix where each row corresponds to the interval and OLS estimate of a coefficient.
Author(s)
Peter Hoff
Bayes-optimal w-function
Description
Compute Bayes optimal w-function
Usage
wfabt(theta, mu, t2, s20, nu0, n, alpha)
Arguments
theta |
value of theta being tested |
mu |
prior mean of theta |
t2 |
prior variance of theta |
s20 |
prior parameter for population variance |
nu0 |
prior parameter for population variance |
n |
sample size |
alpha |
level of test |
Details
Internal function for fabtCI. This function computes the value of w that minimizes the acceptance probability of a biased level-alpha test under a specified prior predictive distribution.
Author(s)
Peter Hoff