DOC PREVIEW
UW-Madison STAT 411 - survey-ex15

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Nordheim Spring 2015 Statistics 411 (April 16) Examples using the “Survey” Package in R > library(survey) Example for stratified random sampling: Consider the example from Prob#4 in Hmwk #4 on estimating the total number of “seal holes” in Svalbord fjords. The data are given in seals.csv . There are 3 strata (zones) with population sizes of 68, 84, and 48 plots per zone. The number of sampled plots per zone are 17, 12, and 11 respectively. The given data have “holes” in the first column and “zone” in the second. Here are the commands needed for “survey”. > sealdat=read.csv("seals.csv",header=T) > head(sealdat) (looks at first few lines of file) zone holes 1 1 0 2 1 0 3 1 0 4 1 0 5 1 1 6 1 1 There are 17, 12, and 11 lines respectively for zones 1, 2, and 3. We need to create a new column with population stratum sizes. > t1=rep(68,17) > t2=rep(84,12) > t3=rep(48,11) > strsz=c(t1,t2,t3) The key command is the svydesign command which specifies the type of design. For SRS and stratified designs, the value for “id” is always “1”. The “strata” argument is required for stratified designs. (This term is deleted for SRS designs.) The “fpc” argument specifies the population size for each stratum. (For SRS designs, every row has the value for the total population.) > sealdes=svydesign(id=~1,strata=~zone,fpc=~strsz,data=sealdat) > svytotal(~holes,sealdes) total SE holes 997.18 118.03 Example for ratio estimation: Consider the example on estimating the ratio of number of physicians per 1000 population (discussed in class and also described in the handout, “Using R for Ratio Estimation”.) Here are the commands for using “survey”. > pop=c(40,300,120,80,20) > phys=c(140,960,400,260,60) > size=rep(50,5) > physdat=data.frame(pop,phys,size)> physdes=svydesign(id=~1,fpc=~size,data=physdat) > svyratio(~phys,~pop,physdes) Ratio estimator: svyratio.survey.design2(~phys, ~pop, physdes) Ratios= pop phys 3.25 SEs= pop phys 0.04017857 Example for two-stage cluster sampling: > slurpdat=read.csv("slurp-surv.csv",header=T) > slurpdat plant nplants nlines line hours 1 1 500 14 1 5.2 2 1 500 14 2 1.4 3 1 500 14 3 7.3 4 1 500 14 4 2.5 5 2 500 26 1 1.3 ……………………………………………………………………………………………… 57 10 500 24 6 3.6 > slurp2=svydesign(id=~plant+line, fpc=~nplants+nlines,data=slurpdat) > slurp2 2 - level Cluster Sampling design With (10, 57) clusters. > svymean(~hours,slurp2) mean SE hours 3.5367


View Full Document

UW-Madison STAT 411 - survey-ex15

Download survey-ex15
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view survey-ex15 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view survey-ex15 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?