[R] How to use Subpopulation data?

David Winsemius dwinsemius at comcast.net
Sat Oct 3 01:53:08 CEST 2009


On Oct 2, 2009, at 2:39 PM, KABELI MEFANE wrote:

> Dear Mr Winsemius
>
> I am sorry to have offended any of you by the mistakes i made. The  
> package i loaded is sampling and there was an unwanted comma between  
> size c(20, )and the bracket. What i wanted was to calculate the sum  
> of H in a sample not in the original dataframe. If i do
> sum(H) i get the sum value of H's in the original dataframe.

Yes, and that would be expected, would it not?
>
>
> Load package sampling
>
> H <- matrix(rnorm(100, mean=50000, sd=5000))
> sampleframe=data.frame(type=c(rep("H",100)),value=c(H))
> sampleframe
>  sum(H)
>
> str=strata(sampleframe,c("type"),size=c(20), method="srswor")
> sample.strat<-getdata(sampleframe,str)
> sample.strat

Seems to me that you should be getting descriptive statisics on the  
sample.strat object rather than on H.
 > summary(sample.strat)
      value       type      ID_unit           Prob        Stratum
  Min.   :37931   H:20   Min.   : 1.00   Min.   :0.2   Min.   :1
  1st Qu.:46547          1st Qu.:20.75   1st Qu.:0.2   1st Qu.:1
  Median :48848          Median :44.50   Median :0.2   Median :1
  Mean   :49193          Mean   :50.45   Mean   :0.2   Mean   :1
  3rd Qu.:51311          3rd Qu.:78.75   3rd Qu.:0.2   3rd Qu.:1
  Max.   :58523          Max.   :98.00   Max.   :0.2   Max.   :1
 >

>
> Thanks for the input. Once again sorry for wasting your time.
>
> Best Regards
>
>
>
>
> --- On Fri, 2/10/09, David Winsemius <dwinsemius at comcast.net> wrote:
>
> From: David Winsemius <dwinsemius at comcast.net>
> Subject: Re: [R] How to use Subpopulation data?
> To: "KABELI MEFANE" <kabelimefane at yahoo.co.uk>
> Cc: R-help at r-project.org
> Date: Friday, 2 October, 2009, 3:38 PM
>
>
> On Oct 1, 2009, at 6:06 AM, KABELI MEFANE wrote:
>
> > Dear Helpers
> >
> > I have a sample frame and i have sampled from it using three  
> methods and now i want to calculate the statistics but i only get  
> the population parameters.
> >
> > H <- matrix(rnorm(100, mean=50000, sd=5000))
> > sampleframe=data.frame(type=c(rep("H",100)),value=c(H))
> > sampleframe
> >
> > str=strata(sampleframe,c("type"),size=c(20,), method="srswor")
> > sample.strat<-getdata(sampleframe,str)
> > sample.strat
>
> If you want the number of rows in sample.strat then length(H) is the  
> wrong approach since that is the original (unsampled) object.
>
> > length(H)
> > i get:
> >
> > length(H)
> > [1] 100
> >
> > Desire to get:
> > length(H)
> > [1] 20
>
> I cannot tell what packages you have loaded and strata is not in the  
> sampling package which I guessed (wrongly) was where you were  
> getting "getdata". When you post code you should precede that code  
> with calls that load any non-base packages.
>
> In later posting you ask for ways to calculate "the sum" but you do  
> not say what it is that you want the sum of.... . Our abilities to  
> read minds is extremely limited.
>
> --David Winsemius
>




More information about the R-help mailing list