Aula baseada na aula de Joel Schneider em Regressão Logística
library(haven)
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, round.POSIXt, trunc.POSIXt, units
setwd("~/Dropbox (Personal)/R Stat")
bd_zulliger <- read_sav("bd_zulliger.sav")
names(bd_zulliger)
## [1] "CodSuj" "Série" "Sexo" "Datanasc" "Diagnóstico"
## [6] "Observações" "Ano_nasc" "Idade" "Série_cat" "Idade_cat"
## [11] "Observação" "grupo" "Diagn1" "Diagn2" "Diagn3"
## [16] "Diagn4" "R" "R1" "R2" "R3"
## [21] "W" "D" "Dd" "S" "dq#"
## [26] "dqo" "dqv" "dqv#" "MH" "FM"
## [31] "mi" "MHa" "MHp" "FMa" "FMp"
## [36] "ma" "mp" "a_ctv" "p_ass" "ma_ctv"
## [41] "mp_ass" "Mov_ap" "fqx#" "fqxo" "fqxu"
## [46] "fqx_" "Popular" "F" "FC" "CF"
## [51] "C" "Cn" "FCA" "CAF" "CA"
## [56] "FT" "TF" "T" "FV" "VF"
## [61] "V" "FY" "YF" "Y" "FD"
## [66] "i2i" "fr" "H" "iHi" "Hd"
## [71] "iHdi" "Hx" "A" "iAi" "Ad"
## [76] "iAdi" "An" "Art" "Ay" "Bl"
## [81] "Bt" "Cg" "Cl" "Ex" "Fi"
## [86] "Food" "Geo" "Hh" "Ls" "Na"
## [91] "Sc" "Sx" "Xy" "DV_neolog" "DV_rdund"
## [96] "DR_frsinad" "DR_crcuns" "Incom" "Fabcom" "Contam"
## [101] "Alog" "Psv_msm" "Psv_cont" "Psv_mec" "Confab"
## [106] "AB" "AG" "COP" "MOR" "PER"
## [111] "CP" "WDA" "Afr" "FC_CFC" "FC_CFC2"
## [116] "lambda" "F_PC" "FAC1" "FAC2" "FAC3"
## [121] "FAC4" "FAC5" "FAC6" "FAC7" "FAC8"
## [126] "FAC9" "FAC10" "r_cat" "RES_1" "DQ#FQx_"
## [131] "DQoFQx_" "DQvFQx_" "DQv#FQx_" "Mfqx#" "Mfqxo"
## [136] "Mfqxu" "Mfqx_" "MH_" "WDfqx#" "WDfqxo"
## [141] "WDfqxu" "WDfqx_" "Sfqx_" "HR_Resp" "HRStep1"
## [146] "HRStep2" "HRStep3" "HRStep4" "HRStep5" "HRStep6"
## [151] "HRStep7" "GHR" "PHR" "Blends" "N_BREAK"
## [156] "EB" "EBBruto" "EA" "es" "Dscore"
## [161] "Adj_es" "Adj_D" "Sum_FM" "Sum_m" "Sum_CA"
## [166] "Sum_V" "Sum_T" "Sum_Y" "Pure_C" "Sum_C"
## [171] "WSumC" "WSumC2" "CA_WSumC" "CAWSumC2" "Sum_S"
## [176] "ProjCor" "BlendsR" "GPHR" "IsolateR" "IsolateR2"
## [181] "A_P" "A_P2" "MA_MP" "MA_MP2" "Sum_H"
## [186] "Pure_H" "Intelect" "Sum6" "WSum6" "M_"
## [191] "XA_PC" "WDA_PC" "X_._PC" "S_._PC" "P_PC"
## [196] "X#_PC" "Xu_PC" "fqxa" "W_PC" "D_PC"
## [201] "dd_PC" "W_M" "W_Mbruto" "W_M_a" "W_M_b"
## [206] "W_M_c" "W2" "MH2" "W_M2" "W_MCat"
## [211] "dq#_PC" "dqo_PC" "dqv#_PC" "dqv_PC" "SUM_PSV"
## [216] "Egocentr" "Egocentr2" "Sum_Rf" "Sum_FD" "Sum_MOR"
## [221] "An_Xy" "interpes" "interpes2" "critcont"
table(bd_zulliger$Diagn2)
##
## 1 2 3 4 5 6 7 8 9
## 14 18 13 18 12 10 220 81 89
attributes(bd_zulliger$Diagn2)
## $format.spss
## [1] "F8.0"
##
## $class
## [1] "labelled"
##
## $labels
## Alc Dep Smt Eqz Pnc Toc Nrm Unv Sel
## 1 2 3 4 5 6 7 8 9
vec <- names(attributes(bd_zulliger$Diagn2)$labels)
vec <- vec[bd_zulliger$Diagn2]
str(vec)
## chr [1:475] "Nrm" "Nrm" "Nrm" "Nrm" "Nrm" "Nrm" "Nrm" ...
library(psych)
##
## Attaching package: 'psych'
## The following object is masked from 'package:Hmisc':
##
## describe
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
diag <- dummy.code(vec)
diag
## Alc Dep Eqz Nrm Pnc Sel Smt Toc Unv
## [1,] 0 0 0 1 0 0 0 0 0
## [2,] 0 0 0 1 0 0 0 0 0
## [3,] 0 0 0 1 0 0 0 0 0
## [4,] 0 0 0 1 0 0 0 0 0
## [5,] 0 0 0 1 0 0 0 0 0
## [6,] 0 0 0 1 0 0 0 0 0
## [7,] 0 0 0 1 0 0 0 0 0
## [8,] 0 0 0 1 0 0 0 0 0
## [9,] 0 0 0 1 0 0 0 0 0
## [10,] 0 0 0 1 0 0 0 0 0
## [11,] 0 0 0 1 0 0 0 0 0
## [12,] 0 0 0 1 0 0 0 0 0
## [13,] 0 0 0 1 0 0 0 0 0
## [14,] 0 0 0 1 0 0 0 0 0
## [15,] 0 0 0 1 0 0 0 0 0
## [16,] 0 0 0 1 0 0 0 0 0
## [17,] 0 0 0 1 0 0 0 0 0
## [18,] 0 0 0 1 0 0 0 0 0
## [19,] 0 0 0 1 0 0 0 0 0
## [20,] 0 0 0 1 0 0 0 0 0
## [21,] 0 0 0 1 0 0 0 0 0
## [22,] 0 0 0 1 0 0 0 0 0
## [23,] 0 0 0 1 0 0 0 0 0
## [24,] 0 0 0 1 0 0 0 0 0
## [25,] 0 0 0 1 0 0 0 0 0
## [26,] 0 0 0 1 0 0 0 0 0
## [27,] 0 0 0 1 0 0 0 0 0
## [28,] 0 0 0 1 0 0 0 0 0
## [29,] 0 0 0 1 0 0 0 0 0
## [30,] 0 0 0 1 0 0 0 0 0
## [31,] 0 0 0 1 0 0 0 0 0
## [32,] 0 0 0 1 0 0 0 0 0
## [33,] 0 0 0 1 0 0 0 0 0
## [34,] 0 0 0 1 0 0 0 0 0
## [35,] 0 0 0 1 0 0 0 0 0
## [36,] 0 0 0 1 0 0 0 0 0
## [37,] 0 0 0 1 0 0 0 0 0
## [38,] 0 0 0 1 0 0 0 0 0
## [39,] 0 0 0 1 0 0 0 0 0
## [40,] 0 0 0 1 0 0 0 0 0
## [41,] 0 0 0 1 0 0 0 0 0
## [42,] 0 0 0 1 0 0 0 0 0
## [43,] 0 0 0 1 0 0 0 0 0
## [44,] 0 0 0 1 0 0 0 0 0
## [45,] 0 0 0 1 0 0 0 0 0
## [46,] 0 0 0 1 0 0 0 0 0
## [47,] 0 0 0 1 0 0 0 0 0
## [48,] 0 0 0 1 0 0 0 0 0
## [49,] 0 0 0 1 0 0 0 0 0
## [50,] 0 0 0 1 0 0 0 0 0
## [51,] 0 0 0 1 0 0 0 0 0
## [52,] 0 0 0 1 0 0 0 0 0
## [53,] 0 0 0 1 0 0 0 0 0
## [54,] 0 0 0 1 0 0 0 0 0
## [55,] 0 0 0 1 0 0 0 0 0
## [56,] 0 0 0 1 0 0 0 0 0
## [57,] 0 0 0 1 0 0 0 0 0
## [58,] 0 0 0 1 0 0 0 0 0
## [59,] 0 0 0 1 0 0 0 0 0
## [60,] 0 0 0 1 0 0 0 0 0
## [61,] 0 0 0 1 0 0 0 0 0
## [62,] 0 0 0 1 0 0 0 0 0
## [63,] 0 0 0 1 0 0 0 0 0
## [64,] 0 0 0 1 0 0 0 0 0
## [65,] 0 0 0 1 0 0 0 0 0
## [66,] 0 0 0 1 0 0 0 0 0
## [67,] 0 0 0 1 0 0 0 0 0
## [68,] 0 0 0 1 0 0 0 0 0
## [69,] 0 0 0 1 0 0 0 0 0
## [70,] 0 0 0 1 0 0 0 0 0
## [71,] 0 0 0 1 0 0 0 0 0
## [72,] 0 0 0 1 0 0 0 0 0
## [73,] 0 0 0 1 0 0 0 0 0
## [74,] 0 0 0 1 0 0 0 0 0
## [75,] 0 0 0 1 0 0 0 0 0
## [76,] 0 0 0 1 0 0 0 0 0
## [77,] 0 0 0 1 0 0 0 0 0
## [78,] 0 0 0 1 0 0 0 0 0
## [79,] 0 0 0 1 0 0 0 0 0
## [80,] 0 0 0 1 0 0 0 0 0
## [81,] 0 0 0 1 0 0 0 0 0
## [82,] 0 0 0 1 0 0 0 0 0
## [83,] 0 0 0 1 0 0 0 0 0
## [84,] 0 0 0 1 0 0 0 0 0
## [85,] 0 0 0 1 0 0 0 0 0
## [86,] 0 0 0 1 0 0 0 0 0
## [87,] 0 0 0 1 0 0 0 0 0
## [88,] 0 0 0 1 0 0 0 0 0
## [89,] 0 0 0 1 0 0 0 0 0
## [90,] 0 0 0 1 0 0 0 0 0
## [91,] 0 0 0 1 0 0 0 0 0
## [92,] 0 0 0 1 0 0 0 0 0
## [93,] 0 0 0 1 0 0 0 0 0
## [94,] 0 0 0 1 0 0 0 0 0
## [95,] 0 0 0 1 0 0 0 0 0
## [96,] 0 0 0 1 0 0 0 0 0
## [97,] 0 0 0 1 0 0 0 0 0
## [98,] 0 0 0 1 0 0 0 0 0
## [99,] 0 0 0 1 0 0 0 0 0
## [100,] 0 0 0 1 0 0 0 0 0
## [101,] 0 0 0 1 0 0 0 0 0
## [102,] 0 0 0 1 0 0 0 0 0
## [103,] 0 0 0 1 0 0 0 0 0
## [104,] 0 0 0 1 0 0 0 0 0
## [105,] 0 0 0 1 0 0 0 0 0
## [106,] 0 0 0 1 0 0 0 0 0
## [107,] 0 0 0 1 0 0 0 0 0
## [108,] 0 0 0 1 0 0 0 0 0
## [109,] 0 0 0 1 0 0 0 0 0
## [110,] 0 0 0 1 0 0 0 0 0
## [111,] 0 0 0 1 0 0 0 0 0
## [112,] 0 0 0 1 0 0 0 0 0
## [113,] 0 0 0 1 0 0 0 0 0
## [114,] 0 0 0 1 0 0 0 0 0
## [115,] 0 0 0 1 0 0 0 0 0
## [116,] 0 0 0 1 0 0 0 0 0
## [117,] 0 0 0 1 0 0 0 0 0
## [118,] 0 0 0 1 0 0 0 0 0
## [119,] 0 0 0 1 0 0 0 0 0
## [120,] 0 0 0 1 0 0 0 0 0
## [121,] 0 0 0 1 0 0 0 0 0
## [122,] 0 0 0 1 0 0 0 0 0
## [123,] 0 0 0 1 0 0 0 0 0
## [124,] 0 0 0 1 0 0 0 0 0
## [125,] 0 0 0 1 0 0 0 0 0
## [126,] 0 0 0 1 0 0 0 0 0
## [127,] 0 0 0 1 0 0 0 0 0
## [128,] 0 0 0 1 0 0 0 0 0
## [129,] 0 0 0 1 0 0 0 0 0
## [130,] 0 0 0 1 0 0 0 0 0
## [131,] 0 0 0 1 0 0 0 0 0
## [132,] 0 0 0 1 0 0 0 0 0
## [133,] 0 0 0 1 0 0 0 0 0
## [134,] 0 0 0 1 0 0 0 0 0
## [135,] 0 0 0 1 0 0 0 0 0
## [136,] 0 0 0 1 0 0 0 0 0
## [137,] 0 0 0 1 0 0 0 0 0
## [138,] 0 0 0 1 0 0 0 0 0
## [139,] 0 0 0 1 0 0 0 0 0
## [140,] 0 0 0 1 0 0 0 0 0
## [141,] 0 0 0 1 0 0 0 0 0
## [142,] 0 0 0 1 0 0 0 0 0
## [143,] 0 0 0 1 0 0 0 0 0
## [144,] 0 0 0 1 0 0 0 0 0
## [145,] 0 0 0 1 0 0 0 0 0
## [146,] 0 0 0 1 0 0 0 0 0
## [147,] 0 0 0 1 0 0 0 0 0
## [148,] 0 0 0 1 0 0 0 0 0
## [149,] 0 0 0 1 0 0 0 0 0
## [150,] 0 0 0 1 0 0 0 0 0
## [151,] 0 0 0 1 0 0 0 0 0
## [152,] 0 0 0 1 0 0 0 0 0
## [153,] 0 0 0 1 0 0 0 0 0
## [154,] 0 0 0 1 0 0 0 0 0
## [155,] 0 0 0 1 0 0 0 0 0
## [156,] 0 0 0 1 0 0 0 0 0
## [157,] 0 0 0 1 0 0 0 0 0
## [158,] 0 0 0 1 0 0 0 0 0
## [159,] 0 0 0 1 0 0 0 0 0
## [160,] 0 0 0 1 0 0 0 0 0
## [161,] 0 0 0 1 0 0 0 0 0
## [162,] 0 0 0 1 0 0 0 0 0
## [163,] 0 0 0 1 0 0 0 0 0
## [164,] 0 0 0 1 0 0 0 0 0
## [165,] 0 0 0 1 0 0 0 0 0
## [166,] 0 0 0 1 0 0 0 0 0
## [167,] 0 0 0 1 0 0 0 0 0
## [168,] 0 0 0 1 0 0 0 0 0
## [169,] 0 0 0 1 0 0 0 0 0
## [170,] 0 0 0 1 0 0 0 0 0
## [171,] 0 0 0 1 0 0 0 0 0
## [172,] 0 0 0 1 0 0 0 0 0
## [173,] 0 0 0 1 0 0 0 0 0
## [174,] 0 0 0 1 0 0 0 0 0
## [175,] 0 0 0 1 0 0 0 0 0
## [176,] 0 0 0 1 0 0 0 0 0
## [177,] 0 0 0 1 0 0 0 0 0
## [178,] 0 0 0 1 0 0 0 0 0
## [179,] 0 0 0 1 0 0 0 0 0
## [180,] 0 0 0 1 0 0 0 0 0
## [181,] 0 0 0 1 0 0 0 0 0
## [182,] 0 0 0 1 0 0 0 0 0
## [183,] 0 0 0 1 0 0 0 0 0
## [184,] 0 0 0 1 0 0 0 0 0
## [185,] 0 0 0 1 0 0 0 0 0
## [186,] 0 0 0 1 0 0 0 0 0
## [187,] 0 0 0 1 0 0 0 0 0
## [188,] 0 0 0 1 0 0 0 0 0
## [189,] 0 0 0 1 0 0 0 0 0
## [190,] 0 0 0 1 0 0 0 0 0
## [191,] 0 0 0 1 0 0 0 0 0
## [192,] 0 0 0 1 0 0 0 0 0
## [193,] 0 0 0 1 0 0 0 0 0
## [194,] 0 0 0 1 0 0 0 0 0
## [195,] 0 0 0 1 0 0 0 0 0
## [196,] 0 0 0 1 0 0 0 0 0
## [197,] 0 0 0 1 0 0 0 0 0
## [198,] 0 0 0 1 0 0 0 0 0
## [199,] 0 0 0 1 0 0 0 0 0
## [200,] 0 0 0 1 0 0 0 0 0
## [201,] 0 0 0 1 0 0 0 0 0
## [202,] 0 0 0 1 0 0 0 0 0
## [203,] 0 0 0 1 0 0 0 0 0
## [204,] 0 0 0 1 0 0 0 0 0
## [205,] 0 0 0 1 0 0 0 0 0
## [206,] 0 0 0 1 0 0 0 0 0
## [207,] 0 0 0 1 0 0 0 0 0
## [208,] 0 0 0 1 0 0 0 0 0
## [209,] 0 0 0 1 0 0 0 0 0
## [210,] 0 0 0 1 0 0 0 0 0
## [211,] 0 0 0 1 0 0 0 0 0
## [212,] 0 0 0 1 0 0 0 0 0
## [213,] 0 0 0 1 0 0 0 0 0
## [214,] 0 0 0 1 0 0 0 0 0
## [215,] 0 0 0 1 0 0 0 0 0
## [216,] 0 0 0 1 0 0 0 0 0
## [217,] 0 0 0 1 0 0 0 0 0
## [218,] 0 0 0 1 0 0 0 0 0
## [219,] 0 0 0 1 0 0 0 0 0
## [220,] 0 0 0 1 0 0 0 0 0
## [221,] 1 0 0 0 0 0 0 0 0
## [222,] 1 0 0 0 0 0 0 0 0
## [223,] 1 0 0 0 0 0 0 0 0
## [224,] 1 0 0 0 0 0 0 0 0
## [225,] 1 0 0 0 0 0 0 0 0
## [226,] 1 0 0 0 0 0 0 0 0
## [227,] 1 0 0 0 0 0 0 0 0
## [228,] 1 0 0 0 0 0 0 0 0
## [229,] 1 0 0 0 0 0 0 0 0
## [230,] 1 0 0 0 0 0 0 0 0
## [231,] 1 0 0 0 0 0 0 0 0
## [232,] 1 0 0 0 0 0 0 0 0
## [233,] 1 0 0 0 0 0 0 0 0
## [234,] 1 0 0 0 0 0 0 0 0
## [235,] 0 1 0 0 0 0 0 0 0
## [236,] 0 1 0 0 0 0 0 0 0
## [237,] 0 1 0 0 0 0 0 0 0
## [238,] 0 1 0 0 0 0 0 0 0
## [239,] 0 1 0 0 0 0 0 0 0
## [240,] 0 1 0 0 0 0 0 0 0
## [241,] 0 1 0 0 0 0 0 0 0
## [242,] 0 1 0 0 0 0 0 0 0
## [243,] 0 1 0 0 0 0 0 0 0
## [244,] 0 1 0 0 0 0 0 0 0
## [245,] 0 1 0 0 0 0 0 0 0
## [246,] 0 1 0 0 0 0 0 0 0
## [247,] 0 1 0 0 0 0 0 0 0
## [248,] 0 1 0 0 0 0 0 0 0
## [249,] 0 1 0 0 0 0 0 0 0
## [250,] 0 1 0 0 0 0 0 0 0
## [251,] 0 1 0 0 0 0 0 0 0
## [252,] 0 1 0 0 0 0 0 0 0
## [253,] 0 0 1 0 0 0 0 0 0
## [254,] 0 0 1 0 0 0 0 0 0
## [255,] 0 0 1 0 0 0 0 0 0
## [256,] 0 0 1 0 0 0 0 0 0
## [257,] 0 0 1 0 0 0 0 0 0
## [258,] 0 0 1 0 0 0 0 0 0
## [259,] 0 0 1 0 0 0 0 0 0
## [260,] 0 0 1 0 0 0 0 0 0
## [261,] 0 0 1 0 0 0 0 0 0
## [262,] 0 0 1 0 0 0 0 0 0
## [263,] 0 0 1 0 0 0 0 0 0
## [264,] 0 0 1 0 0 0 0 0 0
## [265,] 0 0 1 0 0 0 0 0 0
## [266,] 0 0 1 0 0 0 0 0 0
## [267,] 0 0 1 0 0 0 0 0 0
## [268,] 0 0 1 0 0 0 0 0 0
## [269,] 0 0 1 0 0 0 0 0 0
## [270,] 0 0 1 0 0 0 0 0 0
## [271,] 0 0 0 0 1 0 0 0 0
## [272,] 0 0 0 0 1 0 0 0 0
## [273,] 0 0 0 0 1 0 0 0 0
## [274,] 0 0 0 0 1 0 0 0 0
## [275,] 0 0 0 0 1 0 0 0 0
## [276,] 0 0 0 0 1 0 0 0 0
## [277,] 0 0 0 0 1 0 0 0 0
## [278,] 0 0 0 0 1 0 0 0 0
## [279,] 0 0 0 0 1 0 0 0 0
## [280,] 0 0 0 0 1 0 0 0 0
## [281,] 0 0 0 0 1 0 0 0 0
## [282,] 0 0 0 0 1 0 0 0 0
## [283,] 0 0 0 0 0 0 1 0 0
## [284,] 0 0 0 0 0 0 1 0 0
## [285,] 0 0 0 0 0 0 1 0 0
## [286,] 0 0 0 0 0 0 1 0 0
## [287,] 0 0 0 0 0 0 1 0 0
## [288,] 0 0 0 0 0 0 1 0 0
## [289,] 0 0 0 0 0 0 1 0 0
## [290,] 0 0 0 0 0 0 1 0 0
## [291,] 0 0 0 0 0 0 1 0 0
## [292,] 0 0 0 0 0 0 1 0 0
## [293,] 0 0 0 0 0 0 1 0 0
## [294,] 0 0 0 0 0 0 1 0 0
## [295,] 0 0 0 0 0 0 1 0 0
## [296,] 0 0 0 0 0 0 0 1 0
## [297,] 0 0 0 0 0 0 0 1 0
## [298,] 0 0 0 0 0 0 0 1 0
## [299,] 0 0 0 0 0 0 0 1 0
## [300,] 0 0 0 0 0 0 0 1 0
## [301,] 0 0 0 0 0 0 0 1 0
## [302,] 0 0 0 0 0 0 0 1 0
## [303,] 0 0 0 0 0 0 0 1 0
## [304,] 0 0 0 0 0 0 0 1 0
## [305,] 0 0 0 0 0 0 0 1 0
## [306,] 0 0 0 0 0 0 0 0 1
## [307,] 0 0 0 0 0 0 0 0 1
## [308,] 0 0 0 0 0 0 0 0 1
## [309,] 0 0 0 0 0 0 0 0 1
## [310,] 0 0 0 0 0 0 0 0 1
## [311,] 0 0 0 0 0 0 0 0 1
## [312,] 0 0 0 0 0 0 0 0 1
## [313,] 0 0 0 0 0 0 0 0 1
## [314,] 0 0 0 0 0 0 0 0 1
## [315,] 0 0 0 0 0 0 0 0 1
## [316,] 0 0 0 0 0 0 0 0 1
## [317,] 0 0 0 0 0 0 0 0 1
## [318,] 0 0 0 0 0 0 0 0 1
## [319,] 0 0 0 0 0 0 0 0 1
## [320,] 0 0 0 0 0 0 0 0 1
## [321,] 0 0 0 0 0 0 0 0 1
## [322,] 0 0 0 0 0 0 0 0 1
## [323,] 0 0 0 0 0 0 0 0 1
## [324,] 0 0 0 0 0 0 0 0 1
## [325,] 0 0 0 0 0 0 0 0 1
## [326,] 0 0 0 0 0 0 0 0 1
## [327,] 0 0 0 0 0 0 0 0 1
## [328,] 0 0 0 0 0 0 0 0 1
## [329,] 0 0 0 0 0 0 0 0 1
## [330,] 0 0 0 0 0 0 0 0 1
## [331,] 0 0 0 0 0 0 0 0 1
## [332,] 0 0 0 0 0 0 0 0 1
## [333,] 0 0 0 0 0 0 0 0 1
## [334,] 0 0 0 0 0 0 0 0 1
## [335,] 0 0 0 0 0 0 0 0 1
## [336,] 0 0 0 0 0 0 0 0 1
## [337,] 0 0 0 0 0 0 0 0 1
## [338,] 0 0 0 0 0 0 0 0 1
## [339,] 0 0 0 0 0 0 0 0 1
## [340,] 0 0 0 0 0 0 0 0 1
## [341,] 0 0 0 0 0 0 0 0 1
## [342,] 0 0 0 0 0 0 0 0 1
## [343,] 0 0 0 0 0 0 0 0 1
## [344,] 0 0 0 0 0 0 0 0 1
## [345,] 0 0 0 0 0 0 0 0 1
## [346,] 0 0 0 0 0 0 0 0 1
## [347,] 0 0 0 0 0 0 0 0 1
## [348,] 0 0 0 0 0 0 0 0 1
## [349,] 0 0 0 0 0 0 0 0 1
## [350,] 0 0 0 0 0 0 0 0 1
## [351,] 0 0 0 0 0 0 0 0 1
## [352,] 0 0 0 0 0 0 0 0 1
## [353,] 0 0 0 0 0 0 0 0 1
## [354,] 0 0 0 0 0 0 0 0 1
## [355,] 0 0 0 0 0 0 0 0 1
## [356,] 0 0 0 0 0 0 0 0 1
## [357,] 0 0 0 0 0 0 0 0 1
## [358,] 0 0 0 0 0 0 0 0 1
## [359,] 0 0 0 0 0 0 0 0 1
## [360,] 0 0 0 0 0 0 0 0 1
## [361,] 0 0 0 0 0 0 0 0 1
## [362,] 0 0 0 0 0 0 0 0 1
## [363,] 0 0 0 0 0 0 0 0 1
## [364,] 0 0 0 0 0 0 0 0 1
## [365,] 0 0 0 0 0 0 0 0 1
## [366,] 0 0 0 0 0 0 0 0 1
## [367,] 0 0 0 0 0 0 0 0 1
## [368,] 0 0 0 0 0 0 0 0 1
## [369,] 0 0 0 0 0 0 0 0 1
## [370,] 0 0 0 0 0 0 0 0 1
## [371,] 0 0 0 0 0 0 0 0 1
## [372,] 0 0 0 0 0 0 0 0 1
## [373,] 0 0 0 0 0 0 0 0 1
## [374,] 0 0 0 0 0 0 0 0 1
## [375,] 0 0 0 0 0 0 0 0 1
## [376,] 0 0 0 0 0 0 0 0 1
## [377,] 0 0 0 0 0 0 0 0 1
## [378,] 0 0 0 0 0 0 0 0 1
## [379,] 0 0 0 0 0 0 0 0 1
## [380,] 0 0 0 0 0 0 0 0 1
## [381,] 0 0 0 0 0 0 0 0 1
## [382,] 0 0 0 0 0 0 0 0 1
## [383,] 0 0 0 0 0 0 0 0 1
## [384,] 0 0 0 0 0 0 0 0 1
## [385,] 0 0 0 0 0 0 0 0 1
## [386,] 0 0 0 0 0 0 0 0 1
## [387,] 0 0 0 0 0 1 0 0 0
## [388,] 0 0 0 0 0 1 0 0 0
## [389,] 0 0 0 0 0 1 0 0 0
## [390,] 0 0 0 0 0 1 0 0 0
## [391,] 0 0 0 0 0 1 0 0 0
## [392,] 0 0 0 0 0 1 0 0 0
## [393,] 0 0 0 0 0 1 0 0 0
## [394,] 0 0 0 0 0 1 0 0 0
## [395,] 0 0 0 0 0 1 0 0 0
## [396,] 0 0 0 0 0 1 0 0 0
## [397,] 0 0 0 0 0 1 0 0 0
## [398,] 0 0 0 0 0 1 0 0 0
## [399,] 0 0 0 0 0 1 0 0 0
## [400,] 0 0 0 0 0 1 0 0 0
## [401,] 0 0 0 0 0 1 0 0 0
## [402,] 0 0 0 0 0 1 0 0 0
## [403,] 0 0 0 0 0 1 0 0 0
## [404,] 0 0 0 0 0 1 0 0 0
## [405,] 0 0 0 0 0 1 0 0 0
## [406,] 0 0 0 0 0 1 0 0 0
## [407,] 0 0 0 0 0 1 0 0 0
## [408,] 0 0 0 0 0 1 0 0 0
## [409,] 0 0 0 0 0 1 0 0 0
## [410,] 0 0 0 0 0 1 0 0 0
## [411,] 0 0 0 0 0 1 0 0 0
## [412,] 0 0 0 0 0 1 0 0 0
## [413,] 0 0 0 0 0 1 0 0 0
## [414,] 0 0 0 0 0 1 0 0 0
## [415,] 0 0 0 0 0 1 0 0 0
## [416,] 0 0 0 0 0 1 0 0 0
## [417,] 0 0 0 0 0 1 0 0 0
## [418,] 0 0 0 0 0 1 0 0 0
## [419,] 0 0 0 0 0 1 0 0 0
## [420,] 0 0 0 0 0 1 0 0 0
## [421,] 0 0 0 0 0 1 0 0 0
## [422,] 0 0 0 0 0 1 0 0 0
## [423,] 0 0 0 0 0 1 0 0 0
## [424,] 0 0 0 0 0 1 0 0 0
## [425,] 0 0 0 0 0 1 0 0 0
## [426,] 0 0 0 0 0 1 0 0 0
## [427,] 0 0 0 0 0 1 0 0 0
## [428,] 0 0 0 0 0 1 0 0 0
## [429,] 0 0 0 0 0 1 0 0 0
## [430,] 0 0 0 0 0 1 0 0 0
## [431,] 0 0 0 0 0 1 0 0 0
## [432,] 0 0 0 0 0 1 0 0 0
## [433,] 0 0 0 0 0 1 0 0 0
## [434,] 0 0 0 0 0 1 0 0 0
## [435,] 0 0 0 0 0 1 0 0 0
## [436,] 0 0 0 0 0 1 0 0 0
## [437,] 0 0 0 0 0 1 0 0 0
## [438,] 0 0 0 0 0 1 0 0 0
## [439,] 0 0 0 0 0 1 0 0 0
## [440,] 0 0 0 0 0 1 0 0 0
## [441,] 0 0 0 0 0 1 0 0 0
## [442,] 0 0 0 0 0 1 0 0 0
## [443,] 0 0 0 0 0 1 0 0 0
## [444,] 0 0 0 0 0 1 0 0 0
## [445,] 0 0 0 0 0 1 0 0 0
## [446,] 0 0 0 0 0 1 0 0 0
## [447,] 0 0 0 0 0 1 0 0 0
## [448,] 0 0 0 0 0 1 0 0 0
## [449,] 0 0 0 0 0 1 0 0 0
## [450,] 0 0 0 0 0 1 0 0 0
## [451,] 0 0 0 0 0 1 0 0 0
## [452,] 0 0 0 0 0 1 0 0 0
## [453,] 0 0 0 0 0 1 0 0 0
## [454,] 0 0 0 0 0 1 0 0 0
## [455,] 0 0 0 0 0 1 0 0 0
## [456,] 0 0 0 0 0 1 0 0 0
## [457,] 0 0 0 0 0 1 0 0 0
## [458,] 0 0 0 0 0 1 0 0 0
## [459,] 0 0 0 0 0 1 0 0 0
## [460,] 0 0 0 0 0 1 0 0 0
## [461,] 0 0 0 0 0 1 0 0 0
## [462,] 0 0 0 0 0 1 0 0 0
## [463,] 0 0 0 0 0 1 0 0 0
## [464,] 0 0 0 0 0 1 0 0 0
## [465,] 0 0 0 0 0 1 0 0 0
## [466,] 0 0 0 0 0 1 0 0 0
## [467,] 0 0 0 0 0 1 0 0 0
## [468,] 0 0 0 0 0 1 0 0 0
## [469,] 0 0 0 0 0 1 0 0 0
## [470,] 0 0 0 0 0 1 0 0 0
## [471,] 0 0 0 0 0 1 0 0 0
## [472,] 0 0 0 0 0 1 0 0 0
## [473,] 0 0 0 0 0 1 0 0 0
## [474,] 0 0 0 0 0 1 0 0 0
## [475,] 0 0 0 0 0 1 0 0 0
table(diag)
## diag
## 0 1
## 3800 475
bd_zulliger <- cbind(bd_zulliger, diag)
names(bd_zulliger)
## [1] "CodSuj" "Série" "Sexo" "Datanasc" "Diagnóstico"
## [6] "Observações" "Ano_nasc" "Idade" "Série_cat" "Idade_cat"
## [11] "Observação" "grupo" "Diagn1" "Diagn2" "Diagn3"
## [16] "Diagn4" "R" "R1" "R2" "R3"
## [21] "W" "D" "Dd" "S" "dq#"
## [26] "dqo" "dqv" "dqv#" "MH" "FM"
## [31] "mi" "MHa" "MHp" "FMa" "FMp"
## [36] "ma" "mp" "a_ctv" "p_ass" "ma_ctv"
## [41] "mp_ass" "Mov_ap" "fqx#" "fqxo" "fqxu"
## [46] "fqx_" "Popular" "F" "FC" "CF"
## [51] "C" "Cn" "FCA" "CAF" "CA"
## [56] "FT" "TF" "T" "FV" "VF"
## [61] "V" "FY" "YF" "Y" "FD"
## [66] "i2i" "fr" "H" "iHi" "Hd"
## [71] "iHdi" "Hx" "A" "iAi" "Ad"
## [76] "iAdi" "An" "Art" "Ay" "Bl"
## [81] "Bt" "Cg" "Cl" "Ex" "Fi"
## [86] "Food" "Geo" "Hh" "Ls" "Na"
## [91] "Sc" "Sx" "Xy" "DV_neolog" "DV_rdund"
## [96] "DR_frsinad" "DR_crcuns" "Incom" "Fabcom" "Contam"
## [101] "Alog" "Psv_msm" "Psv_cont" "Psv_mec" "Confab"
## [106] "AB" "AG" "COP" "MOR" "PER"
## [111] "CP" "WDA" "Afr" "FC_CFC" "FC_CFC2"
## [116] "lambda" "F_PC" "FAC1" "FAC2" "FAC3"
## [121] "FAC4" "FAC5" "FAC6" "FAC7" "FAC8"
## [126] "FAC9" "FAC10" "r_cat" "RES_1" "DQ#FQx_"
## [131] "DQoFQx_" "DQvFQx_" "DQv#FQx_" "Mfqx#" "Mfqxo"
## [136] "Mfqxu" "Mfqx_" "MH_" "WDfqx#" "WDfqxo"
## [141] "WDfqxu" "WDfqx_" "Sfqx_" "HR_Resp" "HRStep1"
## [146] "HRStep2" "HRStep3" "HRStep4" "HRStep5" "HRStep6"
## [151] "HRStep7" "GHR" "PHR" "Blends" "N_BREAK"
## [156] "EB" "EBBruto" "EA" "es" "Dscore"
## [161] "Adj_es" "Adj_D" "Sum_FM" "Sum_m" "Sum_CA"
## [166] "Sum_V" "Sum_T" "Sum_Y" "Pure_C" "Sum_C"
## [171] "WSumC" "WSumC2" "CA_WSumC" "CAWSumC2" "Sum_S"
## [176] "ProjCor" "BlendsR" "GPHR" "IsolateR" "IsolateR2"
## [181] "A_P" "A_P2" "MA_MP" "MA_MP2" "Sum_H"
## [186] "Pure_H" "Intelect" "Sum6" "WSum6" "M_"
## [191] "XA_PC" "WDA_PC" "X_._PC" "S_._PC" "P_PC"
## [196] "X#_PC" "Xu_PC" "fqxa" "W_PC" "D_PC"
## [201] "dd_PC" "W_M" "W_Mbruto" "W_M_a" "W_M_b"
## [206] "W_M_c" "W2" "MH2" "W_M2" "W_MCat"
## [211] "dq#_PC" "dqo_PC" "dqv#_PC" "dqv_PC" "SUM_PSV"
## [216] "Egocentr" "Egocentr2" "Sum_Rf" "Sum_FD" "Sum_MOR"
## [221] "An_Xy" "interpes" "interpes2" "critcont" "Alc"
## [226] "Dep" "Eqz" "Nrm" "Pnc" "Sel"
## [231] "Smt" "Toc" "Unv"
library(sjPlot)
## Warning: package 'sjPlot' was built under R version 3.3.2
## Visit http://strengejacke.de/sjPlot for package-vignettes.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## combine, src, summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
dt <- filter(bd_zulliger, Nrm==1 | Eqz==1)
fit <- lm(formula = Eqz~fqx_+WSum6+critcont+Mfqx_+GHR+PHR+R, data = dt)
sjt.lm(fit, show.std = TRUE)
Eqz | ||||||
B | CI | std. Beta | CI | p | ||
(Intercept) | 0.22 | 0.12 – 0.31 | <.001 | |||
fqx_ | 0.02 | -0.01 – 0.04 | 0.10 | -0.08 – 0.28 | .261 | |
WSum6 | 0.03 | 0.01 – 0.04 | 0.18 | 0.06 – 0.31 | .005 | |
critcont | 0.01 | -0.01 – 0.04 | 0.08 | -0.06 – 0.21 | .264 | |
Mfqx_ | 0.00 | -0.09 – 0.09 | 0.00 | -0.17 – 0.17 | .995 | |
GHR | 0.00 | -0.04 – 0.04 | 0.01 | -0.14 – 0.16 | .894 | |
PHR | 0.01 | -0.02 – 0.05 | 0.07 | -0.09 – 0.23 | .409 | |
R | -0.03 | -0.04 – -0.01 | -0.33 | -0.50 – -0.16 | <.001 | |
Observations | 238 | |||||
R2 / adj. R2 | .114 / .087 |
fit1 <- lm(formula = Eqz~fqx_+WSum6+R, data = dt)
sjt.lm(fit1, show.std = TRUE)
Eqz | ||||||
B | CI | std. Beta | CI | p | ||
(Intercept) | 0.22 | 0.13 – 0.31 | <.001 | |||
fqx_ | 0.02 | -0.00 – 0.04 | 0.13 | -0.02 – 0.27 | .085 | |
WSum6 | 0.03 | 0.01 – 0.05 | 0.21 | 0.08 – 0.33 | .001 | |
R | -0.03 | -0.04 – -0.01 | -0.29 | -0.44 – -0.15 | <.001 | |
Observations | 238 | |||||
R2 / adj. R2 | .104 / .093 |
ggplot(data = dt, aes(y = Eqz , x = WSum6, color = R)) +
geom_point() +
geom_smooth(method = "lm")
ggplot(data = dt, aes(y = Eqz , x = R, color = R)) +
geom_point() +
geom_smooth(method = "lm")
##### Tranformações logísticas
z <- seq(-4,4,0.01)
logistic <- 1 / (1 + exp(-1 * z * pi / sqrt(3)))
nrm <-dnorm(z)
nrm_ac <- pnorm(z)
log <- dlogis(z)
log_ac <- plogis(z)
dz <- data.frame(z, nrm, nrm_ac, log, log_ac)
ggplot(data = dz) +
geom_line(mapping = aes(y = nrm, x = z), color = "red") +
geom_line(mapping = aes(y = nrm_ac, x = z), color = "orange") +
scale_x_continuous(breaks = seq(-4, 4, by=1))
ggplot(data = dz) +
geom_line(mapping = aes(y = log, x = z), color = "navyblue") +
geom_line(mapping = aes(y = log_ac, x = z), color = "gray") +
scale_x_continuous(breaks = seq(-4, 4, by=1))
dt <- filter(bd_zulliger, Nrm==1 | Eqz==1)
fit0 <- fit0 <- glm(Eqz ~ 1,data = dt, family = binomial)
summary(fit0)
##
## Call:
## glm(formula = Eqz ~ 1, family = binomial, data = dt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.3966 -0.3966 -0.3966 -0.3966 2.2724
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.5033 0.2452 -10.21 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 127.55 on 237 degrees of freedom
## Residual deviance: 127.55 on 237 degrees of freedom
## AIC: 129.55
##
## Number of Fisher Scoring iterations: 5
fit1 <- fit1 <- glm(Eqz~fqx_+WSum6+critcont+Mfqx_+GHR+PHR+R,data = dt, family = binomial)
summary(fit1)
##
## Call:
## glm(formula = Eqz ~ fqx_ + WSum6 + critcont + Mfqx_ + GHR + PHR +
## R, family = binomial, data = dt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.2183 -0.3714 -0.2421 -0.1218 2.7873
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.2599 0.8141 0.319 0.749525
## fqx_ 0.3552 0.2692 1.320 0.186918
## WSum6 0.2261 0.1031 2.193 0.028285 *
## critcont 0.2140 0.2014 1.062 0.288026
## Mfqx_ 0.1596 0.7218 0.221 0.825013
## GHR 0.0603 0.3911 0.154 0.877449
## PHR 0.2883 0.3133 0.920 0.357451
## R -0.6495 0.1840 -3.531 0.000415 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 127.551 on 237 degrees of freedom
## Residual deviance: 98.327 on 230 degrees of freedom
## AIC: 114.33
##
## Number of Fisher Scoring iterations: 7
sjt.glm(fit1, show.r2 = TRUE)
Eqz | ||||
Odds Ratio | CI | p | ||
(Intercept) | 1.30 | 0.26 – 6.57 | .750 | |
fqx_ | 1.43 | 0.82 – 2.40 | .187 | |
WSum6 | 1.25 | 1.01 – 1.53 | .028 | |
critcont | 1.24 | 0.82 – 1.82 | .288 | |
Mfqx_ | 1.17 | 0.24 – 4.65 | .825 | |
GHR | 1.06 | 0.47 – 2.23 | .877 | |
PHR | 1.33 | 0.69 – 2.41 | .357 | |
R | 0.52 | 0.35 – 0.73 | <.001 | |
Observations | 238 | |||
Pseudo-R2 |
R2CS = .116 R2N = .279 D = .178 |
fit2 <- fit2 <- glm(Eqz~fqx_+WSum6+R,data = dt, family = binomial)
summary(fit2)
##
## Call:
## glm(formula = Eqz ~ fqx_ + WSum6 + R, family = binomial, data = dt)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.2718 -0.3934 -0.2610 -0.1455 2.6494
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.34511 0.79284 0.435 0.663360
## fqx_ 0.47517 0.22182 2.142 0.032181 *
## WSum6 0.27697 0.09514 2.911 0.003602 **
## R -0.59588 0.15842 -3.761 0.000169 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 127.55 on 237 degrees of freedom
## Residual deviance: 100.88 on 234 degrees of freedom
## AIC: 108.88
##
## Number of Fisher Scoring iterations: 7
sjt.glm(fit2, show.r2 = TRUE)
Eqz | ||||
Odds Ratio | CI | p | ||
(Intercept) | 1.41 | 0.30 – 6.89 | .663 | |
fqx_ | 1.61 | 1.02 – 2.48 | .032 | |
WSum6 | 1.32 | 1.08 – 1.59 | .004 | |
R | 0.55 | 0.39 – 0.74 | <.001 | |
Observations | 238 | |||
Pseudo-R2 |
R2CS = .106 R2N = .256 D = .150 |
sjp.glm(fit2, trns.ticks = FALSE)
## Waiting for profiling to be done...
sjp.glm(fit2, type = "slope")
library(BaylorEdPsych)
PseudoR2(fit2) %>% round(2)
## McFadden Adj.McFadden Cox.Snell Nagelkerke
## 0.21 0.13 0.11 0.26
## McKelvey.Zavoina Effron Count Adj.Count
## 0.45 0.15 0.92 0.00
## AIC Corrected.AIC
## 108.88 109.05
anova(fit0,fit1,test = "Chisq")
## Analysis of Deviance Table
##
## Model 1: Eqz ~ 1
## Model 2: Eqz ~ fqx_ + WSum6 + critcont + Mfqx_ + GHR + PHR + R
## Resid. Df Resid. Dev Df Deviance Pr(>Chi)
## 1 237 127.551
## 2 230 98.327 7 29.225 0.0001316 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
predict(fit2) %>% qplot
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
predict(fit2, type = "response") %>% qplot
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
library(broom)
## Warning: package 'broom' was built under R version 3.3.2
library(pander)
prev <- augment(fit2)
ggplot(prev,aes(x = .fitted, y = Eqz)) + geom_point(alpha = 0.2,pch = 16) +
geom_smooth(method = "glm", method.args = list(family = "binomial"), se = FALSE)
library(OptimalCutpoints)
cutpoint <- optimal.cutpoints(X = ".fitted", status = "Eqz",
methods = c("Youden", "SpEqualSe"),
data = prev,
tag.healthy = 0)
summary(cutpoint)
##
## Call:
## optimal.cutpoints.default(X = ".fitted", status = "Eqz", tag.healthy = 0,
## methods = c("Youden", "SpEqualSe"), data = prev)
##
## Area under the ROC curve (AUC): 0.822 (0.733, 0.912)
##
## CRITERION: Youden
## Number of optimal cutoffs: 1
##
## Estimate
## cutoff -2.6342933
## Se 0.7777778
## Sp 0.7090909
## PPV 0.1794872
## NPV 0.9750000
## DLR.Positive 2.6736111
## DLR.Negative 0.3133903
## FP 64.0000000
## FN 4.0000000
## Optimal criterion 0.4868687
##
## CRITERION: SpEqualSe
## Number of optimal cutoffs: 1
##
## Estimate
## cutoff -2.5212387192
## Se 0.7222222222
## Sp 0.7227272727
## PPV 0.1756756757
## NPV 0.9695121951
## DLR.Positive 2.6047358834
## DLR.Negative 0.3843466108
## FP 61.0000000000
## FN 5.0000000000
## Optimal criterion 0.0005050505
plot(cutpoint)
## Press return for next page....
## Press return for next page....
## Press return for next page....