Carregando bibliotecas

# "limpar" ambiente
rm(list = ls())

# Carregar bibliotecas
library(readxl)
library(readr) 
library(mfx)
#library(caret)
library(pROC)
library(ResourceSelection)
#library(modEvA)
library(foreign)
library(stargazer) #Hlavac, Marek (2022) 
library(ggplot2)
library(glm2)
library(PerformanceAnalytics)
library(nnet) #logit multinomial
library(car)
library(reshape2)
library(lmtest)
library(MASS)
library(pROC)
library(dplyr)
#library(margins)
#library(broom)
library(corrplot)
library(psych)
library(factoextra)
library(FactoMineR)
library(stats)
library(RColorBrewer)

Exercício de Robustez

Foi retirado a categoria Active da base de informações afim de testar se os resultados do modelo permanecem de maneira similar aos dados originais, afim de atestar o poder preditivo do modelo estimado.

m2 <- read_excel("C:/Users/kassy/OneDrive - caen.ufc.br/1. CAEN/3. Doutorado/Thesis/Test banco mundial/corrigidaBDsemactive.xlsx") #corrigidaBDsemactive base original - alternativa #subsetNBIDScorrigidaBDprincipal 
# Verificar missing values
colSums(is.na(m2))
##                   Region                  Country              IncomeGroup 
##                        0                        0                        0 
##               IDA Status   Financial closure year  Financial closure Month 
##                        0                        0                        0 
##             Project name             RelatedNames              Type of PPI 
##                        0                      186                        0 
##                   catppp           Subtype of PPI           Project status 
##                        0                        0                        0 
##           Primary sector                  sectorR                Subsector 
##                        0                        0                        0 
##                  Segment                 Location           ContractPeriod 
##                        1                        6                        0 
##     GovtGrantingContract        DirectGovtSupport   DirectGovtSupportValue 
##                        0                        0                      313 
##      InDirectGovtSupport InDirectGovtSupportValue             Total Equity 
##                        0                      331                      319 
##           InvestmentYear           PercentPrivate         FeesToGovernment 
##                        0                        0                        0 
##           PhysicalAssets          TotalInvestment         TotalInvestment1 
##                        0                        0                        0 
##                    inv/t             CapacityType                 Capacity 
##                        0                        0                        0 
##               Technology          RelatedProjects              BidCriteria 
##                        0                      309                        0 
##                   catbid              AwardMethod             NumberOfBids 
##                        0                        0                      183 
##                 Sponsors         Sponsors Country      Main Revenue Source 
##                        0                        0                        0 
##     Other Revenue Source      MultiLateralSupport         BiLateralSupport 
##                        0                        3                        3 
##         TotalDebtFunding     DebtEquityGrantRatio             ProjectBanks 
##                        0                      321                        0 
##      UnsolicitedProposal         PublicDisclosure 
##                        0                        0
#colSums(is.na(m2))
#tirar tipos de PPI
#m2 <- subset(m2, `Project status` != "Active")
#m2 <- subset(m2, `Project status` != "Distressed")
#m2 <- subset(m2, `Type of PPI` != "Divestiture")
#with(m1, table(m1$catstatus, m1$`Project status`))

# Crie uma tabela cruzada com as contagens
tabela_contagem <- table(m2$`Type of PPI`)

# Crie um data frame com a contagem e os percentuais
tabela_completa <- data.frame(Contagem = tabela_contagem, Percentual = prop.table(tabela_contagem) * 100)

# Exiba a tabela
print(tabela_completa)
##                   Contagem.Var1 Contagem.Freq               Percentual.Var1
## 1                    Brownfield           145                    Brownfield
## 2                   Divestiture            40                   Divestiture
## 3            Greenfield project            88            Greenfield project
## 4 Management and lease contract            71 Management and lease contract
##   Percentual.Freq
## 1        42.15116
## 2        11.62791
## 3        25.58140
## 4        20.63953
#with(m2, table(m2$catstatus, m2$`Project status`))
# Crie uma tabela cruzada com as contagens
tabela_contagem2 <- table(m2$`Project status`)

# Crie um data frame com a contagem e os percentuais
tabela_completa2 <- data.frame(Contagem = tabela_contagem2, Percentual = prop.table(tabela_contagem2) * 100)

# Exiba a tabela
print(tabela_completa2)
##   Contagem.Var1 Contagem.Freq Percentual.Var1 Percentual.Freq
## 1     Cancelled           176       Cancelled        51.16279
## 2     Concluded           107       Concluded        31.10465
## 3    Distressed            61      Distressed        17.73256

Definição das variáveis m2

Categorização dos tipos de contratos para escrever as equações como:

\(ln(\frac{P(status=Cancelled)}{P(status=Concluded)})\), \(ln(\frac{P(status=Distressed)}{P(status=Concluded)})\)

m2$`Project status` <- as.factor(m2$`Project status`)

m2$`Project status` <- relevel(m2$`Project status`, ref = "Concluded")
is.factor(m2$`Project status`)
## [1] TRUE
ITm2=m2$TotalInvestment1
percentprivm2=m2$PercentPrivate
tm2=m2$ContractPeriod
t2 = tm2^2
#t3 = tm2^3
km2=m2$PhysicalAssets
inv_t=m2$`inv/t`
#inv.year = m2$InvestmentYear
#inv.year = factor(inv.year)
debtm2=m2$TotalDebtFunding
#catstatusm2=m2$catstatus
statusm2=m2$`Project status`

TESTE - Inclusão do Número de Bids.

Hipótese: Relação positiva entre a quantidade de bids e o insucesso dos projetos.

nbids=m2$NumberOfBids

variáveis categóricas m2

catpppm2=m2$catppp

m2$catppp=factor(m2$catppp)
m2$catbid=factor(m2$catbid)
#catsubtypem2=m2$catsubtype
#catsetorm2=m2$catsetor
#catsetor2m2=m2$catsetor2
#catsetorm2=m2$catsetor3
catbidm2 = m2$catbid
award = m2$AwardMethod
m2$AwardMethod = factor(m2$AwardMethod)
award = factor(award)
award <- relevel(award, ref = "Not Available")
m2$sectorR <- as.factor(m2$sectorR)
m2$sectorR <- relevel(m2$sectorR, ref = "Enrg")
is.factor(m2$sectorR)
## [1] TRUE
# numericamente
sector = m2$sectorR
catpppm2 = factor(catpppm2)
#catsetorm2 = factor(catsetorm2)
#catsetor2m2 = factor(catsetor2m2)
#catsetorm2 = factor(catsetorm2)
#catsubtypem2 = factor(catsubtypem2) 
catbidm2 = factor(catbidm2)
#catstatusm2 = factor(catstatusm2)
#status=m2$`Project status`

Categoria de Renda

income = m2$IncomeGroup 
income = factor(income)
income <- relevel(income, ref = "Lower middle income")

Fatores categoricos

resultado_mca <- MCA(m2[, c("catbid", "catppp", "sectorR", "AwardMethod")], graph = FALSE)

summary(resultado_mca)
## 
## Call:
## MCA(X = m2[, c("catbid", "catppp", "sectorR", "AwardMethod")],  
##      graph = FALSE) 
## 
## 
## Eigenvalues
##                        Dim.1   Dim.2   Dim.3   Dim.4   Dim.5   Dim.6   Dim.7
## Variance               0.555   0.410   0.338   0.324   0.303   0.268   0.259
## % of var.             12.338   9.115   7.505   7.200   6.727   5.966   5.759
## Cumulative % of var.  12.338  21.454  28.959  36.159  42.886  48.853  54.612
##                        Dim.8   Dim.9  Dim.10  Dim.11  Dim.12  Dim.13  Dim.14
## Variance               0.252   0.250   0.250   0.236   0.220   0.209   0.172
## % of var.              5.605   5.556   5.556   5.244   4.888   4.642   3.825
## Cumulative % of var.  60.217  65.772  71.328  76.572  81.460  86.101  89.926
##                       Dim.15  Dim.16  Dim.17  Dim.18
## Variance               0.150   0.135   0.087   0.081
## % of var.              3.339   3.002   1.930   1.802
## Cumulative % of var.  93.265  96.268  98.198 100.000
## 
## Individuals (the 10 first)
##             Dim.1    ctr   cos2    Dim.2    ctr   cos2    Dim.3    ctr   cos2  
## 1        | -0.040  0.001  0.001 |  0.133  0.013  0.012 | -0.553  0.263  0.201 |
## 2        | -0.040  0.001  0.001 |  0.133  0.013  0.012 | -0.553  0.263  0.201 |
## 3        | -0.040  0.001  0.001 |  0.133  0.013  0.012 | -0.553  0.263  0.201 |
## 4        | -0.627  0.206  0.206 |  0.293  0.061  0.045 | -0.362  0.113  0.069 |
## 5        | -0.627  0.206  0.206 |  0.293  0.061  0.045 | -0.362  0.113  0.069 |
## 6        | -0.455  0.108  0.131 | -0.324  0.074  0.066 | -0.177  0.027  0.020 |
## 7        | -0.040  0.001  0.001 |  0.133  0.013  0.012 | -0.553  0.263  0.201 |
## 8        |  0.132  0.009  0.015 | -0.484  0.166  0.196 | -0.368  0.117  0.113 |
## 9        | -0.633  0.210  0.130 |  0.161  0.018  0.008 | -0.281  0.068  0.026 |
## 10       | -0.970  0.492  0.586 | -0.218  0.034  0.029 |  0.058  0.003  0.002 |
## 
## Categories (the 10 first)
##              Dim.1     ctr    cos2  v.test     Dim.2     ctr    cos2  v.test  
## catbid_1 |  -0.343   4.059   0.388 -11.530 |   0.023   0.024   0.002   0.762 |
## catbid_2 |   1.916   0.480   0.011   1.916 |  -1.660   0.488   0.008  -1.660 |
## catbid_3 |   1.711   2.682   0.061   4.566 |  -1.569   3.054   0.051  -4.189 |
## catbid_4 |   0.910   3.792   0.094   5.671 |  -0.852   4.501   0.082  -5.310 |
## catbid_5 |   0.758   0.827   0.019   2.551 |   2.879  16.156   0.274   9.692 |
## catbid_6 |   1.129   1.167   0.026   3.013 |   0.666   0.550   0.009   1.777 |
## catbid_7 |   1.753   5.228   0.121   6.434 |  -0.380   0.333   0.006  -1.395 |
## catbid_8 |   0.953   0.713   0.016   2.351 |   0.848   0.765   0.013   2.093 |
## catppp_1 |   0.725   9.981   0.383  11.465 |  -0.520   6.950   0.197  -8.223 |
## catppp_2 |  -1.045   5.716   0.144  -7.019 |  -0.450   1.437   0.027  -3.025 |
##            Dim.3     ctr    cos2  v.test  
## catbid_1  -0.272   4.217   0.245  -9.166 |
## catbid_2  -0.020   0.000   0.000  -0.020 |
## catbid_3   0.161   0.039   0.001   0.429 |
## catbid_4   1.117   9.404   0.141   6.965 |
## catbid_5   3.139  23.318   0.325  10.565 |
## catbid_6   0.274   0.113   0.002   0.731 |
## catbid_7  -0.366   0.375   0.005  -1.345 |
## catbid_8   0.006   0.000   0.000   0.014 |
## catppp_1  -0.168   0.875   0.020  -2.648 |
## catppp_2   0.466   1.869   0.029   3.131 |
## 
## Categorical variables (eta2)
##               Dim.1 Dim.2 Dim.3  
## catbid      | 0.421 0.424 0.506 |
## catppp      | 0.647 0.577 0.071 |
## sectorR     | 0.477 0.458 0.537 |
## AwardMethod | 0.676 0.181 0.237 |
# Visualize as coordenadas das categorias no plano principal
plot(resultado_mca, choix = "var")

# Visualize as coordenadas das observações no plano principal
plot(resultado_mca, choix = "ind")

resultado_mca$ind$coord
##           Dim 1        Dim 2         Dim 3       Dim 4        Dim 5
## 1   -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 2   -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 3   -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 4   -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 5   -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 6   -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 7   -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 8    0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 9   -0.63347547  0.160710692 -0.2805342033 -0.75444776  0.229543302
## 10  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 11  -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 12  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 13  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 14  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 15  -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 16  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 17  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 18  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 19  -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 20  -0.44843573  0.949186172 -0.9076723645  0.29703038 -0.294714162
## 21   0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 22  -0.08933310  0.369961902 -0.1141115255  0.33622319 -0.024320268
## 23  -0.68049379 -0.551762462  0.3649316216  0.88149408 -1.442191198
## 24  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 25  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 26  -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 27  -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 28  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 29  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 30  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 31   0.13859829  0.789745041 -1.0988437594 -0.06636307 -0.296538790
## 32   0.13859829  0.789745041 -1.0988437594 -0.06636307 -0.296538790
## 33  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 34   0.80124212  0.639840195  0.2512591169 -0.81431129 -0.552269143
## 35   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 36  -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 37   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 38  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 39   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 40  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 41   0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 42  -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 43  -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 44  -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 45  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 46  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 47   0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 48  -0.18732120  1.752654442 -0.5123117145 -1.89673494  1.985190175
## 49  -0.01914689 -0.613982613  0.9851839950 -1.57956813 -0.682545883
## 50  -0.01914689 -0.613982613  0.9851839950 -1.57956813 -0.682545883
## 51   0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 52  -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 53  -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 54   0.15450210 -0.299865718  0.1147359189 -0.10095223 -0.324797189
## 55  -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 56  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 57  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 58  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 59  -0.32128815  1.050071309 -0.7201931510 -0.24052886 -0.759189425
## 60   0.45804331  0.129453706  0.6712779561 -0.88809325 -0.850921436
## 61   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 62   0.19386041  0.943505301 -0.9551908643  0.04296041 -0.272870093
## 63   0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 64  -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 65  -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 66  -0.32128815  1.050071309 -0.7201931510 -0.24052886 -0.759189425
## 67   0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 68   0.02191066  1.560457798 -1.1402119902 -0.16674690 -0.460537132
## 69   0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 70   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 71   0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 72   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 73  -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 74  -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 75   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 76   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 77   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 78   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 79   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 80   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 81   0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 82   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 83   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 84   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 85   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 86   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 87   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 88   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 89   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 90   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 91   0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 92   0.91792975 -0.130872562  0.2926273478 -0.71392745 -0.388270801
## 93   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 94  -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 95  -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 96   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 97   0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 98   0.93229609  0.532839051 -0.1856928851 -0.17360240 -0.974543766
## 99  -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 100  0.91792975 -0.130872562  0.2926273478 -0.71392745 -0.388270801
## 101  0.91792975 -0.130872562  0.2926273478 -0.71392745 -0.388270801
## 102  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 103  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 104  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 105  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 106  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 107  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 108  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 109  1.10424585 -0.084113446 -0.0006717592  0.03610492 -0.786876727
## 110  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 111 -0.63347547  0.160710692 -0.2805342033 -0.75444776  0.229543302
## 112 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 113  0.13859829  0.789745041 -1.0988437594 -0.06636307 -0.296538790
## 114  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 115  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 116  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 117  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 118  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 119  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 120  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 121  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 122  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 123  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 124  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 125  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 126  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 127  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 128  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 129  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 130  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 131  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 132  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 133  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 134  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 135  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 136  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 137  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 138 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 139 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 140 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 141 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 142 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 143 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 144 -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 145 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 146 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 147 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 148 -0.43253191 -0.140424587  0.3059073138  0.26244123 -0.322972561
## 149 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 150 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 151 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 152  0.86698950  1.325568588  1.1621233945  0.25949201  0.225111334
## 153 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 154 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 155 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 156 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 157  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 158 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 159 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 160  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 161  0.57629676  0.003995497  0.3058755128  0.58814325 -0.542802148
## 162 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 163 -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 164 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 165  0.02191066  1.560457798 -1.1402119902 -0.16674690 -0.460537132
## 166 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 167  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 168 -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 169  1.08411700  0.824061709 -0.3870369366  0.06615227 -0.052033192
## 170  1.08411700  0.824061709 -0.3870369366  0.06615227 -0.052033192
## 171  0.49770091  0.210520771 -0.3052829203 -0.02717026 -0.026144896
## 172  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 173  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 174  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 175 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 176 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 177 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 178 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 179 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 180 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 181 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 182 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 183 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 184  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 185  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 186  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 187 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 188  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 189  0.02191066  1.560457798 -1.1402119902 -0.16674690 -0.460537132
## 190 -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 191  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 192 -0.03959764  0.133434255 -0.5530720113  0.03741095  0.225166091
## 193  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 194  0.53149458  0.721833131  0.3083336004 -0.15912331 -1.194944450
## 195  1.42731216 -1.063357931 -0.0117698245  0.61798575  0.684422335
## 196 -0.43937573 -0.272589280  0.3872737269 -0.89281094 -0.320419977
## 197 -0.43937573 -0.272589280  0.3872737269 -0.89281094 -0.320419977
## 198  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 199 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 200  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 201 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 202 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 203 -0.62663166  0.292875386 -0.3619006165  0.40080441  0.226990718
## 204 -0.08933310  0.369961902 -0.1141115255  0.33622319 -0.024320268
## 205 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 206  0.08261666 -0.246990595  0.0709096004  0.54593050  0.163346771
## 207 -0.01914689 -0.613982613  0.9851839950 -1.57956813 -0.682545883
## 208 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 209 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 210 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 211 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 212  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 213 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 214 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 215 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 216 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 217  0.75030187  2.096281345  1.1207551636  0.15910818  0.061112992
## 218 -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 219  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 220  0.02191066  1.560457798 -1.1402119902 -0.16674690 -0.460537132
## 221  0.19386041  0.943505301 -0.9551908643  0.04296041 -0.272870093
## 222 -0.43253191 -0.140424587  0.3059073138  0.26244123 -0.322972561
## 223  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 224  0.55296304  0.364281031 -0.1616300253  0.08215322 -0.002476199
## 225 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 226  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 227  0.35825950  1.878846223  1.7853457624 -0.06454679  1.015641852
## 228 -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 229  0.35825950  1.878846223  1.7853457624 -0.06454679  1.015641852
## 230  0.31054804  0.172792544 -0.9138226334  0.14334424 -0.108871750
## 231 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 232  0.01566448  0.287194515 -0.4094191162  0.14673444  0.248834788
## 233 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 234 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 235  0.92225163  1.479328848  1.3057762895  0.36881549  0.248780031
## 236  1.04664315  0.615267123  0.0733358871  0.12436597 -0.708625118
## 237  0.01566448  0.287194515 -0.4094191162  0.14673444  0.248834788
## 238  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 239 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 240  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 241 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 242 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 243 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 244 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 245 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 246 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 247 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 248 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 249  0.01566448  0.287194515 -0.4094191162  0.14673444  0.248834788
## 250  0.75030187  2.096281345  1.1207551636  0.15910818  0.061112992
## 251  0.08261666 -0.246990595  0.0709096004  0.54593050  0.163346771
## 252 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 253  1.16333078 -0.155445634  0.1147041180  0.22474980 -0.544626776
## 254  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 255  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 256  1.16333078 -0.155445634  0.1147041180  0.22474980 -0.544626776
## 257  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 258  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 259  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 260  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 261  0.77158847 -0.868370342  0.2572268649  1.15675292  0.687482889
## 262  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 263  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 264  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 265  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 266  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 267  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 268  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 269  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 270  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 271  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 272  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 273  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 274  1.35862249 -1.027811473  0.0660554700  0.79335946  0.685658262
## 275  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 276  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 277  1.37275438 -0.563603546 -0.1606475798  0.37624341  0.299632190
## 278  0.36177070  2.776359599  6.2284140577  2.90664216  1.469993716
## 279 -0.45468190 -0.324077111 -0.1768794905  0.61051172  0.414657758
## 280  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 281 -0.79163454  0.438799683 -0.4876535253  0.22324842 -0.593366455
## 282 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 283 -1.26752780 -0.392321331  0.5561030164  1.24488753 -1.440366570
## 284 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 285 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 286 -0.97667428 -0.349675797  0.1394846360 -0.82822972 -0.069108991
## 287 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 288 -0.32128815  1.050071309 -0.7201931510 -0.24052886 -0.759189425
## 289 -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 290  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 291  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 292  0.01566448  0.287194515 -0.4094191162  0.14673444  0.248834788
## 293 -0.32128815  1.050071309 -0.7201931510 -0.24052886 -0.759189425
## 294 -0.84732191  0.599586356 -0.1617153526 -1.08187676  0.662367282
## 295 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 296 -0.54832764  0.686711889  0.0701503566 -0.28662785  1.015696609
## 297  0.75030187  2.096281345  1.1207551636  0.15910818  0.061112992
## 298 -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 299  0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 300  0.02191066  1.560457798 -1.1402119902 -0.16674690 -0.460537132
## 301  0.53149458  0.721833131  0.3083336004 -0.15912331 -1.194944450
## 302  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 303  0.40710306  1.585894856  1.5407740029  0.08532622 -0.237539301
## 304 -0.49948408  0.393760523 -0.1744214029 -0.13675484 -0.237484544
## 305 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 306  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 307  0.01566448  0.287194515 -0.4094191162  0.14673444  0.248834788
## 308 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 309 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 310  0.81560847  1.303551808 -0.2270611160 -0.27398623 -1.138542109
## 311  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 312  0.58909728  0.022452562  0.2343259541 -0.24738436 -1.273196059
## 313 -1.01867402  0.075440263  0.3026899823  0.17714943  1.181519579
## 314 -0.01102908  0.763798406  0.3179394475 -0.35120907  0.764385622
## 315  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 316  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 317  0.08261666 -0.246990595  0.0709096004  0.54593050  0.163346771
## 318 -1.05655378  0.791783000  0.4661849231 -2.81186480  3.108094589
## 319  0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 320  0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 321 -0.79163454  0.438799683 -0.4876535253  0.22324842 -0.593366455
## 322 -0.06799045 -0.321031247  1.2297557545 -1.72944114  0.570635270
## 323 -0.06799045 -0.321031247  1.2297557545 -1.72944114  0.570635270
## 324 -0.20460053  0.279358552 -0.6788249201 -0.14014503 -0.595191082
## 325 -0.38279646 -0.376952234 -0.1330531721 -0.03637101 -0.073486202
## 326  0.66965067 -0.406431726 -0.1202617944  0.18253705  0.161522143
## 327 -0.06324333  0.974623230  1.7733136286  0.54910350 -0.071716331
## 328 -0.46152572 -0.456241805 -0.0955130774 -0.54474044  0.417210341
## 329  1.08411700  0.824061709 -0.3870369366  0.06615227 -0.052033192
## 330  0.87469339  1.232219620 -0.1116852388 -0.08534135 -0.896292157
## 331  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 332  0.03781448  0.470847039  0.0733676881 -0.20133606 -0.488795531
## 333  0.81560847  1.303551808 -0.2270611160 -0.27398623 -1.138542109
## 334 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 335 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 336  0.57473094 -0.641259051  0.7126461870 -0.78770942 -0.686923094
## 337 -0.15628527  0.904147012 -0.5944402422 -0.06297288  0.061167748
## 338  0.38101329  0.981233528 -0.3466511512 -0.12755409 -0.190143238
## 339 -0.96983047 -0.217511103  0.0581182228  0.32702244 -0.071661574
## 340  1.08987950 -0.747825059  0.4776484737 -0.50422014 -0.200603762
## 341  0.00206327  0.181893693  0.4254973490  0.11600909 -1.271371431
## 342  0.75030187  2.096281345  1.1207551636  0.15910818  0.061112992
## 343  0.13235211 -0.483518242 -0.3680508854  0.24711827  0.412833130
## 344 -0.06799045 -0.321031247  1.2297557545 -1.72944114  0.570635270

Criação de fatores

#Data frame com as variáveis númericas
data1 <- data.frame(inv_t, t2, tm2, percentprivm2)
datacat <- data.frame(catbidm2, catpppm2, sector)

matcor <- cor(data1)

print(matcor, digits = 2)
##                inv_t    t2   tm2 percentprivm2
## inv_t          1.000 -0.11 -0.16         0.061
## t2            -0.113  1.00  0.87        -0.118
## tm2           -0.163  0.87  1.00        -0.209
## percentprivm2  0.061 -0.12 -0.21         1.000
corrplot(matcor, method = "circle")

cortest.bartlett(data1)
## R was not square, finding R from data
## $chisq
## [1] 517.8158
## 
## $p.value
## [1] 1.219974e-108
## 
## $df
## [1] 6
#Ho: A matriz de correlação da população é uma matriz identidade, ou seja as variáveis não são correlacionadas na população.

#H1: A matriz de correlação da população não é uma matriz identidade, ou seja as variáveis são correlacionadas na população.
KMO(data1)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = data1)
## Overall MSA =  0.51
## MSA for each item = 
##         inv_t            t2           tm2 percentprivm2 
##          0.69          0.50          0.50          0.49

A estatística KMO maior que 0,5 também concorda quanto ao fato de que a análise fatorial pode ser considerada uma técnica apropriada para analisar a matriz de correlação.

Análise Fatorial

fit <- princomp(data1, cor=TRUE)
fit
## Call:
## princomp(x = data1, cor = TRUE)
## 
## Standard deviations:
##    Comp.1    Comp.2    Comp.3    Comp.4 
## 1.4043807 0.9839081 0.9681648 0.3497095 
## 
##  4  variables and  344 observations.
summary(fit)
## Importance of components:
##                           Comp.1    Comp.2    Comp.3     Comp.4
## Standard deviation     1.4043807 0.9839081 0.9681648 0.34970945
## Proportion of Variance 0.4930713 0.2420188 0.2343358 0.03057418
## Cumulative Proportion  0.4930713 0.7350900 0.9694258 1.00000000
screeplot(fit)

plot(fit,type="lines")

A função \(summary(fit)\) mostra a aplicação da análise de componentes principais. O fator 1 responde por 62,82% da variância total. Da mesma forma, o segundo fator responde por 25,03% da variância total, sendo que os dois primeiros fatores respondem por 87,86% da variância total. Várias considerações devem integrar a análise do número de fatores que devem ser usados na análise.

ACP

PCAdente<-principal(data1, nfactors=1,
                n.obs=344,rotate="none", scores=TRUE)
PCAdente
## Principal Components Analysis
## Call: principal(r = data1, nfactors = 1, rotate = "none", n.obs = 344, 
##     scores = TRUE)
## Standardized loadings (pattern matrix) based upon correlation matrix
##                 PC1    h2    u2 com
## inv_t         -0.29 0.084 0.916   1
## t2             0.93 0.865 0.135   1
## tm2            0.95 0.911 0.089   1
## percentprivm2 -0.34 0.113 0.887   1
## 
##                 PC1
## SS loadings    1.97
## Proportion Var 0.49
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 component is sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.12 
##  with the empirical chi square  61.26  with prob <  5e-14 
## 
## Fit based upon off diagonal values = 0.9
PCAdentevarimax <- principal(data1, nfactors=3,
            n.obs=344, rotate="varimax",scores=TRUE)

PCAdentevarimax
## Principal Components Analysis
## Call: principal(r = data1, nfactors = 3, rotate = "varimax", n.obs = 344, 
##     scores = TRUE)
## Standardized loadings (pattern matrix) based upon correlation matrix
##                 RC1   RC3   RC2   h2      u2 com
## inv_t         -0.08  0.03  1.00 1.00 0.00018 1.0
## t2             0.97 -0.02 -0.04 0.94 0.05901 1.0
## tm2            0.96 -0.13 -0.09 0.94 0.06244 1.1
## percentprivm2 -0.09  1.00  0.03 1.00 0.00067 1.0
## 
##                        RC1  RC3  RC2
## SS loadings           1.87 1.01 1.00
## Proportion Var        0.47 0.25 0.25
## Cumulative Var        0.47 0.72 0.97
## Proportion Explained  0.48 0.26 0.26
## Cumulative Proportion 0.48 0.74 1.00
## 
## Mean item complexity =  1
## Test of the hypothesis that 3 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.03 
##  with the empirical chi square  2.61  with prob <  NA 
## 
## Fit based upon off diagonal values = 1
PCAdentevarimax$values
## [1] 1.9722850 0.9680751 0.9373431 0.1222967
PCAdentevarimax$loadings
## 
## Loadings:
##               RC1    RC3    RC2   
## inv_t                        0.997
## t2             0.969              
## tm2            0.955 -0.128       
## percentprivm2         0.995       
## 
##                  RC1   RC3   RC2
## SS loadings    1.866 1.008 1.004
## Proportion Var 0.466 0.252 0.251
## Cumulative Var 0.466 0.718 0.969
biplot(PCAdentevarimax)

pca=PCA(data1, graph = TRUE)

fviz_eig(pca, addlabels=TRUE, ylim = c(0,100))

variaveis=get_pca_var(pca)
head(variaveis$coord)
##                    Dim.1     Dim.2       Dim.3       Dim.4
## inv_t         -0.2892397 0.7928133 -0.53629090  0.01339958
## t2             0.9299385 0.2612701  0.08909578 -0.24292833
## tm2            0.9543668 0.1602624  0.03262447  0.24987126
## percentprivm2 -0.3361900 0.4955564  0.80045787  0.02583277
#pcacat < 
pca <- princomp(data1)
summary(m2$ContractPeriod)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00   10.00   23.00   19.70   25.33   95.00
hist(tm2)

Estimação do Modelo

# logit simples
#m1log=glm(statusm2 ~ tm2 + t2 + nbids + inv_t + sector + percentprivm2 , family = binomial(link = "logit"), data=m2)
logm2 = multinom(statusm2 ~ tm2 + t2 + inv_t + sector + catpppm2, data = m2)
## # weights:  36 (22 variable)
## initial  value 377.922627 
## iter  10 value 227.876047
## iter  20 value 190.950726
## iter  30 value 190.019699
## iter  40 value 189.979269
## final  value 189.978448 
## converged
#logm2 = multinom(statusm2 ~  catpppm2  + tm2 * catpppm2 + pca$scores, data=m2)
#pca$scores + resultado_mca$ind$coord[,3] + tm2 * catpppm2 + catpppm2 + tm2 * sector + tm2*catbidm2 + catbidm2 + award
summary(logm2)
## Call:
## multinom(formula = statusm2 ~ tm2 + t2 + inv_t + sector + catpppm2, 
##     data = m2)
## 
## Coefficients:
##            (Intercept)       tm2           t2     inv_t sectorICT sectorMSW
## Cancelled    -5.977092 0.4290514 -0.003436347 0.1136596  1.673373  7.859907
## Distressed   -6.265847 0.4721160 -0.004084266 0.1159737  1.519066 -3.978704
##            sectorTrp sectorWater catpppm22  catpppm23  catpppm24
## Cancelled  -0.991747   0.9989302  11.97309  0.5269272 -0.7513812
## Distressed -2.429024  -0.1827309  10.10557 -0.7707672 -3.0181366
## 
## Std. Errors:
##            (Intercept)        tm2          t2      inv_t sectorICT    sectorMSW
## Cancelled    0.5589126 0.05559322 0.001723744 0.01908912 0.3566901 2.206398e-05
## Distressed   0.4206308 0.04550350 0.001703742 0.01957658 0.3407531 2.312015e-07
##            sectorTrp sectorWater catpppm22 catpppm23 catpppm24
## Cancelled  0.4073190   0.4189554 0.2769642 0.4951703 0.5611504
## Distressed 0.4383696   0.5039699 0.2769640 0.5146231 0.4738664
## 
## Residual Deviance: 379.9569 
## AIC: 423.9569

Método Stepwise

O método auxilia em selecionar as variáveis importantes para o modelo.

step1 <- step(logm2, direction = 'both')
## Start:  AIC=423.96
## statusm2 ~ tm2 + t2 + inv_t + sector + catpppm2
## 
## trying - tm2 
## # weights:  33 (20 variable)
## initial  value 377.922627 
## iter  10 value 224.522958
## iter  20 value 194.510293
## iter  30 value 194.115525
## iter  40 value 194.089538
## final  value 194.089177 
## converged
## trying - t2 
## # weights:  33 (20 variable)
## initial  value 377.922627 
## iter  10 value 207.298320
## iter  20 value 191.372051
## iter  30 value 190.766352
## iter  40 value 190.743248
## final  value 190.742725 
## converged
## trying - inv_t 
## # weights:  33 (20 variable)
## initial  value 377.922627 
## iter  10 value 221.459019
## iter  20 value 209.968990
## iter  30 value 209.031216
## iter  40 value 209.008003
## final  value 209.007711 
## converged
## trying - sector 
## # weights:  24 (14 variable)
## initial  value 377.922627 
## iter  10 value 220.557032
## iter  20 value 201.844207
## iter  30 value 201.688937
## iter  40 value 201.688569
## final  value 201.688436 
## converged
## trying - catpppm2 
## # weights:  27 (16 variable)
## initial  value 377.922627 
## iter  10 value 214.419669
## iter  20 value 200.212486
## iter  30 value 200.168357
## final  value 200.160393 
## converged
##            Df      AIC
## - t2       20 421.4855
## <none>     22 423.9569
## - tm2      20 428.1784
## - sector   14 431.3769
## - catpppm2 16 432.3208
## - inv_t    20 458.0154
## # weights:  33 (20 variable)
## initial  value 377.922627 
## iter  10 value 207.298320
## iter  20 value 191.372051
## iter  30 value 190.766352
## iter  40 value 190.743248
## final  value 190.742725 
## converged
## 
## Step:  AIC=421.49
## statusm2 ~ tm2 + inv_t + sector + catpppm2
## 
## trying - tm2 
## # weights:  30 (18 variable)
## initial  value 377.922627 
## iter  10 value 269.087291
## iter  20 value 257.855879
## iter  30 value 257.661339
## final  value 257.660958 
## converged
## trying - inv_t 
## # weights:  30 (18 variable)
## initial  value 377.922627 
## iter  10 value 218.660076
## iter  20 value 210.115809
## iter  30 value 209.937314
## final  value 209.931082 
## converged
## trying - sector 
## # weights:  21 (12 variable)
## initial  value 377.922627 
## iter  10 value 215.265767
## iter  20 value 202.490818
## iter  30 value 202.399767
## iter  40 value 202.399038
## iter  50 value 202.395232
## final  value 202.395222 
## converged
## trying - catpppm2 
## # weights:  24 (14 variable)
## initial  value 377.922627 
## iter  10 value 216.732990
## iter  20 value 201.897144
## iter  30 value 201.878258
## iter  40 value 201.877838
## iter  50 value 201.877349
## final  value 201.876619 
## converged
## trying + t2 
## # weights:  36 (22 variable)
## initial  value 377.922627 
## iter  10 value 227.876047
## iter  20 value 190.950726
## iter  30 value 190.019699
## iter  40 value 189.979269
## final  value 189.978448 
## converged
##            Df      AIC
## <none>     20 421.4855
## + +t2      22 423.9569
## - sector   12 428.7904
## - catpppm2 14 431.7532
## - inv_t    18 455.8622
## - tm2      18 551.3219

**Método sugeriu a retirada de \(percentprivm2\)

Modelo estimado sem \(percentprivm2\)

#logm2 = multinom(statusm2 ~ tm2 + t2 + inv_t + sector, data=m2)

#summary(logm2)

Teste de Heterocedasticidade

A proposta seria testar heterocedasticidade no modelo afim de verificar se a variância do período de contrato é a mesma ao longo de toda a amostra. Esperamos que o resultado seja heterocedasticidade para \(tm2\), que poderiamos interpretrar como o ambiente em que são firmados os contratos são não-ergodicos, ou seja, possuem alta variabilidade no tempo, que pode ser concluido como um ambiente incerto sobre os contratos, assim demonstrando a incompletude contratual.

# Obtenha as probabilidades previstas para cada categoria
#probs <- fitted(logm2)

# Construa a matriz de respostas (one-hot encoding)
# Suponha que a variável resposta seja 'Tipo'
#resposta <- model.response(model.frame(logm2))

# Converta para matriz dummy (um 1 para a categoria observada, 0 para as outras)
#Y <- model.matrix(~ resposta - 1)

# Calcule resíduos de Pearson manualmente
#residuos_pearson <- (Y - probs) / sqrt(probs * (1 - probs))

# Para visualizar, pegue uma categoria específica (ex: a primeira)
#residuos_cat1 <- residuos_pearson[,1]

# Agora o plot funciona — ex: contra a variável x1
#plot(tm2, residuos_cat1, main = "Resíduos (categoria 1) vs t", xlab = "t", ylab = "Resíduos")
#abline(h = 0, col = "red")
#residuos <- residuals(logm2, type = "pearson")
#modelo_residual = lm(residuos^2 ~ tm2, data=m2)
#white_test <- bptest(modelo_residual, studentize = FALSE)
#print(white_test)

O valor-p muito baixo (< 2.2e-16) indica forte evidência contra a hipótese nula de homocedasticidade, sugerindo que há heterocedasticidade nos resíduos do modelo.

Análise da razão estatística de máxima verossimilhança (LR statistic)

lr_test <- lrtest(logm2)
## # weights:  6 (2 variable)
## initial  value 377.922627 
## final  value 348.419556 
## converged
print(lr_test)
## Likelihood ratio test
## 
## Model 1: statusm2 ~ tm2 + t2 + inv_t + sector + catpppm2
## Model 2: statusm2 ~ 1
##   #Df  LogLik  Df  Chisq Pr(>Chisq)    
## 1  22 -189.98                          
## 2   2 -348.42 -20 316.88  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#coef_test(logm1)
# Calcular a log-verossimilhança do modelo completo (logm1)
log_likelihood_model <- logLik(logm2)

# Calcular a log-verossimilhança do modelo nulo (intercept apenas)
# Você pode criar um modelo nulo usando a função multinom com apenas ~ 1
null_model <- multinom(statusm2 ~ 1, data = m2)
## # weights:  6 (2 variable)
## initial  value 377.922627 
## final  value 348.419556 
## converged
log_likelihood_null <- logLik(null_model)

# Calcular o R² de McFadden
R2_McFadden <- 1 - (log_likelihood_model / log_likelihood_null)

# Exibir o resultado
print(R2_McFadden)
## 'log Lik.' 0.4547423 (df=22)

O modelo possui um ajuste melhor que o modelo com dados completos.

#Teste de Wald

#wald_test <- waldtest(logm2, vcov = NULL,  test = c("Chisq", "F"), name = NULL)
#waldtent <- coeftest(logm2, vcov. = NULL, df = NULL)
z = summary(logm2)$coefficients/summary(logm2)$standard.errors

z
##            (Intercept)       tm2        t2    inv_t sectorICT   sectorMSW
## Cancelled    -10.69414  7.717692 -1.993537 5.954156  4.691391    356232.5
## Distressed   -14.89631 10.375378 -2.397233 5.924104  4.457967 -17208813.7
##            sectorTrp sectorWater catpppm22 catpppm23 catpppm24
## Cancelled  -2.434816    2.384336  43.22975  1.064133 -1.339002
## Distressed -5.541041   -0.362583  36.48696 -1.497731 -6.369172
# 2-tailed z test
p <- (1 - pnorm(abs(z), 0, 1)) * 2
 
p
##            (Intercept)          tm2         t2        inv_t    sectorICT
## Cancelled            0 1.176836e-14 0.04620266 2.614176e-09 2.713536e-06
## Distressed           0 0.000000e+00 0.01651941 3.140055e-09 8.274074e-06
##            sectorMSW    sectorTrp sectorWater catpppm22 catpppm23    catpppm24
## Cancelled          0 1.489936e-02  0.01710999         0 0.2872683 1.805702e-01
## Distressed         0 3.006795e-08  0.71691642         0 0.1342030 1.900518e-10
##Razão de chances?
## extract the coefficients from the model and exponentiate
exp(coef(logm2))
##            (Intercept)      tm2        t2    inv_t sectorICT    sectorMSW
## Cancelled  0.002536191 1.535800 0.9965696 1.120371  5.330114 2.591281e+03
## Distressed 0.001900103 1.603383 0.9959241 1.122966  4.567957 1.870988e-02
##             sectorTrp sectorWater catpppm22 catpppm23  catpppm24
## Cancelled  0.37092813   2.7153754 158433.74  1.693720 0.47171456
## Distressed 0.08812281   0.8329923  24479.06  0.462658 0.04889224

\(%A razão de chances entre o contrato ser cancelado e concluido considerando a variável Investimento total, ou seja, existe 0,99 chances de o contrato ser cancelado ao invés de concluido.\)

# Dados para a categoria Cancelled
cancelled_results <- data.frame(
  Variable = colnames(exp(coef(logm2))),
  Odds_Ratio = exp(coef(logm2)["Cancelled", ]),
  P_Value = p["Cancelled", ]
)

# Exibir a tabela
print(cancelled_results)#, n=23) 
##                Variable   Odds_Ratio      P_Value
## (Intercept) (Intercept) 2.536191e-03 0.000000e+00
## tm2                 tm2 1.535800e+00 1.176836e-14
## t2                   t2 9.965696e-01 4.620266e-02
## inv_t             inv_t 1.120371e+00 2.614176e-09
## sectorICT     sectorICT 5.330114e+00 2.713536e-06
## sectorMSW     sectorMSW 2.591281e+03 0.000000e+00
## sectorTrp     sectorTrp 3.709281e-01 1.489936e-02
## sectorWater sectorWater 2.715375e+00 1.710999e-02
## catpppm22     catpppm22 1.584337e+05 0.000000e+00
## catpppm23     catpppm23 1.693720e+00 2.872683e-01
## catpppm24     catpppm24 4.717146e-01 1.805702e-01

As variáveis \(catppm23\) Greenfield project, setor de transportes \(sectorTrp\) e setor de água e esgoto \(sectorWater\) são estatísticamente insgnificantes nos efeitos \(P(\frac{cancelled}{concluded})\).

A variável Investimento total \(ITm1\) possui efeito similar aos dados completos, ou seja, um efeito muito pequeno sobre a probabilidade de cancelamento.

\(tm1\) tempo de contrato possui efeito bem similar ao obervado nos dados completos, aumentando cerca de 31% a chance de cancelamento do contrato quando aumentando uma unidade do período de contrato.

Assim como nos dados completos a variável \(catpppm4\) (Management and Lease Contracts) possui mais influência para o evento ser concluido do que cancelado.

As variáveis setorias neste teste de robustez seguem a mesma ordem de influencia sobre o status dos contratos, contudo as variáveis \(sectorTrp\) e \(sectorWater\) não possuem significância estatística a 5%, mas ainda mantendo ordem de chance semelhante. A variável \(sectorICT\) continuou tendo maior chance de ser cancelada, porém a ordem da chance teve sua escala aumentada de 4.62 para 18.93.

Todos os efeitos nas variáveis categóricas bid mantiveram maior chance de cancelamento, modificando apenas a escala, sendo todas elas significante estatísticamente.

Nas variáveis categorica de adjudicação do contrato, apenas \(awardCompetitivenegociation\) teve mudança de posição, onde a mesma possui uma grande chance de ser conluida versus o cancelamento, em contraste com o resultado dos dados completos que possuiam 2 vezes mais chances de ser cancelada.

Distressed

# Dados para a categoria Distressed
distressed_results <- data.frame(
  Variable = colnames(exp(coef(logm2))),
  Odds_Ratio = exp(coef(logm2)["Distressed", ]),
  P_Value = p["Distressed", ]
)

# Exibir a tabela
distressed_results

Todas as variáveis presentes na categoria Distressed possuem a mesma direção de chance quando comparadas aos dados completos, mudando apenas a ordem de grandeza da razão de chances. Nessa estimação apenas a variável \(sectorWater\) não possui significância estatística.

Efeitos marginais

Calculo dos efeitos marginais

#MX <- cbind((rep(1,length(statusm2))), catpppm2)
#MX <- MX[rep(seq(along=MX), each=length(coef(logm2))),]
#ZZ <- MX %*% coef(logm2)
#ZZ <- MX %*% m1log$coefficients

#lal <- function(typeppp) {exp(catpppm2)/(1+exp(catpppm2))}

#MarEFF <- mean(lal(ZZ)*(1-lal(ZZ)))*coefficients(logm2)[2]

#print(MarEFF)

Confusão

# Obter as probabilidades estimadas
pp <- fitted(logm2)

# Definir um limite de probabilidade (por exemplo, 0,5)
limite_probabilidade <- 0.5

# Classificar as observações com base nas probabilidades
classificacao_estimada <- apply(pp, 1, function(x) {
  ifelse(max(x) >= limite_probabilidade, which.max(x), NA)
})

# Adicionar a classificação estimada ao conjunto de dados original
m2$classificacao_estimada <- classificacao_estimada


# Comparar com a classificação real
tabela_comparacao <- table(statusm2, m2$classificacao_estimada)
print(tabela_comparacao)
##             
## statusm2       1   2   3
##   Concluded  102   5   0
##   Cancelled   13 154   7
##   Distressed   3  40  16

Coluna 1: A categoria real da variável dependente.

Coluna 2: A categoria estimada pelo modelo.

Coluna 3: O número de observações que foram classificadas corretamente pelo modelo.

# Crie a tabela de comparação
tabela_comparacao <- table(statusm2, m2$classificacao_estimada)

# Calcule o número total de observações em cada categoria real
total_real <- rowSums(tabela_comparacao)

# Calcule o número total de observações estimadas em cada categoria
total_estimado <- colSums(tabela_comparacao)

# Calcule a taxa de precisão (percentual de acerto) para cada categoria
taxa_precisao <- diag(tabela_comparacao) / total_real * 100

# Calcule a taxa de precisão global (total)
taxa_precisao_global <- sum(diag(tabela_comparacao)) / sum(total_real) * 100

# Adicione o total estimado à tabela de comparação
tabela_comparacao <- rbind(tabela_comparacao, Total_Estimado = total_estimado)

# Adicione a taxa de precisão à tabela de comparação
tabela_comparacao <- cbind(tabela_comparacao, Taxa_Precisao = c(taxa_precisao, Taxa_Precisao_Global = taxa_precisao_global))

# Renomeie a última coluna
colnames(tabela_comparacao)[ncol(tabela_comparacao)] <- "Taxa de Precisão (%)"

# Imprima a tabela
print(tabela_comparacao)
##                  1   2  3 Taxa de Precisão (%)
## Concluded      102   5  0             95.32710
## Cancelled       13 154  7             88.50575
## Distressed       3  40 16             27.11864
## Total_Estimado 118 199 23             80.00000

A matriz de confusão apresentada reflete o desempenho de um modelo de classificação multiclasse. Conclusões por Classe:

Concluded (1): O modelo acertou 102 previsões desta classe, com uma taxa de precisão de 97.14%. Houve 3 casos que foram erroneamente classificados como ‘Cancelled’ e nenhum como ‘Distressed’.

Cancelled (2): Foram corretamente previstas 156 observações desta classe, com uma taxa de precisão de 91.23%. No entanto, o modelo cometeu erros ao classificar 5 casos como ‘Concluded’ e 10 como ‘Distressed’.

Distressed (3): O modelo acertou 21 previsões para esta classe, mas com uma taxa de precisão relativamente baixa de 35.59%. Houve 2 observações erroneamente classificadas como ‘Concluded’ e 36 como ‘Cancelled’.

Total Estimado: O total de estimativas mostra a soma das previsões do modelo para cada classe. Por exemplo, 109 observações foram previstas como ‘Concluded’, 195 como ‘Cancelled’ e 31 como ‘Distressed’.

Curva ROC

A curva ROC (Receiver Operating Characteristic) é usada para avaliar a capacidade preditiva de um modelo em relação à classificação binária. No entanto, ela pode ser adaptada para modelos de classificação multinomial usando várias estratégias, como a análise one-vs-rest ou one-vs-one.

A estratégia comum para criar uma curva ROC em um modelo logit multinomial:

O problema foi transformado em vários problemas de classificação binária. Isso foi feito treinando o modelo para cada classe em relação a todas as outras classes combinadas. Utilizando a métrica de interesse (como a taxa de verdadeiros positivos e a taxa de falsos positivos) para avaliar cada modelo de classificação binária resultante. A curva ROC com base nessas métricas para cada classe:

# Transformar o problema em vários problemas de classificação binária
# Supondo que "logm2" é o objeto que representa o modelo logit multinomial
# e "m2" é o conjunto de dados correspondente

# Adicione um pacote para trabalhar com a lógica de classificação


# Crie uma função para ajustar modelos one-vs-rest
fit_one_vs_rest <- function(class_label) {
  binary_data <- m2
  binary_data$target <- ifelse(statusm2 == class_label, 1, 0)
  binary_model <- glm(target ~ ITm2 + km2 + tm2 + percentprivm2 + catpppm2 + sector + debtm2 + catbidm2, data = binary_data, family = binomial)
  return(binary_model)
}

# Ajuste um modelo para cada classe
class_labels <- unique(statusm2)
binary_models <- lapply(class_labels, fit_one_vs_rest)
## Warning: glm.fit: probabilidades ajustadas numericamente 0 ou 1 ocorreu
# Calcular as métricas para cada modelo binário
roc_list <- lapply(binary_models, function(model) {
  roc_obj <- roc(statusm2, predict(model, type = "response"))
  return(roc_obj)
})
## Warning in roc.default(statusm2, predict(model, type = "response")): 'response'
## has more than two levels. Consider setting 'levels' explicitly or using
## 'multiclass.roc' instead
## Setting levels: control = Concluded, case = Cancelled
## Setting direction: controls < cases
## Warning in roc.default(statusm2, predict(model, type = "response")): 'response'
## has more than two levels. Consider setting 'levels' explicitly or using
## 'multiclass.roc' instead
## Setting levels: control = Concluded, case = Cancelled
## Setting direction: controls > cases
## Warning in roc.default(statusm2, predict(model, type = "response")): 'response'
## has more than two levels. Consider setting 'levels' explicitly or using
## 'multiclass.roc' instead
## Setting levels: control = Concluded, case = Cancelled
## Setting direction: controls < cases
# Plotar a curva ROC
plot(roc_list[[1]], col = 1, main = "Curvas ROC para o modelo logit multinomial")
for (i in 2:length(roc_list)) {
  lines(roc_list[[i]], col = i)
}
legend("bottomright", legend = class_labels, col = 1:length(roc_list), lty = 1)

A categoria Cancelled possui melhor medida de classificação considerando este exercício de robustez do que com os dados completos. O que também se reflete nas probabilidades estimadas abaixo.

Probabilidades estimadas

head(pp <- fitted(logm2)) 
##     Concluded Cancelled Distressed
## 1 0.068085091 0.6562833  0.2756316
## 2 0.066897714 0.6570453  0.2760570
## 3 0.015211602 0.6780056  0.3067828
## 4 0.007447034 0.8821684  0.1103845
## 5 0.009664535 0.8807192  0.1096163
## 6 0.011179388 0.8984335  0.0903871

Conclusão

De maneira geral o teste de robustez valida os resultados do modelo principal com os dados de todas as categorias de contrato.