# Likelihood of observing m animals twice (recaptures), of n1 seen the first day and n2 the second, # given total population size N and probability of observing one animal on one day p. llike.mr=function(p,m,n1,n2) { part2=m*dbinom(x=2,size=2,prob=p,log=TRUE) part1=(n1+n2-2*m)*dbinom(x=1,size=2,prob=p,log=TRUE) # part0=(N-n1-n2+m)*dbinom(x=0,size=2,prob=p,log=TRUE) return(part1+part2) } # Given vectors N and p, find likelihood of all maxllike=function(prob,recap,day1,day2) { counter=1 llike=p=n=numeric() for(i in 1:length(prob)) # for(j in 1:length(total)) { llike[counter]=llike.mr(p=prob[i],m=recap,n1=day1,n2=day2) p[counter]=prob[i] # n[counter]=total[j] counter=counter+1 } return(data.frame(p,llike)) }