[R] query in loops
jim holtman
jho|tm@n @end|ng |rom gm@||@com
Mon Dec 5 23:05:47 CET 2022
So what is the problem that you would like help in correcting? The program
seems to run.
Thanks
Jim Holtman
*Data Munger Guru*
*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*
On Mon, Dec 5, 2022 at 12:59 PM ASHLIN VARKEY <ashlinvarkey using gmail.com>
wrote:
> 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])
> }
> }
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list