remove(list=ls())
setwd("/home/andre/Arquivos/Pendrive/KINGSTON/IFES/IFES_2014_02/Projetos/lertextoR")
require(gdata)
## Loading required package: gdata
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
##
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
##
## Attaching package: 'gdata'
## The following object is masked from 'package:stats':
##
## nobs
## The following object is masked from 'package:utils':
##
## object.size
dir()
## [1] "análise camara.R"
## [2] "análise Miguel.R"
## [3] "andre.xls"
## [4] "camara"
## [5] "corpus"
## [6] "dados.txt"
## [7] "material - analise-de-conteudo"
## [8] "miguel"
## [9] "modelo_.html"
## [10] "modelo .Rmd"
## [11] "modelo_.Rmd"
## [12] "nao"
## [13] "planilha discursos impeachment2.xlsx"
## [14] "planilha discursos impeachment3.xlsx"
## [15] "planilha discursos impeachment.xlsx"
## [16] "Resumo.odt"
## [17] "rsconnect"
## [18] "sim"
## [19] "Word cloud generator in R : One killer function to do everything you need"
dados<-read.xls("planilha discursos impeachment3.xlsx" , encoding = "latin1")
attach (dados)
head(dados)
## Partido Estado Voto Gênero Sim Não Região
## 1 DEM RR Sim M 1 0 Norte
## 2 PHS RR Sim M 1 0 Norte
## 3 PR RR Não M 0 1 Norte
## 4 PP RR Sim M 1 0 Norte
## 5 PRB RR Sim M 1 0 Norte
## 6 PSB RR Sim F 1 0 Norte
Partido = relevel(Partido, ref = "PMDB")
Região = relevel(Região, ref = "NORDESTE")
fit2= glm(cbind(Sim, Não)~ Partido+Região+Gênero,family = binomial)
anova(fit2,test="Chisq")
## Analysis of Deviance Table
##
## Model: binomial, link: logit
##
## Response: cbind(Sim, Não)
##
## Terms added sequentially (first to last)
##
##
## Df Deviance Resid. Df Resid. Dev Pr(>Chi)
## NULL 512 598.32
## Partido 24 322.04 488 276.28 < 2.2e-16 ***
## Região 5 62.52 483 213.77 3.663e-12 ***
## Gênero 1 3.56 482 210.21 0.05921 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
require(hnp)
## Loading required package: hnp
## Loading required package: MASS
hnp(fit2,conf = 0.95)
## Binomial model

summary(fit2)
##
## Call:
## glm(formula = cbind(Sim, Não) ~ Partido + Região + Gênero,
## family = binomial)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.79985 -0.00002 0.00008 0.33338 1.93062
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -9.661e-02 5.946e-01 -0.162 0.87093
## PartidoDEM 1.872e+01 3.071e+03 0.006 0.99514
## PartidoPCdoB -2.241e+01 5.112e+03 -0.004 0.99650
## PartidoPDT -3.470e+00 7.427e-01 -4.672 2.99e-06 ***
## PartidoPEN -8.677e-01 1.468e+00 -0.591 0.55451
## PartidoPHS -2.290e-01 1.234e+00 -0.186 0.85281
## PartidoPMB 1.700e+01 1.773e+04 0.001 0.99923
## PartidoPP -3.595e-01 5.379e-01 -0.668 0.50392
## PartidoPPS 1.884e+01 5.515e+03 0.003 0.99728
## PartidoPR -1.361e+00 5.068e-01 -2.685 0.00725 **
## PartidoPRB 1.867e+01 3.436e+03 0.005 0.99567
## PartidoPROS -2.467e+00 1.110e+00 -2.222 0.02627 *
## PartidoPSB 7.879e-01 7.290e-01 1.081 0.27980
## PartidoPSC 1.844e+01 5.040e+03 0.004 0.99708
## PartidoPSD -7.027e-01 5.850e-01 -1.201 0.22968
## PartidoPSDB 1.837e+01 2.226e+03 0.008 0.99342
## PartidoPSL 1.737e+01 1.007e+04 0.002 0.99862
## PartidoPSOL -2.381e+01 7.083e+03 -0.003 0.99732
## PartidoPT -2.378e+01 2.125e+03 -0.011 0.99107
## PartidoPTB -9.863e-01 6.723e-01 -1.467 0.14236
## PartidoPTdoB -1.778e+00 1.555e+00 -1.144 0.25278
## PartidoPTN -1.122e+00 7.840e-01 -1.432 0.15221
## PartidoPV 1.858e+01 6.611e+03 0.003 0.99776
## PartidoRede -3.753e+00 1.154e+00 -3.252 0.00115 **
## PartidoSD 1.849e+01 4.316e+03 0.004 0.99658
## RegiãoCENTROESTE 3.032e+00 9.373e-01 3.235 0.00122 **
## RegiãoNorte 9.069e-01 4.161e-01 2.180 0.02929 *
## RegiãoSUDESTE 2.697e+00 4.903e-01 5.501 3.78e-08 ***
## RegiãoSUL 3.320e+00 8.243e-01 4.028 5.62e-05 ***
## RegiãoSUL 2.834e+00 9.161e-01 3.094 0.00198 **
## GêneroM 9.643e-01 5.055e-01 1.908 0.05642 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 598.32 on 512 degrees of freedom
## Residual deviance: 210.21 on 482 degrees of freedom
## AIC: 290.59
##
## Number of Fisher Scoring iterations: 19
require(brglm) # Redução de viés
## Loading required package: brglm
## Loading required package: profileModel
fit2= brglm(cbind(Sim, Não)~ Partido+Região+Gênero,
family = binomial,method = "brglm.fit")
require(hnp)
hnp(fit2,conf = 0.95)
## Binomial model

summary(fit2)
##
## Call:
## brglm(formula = cbind(Sim, Não) ~ Partido + Região + Gênero,
## family = binomial, method = "brglm.fit")
##
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.844e-02 5.584e-01 -3.300e-02 0.973663
## PartidoDEM 2.413e+00 1.507e+00 1.601e+00 0.109413
## PartidoPCdoB -4.904e+00 1.687e+00 -2.907e+00 0.003645 **
## PartidoPDT -3.171e+00 6.941e-01 -4.568e+00 4.92e-06 ***
## PartidoPEN -8.483e-01 1.465e+00 -5.790e-01 0.562629
## PartidoPHS -4.383e-01 1.140e+00 -3.850e-01 0.700507
## PartidoPMB 1.126e+15 6.711e+07 1.678e+07 < 2e-16 ***
## PartidoPP -3.423e-01 5.234e-01 -6.540e-01 0.513161
## PartidoPPS 1.391e+00 1.763e+00 7.890e-01 0.429995
## PartidoPR -1.279e+00 4.914e-01 -2.603e+00 0.009238 **
## PartidoPRB 2.127e+00 1.541e+00 1.381e+00 0.167409
## PartidoPROS -2.359e+00 1.046e+00 -2.255e+00 0.024130 *
## PartidoPSB 6.786e-01 6.942e-01 9.780e-01 0.328290
## PartidoPSC 1.202e+00 1.658e+00 7.250e-01 0.468402
## PartidoPSD -6.722e-01 5.672e-01 -1.185e+00 0.235964
## PartidoPSDB 2.692e+00 1.474e+00 1.827e+00 0.067711 .
## PartidoPSL -1.004e+00 1.827e+00 -5.500e-01 0.582550
## PartidoPSOL -5.595e+00 1.684e+00 -3.324e+00 0.000889 ***
## PartidoPT -7.731e+00 1.450e+00 -5.332e+00 9.70e-08 ***
## PartidoPTB -9.576e-01 6.548e-01 -1.462e+00 0.143628
## PartidoPTdoB -1.822e+00 1.473e+00 -1.236e+00 0.216300
## PartidoPTN -1.088e+00 7.656e-01 -1.421e+00 0.155235
## PartidoPV 8.552e-01 1.751e+00 4.880e-01 0.625311
## PartidoRede -3.417e+00 1.126e+00 -3.034e+00 0.002411 **
## PartidoSD 1.550e+00 1.585e+00 9.780e-01 0.328265
## RegiãoCENTROESTE 2.633e+00 8.131e-01 3.238e+00 0.001203 **
## RegiãoNorte 8.128e-01 3.952e-01 2.056e+00 0.039738 *
## RegiãoSUDESTE 2.444e+00 4.372e-01 5.590e+00 2.27e-08 ***
## RegiãoSUL 2.952e+00 7.308e-01 4.039e+00 5.37e-05 ***
## RegiãoSUL 2.432e+00 7.879e-01 3.087e+00 0.002022 **
## GêneroM 8.668e-01 4.569e-01 1.897e+00 0.057845 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 527.29 on 512 degrees of freedom
## Residual deviance: 221.22 on 482 degrees of freedom
## Penalized deviance: 249.3235
## AIC: 301.6