Substituting Variables in an Equation
Posted: Fri Jul 08, 2011 11:19 am
I am currently estimating parameters for a fairly large equation.
I would like to be able to try different forumlae within the equation.
In order to manage this and make the code more readable and flexible I am trying to use variables within an equation so that I can change parts of it.
For example something like this:
weight = p^c(1) / ( p^c(1) + (1-p)^c(1) )^ (1/ c(1))
value1 = z1 ^ c(2)
value2 = z2 ^c(2)
equation = weight * value1 + (1-weight ) * value2
However, when I write my code I am not substituting/ using variables correctly.
I guess I am just trying to figure out how to merge separate equations together in order to then estimate the parameters of a larger equation.
Here is something like what I have written:
Any advice on perhaps a technique or object I could use to accomplish this would really be appreciated!
Thanks,
Jen
I would like to be able to try different forumlae within the equation.
In order to manage this and make the code more readable and flexible I am trying to use variables within an equation so that I can change parts of it.
For example something like this:
weight = p^c(1) / ( p^c(1) + (1-p)^c(1) )^ (1/ c(1))
value1 = z1 ^ c(2)
value2 = z2 ^c(2)
equation = weight * value1 + (1-weight ) * value2
However, when I write my code I am not substituting/ using variables correctly.
I guess I am just trying to figure out how to merge separate equations together in order to then estimate the parameters of a larger equation.
Here is something like what I have written:
Code: Select all
'First I use some variables to store a series name so that I can trade these out as necessary
'nn_p1, nn_z1, nn_z2 are each a series
%p1 = "nn_p1"
%z1 = "nn_z1"
%z2 = "nn_z2"
' %Gamma and %Alpha are each coefficients (c(1) and c(2)) that I will be estimating.
' I need to constrain them so I have taken them each separately here....
%gamma = "(1.99 * @logit(c(1)) + 0.01)" '<--- constrain gamma between 0.01 and 2 (H-L)*@logit(c(1)) +L
%alpha = "(9.999 * @logit(c(2)) + 0.001)"
' Three equations here: weight, value1 and value 2
' I want to merge them together to make a larger equation
%weight = {%p1} ^ {%gamma} / ( {%p1} ^ {%gamma} + ( 1-{%p1} ) ^ {%gamma} )^ (1/ {%gamma} )
%value1 = "{%z1}^{%alpha}"
%value2 = "{%z2}^{%alpha}"
'Here I am trying to estimate coefficients c(1) and c(2) by merging together the 3 equations from above
equation eq.ls {%weight} * {%value1} + (1- {%weight}) * {%value2}
Any advice on perhaps a technique or object I could use to accomplish this would really be appreciated!
Thanks,
Jen