ajout d'intervalle de confiance, test wald

This commit is contained in:
François Pelletier 2014-02-26 20:03:47 -05:00
parent d8bbce7d4f
commit 348cadd3f3
6 changed files with 152 additions and 0 deletions

28
R/Wald.Test.R Normal file
View file

@ -0,0 +1,28 @@
# Wald test for estimating equations
#
# Author: Francois Pelletier
#
# LGPL-3.0
###############################################################################
#' Wald test for estimating equations
#' @param param Estimated parameters
#' @param n Size of estimation sample
#' @param R Matrix of linear coefficients of the constraints
#' @param r vector of linear constants of the constraints
#' @param eqn.covariance Covariance matrix of the estimating equations
#' @param eqn.gradient Gradient matrix of the estimating equations
#' @param alpha level of confidence
#' @return A list containing the statistic, p-value and reject of the null hypothesis
#'
#' @author François Pelletier
Wald.Test <- function(param,n,R,r,eqn.covariance,eqn.gradient,alpha=0.05)
{
wald.stat <- n * t(R %*% param - r) %*%
ginv(R %*% eqn.gradient %*% eqn.covariance %*%
t(eqn.gradient) %*% t(R)) %*%
(R %*% param - r)
PV <- pchisq(wald.stat,nrow(R))
list(wald.stat=wald.stat, p.value=PV, reject=PV>1-alpha)
}

View file

@ -0,0 +1,22 @@
# Confidence interval for QEE estimates
#
# Author: Francois Pelletier
#
# LGPL-3.0
###############################################################################
#' Confidence interval for QEE estimates
#'
#' Uses covariance.GEE
#' @param param Vector of parameters of the distribution function
#' @param covariance Covariance matrix
#' @param alpha confidence level
#' @return 3 line matrix with lower bound, estimate and upper bound
#'
#' @author François Pelletier
confidence.interval.QEE <- function(param,covariance,n,alpha=0.05)
{
cbind(LOWER=param - sqrt(diag(covariance))*qt(alpha,n,lower=F),
ESTIMATE=param,
UPPER=param + sqrt(diag(covariance))*qt(alpha,n,lower=F))
}

19
R/covariance.QEE.R Normal file
View file

@ -0,0 +1,19 @@
# Covariance matrix using the component matrix M and V from QEE
#
# Author: Francois Pelletier
#
# LGPL-3.0
###############################################################################
#' Covariance matrix using the component matrix M and V from QEE
#'
#' Covariance matrix using the component matrix M and V from QEE
#' @param M Gradient matrix
#' @param V Covariance matrix of equations
#' @param n Sample size
#' @return Weighted covariance matrix
#' @author François Pelletier
covariance.QEE <- function(M,V,n) ## Omega
{
ginv(M %*% ginv(V) %*% t(M))/n
}