density function coding
density function coding
Good day,
You help is needed to solve this coding problem. In my estimation stage I need to code a dummy variable (d) with 1 if the sign of the variable is positive and 0 otherwise. The defined density function has two parts and the initial code is:
frml xxx = %sign(dy)
frml if xxx > 0.0 {
xx = 1.0
}
else {
xx = 0.0
}
frml d = ((xxx)^2.0-xxx)/(1.0 + %abs(xxx))
frml k = log( 4/(sigma1*(1-(%sign(lamda1)*(%betainc(a1,1/alpha1,1/alpha1)))) )
frml h1 = 0.5*(1+%sign(lamda1)*(%gammainc((%abs(a1/(2^0.5)))^alpha1,1/alpha1)))
frml h2 = 0.5*(1+%sign(lamda2)*(%gammainc((%abs(a2/(2^0.5)))^alpha2,1/alpha2)))
frml p11 = alpha1/(2*(2^0.5)*(%gamma(1/alpha1)))
frml p12 = -(%abs(y/((2^0.5)*sigma1)))^alpha1
frml logl = (k + log(p11)+ log(h1))*d + (k + log(p12) + log(h2) )*(1-d)
nonlin a1 a2 alpha1 alpha2 sigma1 sigma2 lamda1 lamda2
maximize(pmethod=simplex,piters=5,method=bfgs,trace,iters=200) logl start+1 end
Thanks for your help.
Sam
You help is needed to solve this coding problem. In my estimation stage I need to code a dummy variable (d) with 1 if the sign of the variable is positive and 0 otherwise. The defined density function has two parts and the initial code is:
frml xxx = %sign(dy)
frml if xxx > 0.0 {
xx = 1.0
}
else {
xx = 0.0
}
frml d = ((xxx)^2.0-xxx)/(1.0 + %abs(xxx))
frml k = log( 4/(sigma1*(1-(%sign(lamda1)*(%betainc(a1,1/alpha1,1/alpha1)))) )
frml h1 = 0.5*(1+%sign(lamda1)*(%gammainc((%abs(a1/(2^0.5)))^alpha1,1/alpha1)))
frml h2 = 0.5*(1+%sign(lamda2)*(%gammainc((%abs(a2/(2^0.5)))^alpha2,1/alpha2)))
frml p11 = alpha1/(2*(2^0.5)*(%gamma(1/alpha1)))
frml p12 = -(%abs(y/((2^0.5)*sigma1)))^alpha1
frml logl = (k + log(p11)+ log(h1))*d + (k + log(p12) + log(h2) )*(1-d)
nonlin a1 a2 alpha1 alpha2 sigma1 sigma2 lamda1 lamda2
maximize(pmethod=simplex,piters=5,method=bfgs,trace,iters=200) logl start+1 end
Thanks for your help.
Sam
Re: density function coding
Isn't dy just data? If it is, then you don't need a FRML for xxx; you can just stick with
set xxx = (dy>0)
There's clearly something amiss with the rest of your formulas, though, since lamda1 and lamda2 only enter in %sign(...) functions, so only their signs are determined.
set xxx = (dy>0)
There's clearly something amiss with the rest of your formulas, though, since lamda1 and lamda2 only enter in %sign(...) functions, so only their signs are determined.
Re: density function coding
Thanks Tom for you reply.
Yes dy is just data series. What I originally have for lamda is rather: lamda/%abs(lamda) which is coded as %sign(lamda). I'll recode it as: lamda/%abs(lamda).
Yes dy is just data series. What I originally have for lamda is rather: lamda/%abs(lamda) which is coded as %sign(lamda). I'll recode it as: lamda/%abs(lamda).
Re: density function coding
Hi Tom,
One more question:
How can we deal with formulas that include the absolute value of variable with power (another coef) and frml with %abs :
dec real a1 a2 alpha1 alpha2 sigma1 sigma2 lamda1 lamda2
compute alpha1 = 2.0
compute alpha2 = 2.0
compute sigma1 = sqrt(dyvar)
compute sigma2 =sqrt(dyvar)
compute lamda1 = -0.0001
compute lamda2 = -0.0001
compute a1 = ((%abs(lamda1))^alpha1)/(1.0+((%abs(lamda1))^alpha1))
compute a2 = ((%abs(lamda2))^alpha2)/(1.0+((%abs(lamda2))^alpha2))
and
frml k = log( 4/(sigma1*(1-((lamda1/%abs(lamda1))*(%betainc(a1,1/alpha1,1/alpha1)))) )
or should I just code it as:
frml k = log( 4/(sigma1*(1-(%sign(lamda1)*(%betainc(a1,1/alpha1,1/alpha1)))) )
where %sign(lamda) is replacing lamda1/%abs(lamda1)
Thanks for you help.
Sam
One more question:
How can we deal with formulas that include the absolute value of variable with power (another coef) and frml with %abs :
dec real a1 a2 alpha1 alpha2 sigma1 sigma2 lamda1 lamda2
compute alpha1 = 2.0
compute alpha2 = 2.0
compute sigma1 = sqrt(dyvar)
compute sigma2 =sqrt(dyvar)
compute lamda1 = -0.0001
compute lamda2 = -0.0001
compute a1 = ((%abs(lamda1))^alpha1)/(1.0+((%abs(lamda1))^alpha1))
compute a2 = ((%abs(lamda2))^alpha2)/(1.0+((%abs(lamda2))^alpha2))
and
frml k = log( 4/(sigma1*(1-((lamda1/%abs(lamda1))*(%betainc(a1,1/alpha1,1/alpha1)))) )
or should I just code it as:
frml k = log( 4/(sigma1*(1-(%sign(lamda1)*(%betainc(a1,1/alpha1,1/alpha1)))) )
where %sign(lamda) is replacing lamda1/%abs(lamda1)
Thanks for you help.
Sam
Re: density function coding
By all means use the %SIGN function. I was just pointing out that in what you had posted, only the signs of lamda1 and lamda2 would matter. This new one shows that they also enter more generally.
Re: density function coding
Thanks Tom,
I used both %sign and %abs and none seems to work with my code:
In,
compute a1 = ((%abs(lamda1))^alpha1)/(1.0+((%abs(lamda1))^alpha1))
I got the error:
Can't Interpret MATRIX(REAL) ** or ^ REAL
## SX27. Illegal Combination of Data Types for Operation
>>>>bs(lamda1))^alpha1)<<<<
Thnks
I used both %sign and %abs and none seems to work with my code:
In,
compute a1 = ((%abs(lamda1))^alpha1)/(1.0+((%abs(lamda1))^alpha1))
I got the error:
Can't Interpret MATRIX(REAL) ** or ^ REAL
## SX27. Illegal Combination of Data Types for Operation
>>>>bs(lamda1))^alpha1)<<<<
Thnks
Re: density function coding
Hi again,
I also tried to use the log exp way to remove the real power but exp(%abs(lamda1)) or log(%abs(lamda1)) is not working with rats:
compute a1 = (log(exp(alpha1*(%abs(lamda1))))) /(1.0+( log(exp(alpah1*(%abs(lamda1))))))
the error:
Can't Find Match for EXP(MATRIX(REAL)). Closest Match is EXP(REAL)
## SX27. Illegal Combination of Data Types for Operation
>>>>ha1*(%abs(lamda1)))<<<<
Any help please,
Sam
I also tried to use the log exp way to remove the real power but exp(%abs(lamda1)) or log(%abs(lamda1)) is not working with rats:
compute a1 = (log(exp(alpha1*(%abs(lamda1))))) /(1.0+( log(exp(alpah1*(%abs(lamda1))))))
the error:
Can't Find Match for EXP(MATRIX(REAL)). Closest Match is EXP(REAL)
## SX27. Illegal Combination of Data Types for Operation
>>>>ha1*(%abs(lamda1)))<<<<
Any help please,
Sam
Re: density function coding
Use just abs(...), not %abs(...) for scalars. abs is one of a handful of common functions which don't use the % prefix. %abs is for element-by-element absolute value for a matrix.sam2010 wrote:Thanks Tom,
I used both %sign and %abs and none seems to work with my code:
In,
compute a1 = ((%abs(lamda1))^alpha1)/(1.0+((%abs(lamda1))^alpha1))
I got the error:
Can't Interpret MATRIX(REAL) ** or ^ REAL
## SX27. Illegal Combination of Data Types for Operation
>>>>bs(lamda1))^alpha1)<<<<
Thnks
Re: density function coding
Thanks Tom for your kind help.
Sam
Sam