Docsity

Tecniche d'indagine, Appunti di Statistica

Toggle sidebar
bg1
CAMPIONE CASUALE SEMPLICE (CCS/SRS)
> library (sampling)
> data (nome data frame)
> srs <- srswor (n, nrow (nome data frame))
> data_srs <- nome data frame [srs ==1,]
> data_srs
STIMA CAMPIONE CASUALE SEMPLICE (CCS/SRS)
> library (survey)
> data (nome data frame)
> pik <- rep (n/nrow(nome data frame),n)
> srs_design <- svydesign (id= 1, fpc= pik, data= data_srs)
> totest <- svytotal ( variabile da stimare, srs_design)
> totest
> cv (totest)
> coef (totest)
> var <- svyvar ( variabile da stimare, srs_design)
PPS
> library (sampling)
> data (nome data frame)
PROB. VARIABILI
> pik <- inclusionprobabilities (nomedataframe$var dimensionale, n)
> pps <- UPtille (pik)
> data_pps <- nome data frame [pps ==1,]
> data_pps
STIMA PPS
> library (survey)
> data (nome data frame)
> pik2 <- pik [pps ==1,]
> pps_design <- svydesign (id=1, fpc = pik2, data= data_pps)
> totest <- svytotal ( elenco variabili, pps_design)
> cv (totest)
> coef (totest)
> var <- svyvar ( variabili da stimare, pps_design)
CAMPIONE STRATIFICATO
> library (sampling)
> data (nome data frame)
> numpop <- table (nome data frame [ ,posizione variabile])
> numpop <- ceiling ((numpop/sum(numpop))*n)
> stratif <- strata (nome data frame, stranames = c(“Ateco”),
size= numpop, method=”srswor”)
> data_stratif <- getdata (nome data frame, stratif)
> data_stratif
STIMA STRATIFICATO
> library (survey)
> data (nome data frame)
> dstratif <- svydesign (id=1, strata= REG, data= data_stratif, fpc= stratif [,3],
probs=stratif[,3])
> totest <- svytotal ( variabile da stimare, dstratif, deff= TRUE)
> cv (totest)
> coef (totest)
> var <- svyvar (variabile da stimare, dstratif)
CAMPIONE BILANCIATO
> library (sampling)
> data (nome data frame)
> pik <- rep (n/ nrow(nome data frame), nrow (nome data frame))
> x <- as.matrix (nome data frame [ ,c(variabili da sottoporre a vincolo)]
> bal <- samplecube (x, pik, comment =TRUE)
> data_bal <- nome data frame [bal==1,]
> data_bal
STIMA BILANCIATO
> library (survey)
> data (nome data frame)
> bal_design <- svydesign (id =1, fpc=pik, data= data_bal)
> totest <- svytotal ( elenco variabili, bal_design)
> totest
CALIBRAZIONE/REGRESSIONE
pf2

Anteprima parziale del testo

Scarica Tecniche d'indagine e più Appunti in PDF di Statistica solo su Docsity!

CAMPIONE CASUALE SEMPLICE (CCS/SRS)

library (sampling) data (nome data frame) srs <- srswor (n, nrow (nome data frame)) data_srs <- nome data frame [srs ==1,] data_srs STIMA CAMPIONE CASUALE SEMPLICE (CCS/SRS) library (survey) data (nome data frame) pik <- rep (n/nrow(nome data frame),n) srs_design <- svydesign (id= 1, fpc= pik, data= data_srs) totest <- svytotal ( variabile da stimare, srs_design) totest cv (totest) coef (totest) var <- svyvar ( variabile da stimare, srs_design)

PPS

library (sampling) data (nome data frame) PROB. VARIABILI pik <- inclusionprobabilities (nomedataframe$var dimensionale, n) pps <- UPtille (pik) data_pps <- nome data frame [pps ==1,] data_pps STIMA PPS library (survey) data (nome data frame) pik2 <- pik [pps ==1,] pps_design <- svydesign (id=1, fpc = pik2, data= data_pps) totest <- svytotal ( elenco variabili, pps_design) cv (totest) coef (totest) var <- svyvar ( variabili da stimare, pps_design)

CAMPIONE STRATIFICATO

library (sampling) data (nome data frame) numpop <- table (nome data frame [ ,posizione variabile]) numpop <- ceiling ((numpop/sum(numpop))*n) stratif <- strata (nome data frame, stranames = c(“Ateco”), size= numpop, method=”srswor”) data_stratif <- getdata (nome data frame, stratif) data_stratif STIMA STRATIFICATO library (survey) data (nome data frame) dstratif <- svydesign (id=1, strata= REG, data= data_stratif, fpc= stratif [,3], probs=stratif[,3]) totest <- svytotal ( variabile da stimare, dstratif, deff= TRUE) cv (totest) coef (totest) var <- svyvar (variabile da stimare, dstratif)

CAMPIONE BILANCIATO

library (sampling) data (nome data frame) pik <- rep (n/ nrow(nome data frame), nrow (nome data frame)) x <- as.matrix (nome data frame [ ,c(variabili da sottoporre a vincolo)] bal <- samplecube (x, pik, comment =TRUE) data_bal <- nome data frame [bal==1,] data_bal STIMA BILANCIATO library (survey) data (nome data frame) bal_design <- svydesign (id =1, fpc=pik, data= data_bal) totest <- svytotal ( elenco variabili, bal_design) totest

CALIBRAZIONE/REGRESSIONE

totpop <- c (‘(Intercept)’= nrow (nome data frame), Add= sum (nome data frame [,posizione variabile]), Fatt =sum (nome data frame [,posizione variabile]) REGRESSIONE dstratifg <- calibrate (dstratif, elenco variabili, totpop) CALIBRAZIONE dstratifg <- calibrate (dstratif, elenco variabili, calfun =”logit”, bounds =c(min, max), totpop)

Se chiede diff

diff <- weight (dstratifg)/ weight (dstratif)

BOOTSTRAP

boot_design <- as.svrepdesign (dstratif, type = “bootstrap” , replicates=1000) totest <- svytotal ( variabili, boot_design)

JACK KNIFE

jk_design <- as.svrepdesign (dstratif, type= “JKn”) totest <- svytotal ( variabili, jk_design)

STIME PER DOMINI

emerg_high <- subset (dstratif, emer > 20) emerg_low <- subset (dstratif, emer == 0) svymean ( variabile, emerg_high oppure emerg_low) svyby ( variabile su cui fare la stima, stype, dstratif, svytotal)

STIMA DI TABELLA A DOPPIA ENTRATA

tab <- svytotal ( interaction (variabile1, variabile2), dstratif) tab TABELLA DELL’INTERAZIONE ftab <- ftable (tab, rownames=list (Obiettivo=c(“No”,”Yes”), Premio=c(“No”,”Yes”)))