Hi, this is a question about R Studio. I have this following code : ############
ID: 3841940 • Letter: H
Question
Hi, this is a question about R Studio.
I have this following code :
######################################################################
# finding the value of t(i)
sig<-5
tau<-1
ttotal<-10 # ~ 9.9999
r<--20:20
lam<-runif(1,0); # generate initial value of lambda
print(lam)
Pi<-pnorm((r+.5)/sig)-pnorm((r-.5)/sig) # given formula for probability of detct in i cell
count<-1 # initial counting
while(1) {
g<-tau*log(Pi/(lam*tau)) # compute g
t<-pmax(0,g) # compute t
a<-sum(t)
b<-tau*length(r)
if (a>=9.9999) {break} else
if (a!=ttotal) {lam<-lam*exp((a-ttotal)/b)} # update "lam" value
count<-count+1 #update counting
}
print(count)
print(lam)
UDM<-Pi*(exp((-t)/1)) # calculate undetected mass
DM<-Pi*(1-exp((-t)/1)) # calculate detected mass
######################################################################
What I want to do is to make a stacked bar plot (using barplot is more favorable) that looks like the figure in the attachment. Any help is deeply appreciated, Thanks.
DM (i) and UDM (i) -1 D Optimal Search DM UD Total DM 0.4435 20 15 -10 -6 -2 1 4 7 10 14 18 CellExplanation / Answer
######################################################################
# finding the value of t(i)
sig<-5
tau<-1
ttotal<-10 # ~ 9.9999
r<--20:20
lam<-runif(1,0); # generate initial value of lambda
print(lam)
Pi<-pnorm((r+.5)/sig)-pnorm((r-.5)/sig) # given formula for probability of detct in i cell
count<-1 # initial counting
while(1) {
g<-tau*log(Pi/(lam*tau)) # compute g
t<-pmax(0,g) # compute t
a<-sum(t)
b<-tau*length(r)
if (a>=9.9999) {break} else
if (a!=ttotal) {lam<-lam*exp((a-ttotal)/b)} # update "lam" value
count<-count+1 #update counting
}
print(count)
print(lam)
UDM<-Pi*(exp((-t)/1)) # calculate undetected mass
DM<-Pi*(1-exp((-t)/1)) # calculate detected mass
######################################################################
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.