Consultoria Estatística

Introdução

Está atividade tem como principal objetivo analisar o banco de dados referente aos alunos de campina grande, onde, o pesquisador tem como interesse descobrir quais variáveis têm influencia na obesidade dos alunos.

Dados

dados<- read.table("C:\\Users\\USER\\Desktop\\Nova pasta\\Dados_Aula1.txt", header = T)
dados

Este banco de dados consiste em 525 observações , 13 variáveis, na qual algumas dessas variáveis tratam da pressão arterial, da massa corpórea, IMC como também a idade dos alunos em estudos.

attach(dados)
library(fBasics)
## Loading required package: timeDate
## Loading required package: timeSeries
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:fBasics':
## 
##     tr
## The following object is masked from 'package:timeSeries':
## 
##     outlier

Análise Descritiva

describe(dados)

Analisando as variáveis em estudo vemos que PEMED E PIMED tem media igual a 100.67 e 78.31 respectivamente, como também desvios padrões iguais a 28.07 e 23.84. Uma observação importante é que todas as variáveis têm a média bem próxima da mediana, com exceção da variável TOTAFIS que também tem o maior dos desvios padrão. #Histogramas

a<-round(basicStats(dados),3)
histPlot(as.timeSeries(PEMED))

histPlot(as.timeSeries(PIMED))

histPlot(as.timeSeries(IDADE))

histPlot(as.timeSeries(IMC))

histPlot(as.timeSeries(HRSEDCAL))

histPlot(as.timeSeries(NMEDPAS))

histPlot(as.timeSeries(NMEDPAD))

histPlot(as.timeSeries(MEDCABDO))

histPlot(as.timeSeries(TOTAFIS))

histPlot(as.timeSeries(HDL))

histPlot(as.timeSeries(TG))

histPlot(as.timeSeries(GLICEMIA))

histPlot(as.timeSeries(ESCMATER))

Com os histogramas percebemos que apenas as variáveis GLICEMIA, NMEDPAS E NMEDPAD aparentam seguir uma normal. Com isso iremos usar o gráfico QQplot para sabermos se as variáveis seguem ou não uma distribuição normal.

library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
## The following object is masked from 'package:fBasics':
## 
##     densityPlot
par(mfrow= c(2,2))
qqPlot(PEMED)
## [1] 337 377
qqPlot(PIMED)
## [1] 305 369
qqPlot(IDADE)
## [1] 282 369
qqPlot(IMC)

## [1] 385 252
qqPlot(HRSEDCAL)
## [1] 364 306
qqPlot(NMEDPAS)
## [1]  64 256
qqPlot(NMEDPAD)
## [1] 379 210
qqPlot(MEDCABDO)

## [1] 75 42
qqPlot(TOTAFIS)
## [1] 486 441
qqPlot(HDL)
## [1]  56 164
qqPlot(TG)
## [1] 213 485
qqPlot(GLICEMIA)

## [1]  74 274
qqPlot(ESCMATER)
## [1] 12 17

Como era esperado apenas as variáveis GLICEMIA, NMEDPAS E NMEDPAD seguem aproximadamente uma distribuição normal.

O gráfico de Correlação é dado por:

library(corrplot)
## corrplot 0.84 loaded
corrplot(cor(dados), order = "hclust",tl.col = 'black', tl.cex = 0.75)

Após verificarmos a normalidade das variáveis junto a correlação entre elas, iremos em busca de um modelo linear da relação das variáveis de interesse com as demais variáveis.

modelo1<-lm(PEMED~IDADE+IMC+HRSEDCAL+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA+ESCMATER)

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IDADE + IMC + HRSEDCAL + NMEDPAS + NMEDPAD + 
##     MEDCABDO + TOTAFIS + HDL + TG + GLICEMIA + ESCMATER)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -56.319 -15.392  -3.154  11.919 132.494 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 10.915719  26.835516   0.407 0.684351    
## IDADE       -0.425695   1.106764  -0.385 0.700671    
## IMC         -1.265368   0.699488  -1.809 0.071038 .  
## HRSEDCAL     0.372214   0.627307   0.593 0.553207    
## NMEDPAS      0.957581   0.157876   6.065 2.56e-09 ***
## NMEDPAD     -0.913729   0.210209  -4.347 1.67e-05 ***
## MEDCABDO     0.915734   0.328320   2.789 0.005481 ** 
## TOTAFIS      0.013892   0.003573   3.888 0.000115 ***
## HDL         -0.302855   0.123333  -2.456 0.014396 *  
## TG          -0.051642   0.030733  -1.680 0.093496 .  
## GLICEMIA     0.288259   0.165993   1.737 0.083062 .  
## ESCMATER     0.446438   0.318520   1.402 0.161639    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.42 on 513 degrees of freedom
## Multiple R-squared:  0.1969, Adjusted R-squared:  0.1797 
## F-statistic: 11.44 on 11 and 513 DF,  p-value: < 2.2e-16

Retirando a variável IDADE já que foi ela quem teve maior p-valor.

modelo1 <- lm(PEMED~+IMC+HRSEDCAL+NMEDPAS+NMEDPAD+MEDCABDO+TOTAFIS+HDL+TG+GLICEMIA+ESCMATER)
summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ +IMC + HRSEDCAL + NMEDPAS + NMEDPAD + MEDCABDO + 
##     TOTAFIS + HDL + TG + GLICEMIA + ESCMATER)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -56.007 -15.617  -3.132  12.247 133.238 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.616437  18.958009   0.191 0.848789    
## IMC         -1.264080   0.698900  -1.809 0.071086 .  
## HRSEDCAL     0.381736   0.626298   0.610 0.542454    
## NMEDPAS      0.951391   0.156924   6.063 2.59e-09 ***
## NMEDPAD     -0.905115   0.208839  -4.334 1.76e-05 ***
## MEDCABDO     0.908534   0.327514   2.774 0.005738 ** 
## TOTAFIS      0.013972   0.003564   3.920 0.000101 ***
## HDL         -0.303869   0.123202  -2.466 0.013972 *  
## TG          -0.051071   0.030671  -1.665 0.096502 .  
## GLICEMIA     0.294755   0.164994   1.786 0.074615 .  
## ESCMATER     0.466305   0.314044   1.485 0.138199    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.4 on 514 degrees of freedom
## Multiple R-squared:  0.1967, Adjusted R-squared:  0.1811 
## F-statistic: 12.59 on 10 and 514 DF,  p-value: < 2.2e-16

Retirando a variável HRSEDCAL

modelo1<-lm(PEMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA+ESCMATER)
summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL + TG + GLICEMIA + ESCMATER)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -56.182 -15.768  -3.251  12.198 132.480 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.819005  18.943526   0.202 0.840309    
## IMC         -1.240335   0.697387  -1.779 0.075904 .  
## NMEDPAS      0.942461   0.156143   6.036 3.03e-09 ***
## NMEDPAD     -0.889417   0.207119  -4.294 2.10e-05 ***
## MEDCABDO     0.907415   0.327309   2.772 0.005767 ** 
## TOTAFIS      0.013925   0.003561   3.910 0.000105 ***
## HDL         -0.302036   0.123091  -2.454 0.014467 *  
## TG          -0.050901   0.030651  -1.661 0.097393 .  
## GLICEMIA     0.299799   0.164686   1.820 0.069274 .  
## ESCMATER     0.471972   0.313714   1.504 0.133075    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.38 on 515 degrees of freedom
## Multiple R-squared:  0.1961, Adjusted R-squared:  0.1821 
## F-statistic: 13.96 on 9 and 515 DF,  p-value: < 2.2e-16

Retirando a variável ESCMATER

modelo1<-lm(PEMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA)

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL + TG + GLICEMIA)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -57.931 -15.891  -3.683  12.657 132.266 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.862387  18.953989   0.257  0.79764    
## IMC         -1.362617   0.693482  -1.965  0.04996 *  
## NMEDPAS      0.920554   0.155653   5.914 6.08e-09 ***
## NMEDPAD     -0.878236   0.207239  -4.238 2.67e-05 ***
## MEDCABDO     0.973064   0.324784   2.996  0.00287 ** 
## TOTAFIS      0.014203   0.003561   3.989 7.61e-05 ***
## HDL         -0.288495   0.122911  -2.347  0.01929 *  
## TG          -0.050492   0.030688  -1.645  0.10051    
## GLICEMIA     0.326482   0.163929   1.992  0.04694 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.41 on 516 degrees of freedom
## Multiple R-squared:  0.1926, Adjusted R-squared:  0.1801 
## F-statistic: 15.38 on 8 and 516 DF,  p-value: < 2.2e-16

Retirando a variável TG

modelo1<-lm(PEMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+GLICEMIA)

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL + GLICEMIA)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -57.830 -15.865  -3.662  12.924 132.629 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.678006  18.953055   0.352  0.72472    
## IMC         -1.391634   0.694401  -2.004  0.04558 *  
## NMEDPAS      0.935003   0.155661   6.007 3.57e-09 ***
## NMEDPAD     -0.932204   0.204964  -4.548 6.75e-06 ***
## MEDCABDO     0.929307   0.324228   2.866  0.00432 ** 
## TOTAFIS      0.014332   0.003566   4.019 6.71e-05 ***
## HDL         -0.251250   0.121008  -2.076  0.03836 *  
## GLICEMIA     0.302468   0.163547   1.849  0.06497 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.46 on 517 degrees of freedom
## Multiple R-squared:  0.1884, Adjusted R-squared:  0.1774 
## F-statistic: 17.14 on 7 and 517 DF,  p-value: < 2.2e-16

Retirando a variável glicemia

modelo1<-lm(PEMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+TOTAFIS+HDL)

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -61.04 -15.70  -3.41  11.69 134.07 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 24.584180  16.331486   1.505 0.132850    
## IMC         -1.458466   0.695079  -2.098 0.036365 *  
## NMEDPAS      0.965939   0.155121   6.227 9.84e-10 ***
## NMEDPAD     -0.956936   0.205005  -4.668 3.88e-06 ***
## MEDCABDO     0.986000   0.323528   3.048 0.002424 ** 
## TOTAFIS      0.013974   0.003569   3.915 0.000102 ***
## HDL         -0.231477   0.120816  -1.916 0.055922 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.52 on 518 degrees of freedom
## Multiple R-squared:  0.183,  Adjusted R-squared:  0.1735 
## F-statistic: 19.34 on 6 and 518 DF,  p-value: < 2.2e-16

Retirando a variável HDL

modelo1<-lm(PEMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+TOTAFIS)

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -62.592 -15.986  -3.646  11.463 134.977 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.74726   14.41573   0.676  0.49924    
## IMC         -1.64006    0.69036  -2.376  0.01788 *  
## NMEDPAS      0.96243    0.15551   6.189 1.23e-09 ***
## NMEDPAD     -0.95586    0.20553  -4.651 4.20e-06 ***
## MEDCABDO     1.11495    0.31726   3.514  0.00048 ***
## TOTAFIS      0.01442    0.00357   4.040 6.15e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.58 on 519 degrees of freedom
## Multiple R-squared:  0.1772, Adjusted R-squared:  0.1693 
## F-statistic: 22.35 on 5 and 519 DF,  p-value: < 2.2e-16

Por fim chegamos ao modelo final que descreve a variável PEMED = 9.7472 - 1.64IMC +0.9624NMEDPAS -0.95586NMEDPAD + 1.1149MEDCABDO +0.01442TOTAFIS

Fazendo o mesmo para a variável PIMED teremos o seguinte.

modelo2<-lm(PIMED~IDADE+IMC+HRSEDCAL+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA+ESCMATER)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ IDADE + IMC + HRSEDCAL + NMEDPAS + NMEDPAD + 
##     MEDCABDO + TOTAFIS + HDL + TG + GLICEMIA + ESCMATER)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -58.083 -14.768  -0.931  12.424  86.327 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -17.466041  22.279458  -0.784 0.433430    
## IDADE        -0.924230   0.918861  -1.006 0.314965    
## IMC          -0.706403   0.580731  -1.216 0.224390    
## HRSEDCAL     -0.531781   0.520804  -1.021 0.307699    
## NMEDPAS       0.917379   0.131073   6.999 8.10e-12 ***
## NMEDPAD      -0.686498   0.174520  -3.934 9.52e-05 ***
## MEDCABDO      0.697984   0.272579   2.561 0.010732 *  
## TOTAFIS       0.010167   0.002967   3.427 0.000659 ***
## HDL          -0.204687   0.102394  -1.999 0.046133 *  
## TG           -0.036578   0.025515  -1.434 0.152296    
## GLICEMIA      0.446816   0.137811   3.242 0.001263 ** 
## ESCMATER     -0.254201   0.264443  -0.961 0.336868    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.1 on 513 degrees of freedom
## Multiple R-squared:  0.2325, Adjusted R-squared:  0.216 
## F-statistic: 14.13 on 11 and 513 DF,  p-value: < 2.2e-16

Retirando a variável IDADE

modelo2<-lm(PIMED~IMC+HRSEDCAL+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA+ESCMATER)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ IMC + HRSEDCAL + NMEDPAS + NMEDPAD + MEDCABDO + 
##     TOTAFIS + HDL + TG + GLICEMIA + ESCMATER)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -58.468 -14.576  -0.973  12.562  87.402 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -33.313593  15.752613  -2.115 0.034928 *  
## IMC          -0.703607   0.580731  -1.212 0.226226    
## HRSEDCAL     -0.511107   0.520404  -0.982 0.326496    
## NMEDPAS       0.903941   0.130391   6.933 1.24e-11 ***
## NMEDPAD      -0.667796   0.173529  -3.848 0.000134 ***
## MEDCABDO      0.682353   0.272139   2.507 0.012470 *  
## TOTAFIS       0.010340   0.002962   3.491 0.000522 ***
## HDL          -0.206891   0.102372  -2.021 0.043800 *  
## TG           -0.035338   0.025486  -1.387 0.166163    
## GLICEMIA      0.460919   0.137097   3.362 0.000831 ***
## ESCMATER     -0.211069   0.260945  -0.809 0.418969    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.1 on 514 degrees of freedom
## Multiple R-squared:  0.231,  Adjusted R-squared:  0.216 
## F-statistic: 15.44 on 10 and 514 DF,  p-value: < 2.2e-16

Retirando a variável ESCMATER

modelo2<-lm(PIMED~IMC+HRSEDCAL+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ IMC + HRSEDCAL + NMEDPAS + NMEDPAD + MEDCABDO + 
##     TOTAFIS + HDL + TG + GLICEMIA)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -57.187 -15.149  -1.309  12.452  87.543 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -33.773178  15.737078  -2.146 0.032332 *  
## IMC          -0.648195   0.576482  -1.124 0.261369    
## HRSEDCAL     -0.523568   0.520002  -1.007 0.314476    
## NMEDPAS       0.913437   0.129818   7.036 6.32e-12 ***
## NMEDPAD      -0.672279   0.173382  -3.877 0.000119 ***
## MEDCABDO      0.652984   0.269615   2.422 0.015783 *  
## TOTAFIS       0.010215   0.002957   3.455 0.000596 ***
## HDL          -0.212881   0.102069  -2.086 0.037501 *  
## TG           -0.035516   0.025476  -1.394 0.163895    
## GLICEMIA      0.449161   0.136279   3.296 0.001049 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.1 on 515 degrees of freedom
## Multiple R-squared:   0.23,  Adjusted R-squared:  0.2165 
## F-statistic: 17.09 on 9 and 515 DF,  p-value: < 2.2e-16

Retirando a variável HRSEDCAL

modelo2<-lm(PIMED~IMC+NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL + TG + GLICEMIA)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -58.194 -14.877  -1.359  12.524  86.811 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -34.068190  15.734560  -2.165 0.030831 *  
## IMC          -0.678748   0.575691  -1.179 0.238936    
## NMEDPAS       0.926047   0.129214   7.167 2.67e-12 ***
## NMEDPAD      -0.693993   0.172038  -4.034 6.31e-05 ***
## MEDCABDO      0.653438   0.269618   2.424 0.015712 *  
## TOTAFIS       0.010275   0.002956   3.476 0.000552 ***
## HDL          -0.215619   0.102034  -2.113 0.035063 *  
## TG           -0.035755   0.025475  -1.404 0.161061    
## GLICEMIA      0.441803   0.136084   3.247 0.001244 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.1 on 516 degrees of freedom
## Multiple R-squared:  0.2285, Adjusted R-squared:  0.2165 
## F-statistic:  19.1 on 8 and 516 DF,  p-value: < 2.2e-16

Retirando a variável IMC

modelo2<-lm(PIMED~NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+HDL+TG+GLICEMIA)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     HDL + TG + GLICEMIA)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -56.286 -14.936  -1.156  12.322  87.195 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -29.255726  15.201637  -1.925 0.054839 .  
## NMEDPAS       0.947570   0.127966   7.405 5.37e-13 ***
## NMEDPAD      -0.715083   0.171170  -4.178 3.46e-05 ***
## MEDCABDO      0.369939   0.122011   3.032 0.002551 ** 
## TOTAFIS       0.010184   0.002956   3.445 0.000617 ***
## HDL          -0.232759   0.101031  -2.304 0.021628 *  
## TG           -0.036519   0.025477  -1.433 0.152339    
## GLICEMIA      0.450480   0.135937   3.314 0.000985 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.11 on 517 degrees of freedom
## Multiple R-squared:  0.2264, Adjusted R-squared:  0.2159 
## F-statistic: 21.61 on 7 and 517 DF,  p-value: < 2.2e-16

retiramos a variável TG

modelo2<-lm(PIMED~NMEDPAS+NMEDPAD+MEDCABDO+
              TOTAFIS+GLICEMIA)

summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     GLICEMIA)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -55.48 -14.74  -1.94  12.01  88.90 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -38.481727  14.327638  -2.686 0.007467 ** 
## NMEDPAS       0.963529   0.128246   7.513 2.54e-13 ***
## NMEDPAD      -0.761353   0.169593  -4.489 8.81e-06 ***
## MEDCABDO      0.379582   0.116718   3.252 0.001220 ** 
## TOTAFIS       0.010630   0.002963   3.588 0.000365 ***
## GLICEMIA      0.410312   0.135523   3.028 0.002587 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.19 on 519 degrees of freedom
## Multiple R-squared:  0.2169, Adjusted R-squared:  0.2093 
## F-statistic: 28.74 on 5 and 519 DF,  p-value: < 2.2e-16

Assim ficou o segundo modelo PIMED= -38.482 +0.9586NMEPAS - 0.7613NMEPAD + 0.3795MEDCABDO + 0.01063TOTAFIS+ 0.4103GLICEMIA Por fim fizemos a análise dos resíduos de cada modelo

Análise de Residíuos

summary(modelo1)
## 
## Call:
## lm(formula = PEMED ~ IMC + NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -62.592 -15.986  -3.646  11.463 134.977 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.74726   14.41573   0.676  0.49924    
## IMC         -1.64006    0.69036  -2.376  0.01788 *  
## NMEDPAS      0.96243    0.15551   6.189 1.23e-09 ***
## NMEDPAD     -0.95586    0.20553  -4.651 4.20e-06 ***
## MEDCABDO     1.11495    0.31726   3.514  0.00048 ***
## TOTAFIS      0.01442    0.00357   4.040 6.15e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25.58 on 519 degrees of freedom
## Multiple R-squared:  0.1772, Adjusted R-squared:  0.1693 
## F-statistic: 22.35 on 5 and 519 DF,  p-value: < 2.2e-16
summary(modelo2)
## 
## Call:
## lm(formula = PIMED ~ NMEDPAS + NMEDPAD + MEDCABDO + TOTAFIS + 
##     GLICEMIA)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -55.48 -14.74  -1.94  12.01  88.90 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -38.481727  14.327638  -2.686 0.007467 ** 
## NMEDPAS       0.963529   0.128246   7.513 2.54e-13 ***
## NMEDPAD      -0.761353   0.169593  -4.489 8.81e-06 ***
## MEDCABDO      0.379582   0.116718   3.252 0.001220 ** 
## TOTAFIS       0.010630   0.002963   3.588 0.000365 ***
## GLICEMIA      0.410312   0.135523   3.028 0.002587 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.19 on 519 degrees of freedom
## Multiple R-squared:  0.2169, Adjusted R-squared:  0.2093 
## F-statistic: 28.74 on 5 and 519 DF,  p-value: < 2.2e-16

Vimos que para os modelos finais tanto para PEMED QUANTO PIMED obteve-se um R² ajustado relativamente baixo 0.1693 e 0.2093 respectivamente, ou seja, os modelos não se adequam bem aos dados. Levando em consideração esse resultado iremos fazer a analise da variância dos resíduos (ANOVA).

confint(modelo1)
##                     2.5 %      97.5 %
## (Intercept) -18.573093634 38.06760660
## IMC          -2.996297490 -0.28382830
## NMEDPAS       0.656927932  1.26793587
## NMEDPAD      -1.359639552 -0.55209041
## MEDCABDO      0.491668683  1.73822696
## TOTAFIS       0.007410246  0.02143821
confint(modelo2)
##                     2.5 %      97.5 %
## (Intercept) -66.629021624 -10.3344326
## NMEDPAS       0.711583391   1.2154745
## NMEDPAD      -1.094526873  -0.4281790
## MEDCABDO      0.150284221   0.6088790
## TOTAFIS       0.004809101   0.0164507
## GLICEMIA      0.144071860   0.6765523

Aqui podemos ter acesso aos respectivos intervalos de confiança dos parâmetros dos modelos 1 e 2

anova(modelo1)
anova(modelo2)

Analisando os resultados das ANOVAS, podemos concluir que ambos modelos tem erros homocedásticos em até 0.001 nível de significância, ou seja, a variância dos erros parece ser constante com o decorrer do tempo. Em seguida vamos fazer os gráficos de resíduos junto aos valores ajustados.

par(mfrow=c(1,1))
plot(PEMED, rstandard(modelo1),ylim = c(-2.5,2.5),main="Gráficos dos resíduos vs valores ajustados")
abline(h=c(0,-2.33,2.33),lty=2)

plot(PIMED, rstandard(modelo2),ylim = c(-2.5,2.5),main="Gráficos dos resíduos vs valores ajustados")
abline(h=c(0,-2.33,2.33),lty=2)

Agora, observaremos o gráfico das probabilidades normais:

z = rstandard(modelo1)
qqnorm(z, main='Gráfico das probabilidades normais', xlab='Quantis teóricos',
ylab='Quantis amostrais')
qqline(z)

t = rstandard(modelo2)
qqnorm(z, main='Gráfico das probabilidades normais', xlab='Quantis teóricos',
ylab='Quantis amostrais')
qqline(t)

Para ambos os casos, os modelos não aparentam seguir uma distribuição normal, assim iremos realizar o teste de Shapiro-Wilk para analisarmos a normalidade dos resíduos de cada um dos dois modelos.

shapiro.test(z)
## 
##  Shapiro-Wilk normality test
## 
## data:  z
## W = 0.95898, p-value = 6.435e-11
shapiro.test(t)
## 
##  Shapiro-Wilk normality test
## 
## data:  t
## W = 0.97206, p-value = 1.863e-08

Usando como base o teste de Shapiro-Wilk podemos afirmar que as populações em estudos não provem de uma população que tenha uma distribuição normal. Daí podiamos sugerir a utilização de outro tipos de modelo(MLG) para estimar os paramêtros, dado que a população não provem de uma distribuição normal.