install.packages("foreign") library(foreign) POP <- read.spss("gss.sav", to.data.frame=TRUE) names(POP) View(POP) dim(POP)[1] n <-100 #set.seed(2) index <- sample(1:dim(POP)[1], n, replace = TRUE) fc <- n/dim(POP)[1] campione <- POP[index, ] attach(campione) View(campione) tab <- table(POP$GENDER)/length(POP$GENDER) tab[1] tab <- table(POP$UNEMPALL)/length(POP$UNEMPALL) tab[1] # vero valore del parametro di interesse pi di maschi stimaDonne <- 0 stimaNo <- 0 for(i in 1:1000){ index <- sample(1:32019, 100, replace = F) campione <- POP[index, ] tt <- table(campione$GENDER)/length(campione$GENDER) tt1 <- table(campione$UNEMPALL)/length(campione$UNEMPALL) stimaDonne[i]<- tt[2] stimaNo[i]<- tt1[1] } hist(stimaDonne) hist(stimaNo) sd(stimaDonne) sd(stimaNo) sqrt(0.5*0.5/100) sqrt(0.97*0.03/100)