enlever la partie contraintes, va refaire d'autres fonctions plus tard
pour ça
This commit is contained in:
parent
ca602c5f75
commit
445e334b28
8 changed files with 40 additions and 49 deletions
|
@ -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))<epsilon)
|
||||
return(list(par=theta2,cov=S))
|
||||
else if (i>max.iter)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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,...)))
|
||||
}
|
|
@ -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,...)
|
||||
}
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue