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 length(H) i get: length(H) [1] 100 Desire to get: length(H) [1] 20 Best Regards [[alternative HTML version deleted]]
On Thu, 2009-10-01 at 10:06 +0000, 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")Try using str=strata(sampleframe,c("type"),size=20, method="srswor") or better str <- strata(sampleframe,c("type"),size=20, method="srswor") -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil
Thanks i was not aware of str, i have a very large code since i am new to r. I forgot to mention that the package is sampling. Actually i have this simulated code: n <- c(100,400,1000,1500,2000) x <- c(2,3,3,3,5) y <- c(7,7,9,10,10) s <- function(mn, mx, n) {sample(mn:mx, n, replace=TRUE)} rating=unlist(mapply(s, x, y, n)) Hypermarket <- matrix(rnorm(100, mean=50000, sd=5000)) Supermarket <- matrix(rnorm(400, mean=34000, sd=3000)) Minimarket <- matrix(rnorm(1000, mean=10000,sd=2000)) Cornershop <- matrix(rnorm(1500, mean=2500, sd=500)) Spazashop <- matrix(rnorm(2000, mean=1000, sd=250)) dat=data.frame(type=c(rep("Hypermarket",100), rep("Supermarket",400), rep("Minimarket",1000),rep("Cornershop",1500), rep("Spazashop",2000)), value=c(Hypermarket, Supermarket, Minimarket, Cornershop,Spazashop)) ##sample frame sampleframe=data.frame(type=c(rep("Hypermarket",100), rep("Supermarket",400), rep("Minimarket",1000),rep("Cornershop",1500), rep("Spazashop",2000)), value=c(Hypermarket, Supermarket, Minimarket, Cornershop,Spazashop), ratings =cbind(rating)) ## package sampling stra=strata(sampleframe,c("type","value","rating"),size=c(20,80,200,300,400), method="srswor") sample.strat<-getdata(sampleframe,stra) sample.strat now i want to find different estimates from sample.strat Help appreciated. [[alternative HTML version deleted]]
On Thu, 2009-10-01 at 13:34 +0000, KABELI MEFANE wrote:> ## package sampling > > stra=strata(sampleframe,c("type","value","rating"),size=c(20,80,200,300,400), > method="srswor") > sample.strat<-getdata(sampleframe,stra) > > sample.strat >Try: stra<-strata(sampleframe,size=c(20,80,200,300,400),method="srswor") sample.strat<-getdata(sampleframe,stra) sample.strat -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil
Thanks But it seems like you don't get my problem. Do you mean that there is something wrong with the code as it seems like what you are doing is suggesting different ways to write a code. Will i get to use the variable that have been name previously like if i want to calculate the standard deviation of stratum hypermarket in a sample not population, the first start is to check if it would help me is to check the length() of different levels if it is not same as that of the original data Best Regards I rest my case, i might dream it --- On Thu, 1/10/09, Bernardo Rangel Tura <tura@centroin.com.br> wrote: From: Bernardo Rangel Tura <tura@centroin.com.br> Subject: Re: [R] How to use Subpopulation data? To: "r-help" <r-help@stat.math.ethz.ch> Date: Thursday, 1 October, 2009, 10:18 PM On Thu, 2009-10-01 at 13:34 +0000, KABELI MEFANE wrote:> ## package sampling > > stra=strata(sampleframe,c("type","value","rating"),size=c(20,80,200,300,400), > method="srswor") > sample.strat<-getdata(sampleframe,stra) > > sample.strat >Try: stra<-strata(sampleframe,size=c(20,80,200,300,400),method="srswor") sample.strat<-getdata(sampleframe,stra) sample.strat -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil ______________________________________________ R-help@r-project.org mailing list 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]]
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.stratIf 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] 20I 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