From 445e334b287de590251f6e4f428c9d04e499e4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Sat, 8 Mar 2014 00:37:30 -0500 Subject: [PATCH] =?UTF-8?q?enlever=20la=20partie=20contraintes,=20va=20ref?= =?UTF-8?q?aire=20d'autres=20fonctions=20plus=20tard=20pour=20=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/iterative.GMM.R | 12 ++++++------ R/mean.variance.gmm.vector.R | 4 ++-- R/objective.GMM.R | 13 ++++--------- R/optim.GMM.R | 21 +++++++++++++-------- man/iterative.GMM.Rd | 6 ++++-- man/meanvariance.gmm.vector.Rd | 4 ++-- man/objective.GMM.Rd | 12 +++--------- man/optim.GMM.Rd | 17 ++++++----------- 8 files changed, 40 insertions(+), 49 deletions(-) diff --git a/R/iterative.GMM.R b/R/iterative.GMM.R index 8282398..7b02b0d 100644 --- a/R/iterative.GMM.R +++ b/R/iterative.GMM.R @@ -9,7 +9,7 @@ #' #' @param start Starting values for the parameters and lagrangian #' @param conditions.vector Vector of moment conditions -#' @param sample Individual data sample +#' @param data Individual data sample #' @param ... Functions of the vector of moment conditions #' @param W Weighting matrix #' @param R Linear constraint matrix of coefficients @@ -19,15 +19,15 @@ #' @return A list containing the optimized vector of parameter and corresponding covariance matrix #' @export iterative.GMM #' @author François Pelletier -iterative.GMM <- function(start,conditions.vector,sample,..., - W,R,r,max.iter=50,epsilon=1E-6) +iterative.GMM <- function(start,conditions.vector,data,..., + W=diag(length(conditions.vector)),R=0,r=0,lagrangian.start=rep(0,length(conditions.vector)),max.iter=50,epsilon=1E-6) { - theta1 <- optim.GMM(start,conditions.vector,sample,...,W,R,r) + theta1 <- optim.GMM(start,conditions.vector,data,...,W,R,r,lagrangian.start) i <- 1 repeat { - theta2 <- optim.GMM(theta1,conditions.vector,sample,...,W,R,r) - S <- covariance.GMM(conditions.vector,param,sample,...) + theta2 <- optim.GMM(theta1,conditions.vector,data,...,W,R,r,lagrangian.start) + S <- covariance.GMM(conditions.vector,param,data,...) if(sqrt(sum((theta1-theta2)^2))max.iter) diff --git a/R/mean.variance.gmm.vector.R b/R/mean.variance.gmm.vector.R index 3041067..90b32ed 100644 --- a/R/mean.variance.gmm.vector.R +++ b/R/mean.variance.gmm.vector.R @@ -8,13 +8,13 @@ #' GMM vector for mean and variance moment conditions #' @param param Estimated parameters -#' @param sample Data Sample +#' @param X Data Sample #' @param meanf Mean function #' @param variancef Variance function #' @return A two column matrix of differences #' @export meanvariance.gmm.vector #' @author François Pelletier -meanvariance.gmm.vector <- function(param,sample,meanf,variancef) +meanvariance.gmm.vector <- function(param,X,meanf,variancef) { cbind(X-meanf(param),(X-meanf(param))^2 - variancef(param)) } diff --git a/R/objective.GMM.R b/R/objective.GMM.R index 93c2ad0..ce00a1b 100644 --- a/R/objective.GMM.R +++ b/R/objective.GMM.R @@ -6,20 +6,15 @@ ############################################################################### #' Objective function for the GMM method -#' @param param.lagrangian Vector of parameters and Lagrangian to optimize +#' @param param Vector of parameters #' @param conditions.vector Vector of moment conditions -#' @param sample Individual data sample +#' @param data Individual data sample #' @param ... Functions 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 #' @export objective.GMM #' @author François Pelletier -objective.GMM <- function(param.lagrangian,conditions.vector,sample,..., - W=diag(length(conditions.vector)),R=0,r=0) +objective.GMM <- function(param,conditions.vector,data,W,...) { - param <- param.lagrangian[1:num.param] - lagrangian <- param.lagrangian[num.param+1:length(param.lagrangian)] - colMeans(conditions.vector(param,sample,...)) %*% ginv(W) %*% colMeans(conditions.vector(param,sample,...))+ abs(t(R %*% param - r) %*% lagrangian) + as.vector(colMeans(conditions.vector(param,data,...)) %*% ginv(W) %*% colMeans(conditions.vector(param,data,...))) } \ No newline at end of file diff --git a/R/optim.GMM.R b/R/optim.GMM.R index 4f9c99e..77c57f9 100644 --- a/R/optim.GMM.R +++ b/R/optim.GMM.R @@ -1,16 +1,21 @@ -#' Optimization with constraints for GMM methos +# Optimization for GMM method +# +# Author: Francois Pelletier +# +# LGPL-3.0 +############################################################################### + +#' Optimization for GMM method #' -#' @param start Starting values for the parameters and lagrangian +#' @param start Starting values for the parameters #' @param conditions.vector Vector of moment conditions -#' @param sample Individual data sample +#' @param data Individual data sample #' @param ... Functions 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 +#' @return a list with optimization results #' @export optim.GMM #' @author François Pelletier -optim.GMM <- function(start,conditions.vector,sample,...,W,R,r) +optim.GMM <- function(start,conditions.vector,data,W,...) { - optim(start,objective.GMM,conditions.vector,sample,...,W,R,r) + optim(start,objective.GMM,conditions.vector,data,W,...) } \ No newline at end of file diff --git a/man/iterative.GMM.Rd b/man/iterative.GMM.Rd index 60c857e..312fd15 100644 --- a/man/iterative.GMM.Rd +++ b/man/iterative.GMM.Rd @@ -2,7 +2,9 @@ \alias{iterative.GMM} \title{Iterative GMM method} \usage{ -iterative.GMM(start, conditions.vector, sample, ..., W, R, r, max.iter = 50, +iterative.GMM(start, conditions.vector, data, ..., + W = diag(length(conditions.vector)), R = 0, r = 0, + lagrangian.start = rep(0, length(conditions.vector)), max.iter = 50, epsilon = 1e-06) } \arguments{ @@ -11,7 +13,7 @@ iterative.GMM(start, conditions.vector, sample, ..., W, R, r, max.iter = 50, \item{conditions.vector}{Vector of moment conditions} - \item{sample}{Individual data sample} + \item{data}{Individual data sample} \item{...}{Functions of the vector of moment conditions} diff --git a/man/meanvariance.gmm.vector.Rd b/man/meanvariance.gmm.vector.Rd index 024c862..a90da73 100644 --- a/man/meanvariance.gmm.vector.Rd +++ b/man/meanvariance.gmm.vector.Rd @@ -2,12 +2,12 @@ \alias{meanvariance.gmm.vector} \title{GMM vector for mean and variance moment conditions} \usage{ -meanvariance.gmm.vector(param, sample, meanf, variancef) +meanvariance.gmm.vector(param, X, meanf, variancef) } \arguments{ \item{param}{Estimated parameters} - \item{sample}{Data Sample} + \item{X}{Data Sample} \item{meanf}{Mean function} diff --git a/man/objective.GMM.Rd b/man/objective.GMM.Rd index 1db2a3e..345bd20 100644 --- a/man/objective.GMM.Rd +++ b/man/objective.GMM.Rd @@ -2,24 +2,18 @@ \alias{objective.GMM} \title{Objective function for the GMM method} \usage{ -objective.GMM(param.lagrangian, conditions.vector, sample, ..., - W = diag(length(conditions.vector)), R = 0, r = 0) +objective.GMM(param, conditions.vector, data, W, ...) } \arguments{ - \item{param.lagrangian}{Vector of parameters and - Lagrangian to optimize} + \item{param}{Vector of parameters} \item{conditions.vector}{Vector of moment conditions} - \item{sample}{Individual data sample} + \item{data}{Individual data sample} \item{...}{Functions 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 index 12fa2e6..5cb4204 100644 --- a/man/optim.GMM.Rd +++ b/man/optim.GMM.Rd @@ -1,30 +1,25 @@ \name{optim.GMM} \alias{optim.GMM} -\title{Optimization with constraints for GMM methos} +\title{Optimization for GMM method} \usage{ -optim.GMM(start, conditions.vector, sample, ..., W, R, r) +optim.GMM(start, conditions.vector, data, W, ...) } \arguments{ - \item{start}{Starting values for the parameters and - lagrangian} + \item{start}{Starting values for the parameters} \item{conditions.vector}{Vector of moment conditions} - \item{sample}{Individual data sample} + \item{data}{Individual data sample} \item{...}{Functions 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 +a list with optimization results } \description{ -Optimization with constraints for GMM methos +Optimization for GMM method } \author{ François Pelletier