library(readxl) # Importar planilha de excel
library(tidyverse) # manipulação dos dados
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
dados <- read_excel("data/dados.xlsx")
dados
## # A tibble: 14 × 4
## sujieito idade peso estatura
## <dbl> <dbl> <dbl> <dbl>
## 1 1 18 67 1.75
## 2 2 23 115 1.65
## 3 3 54 78 1.65
## 4 4 23 54 1.75
## 5 5 45 98 1.65
## 6 6 27 43 1.75
## 7 7 32 124 1.65
## 8 8 60 90 1.75
## 9 9 73 93 1.65
## 10 10 73 102 1.75
## 11 11 89 112 1.65
## 12 12 65 94 1.65
## 13 13 63 115 1.65
## 14 14 71 122 1.65
dados_novos <-
dados |>
mutate(
IMC = round(peso / estatura ^ 2,digits = 2)
)
dados_novos
## # A tibble: 14 × 5
## sujieito idade peso estatura IMC
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 18 67 1.75 21.9
## 2 2 23 115 1.65 42.2
## 3 3 54 78 1.65 28.6
## 4 4 23 54 1.75 17.6
## 5 5 45 98 1.65 36
## 6 6 27 43 1.75 14.0
## 7 7 32 124 1.65 45.6
## 8 8 60 90 1.75 29.4
## 9 9 73 93 1.65 34.2
## 10 10 73 102 1.75 33.3
## 11 11 89 112 1.65 41.1
## 12 12 65 94 1.65 34.5
## 13 13 63 115 1.65 42.2
## 14 14 71 122 1.65 44.8
dados_novos <-
dados_novos |>
mutate(
IMC_classe = case_when(IMC < 30 ~ "Eutrofico",
IMC >= 30 ~ "Obeso")
)
dados_novos
## # A tibble: 14 × 6
## sujieito idade peso estatura IMC IMC_classe
## <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
## 1 1 18 67 1.75 21.9 Eutrofico
## 2 2 23 115 1.65 42.2 Obeso
## 3 3 54 78 1.65 28.6 Eutrofico
## 4 4 23 54 1.75 17.6 Eutrofico
## 5 5 45 98 1.65 36 Obeso
## 6 6 27 43 1.75 14.0 Eutrofico
## 7 7 32 124 1.65 45.6 Obeso
## 8 8 60 90 1.75 29.4 Eutrofico
## 9 9 73 93 1.65 34.2 Obeso
## 10 10 73 102 1.75 33.3 Obeso
## 11 11 89 112 1.65 41.1 Obeso
## 12 12 65 94 1.65 34.5 Obeso
## 13 13 63 115 1.65 42.2 Obeso
## 14 14 71 122 1.65 44.8 Obeso
Para comparar os grupos (Obesos vs. eutróficos) faremos um teste-t independente.
resultado_testt = t.test(idade ~ IMC_classe, dados_novos)
resultado_testt
##
## Welch Two Sample t-test
##
## data: idade by IMC_classe
## t = -2.0499, df = 9.2803, p-value = 0.06969
## alternative hypothesis: true difference in means between group Eutrofico and group Obeso is not equal to 0
## 95 percent confidence interval:
## -48.125143 2.258476
## sample estimates:
## mean in group Eutrofico mean in group Obeso
## 36.40000 59.33333
paste("O valor do t é", round(resultado_testt$statistic, 2))
## [1] "O valor do t é -2.05"
paste("O valor exato de P é:", round(resultado_testt$p.value, 4))
## [1] "O valor exato de P é: 0.0697"
paste("o intervalor de confiança 95% é:", round(resultado_testt$conf.int[c(1,2)], 2))
## [1] "o intervalor de confiança 95% é: -48.13"
## [2] "o intervalor de confiança 95% é: 2.26"
dados_novos
## # A tibble: 14 × 6
## sujieito idade peso estatura IMC IMC_classe
## <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
## 1 1 18 67 1.75 21.9 Eutrofico
## 2 2 23 115 1.65 42.2 Obeso
## 3 3 54 78 1.65 28.6 Eutrofico
## 4 4 23 54 1.75 17.6 Eutrofico
## 5 5 45 98 1.65 36 Obeso
## 6 6 27 43 1.75 14.0 Eutrofico
## 7 7 32 124 1.65 45.6 Obeso
## 8 8 60 90 1.75 29.4 Eutrofico
## 9 9 73 93 1.65 34.2 Obeso
## 10 10 73 102 1.75 33.3 Obeso
## 11 11 89 112 1.65 41.1 Obeso
## 12 12 65 94 1.65 34.5 Obeso
## 13 13 63 115 1.65 42.2 Obeso
## 14 14 71 122 1.65 44.8 Obeso
Vamos retirar a variável categórica e o ID do sujeito
dados_corr <-
dados_novos |>
select(
-sujieito,
-IMC_classe
)
dados_corr
## # A tibble: 14 × 4
## idade peso estatura IMC
## <dbl> <dbl> <dbl> <dbl>
## 1 18 67 1.75 21.9
## 2 23 115 1.65 42.2
## 3 54 78 1.65 28.6
## 4 23 54 1.75 17.6
## 5 45 98 1.65 36
## 6 27 43 1.75 14.0
## 7 32 124 1.65 45.6
## 8 60 90 1.75 29.4
## 9 73 93 1.65 34.2
## 10 73 102 1.75 33.3
## 11 89 112 1.65 41.1
## 12 65 94 1.65 34.5
## 13 63 115 1.65 42.2
## 14 71 122 1.65 44.8
correlacoes <- cor(dados_corr)
correlacoes
## idade peso estatura IMC
## idade 1.0000000 0.4832516 -0.3681510 0.4693494
## peso 0.4832516 1.0000000 -0.6837613 0.9903293
## estatura -0.3681510 -0.6837613 1.0000000 -0.7747160
## IMC 0.4693494 0.9903293 -0.7747160 1.0000000
cor.test(dados_corr$idade, dados_corr$IMC)
##
## Pearson's product-moment correlation
##
## data: dados_corr$idade and dados_corr$IMC
## t = 1.8413, df = 12, p-value = 0.09042
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.0815344 0.8005662
## sample estimates:
## cor
## 0.4693494
TODAS ESSES DADOS VOCÊS TAMBÉM JÁ CONHECEM, BASTA PEGA-LOS!
library(corrplot)
## Warning: pacote 'corrplot' foi compilado no R versão 4.4.1
## corrplot 0.92 loaded
corrplot(correlacoes,method = "number")
corrplot(correlacoes,
method = "number",
type = "lower")
testRes = cor.mtest(dados_corr, conf.level = 0.95)
## specialized the insignificant value according to the significant level
corrplot(correlacoes,
method = "number",
p.mat = testRes$p,
sig.level = 0.05,
type = "lower",
order = 'hclust',
addrect = 2)
corrplot(correlacoes,
p.mat = testRes$p,
method = 'color',
diag = FALSE,
type = 'lower',
sig.level = c(0.001, 0.01, 0.05),
pch.cex = 1.9,
insig = 'label_sig',
pch.col = 'grey20',
order = 'AOE')
Vamos considerar que queremover ver a idade é um preditor de IMC.
Equação da regressão - Y = β0 + β1X1 + βnXn + εX1
Para isso, iremos rodar 2 modelos:
modelo sem ajuste = IMC ~ idade;
modelo com ajustes = IMC ~ idade + peso + estatura;
library(sjPlot)
model_sem_ajuste <- lm(IMC ~ idade,data = dados_novos)
sjPlot::tab_model(model_sem_ajuste)
| IMC | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 22.83 | 9.38 – 36.28 | 0.003 |
| idade | 0.20 | -0.04 – 0.45 | 0.090 |
| Observations | 14 | ||
| R2 / R2 adjusted | 0.220 / 0.155 | ||
Mas será que as outras variáveis podem interferir nessa associação?
Vamos fazer os ajustes!!!
model_com_ajuste <- lm(IMC ~ idade + peso + estatura,data = dados_novos)
sjPlot::tab_model(model_com_ajuste)
| IMC | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 63.76 | 52.42 – 75.09 | <0.001 |
| idade | -0.01 | -0.02 – 0.00 | 0.099 |
| peso | 0.35 | 0.34 – 0.36 | <0.001 |
| estatura | -37.11 | -43.34 – -30.88 | <0.001 |
| Observations | 14 | ||
| R2 / R2 adjusted | 0.999 / 0.999 | ||
Vamos fazer um plot bonitinho!
dados_novos |>
select(IMC, idade) |>
ggplot(mapping = aes(x = idade, y = IMC)) +
geom_point() +
geom_smooth(method = "lm") +
theme_classic()
## `geom_smooth()` using formula = 'y ~ x'
Vejam alguns exemplos: