library(dplyr)
library(survey)
library(reshape)
library(readr)
library(readxl)
library(gtools)
library(erer)
library(VGAM)
options( survey.lonely.psu = "adjust" )
setwd("W:\\Amostra\\Reponderação\\4_tri\\Workspace")
# Trazendo dados trabalhados na Reponderação das Estratégias 2 e 3
coleta_4tri<-readRDS(file="W:/Amostra/Reponderação/4_tri/255/Bases/SIPS_4tri_1744.rds")
coleta_4tri$aux <- 1
#Trazendo dados populacionais
Pos_estratos <- read.csv("W:\\Amostra\\Reponderação\\4_tri\\Workspace\\vetor_calib.csv", sep=";", dec=",", header=TRUE)
x <- subset(coleta_4tri, pos_estrato == "ServiçosIntermediário")
#Concacentando os Estratos com o Tipo de produto
Pos_estratos$pos_estrato <- paste0(Pos_estratos$Estrato,Pos_estratos$Tipo_produto)
# Vetor segundo IPCA nos 3 estratos
Pos_est1 <- Pos_estratos %>%
select(Pop_Est1,pos_estrato)
# Excluindo industria
Pos_est1 <- subset(Pos_est1,Pop_Est1>0)
coleta_4tri <- subset(coleta_4tri,Estrato != "Industria"& Estrato != "Intermediário")
plano_SIPS <- svydesign(ids = ~ 1, strata = ~ amostra_dominio, weights = ~peso_dsn,
data = coleta_4tri, nest = TRUE)
#Calibração
calibra2 = postStratify(plano_SIPS, ~pos_estrato, Pos_est1)
# Trazendo o peso para a base de dados
coleta_4tri$peso_est1 <- weights(calibra2)
# Calculando os fatores de ajuste (gweigths)
coleta_4tri$gweights2 <-coleta_4tri$peso_est1/coleta_4tri$peso_dsn
pesos_agregados<-coleta_4tri %>%
select(P1,pos_estrato,peso_est1)
pesos_agregados<-unique(pesos_agregados)
#####################################################################################
# Declarando o plano amostral sob a 2ª calibração
coleta_4tri$pos_estrato <- ifelse(coleta_4tri$pos_estrato == "ServiçosSPF", "Serviços SPF", coleta_4tri$pos_estrato)
pl_est1 <- svydesign(ids = ~ 1, strata = ~ amostra_dominio, weights = ~peso_est1,
data = coleta_4tri, nest = TRUE)
#Total pós estrato
total <- as.data.frame(svyby(~aux,~pos_estrato,pl_est1, svytotal,pps = "TRUE",na.rm = "TRUE"))
#Total estrato
total2 <- as.data.frame(svyby(~aux,~Estrato,pl_est1, svytotal,pps = "TRUE",na.rm = "TRUE"))
rm(total, total2,x)
#Primeiro cruzamento
probit_cz1=svyolr(P18_probit~P4_v2, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1)
Call:
svyolr(P18_probit ~ P4_v2, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
P4_v22 0.3160 0.1117 2.829
P4_v23 0.6368 0.1704 3.738
Intercepts:
Value Std. Error t value
1|2 -0.070 0.068 -1.033
2|3 1.580 0.104 15.206
(22 observations deleted due to missingness)
#AIC
probit_cz1$deviance+2*length(probit_cz1$coefficients)
[1] 1843
#Segundo cruzamento
probit_cz2=svyolr(P18_probit~P10_v2, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2)
Call:
svyolr(P18_probit ~ P10_v2, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
P10_v22 0.1314 0.1126 1.1671
P10_v23 0.1972 0.2033 0.9701
Intercepts:
Value Std. Error t value
1|2 -0.157 0.071 -2.213
2|3 1.427 0.096 14.825
(25 observations deleted due to missingness)
#AIC
probit_cz2$deviance+2*length(probit_cz2$coefficients)
[1] 1888
probit_cz1_AFD=svyolr(P18_probit~AFD_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_AFD)
Call:
svyolr(P18_probit ~ AFD_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
AFD_42 0.03073 0.1806 0.1701
AFD_43 0.37376 0.4277 0.8739
Intercepts:
Value Std. Error t value
1|2 -0.354 0.118 -2.987
2|3 1.970 0.216 9.100
(860 observations deleted due to missingness)
probit_cz1_AFD$deviance+2*length(probit_cz1_AFD$coefficients)
[1] 285.7
probit_cz1_AND=svyolr(P18_probit~AND_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_AND)
Call:
svyolr(P18_probit ~ AND_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
AND_42 0.3433 0.1523 2.254
AND_43 0.9613 0.3662 2.625
Intercepts:
Value Std. Error t value
1|2 0.101 0.105 0.962
2|3 1.589 0.151 10.544
(788 observations deleted due to missingness)
probit_cz1_AND$deviance+2*length(probit_cz1_AND$coefficients)
[1] 469.1
probit_cz1_COM=svyolr(P18_probit~COM_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_COM)
Call:
svyolr(P18_probit ~ COM_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
COM_42 -0.1538 0.4682 -0.3285
Intercepts:
Value Std. Error t value
1|2 -1.179 0.291 -4.047
2|3 0.567 0.325 1.744
(1021 observations deleted due to missingness)
probit_cz1_COM$deviance+2*length(probit_cz1_COM$coefficients)
[1] 48.22
probit_cz1_DESP=svyolr(P18_probit~DESP_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_DESP)
Call:
svyolr(P18_probit ~ DESP_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
DESP_42 0.2997 0.3021 0.9922
DESP_43 0.3366 0.7571 0.4445
Intercepts:
Value Std. Error t value
1|2 0.107 0.210 0.509
2|3 2.030 0.225 9.011
(937 observations deleted due to missingness)
probit_cz1_DESP$deviance+2*length(probit_cz1_DESP$coefficients)
[1] 178.7
probit_cz1_TP=svyolr(P18_probit~TP_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_TP)
Call:
svyolr(P18_probit ~ TP_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
TP_42 0.2843 0.1812 1.569
TP_43 0.6037 0.3336 1.810
Intercepts:
Value Std. Error t value
1|2 -0.293 0.115 -2.548
2|3 1.450 0.141 10.257
(864 observations deleted due to missingness)
probit_cz1_TP$deviance+2*length(probit_cz1_TP$coefficients)
[1] 334
probit_cz1_VT=svyolr(P18_probit~VT_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_VT)
Call:
svyolr(P18_probit ~ VT_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
VT_42 0.5776 0.2418 2.389
VT_43 0.7418 0.4952 1.498
Intercepts:
Value Std. Error t value
1|2 -0.054 0.164 -0.332
2|3 2.088 0.266 7.851
(936 observations deleted due to missingness)
probit_cz1_VT$deviance+2*length(probit_cz1_VT$coefficients)
[1] 176.6
probit_cz1_HB=svyolr(P18_probit~HB_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_HB)
Call:
svyolr(P18_probit ~ HB_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
HB_42 0.06332 0.6887 0.09194
HB_43 5.73866 0.9477 6.05563
Intercepts:
Value Std. Error t value
1|2 0.703 0.474 1.483
2|3 6.169 0.481 12.829
(1011 observations deleted due to missingness)
probit_cz1_HB$deviance+2*length(probit_cz1_HB$coefficients)
[1] 43.24
probit_cz1_DP=svyolr(P18_probit~DP_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_DP)
Call:
svyolr(P18_probit ~ DP_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
DP_42 -0.7731 0.8170 -0.9462
DP_43 -5.5312 0.3585 -15.4281
Intercepts:
Value Std. Error t value
1|2 -0.071 0.308 -0.232
2|3 0.791 0.327 2.415
(1024 observations deleted due to missingness)
probit_cz1_DP$deviance+2*length(probit_cz1_DP$coefficients)
[1] 45.01
probit_cz1_CP=svyolr(P18_probit~CP_4, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz1_CP)
Call:
svyolr(P18_probit ~ CP_4, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
CP_42 0.6539 0.3724 1.7558
CP_43 0.1771 0.6196 0.2857
Intercepts:
Value Std. Error t value
1|2 -0.098 0.285 -0.344
2|3 1.764 0.393 4.485
(999 observations deleted due to missingness)
probit_cz1_CP$deviance+2*length(probit_cz1_CP$coefficients)
[1] 84.5
probit_cz2_AFD=svyolr(P18_probit~AFD_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_AFD)
Call:
svyolr(P18_probit ~ AFD_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
AFD_102 0.3791 0.1831 2.071
AFD_103 0.6509 0.5905 1.102
Intercepts:
Value Std. Error t value
1|2 -0.191 0.132 -1.442
2|3 2.174 0.238 9.144
(859 observations deleted due to missingness)
probit_cz2_AFD$deviance+2*length(probit_cz2_AFD$coefficients)
[1] 282.3
probit_cz2_AND=svyolr(P18_probit~AND_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_AND)
Call:
svyolr(P18_probit ~ AND_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
AND_102 0.05472 0.1530 0.3578
AND_103 -1.00633 0.6095 -1.6512
Intercepts:
Value Std. Error t value
1|2 -0.064 0.106 -0.602
2|3 1.377 0.137 10.072
(789 observations deleted due to missingness)
probit_cz2_AND$deviance+2*length(probit_cz2_AND$coefficients)
[1] 477
probit_cz2_COM=svyolr(P18_probit~COM_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_COM)
Call:
svyolr(P18_probit ~ COM_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
COM_102 0.0823027 0.5460 0.1507330
COM_103 -0.0003125 0.6005 -0.0005204
Intercepts:
Value Std. Error t value
1|2 -1.100 0.537 -2.049
2|3 0.686 0.491 1.397
(1020 observations deleted due to missingness)
probit_cz2_COM$deviance+2*length(probit_cz2_COM$coefficients)
[1] 51.43
probit_cz2_DESP=svyolr(P18_probit~DESP_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_DESP)
Call:
svyolr(P18_probit ~ DESP_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
DESP_102 0.7418 0.3042 2.438
DESP_103 -1.1156 0.6471 -1.724
Intercepts:
Value Std. Error t value
1|2 0.143 0.212 0.675
2|3 2.204 0.261 8.429
(938 observations deleted due to missingness)
probit_cz2_DESP$deviance+2*length(probit_cz2_DESP$coefficients)
[1] 165.8
probit_cz2_TP=svyolr(P18_probit~TP_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_TP)
Call:
svyolr(P18_probit ~ TP_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
TP_102 0.3618 0.1758 2.058
TP_103 0.6233 0.4032 1.546
Intercepts:
Value Std. Error t value
1|2 -0.267 0.125 -2.138
2|3 1.484 0.166 8.954
(865 observations deleted due to missingness)
probit_cz2_TP$deviance+2*length(probit_cz2_TP$coefficients)
[1] 330.7
probit_cz2_VT=svyolr(P18_probit~VT_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_VT)
Call:
svyolr(P18_probit ~ VT_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
VT_102 0.06228 0.2235 0.2787
VT_103 0.41865 0.5951 0.7035
Intercepts:
Value Std. Error t value
1|2 -0.254 0.167 -1.516
2|3 1.769 0.198 8.933
(939 observations deleted due to missingness)
probit_cz2_VT$deviance+2*length(probit_cz2_VT$coefficients)
[1] 179.7
probit_cz2_HB=svyolr(P18_probit~HB_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_HB)
Call:
svyolr(P18_probit ~ HB_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
HB_102 -0.9879 0.6025 -1.640
HB_103 -4.9780 0.5340 -9.322
Intercepts:
Value Std. Error t value
1|2 0.193 0.498 0.388
2|3 1.967 0.430 4.578
(1011 observations deleted due to missingness)
probit_cz2_HB$deviance+2*length(probit_cz2_HB$coefficients)
[1] 44.56
probit_cz2_DP=svyolr(P18_probit~DP_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_DP)
Call:
svyolr(P18_probit ~ DP_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
DP_102 0.1159 0.5369 0.2159
DP_103 0.6309 0.4220 1.4952
Intercepts:
Value Std. Error t value
1|2 0.217 0.402 0.540
2|3 1.044 0.492 2.124
(1024 observations deleted due to missingness)
probit_cz2_DP$deviance+2*length(probit_cz2_DP$coefficients)
[1] 46.98
probit_cz2_CP=svyolr(P18_probit~CP_10, design = pl_est1,method="probit",na.action = na.omit)
summary(probit_cz2_CP)
Call:
svyolr(P18_probit ~ CP_10, design = pl_est1, method = "probit",
na.action = na.omit)
Coefficients:
Value Std. Error t value
CP_102 -0.07865 0.3576 -0.2199
CP_103 0.44452 0.3238 1.3729
Intercepts:
Value Std. Error t value
1|2 -0.453 0.313 -1.448
2|3 1.342 0.389 3.453
(999 observations deleted due to missingness)
probit_cz2_CP$deviance+2*length(probit_cz2_CP$coefficients)
[1] 87.84