It took me a while to figure this out so I may as well document it here. The problem is solved in http://idisk.me.com/fonnesbeck-Public/Mt.py but I didn't immediatley figure out the details.
I want to use the multinomial distribution.
My first attempt was
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
P=[]
for t in range(-0+nAge):
@deterministic
def ProbAge(Mort=Mort, nAge=nAge, Age=t):
return (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-t))
ProbAge.__name__="P["+str(t)+"]"
P.append(ProbAge)
AF=Multinomial('AF',n=nAnimal,p=P,value=AgeFreq,observed=True)
There were no error-messages. When I ran the model, the parameter values remained constant. Something was wrong.
Then I found the Lambda function and tried this.
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
Age=range(nAge)
P = Lambda('P', lambda Mort=Mort: (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-Age)))
The error I got was
NameError: global name 'exp' is not defined
Then I used reshape for my numerical constants.
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
Age=reshape(range(nAge),nAge)
P = Lambda('P', lambda Mort=Mort: (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-Age)))
And everything seems to work OK.
Wayne Hajas.
My first attempt was
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
P=[]
for t in range(-0+nAge):
@deterministic
def ProbAge(Mort=Mort, nAge=nAge, Age=t):
return (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-t))
ProbAge.__name__="P["+str(t)+"]"
P.append(ProbAge)
AF=Multinomial('AF',n=nAnimal,p=P,value=AgeFreq,observed=True)There were no error-messages. When I ran the model, the parameter values remained constant. Something was wrong.
Then I found the Lambda function and tried this.
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
Age=range(nAge)
P = Lambda('P', lambda Mort=Mort: (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-Age)))The error I got was
NameError: global name 'exp' is not defined
Then I used reshape for my numerical constants.
Mort=Uniform('Mort',.01,.99,.1)
nAge=10
Age=reshape(range(nAge),nAge)
P = Lambda('P', lambda Mort=Mort: (1-exp(Mort)) / (1-exp(nAge*Mort)) * exp(Mort*(-1+nAge-Age)))