Ajout de fonctions d'optimisation et covariance
This commit is contained in:
parent
0677c1078e
commit
6ee762daea
8 changed files with 112 additions and 9 deletions
|
@ -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
|
||||
}
|
19
R/delta.method.covariance.GMM.R
Normal file
19
R/delta.method.covariance.GMM.R
Normal file
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
15
R/optim.GMM.R
Normal file
15
R/optim.GMM.R
Normal file
|
@ -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))
|
||||
}
|
|
@ -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}
|
24
man/delta.method.covariance.GMM.Rd
Normal file
24
man/delta.method.covariance.GMM.Rd
Normal file
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
32
man/optim.GMM.Rd
Normal file
32
man/optim.GMM.Rd
Normal file
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in a new issue