From 6ee762daeade0483af1c1157ecc1d5a2c1cb70c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Thu, 27 Feb 2014 23:05:30 -0500 Subject: [PATCH] Ajout de fonctions d'optimisation et covariance --- R/covariance.GMM.R | 2 +- R/delta.method.covariance.GMM.R | 19 ++++++++++++ R/objective.GMM.R | 10 ++++-- R/optim.GMM.R | 15 +++++++++ man/{gmmGAL.mu.vcov.Rd => covariance.GMM.Rd} | 6 ++-- man/delta.method.covariance.GMM.Rd | 24 +++++++++++++++ man/{obj.gmmGAL.mu.Rd => objective.GMM.Rd} | 13 ++++++-- man/optim.GMM.Rd | 32 ++++++++++++++++++++ 8 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 R/delta.method.covariance.GMM.R create mode 100644 R/optim.GMM.R rename man/{gmmGAL.mu.vcov.Rd => covariance.GMM.Rd} (78%) create mode 100644 man/delta.method.covariance.GMM.Rd rename man/{obj.gmmGAL.mu.Rd => objective.GMM.Rd} (51%) create mode 100644 man/optim.GMM.Rd diff --git a/R/covariance.GMM.R b/R/covariance.GMM.R index 42820d5..e13396a 100644 --- a/R/covariance.GMM.R +++ b/R/covariance.GMM.R @@ -12,7 +12,7 @@ #' @return A square covariance matrix #' #' @author François Pelletier -gmmGAL.mu.vcov <- function(conditions.vector,n,...) +covariance.GMM <- function(conditions.vector,n,...) { t(conditions.vector(...)) %*% conditions.vector(...) / n } \ No newline at end of file diff --git a/R/delta.method.covariance.GMM.R b/R/delta.method.covariance.GMM.R new file mode 100644 index 0000000..7a57ee4 --- /dev/null +++ b/R/delta.method.covariance.GMM.R @@ -0,0 +1,19 @@ +# Covariance matrix of the parameters using delta method +# +# Author: Francois Pelletier +# +# LGPL-3.0 +############################################################################### + + +#' Covariance matrix of the parameters using delta method +#' @param covariance Covariance matrix of the moment conditions +#' @param gradient Gradient matrix of the moment conditions +#' @param size Sample size +#' @return The covariance matrix of the parameters +#' +#' @author François Pelletier +delta.method.covariance.GMM <- function(covariance,gradient,size) +{ + ginv(gradient %*% ginv(covariance) %*% t(gradient))/size +} diff --git a/R/objective.GMM.R b/R/objective.GMM.R index f99937a..2813cd4 100644 --- a/R/objective.GMM.R +++ b/R/objective.GMM.R @@ -6,13 +6,19 @@ ############################################################################### #' Objective function for the GMM method +#' @param param Vector of parameters to optimize #' @param conditions.vector Vector of moment conditions #' @param ... Parameters of the vector of moment conditions #' @param W Weighting matrix +#' @param R Linear constraint matrix of coefficients +#' @param r Linear constraint constants #' @return A scalar value #' #' @author François Pelletier -obj.gmmGAL.mu <- function(conditions.vector,...,W=diag(length(conditions.vector))) +objective.GMM <- function(param.lagrangian,conditions.vector,num.param,..., + W=diag(length(conditions.vector)),R=0,r=0) { - colMeans(conditions.vector(...)) %*% ginv(W) %*% colMeans(conditions.vector(...)) + param <- param.lagrangian[1:num.param] + lagrangian <- param.lagrangian[num.param+1:length(param.lagrangian)] + colMeans(conditions.vector(param,...)) %*% ginv(W) %*% colMeans(conditions.vector(param,...))+ abs(t(R %*% param - r) %*% lagrangian) } \ No newline at end of file diff --git a/R/optim.GMM.R b/R/optim.GMM.R new file mode 100644 index 0000000..cf7d859 --- /dev/null +++ b/R/optim.GMM.R @@ -0,0 +1,15 @@ +#' Optimization with constraints for GMM methos +#' +#' @param start Starting values for the parameters and lagrangian +#' @param conditions.vector Vector of moment conditions +#' @param number of parameters of the distribution +#' @param ... Parameters of the vector of moment conditions +#' @param W Weighting matrix +#' @param R Linear constraint matrix of coefficients +#' @param r Linear constraint constants +#' @return une liste contenant le résultat de l'optimisation +#' @author François Pelletier +optim.GMM <- function(start,conditions.vector,num.param,...,W,R,r) +{ + optim(c(start,objective.GMM,conditions.vector,num.param,...,W,R,r)) +} \ No newline at end of file diff --git a/man/gmmGAL.mu.vcov.Rd b/man/covariance.GMM.Rd similarity index 78% rename from man/gmmGAL.mu.vcov.Rd rename to man/covariance.GMM.Rd index 3a4a2aa..01a7637 100644 --- a/man/gmmGAL.mu.vcov.Rd +++ b/man/covariance.GMM.Rd @@ -1,8 +1,8 @@ -\name{gmmGAL.mu.vcov} -\alias{gmmGAL.mu.vcov} +\name{covariance.GMM} +\alias{covariance.GMM} \title{Estimated covariance matrix} \usage{ -gmmGAL.mu.vcov(conditions.vector, n, ...) +covariance.GMM(conditions.vector, n, ...) } \arguments{ \item{conditions.vector}{Vector of moment conditions} diff --git a/man/delta.method.covariance.GMM.Rd b/man/delta.method.covariance.GMM.Rd new file mode 100644 index 0000000..430aa7a --- /dev/null +++ b/man/delta.method.covariance.GMM.Rd @@ -0,0 +1,24 @@ +\name{delta.method.covariance.GMM} +\alias{delta.method.covariance.GMM} +\title{Covariance matrix of the parameters using delta method} +\usage{ +delta.method.covariance.GMM(covariance, gradient, size) +} +\arguments{ + \item{covariance}{Covariance matrix of the moment + conditions} + + \item{gradient}{Gradient matrix of the moment conditions} + + \item{size}{Sample size} +} +\value{ +The covariance matrix of the parameters +} +\description{ +Covariance matrix of the parameters using delta method +} +\author{ +François Pelletier +} + diff --git a/man/obj.gmmGAL.mu.Rd b/man/objective.GMM.Rd similarity index 51% rename from man/obj.gmmGAL.mu.Rd rename to man/objective.GMM.Rd index f20c119..bdc88b6 100644 --- a/man/obj.gmmGAL.mu.Rd +++ b/man/objective.GMM.Rd @@ -1,15 +1,22 @@ -\name{obj.gmmGAL.mu} -\alias{obj.gmmGAL.mu} +\name{objective.GMM} +\alias{objective.GMM} \title{Objective function for the GMM method} \usage{ -obj.gmmGAL.mu(conditions.vector, ..., W = diag(length(conditions.vector))) +objective.GMM(param.lagrangian, conditions.vector, num.param, ..., + W = diag(length(conditions.vector)), R = 0, r = 0) } \arguments{ + \item{param}{Vector of parameters to optimize} + \item{conditions.vector}{Vector of moment conditions} \item{...}{Parameters of the vector of moment conditions} \item{W}{Weighting matrix} + + \item{R}{Linear constraint matrix of coefficients} + + \item{r}{Linear constraint constants} } \value{ A scalar value diff --git a/man/optim.GMM.Rd b/man/optim.GMM.Rd new file mode 100644 index 0000000..d63a94e --- /dev/null +++ b/man/optim.GMM.Rd @@ -0,0 +1,32 @@ +\name{optim.GMM} +\alias{optim.GMM} +\title{Optimization with constraints for GMM methos} +\usage{ +optim.GMM(start, conditions.vector, num.param, ..., W, R, r) +} +\arguments{ + \item{start}{Starting values for the parameters and + lagrangian} + + \item{conditions.vector}{Vector of moment conditions} + + \item{number}{of parameters of the distribution} + + \item{...}{Parameters of the vector of moment conditions} + + \item{W}{Weighting matrix} + + \item{R}{Linear constraint matrix of coefficients} + + \item{r}{Linear constraint constants} +} +\value{ +une liste contenant le résultat de l'optimisation +} +\description{ +Optimization with constraints for GMM methos +} +\author{ +François Pelletier +} +