[R] sampling and gini index
Carlos Ortega
carlos.ortega at minorplanet.com
Mon Mar 10 16:34:33 CET 2003
Cesar,
For the first part, please check the function included. For the sampling,
please check "?sample".
Regards,
Carlos.
g.index<-function(y) {
sum.res<-0
y.lg<-length(y)
y.mean<-mean(y)
for (i in 1:y.lg) {
for (j in 1:y.lg) {
ratio.res<-abs(y[i]-y[j]) / (2 * y.lg^2 * y.mean)
sum.res<-sum.res+ratio.res
}
}
return(sum.res)
}
y<-rnorm(284)
g.index(y)
-----Mensaje original-----
De: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]En nombre de Cesar Ortega
Enviado el: lunes, 10 de marzo de 2003 12:17
Para: r-help at stat.math.ethz.ch
CC: r-help at stat.math.ethz.ch
Asunto: [R] sampling and gini index
Hi there,
I am new in R, and I was wondering if I could do the following in R,
since I have tried in SPSS and I have only done part of it. I
would appreciate any help to build this routine in R, if possible:
I have a column of 284 elements Y, [...]
>
> Iam reading these as 284 cases with a single
> variable, which I will call Y
>
>>
> > where first I need to calculate:
> >
> >GINP=[SUMi SUMj {|Yi - Yj|}]/[2(N**2)*MEAN(Y)], where Yi and Yj
> are
> >the 284 elements, 0<Y1<=Y2...<=Y284. j: is the next position of i.
>
> Here, I am doing a calculation to yield a single number.
> Calculating
(I assume that N=284)
>
>
> >Next, I need to take the 284 numbers and resampling them in
> [groups
> >of] n data (like 3, 4, 5, etc) for M number of samples ( like
> 1000,
> >2000, etc, one at a time) in 3 sampling methods:
> >
> >1. Simple sampling without replacing.
> >2. Fixed systematic sampling.
> >3. Proportional sampling Madow.
>
SIMPLE SAMPLING WITHOUT REPLACING THE POSITION VALUE, FOR INTANCE 3, IF
WE HAVE THE POSITION 3,7,9 WITH ITS VALUES, WE COULD HAVE 3,7,10, BUT
WE COULD NOT HAVE THE POSITIONS 9,3,7 AGAIN. SO THIS IS A COMBINATION,
AND IF WE TAKE 3 COMBINATIONS OUT 284 WE HAVE 284!/(3!*281!). AND WE
NEED TO START FROM 1000 GROUPS OF COMBINATIONS. IT IS LIKE
IF WE HAVE 1,2,3,4,5 AND WE WANT COMBINATIONS OF 2, WE COULD HAVE IN
1,2 AND 1,3 AND 1,4 AND 1,5 AND 2,3 AND 2,4, ETC, BUT IN RANDOM ORDER.
>
> >After I have the M(1000, 2000) samples of n ( 3,4, 5)elements in
> a column,
>
>
>
> >I need to take one by one each of the 1000 samples of each n
> elements
> >and calculate:
> >
> >PI(i)=n/N in simple and fixed sampling and i belogns to the
> sample. In
> >MADOW PI(i) is proprortional to an auxiliary variable Xi:PI(i)=
> RXi,
> >where r= MOD(TN,R), and TN=SUMi(Xi), i to N.
>
WE KNOW r, AND TN, BUT WE NEED TO FIND R FROM THE MODAL AND r.
AND CALCULATE:
> >ESTIMATED N= SUM {1/PI(i)};
> >ESTIMATED T(Y)= SUM {Yi/PI(i)}; i belongs to the sample.
GINMi=[SUMi{(Yi/PI(i))*[1/PI(i)+SUMj(2/PI(j)]}]/[(2*ESTIMATED
N*ESTIMATED T)]. i belongs to M (1000) times, WHERE j=i+1
WE HAVE ONLY ONE VARIABLE Y, BUT WITH THE FIRST POSITION i AND THE NEXT
j, IN THE ASCENDING ORDER.
> >And last to get the errors as:
> >
> >E1= [SUMi {|GINP-GINMi |}]/[M] ; i belongs M
> >
> >E2= SQRT[SUMi {|GINP-GINMi |}]/[M]; i belongs TO M
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
### This email has been checked for all known viruses by the
### Firstnet anti-virus system - http://www.firstnet.net.uk
### Please email fav at firstnet.net.uk for details.
_____
The information in this email is confidential and it may not be\... [[dropped]]
More information about the R-help
mailing list