[R] query in loops

ASHLIN VARKEY @@h||nv@rkey @end|ng |rom gm@||@com
Mon Dec 5 08:40:51 CET 2022


Sir,
I want to write a loop in R to find the AIC factor. For its calculation, I
need to run an algorithm in the attached file. Here  'x' represents the
dataset and xi denotes the i-th observation after arranging it in ascending
order. Q(u) and q(u) represent the quantile function and quantile density
function respectively. For my distribution Q(u) and q(u) are given below.
Q(u)=-α log⁡(1-u)+(b-α)u+((r-b))/2 u^2
q(u)=b+u(r-b+α/(1-u)).
Can you please help me to correct this program based on the algorithm?
*R code*
x=c(0.047, 0.296, 0.540, 1.271, 0.115, 0.334, 0.570, 1.326, 0.121, 0.395,
0.641, 1.447, 0.132, 0.458, 0.644, 1.485, 0.164, 0.466, 0.696, 1.553,
0.197, 0.501, 0.841,1.581,
0.203,0.507, 0.863, 1.589, 3.743, 0.260, 0.529, 1.099, 2.178, 0.282, 0.534,
1.219, 2.343, 2.416, 2.444, 2.825, 2.830, 3.578, 3.658, 3.978, 4.033)
xi=sort(x)
xi
n=45
alpha=-1.014
b=.949
r=3.11
u=c()
D=c()
q=c()
Q=c()
for (i in 1:n) {
    u[i]=i/(n+1)
    Q[i]=-alpha*log(1-u[i])+(b-alpha)*u[i]+((r-b)/2)*(u[i]^2)
    q[i]=b+u[i]*(r-b+(alpha/(1-u[i])))
    D[i]=Q[i]-xi[i]
    if (D[i]<(10^-7)) {
      print (q[i])
    }
    else{
      u[i+1]=u[i]+((xi[i]-Q[i])/q[i])
    }
  }


More information about the R-help mailing list