waqar
July 28, 2020, 6:38am
1
I need output for all 8 columns of MU by using all possible values of pbar
I use this code but I get only last column of MU all other results are not saved
please help thank you
s=1
g=c(rep(c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))))
r=c(rep(c(rep(c(2:4),4))))
i=c(rep(rep(c(1:3),4)))
for(waqar in 1:8){
if(waqar==1){
pbar=c(0.99);
}else if(waqar==2){
pbar=c(0.95);
}else if(waqar==3){
pbar=c(0.9);
}else if(waqar==4){
pbar=c(0.5);
}else if(waqar==5){
pbar=c(0.25);
}else if(waqar==6){
pbar=c(0.1);
}else if(waqar==7){
pbar=c(0.05);
}else if(waqar==8){
pbar=c(0.01);
}
MU = paste('MU',waqar,sep="")
MU=c(waqar)
for(w in 1:length(g)){
f <- function(mu) (pbar-(1-mu)/(r[w]*g[w]*mu+1-mu)-(r[w]*g[w]*mu*(1-mu))/(((r[w]*g[w]*mu*(1+i[w])+1-mu))*(r[w]*g[w]*mu*(1+i[w])+1-2*mu)))
MU[w]=uniroot(f, lower=0, upper=1)$root;
}
}
cbind(s,g,r,i,MU)
not sure... maybe you intend something like this ?
s=1
g=c(rep(c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))))
r=c(rep(c(rep(c(2:4),4))))
i=c(rep(rep(c(1:3),4)))
MU <- list()
for(waqar in 1:8){
if(waqar==1){
pbar=c(0.99);
}else if(waqar==2){
pbar=c(0.95);
}else if(waqar==3){
pbar=c(0.9);
}else if(waqar==4){
pbar=c(0.5);
}else if(waqar==5){
pbar=c(0.25);
}else if(waqar==6){
pbar=c(0.1);
}else if(waqar==7){
pbar=c(0.05);
}else if(waqar==8){
pbar=c(0.01);
}
MUtemp = paste('MU',waqar,sep="")
MUtemp=c(waqar)
for(w in 1:length(g)){
f <- function(mu) (pbar-(1-mu)/(r[w]*g[w]*mu+1-mu)-(r[w]*g[w]*mu*(1-mu))/(((r[w]*g[w]*mu*(1+i[w])+1-mu))*(r[w]*g[w]*mu*(1+i[w])+1-2*mu)))
MUtemp[w]=uniroot(f, lower=0, upper=1)$root;
}
MU[waqar] <- list(MUtemp)
}
purrr::map(1:8,~cbind(s,g,r,i,MU[[.]]))
waqar
July 28, 2020, 9:34am
3
yes i need like this but the result should be like s,g,r,i, MU1,....,MU8 i mean i need a single table
thank you
waqar:
should be like s,g,r,i, MU1,....,MU8
cbind(s,g,r,i,MU[[1]],MU[[2]],
MU[[3]],MU[[4]],
MU[[5]],MU[[5]],
MU[[7]],MU[[8]])
waqar
July 28, 2020, 9:45am
5
yes it works as i wants Thank you so much
system
Closed
August 18, 2020, 9:46am
6
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.