Hi all,
I am new to ForwardDiff and coding up a simple example of minimum distance estimation. I would ideally like to be able to set up the problem in the traditional way of:
[distance between parameter implied moments and sample moments]^TWeighting matrix[distance between parameter implied moments and sample moments]
Unfortunately, when I try to do this, I trigger the following error:
MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{typeof(MDE_Criterion), Float64}, Float64, 2})
Closest candidates are:
(::Type{T})(::Real, !Matched::RoundingMode) where T<:AbstractFloat at rounding.jl:200
(::Type{T})(::T) where T<:Number at boot.jl:772
(::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
If I specify (implicitly) that I am using the identity (by squaring the difference between moments), then there is no trouble, but when I let the function use an arbitrary weighting matrix it does not work.
Full code included below:
function OneStep(θ,SampleMoments,T,W)
#ρ_guess = θ[1]
#σ_guess = θ[2]
#(θ[2]^2)/(1-θ[1]^2) = σ^2/(1-ρ^2)
moments = copy(SampleMoments)
count = 1
for t in 1:T
for j in t:T
moments[count] = ((θ[1]^(j-t))*(θ[2]^2)/(1-θ[1]^2) - SampleMoments[count])
count += 1
end
end
return diff'*W*moments
end
Any help would be much appreciated!