

if(!file.exists("./data")){dir.create("./data")}
df <- read_csv("https://tinyurl.com/contextosm")glimpse(df)Rows: 1,000
Columns: 98
$ a1 <dbl> 1, 1, 1, 1, 2, 2, 2, 1, 1, 3, 2, 1, 1, …
$ a2 <dbl> 1, 1, 1, 1, 1, 1, 2, 1, 1, 3, 2, 1, 1, …
$ a3 <dbl> 1, 1, 1, 1, 3, 1, 2, 1, 1, 2, 2, 1, 1, …
$ a4 <dbl> 1, 1, 2, 1, 2, 1, 2, 1, 1, 3, 3, 1, 1, …
$ a5 <dbl> 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, …
$ a6 <dbl> 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, …
$ a7 <dbl> 1, 1, 1, 1, 2, 1, 3, 1, 1, 2, 2, 1, 1, …
$ d1 <dbl> 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 2, 1, 1, …
$ d2 <dbl> 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 2, 1, 1, …
$ d3 <dbl> 1, 1, 1, 1, 2, 2, 2, 1, 1, 3, 2, 1, 1, …
$ d4 <dbl> 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, …
$ d5 <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, …
$ d6 <dbl> 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, …
$ d7 <dbl> 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, …
$ e1 <dbl> 1, 1, 1, 1, 2, 2, 2, 1, 1, 3, 2, 1, 1, …
$ e2 <dbl> 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 2, 1, 1, …
$ e3 <dbl> 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1, 1, …
$ e4 <dbl> 1, 1, 2, 1, 3, 2, 2, 1, 1, 3, 2, 1, 1, …
$ e5 <dbl> 1, 1, 2, 1, 3, 2, 2, 1, 1,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 0, 0, …
$ srq18 <dbl> 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, …
$ srq19 <dbl> 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, …
$ srq20 <dbl> 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, …
$ genero <chr> "Feminino", "Feminino", "Feminino", "Fe…
$ idade <dbl> 37, 46, 44, 46, 46, 36, 41, 61, 37, 25,…
$ cor_raca <chr> "Pardo", "Pardo", "Pardo", "Pardo", "Pa…
$ escolaridade <chr> "Especialização", "Especialização", "Es…
$ estado_civil <chr> "Casado(a)", "Solteiro(a)", "Divorciado…
$ filhos <dbl> 2, 1, 2, 2, 0, 0, 1, 2, 1, 0, 2, 0, 0, …
$ renda_familiar_mensal <dbl> 4000, 4000, 4000, 3500, 6600, 4000, 300…
$ dependentes_da_renda_familar <dbl> 4, 3, 2, 3, 3, 5, 2, 1, 3, 7, 3, 1, 2, …
$ renda_pos_pandemia <chr> "Aumentou", "Diminuiu", "Ficou estável"…
$ estado <chr> "Tocantins", "Ceará", "Pernambuco", "Ce…
$ regiao <chr> "Norte", "Nordeste", "Nordeste", "Norde…
$ grupo_de_risco <chr> "Não", "Sim", "Não", "Sim", "Não", "Não…
$ diag_covid <chr> "Não", "Não", "Não", "Não", "Não", "Sim…
$ perda_covid <chr> "Sim", "Sim", "Não", "Não", "Sim", "Sim…
$ tempo_experiencia_rede_publica <dbl> 6, 18, 25, 24, 11, 12, 5, 34, 5, 3, 5, …
$ tipo_contrato <chr> "Efetivo/Concursado", "Efetivo/Concursa…
$ niveis_de_ensino <chr> "Ensino Fundamental 1", "Atua em mais d…
df |>
select(tmcs:est)# A tibble: 1,000 × 4
tmcs ans dep est
<dbl> <dbl> <dbl> <dbl>
1 0 7 7 7
2 2 7 7 7
3 1 8 7 9
4 1 7 7 7
5 8 12 10 14
6 17 8 12 14
7 11 15 8 13
8 0 7 7 7
9 1 7 7 7
10 20 17 17 17
# ℹ 990 more rows
df |>
select(org:rel)# A tibble: 1,000 × 3
org cond rel
<dbl> <dbl> <dbl>
1 1 1 1
2 1 1 1
3 2.8 2.5 2.2
4 3 2.38 2
5 2.6 2.25 1.1
6 3.8 3.12 2.6
7 3.67 3.75 2.7
8 2.93 3 2.4
9 2.47 2.38 1.4
10 2.33 2.75 3.2
# ℹ 990 more rows
Examinar o efeito de diferentes variáveis (preditoras / independentes) em uma única variável de resultado (dependente)
O uso o termo predição é essencial, pois a análise examina se uma variável prediz (explica ou repercute) outra variável
# A tibble: 5 × 2
x y
<dbl> <dbl>
1 0 2
2 1 4
3 2 6
4 3 8
5 4 10
reg_line |>
ggplot(aes(x,y)) +
geom_smooth(
method = "lm",
se = F,
color = "blue"
) +
geom_point(
color = "red",
size = 3
) +
theme_classic()
\[ y = a + bx \]
reg_line# A tibble: 5 × 2
x y
<dbl> <dbl>
1 0 2
2 1 4
3 2 6
4 3 8
5 4 10
df |>
select(org, tmcs) |>
slice_head(n = 10)# A tibble: 10 × 2
org tmcs
<dbl> <dbl>
1 1 0
2 1 2
3 2.8 1
4 3 1
5 2.6 8
6 3.8 17
7 3.67 11
8 2.93 0
9 2.47 1
10 2.33 20
df |>
summarise(
across(c(tmcs,org),
list("M" = mean,
"DP" = sd,
"MIN" = min,
"MAX" = max))
) |>
pivot_longer(
cols = everything(),
names_to = c("Variável", ".value"),
names_sep = "_"
)# A tibble: 2 × 5
Variável M DP MIN MAX
<chr> <dbl> <dbl> <dbl> <dbl>
1 tmcs 4.80 4.94 0 20
2 org 2.95 0.773 1 4.93
df |>
ggplot(aes(org)) +
geom_histogram(
fill = "white",
color = "gray"
) +
labs(
y = NULL,
x = "Organização do Trabalho"
) +
theme_classic()
df |>
ggplot(aes(tmcs)) +
geom_histogram(
fill = "white",
color = "gray",
bins = 20
) +
labs(
y = NULL,
x = "TMCs"
) +
theme_classic()
cor.test(df$org,df$tmcs)
Pearson's product-moment correlation
data: df$org and df$tmcs
t = 13.436, df = 998, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3375806 0.4426364
sample estimates:
cor
0.391383
df |>
ggplot(aes(org,tmcs)) +
geom_jitter() +
geom_smooth(
method = "lm",
se = F,
color = "red"
) +
labs(
x = "Organização do Trabalho",
y = "Transtornos Mentais Comuns"
) +
theme_classic()
\[ y = a + bx \]
\[ y = a + bx \]
Notação da regressão:
“~”
VD ~ VI1 + VI2 + VIn
fit_cont <- lm(tmcs ~ org, data = df) summary(fit_cont)
Call:
lm(formula = tmcs ~ org, data = df)
Residuals:
Min 1Q Median 3Q Max
-9.4166 -3.4224 -0.9221 2.7411 17.0763
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.5703 0.5673 -4.531 6.58e-06 ***
org 2.4973 0.1859 13.436 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.544 on 998 degrees of freedom
Multiple R-squared: 0.1532, Adjusted R-squared: 0.1523
F-statistic: 180.5 on 1 and 998 DF, p-value: < 2.2e-16
tabela_de_regressao# A tibble: 2 × 5
Preditor Estimativas `Erro-padrão` t p
<chr> <dbl> <dbl> <dbl> <chr>
1 (Intercept) -2.57 0.57 -4.53 < .001
2 org 2.5 0.19 13.4 < .001
\[ y = a + bx \]
org = 2.50\[ tmcs = -2.57 + 2.50org \]
tabela_de_regressao# A tibble: 2 × 5
Preditor Estimativas `Erro-padrão` t p
<chr> <dbl> <dbl> <dbl> <chr>
1 (Intercept) -2.57 0.57 -4.53 < .001
2 org 2.5 0.19 13.4 < .001
\[ tmcs = -2.57 + 2.50org \]
org maior a pontuação em tmcs
org):
org, há um aumento associado de, em média, 2.50 unidades de tmcs
cor_org_tmcs <- cor.test(df$org,df$tmcs)
cor_org_tmcs
Pearson's product-moment correlation
data: df$org and df$tmcs
t = 13.436, df = 998, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3375806 0.4426364
sample estimates:
cor
0.391383
r <- cor_org_tmcs$estimate
r^2 |>
round(4) cor
0.1532
summary(fit_cont)
Call:
lm(formula = tmcs ~ org, data = df)
Residuals:
Min 1Q Median 3Q Max
-9.4166 -3.4224 -0.9221 2.7411 17.0763
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.5703 0.5673 -4.531 6.58e-06 ***
org 2.4973 0.1859 13.436 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.544 on 998 degrees of freedom
Multiple R-squared: 0.1532, Adjusted R-squared: 0.1523
F-statistic: 180.5 on 1 and 998 DF, p-value: < 2.2e-16
\[ tmcs = -2.57 + 2.50org \]
# A tibble: 1 × 3
id tmcs org
<int> <dbl> <dbl>
1 15 4 2.87
\[ tmcs = -2.57 + 2.50*2.867 = 4.598 \]
\[ resíduo = 4 - 4.598 = -0.598 \]
df |>
ggplot(aes(org,tmcs)) +
geom_point() +
geom_smooth(
method = "lm",
se = F,
color = "red"
) +
labs(
x = "Organização do Trabalho",
y = "Transtornos Mentais Comuns"
) +
theme_classic()+
geom_segment(aes(x = 2.867, y = 4,
xend = 2.867, yend = 4.598),
color = "blue")+
geom_segment(aes(x = 4.07, y = 20,
xend = 4.07, yend = 7.59),
color = "blue") +
geom_segment(aes(x = 3.4, y = 10,
xend = 3.4, yend = 5.92),
color = "blue")
# A tibble: 15 × 5
id tmcs org .fitted .resid
<int> <dbl> <dbl> <dbl> <dbl>
1 1 0 1 -0.073 0.073
2 2 2 1 -0.073 2.07
3 3 1 2.8 4.42 -3.42
4 4 1 3 4.92 -3.92
5 5 8 2.6 3.92 4.08
6 6 17 3.8 6.92 10.1
7 7 11 3.67 6.59 4.41
8 8 0 2.93 4.76 -4.76
9 9 1 2.47 3.59 -2.59
10 10 20 2.33 3.26 16.7
11 11 12 3.67 6.59 5.41
12 12 0 2.73 4.26 -4.26
13 13 2 3.13 5.26 -3.26
14 14 3 3.67 6.59 -3.59
15 15 4 2.87 4.59 -0.589
Quanto a pontuação em TMCs pode variar em função do pertencimento ao grupo de risco para covid-19?
df |>
select(tmcs, grupo_de_risco) |>
slice_head(n = 10) # A tibble: 10 × 2
tmcs grupo_de_risco
<dbl> <chr>
1 0 Não
2 2 Sim
3 1 Não
4 1 Sim
5 8 Não
6 17 Não
7 11 Não
8 0 Sim
9 1 Não
10 20 Não
df |>
summarise(
across(c(tmcs),
list("M" = mean,
"DP" = sd,
"MIN" = min,
"MAX" = max))
) |>
pivot_longer(
cols = everything(),
names_to = c("Variável", ".value"),
names_sep = "_"
)# A tibble: 1 × 5
Variável M DP MIN MAX
<chr> <dbl> <dbl> <dbl> <dbl>
1 tmcs 4.80 4.94 0 20
df |>
ggplot(aes(tmcs)) +
geom_histogram(
fill = "white",
color = "gray",
bins = 20
) +
labs(
y = NULL,
x = "TMCs"
) +
theme_classic()
df |>
ggplot(aes(grupo_de_risco,tmcs))+
geom_boxplot() +
geom_jitter(aes(grupo_de_risco),
alpha = 0.1,
size = 1.5,
color = "blue") +
labs(
x = "Grupo de Risco para covid-19",
y = "TMCs"
) +
theme_classic()
t.test(tmcs ~ fct_relevel(grupo_de_risco, "Sim"), data = df,var.equal = T)
Two Sample t-test
data: tmcs by fct_relevel(grupo_de_risco, "Sim")
t = 3.0395, df = 998, p-value = 0.002431
alternative hypothesis: true difference in means between group Sim and group Não is not equal to 0
95 percent confidence interval:
0.3887405 1.8051091
sample estimates:
mean in group Sim mean in group Não
5.630081 4.533156
fit_cat <- lm(tmcs ~ grupo_de_risco, data = df) summary(fit_cat)
Call:
lm(formula = tmcs ~ grupo_de_risco, data = df)
Residuals:
Min 1Q Median 3Q Max
-5.630 -4.533 -1.533 3.370 15.467
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.5332 0.1790 25.33 < 2e-16 ***
grupo_de_riscoSim 1.0969 0.3609 3.04 0.00243 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 4.915 on 998 degrees of freedom
Multiple R-squared: 0.009172, Adjusted R-squared: 0.00818
F-statistic: 9.239 on 1 and 998 DF, p-value: 0.002431
tabela_de_regressao_cat# A tibble: 2 × 5
Preditor Estimativas `Erro-padrão` t p
<chr> <dbl> <dbl> <dbl> <chr>
1 (Intercept) 4.53 0.18 25.3 < .001
2 grupo_de_riscoSim 1.1 0.36 3.04 < .001
dif# A tibble: 2 × 3
grupo_de_risco M DIF
<chr> <dbl> <dbl>
1 Não 4.53 0
2 Sim 5.63 1.10
