H, i am a beginner in R and I have problems dealing with for loops. What I am trying to do is store 25 values of tau, b0 and b1. In order to find b1 we have to find the lowest value of Out function in the code ( b1 should be close to the value 1 ) and I want use this b1 in the for loop to find b0 and b1 and should be stored in a vector of length 25 ( I should have a list of b0 ,b1 tau). Please help and thanks in advance! I have added what I intend to do
I want
b1[1], b1[2],..., b1[25]
t[1],t[2],...,t[25]
b0[1],b0[2],...,b0[25]
by solving the problem in the picture
set.seed(22)
#Inverse Transformation on CDF
Simburr.f1 <- function(n, tau) {
u=runif(n)
x<- runif(n)
lambda = exp(1+x)
y= (1/(u^(1/lambda))-1)^(1/tau)
y
}
y33 = Simburr.f1(25,0.5)
#------------------------------------
# We fix Tau = 0.5
est3 = function(m) {
x=runif(25)
Out = rep(0,m)
k= seq(0.05,2,l=m)
for ( i in 1:m){
Out[i]= log(mean(x)) -log(mean(exp(k[i]*x)*log(1+y33^0.5)*x) ) + log(mean(log(1+y33^0.5)*exp(k[i]*x)))
}
Out
}
p=est3(200)
k[which.min(abs(p-0))] # = B1
#--------------------------------------
x =runif(25)
tau[1]= 0.5
b0[1] = 1
b1[1] = 1
# Iterative process
for ( i in 2:25){
b0[i]= -log(mean(log(1+y33^(tau[i-1]))*exp(b1[i-1]*x)))
tau[i] =1/( mean((exp(b0[i-1]+b1[i-1]*x)+1)*(y33^tau[i-1])*log(y33)/(1+y33^tau[i-1])) -mean(log(y33)))
}