#CARGA DE BASE DE DATOS

library(readxl)
## Warning: package 'readxl' was built under R version 4.4.1
library(readxl)

ruta <- file.path(
  "/Users",
  Sys.info()[["user"]],
  "Desktop",
  "2025_2026",
  "TFG_2025",
  "TFG_2025_2026",
  "tabaco26.xlsx"
)

file.exists(ruta)
## [1] TRUE
tabaco26 <- read_excel(ruta)
## New names:
## • `` -> `...7`
library(sjPlot)
## #refugeeswelcome
library(psych)
tabaco26$curso<-factor(tabaco26$curso, levels = c("primero", "segundo", "tercero", "cuarto"))

#DATOS SOCIODEMOGRAFICOS Y CLINICOS

plot_frq(tabaco26$sexo)

plot_frq(tabaco26$curso)

plot_frq(tabaco26$proce)

plot_frq(tabaco26$procer)

plot_frq(tabaco26$antecedentes)

table(tabaco26$espeenfer)
## 
##                           alergia                           Alergia 
##                                 8                                 9 
##                              asma                              Asma 
##                                10                                 9 
##                     asma alergica                     Asma alergica 
##                                 1                                 1 
##                  asma de esfuerzo                   asma estacional 
##                                 1                                 1 
##                    asma por polen                    asma y alergia 
##                                 1                                 2 
##                    Asma y alergia                     asma, alergia 
##                                 2                                 2 
##                     Asma, alergia Asma, bronquitis cronica, alergia 
##                                 1                                 1 
##                              EPOC                          Neumonía 
##                                 1                                 1
table(tabaco26$espeenfer)
## 
##                           alergia                           Alergia 
##                                 8                                 9 
##                              asma                              Asma 
##                                10                                 9 
##                     asma alergica                     Asma alergica 
##                                 1                                 1 
##                  asma de esfuerzo                   asma estacional 
##                                 1                                 1 
##                    asma por polen                    asma y alergia 
##                                 1                                 2 
##                    Asma y alergia                     asma, alergia 
##                                 2                                 2 
##                     Asma, alergia Asma, bronquitis cronica, alergia 
##                                 1                                 1 
##                              EPOC                          Neumonía 
##                                 1                                 1
plot_frq(tabaco26$medicacion)

table(tabaco26$espemedi)
## 
##        antistaminicos     bromuro ipatropio            cetirizina 
##                     1                     2                     1 
##              Ebartina            Formoterol               nasonex 
##                     1                     1                     1 
##            salbutamol            Salbutamol             salbutmol 
##                     8                     4                     1 
## symbicort, salbutamol             terbasmin              Ventolín 
##                     1                     1                     2
plot_frq(tabaco26$sintomas)

DATOS DE CONSUMO

plot_frq(tabaco26$N1)

plot_frq(tabaco26$fuma)

plot_frq(tabaco26$N1A)

plot_frq(tabaco26$N1B)

plot_frq(tabaco26$N1C)

plot_frq(tabaco26$N1D)

plot_frq(tabaco26$N1E)

plot_frq(tabaco26$N1F)

#DIFERENCIAS DE CONSUMO DE TABACO POR SEXO, CURSO, PROCEDENCIA DE ESTUDIOS, ENFERMEDAD Y MEDICACIÓN (NO HAY DIFERENCIAS ESTADÍSTICAS)

sjt.xtab(tabaco26$fuma, tabaco26$sexo, show.col.prc = T)
fuma sexo Total
hombre mujer
fuma 16
28.1 %
48
22.1 %
64
23.4 %
no fuma 41
71.9 %
169
77.9 %
210
76.6 %
Total 57
100 %
217
100 %
274
100 %
χ2=0.591 · df=1 · &phi=0.057 · p=0.442
sjt.xtab(tabaco26$fuma, tabaco26$curso, show.col.prc = T)
fuma curso Total
primero segundo tercero cuarto
fuma 17
17.9 %
11
22.9 %
25
26.6 %
11
29.7 %
64
23.4 %
no fuma 78
82.1 %
37
77.1 %
69
73.4 %
26
70.3 %
210
76.6 %
Total 95
100 %
48
100 %
94
100 %
37
100 %
274
100 %
χ2=2.979 · df=3 · Cramer’s V=0.104 · p=0.395
sjt.xtab(tabaco26$fuma, tabaco26$procer, show.col.prc = T)
fuma procer Total
bachiller no bachiller
fuma 41
20.6 %
23
30.7 %
64
23.4 %
no fuma 158
79.4 %
52
69.3 %
210
76.6 %
Total 199
100 %
75
100 %
274
100 %
χ2=2.545 · df=1 · &phi=0.106 · p=0.111
sjt.xtab(tabaco26$fuma, tabaco26$antecedentes, show.col.prc = T)
fuma antecedentes Total
no si
fuma 54
24.2 %
10
19.6 %
64
23.4 %
no fuma 169
75.8 %
41
80.4 %
210
76.6 %
Total 223
100 %
51
100 %
274
100 %
χ2=0.268 · df=1 · &phi=0.042 · p=0.604
sjt.xtab(tabaco26$fuma, tabaco26$medicacion, show.col.prc = T)
fuma medicacion Total
no si
fuma 57
23 %
7
26.9 %
64
23.4 %
no fuma 191
77 %
19
73.1 %
210
76.6 %
Total 248
100 %
26
100 %
274
100 %
χ2=0.043 · df=1 · &phi=0.027 · Fisher’s p=0.631

#CARACTERÍSTICAS DEL CONSUMO

describeBy(tabaco26$n14, na.rm = TRUE)
## Warning in describeBy(tabaco26$n14, na.rm = TRUE): no grouping variable
## requested
describeBy(tabaco26$n15, na.rm = TRUE)
## Warning in describeBy(tabaco26$n15, na.rm = TRUE): no grouping variable
## requested
describeBy(tabaco26$n16, na.rm = TRUE)
## Warning in describeBy(tabaco26$n16, na.rm = TRUE): no grouping variable
## requested
plot_frq(tabaco26$N17, coord.flip = T)

describe.by(tabaco26$n17a)
## Warning in describe.by(tabaco26$n17a): describe.by is deprecated.  Please use
## the describeBy function
## Warning in describeBy(x = x, group = group, mat = mat, type = type, ...): no
## grouping variable requested
describe.by(tabaco26$n17b1)
## Warning in describe.by(tabaco26$n17b1): describe.by is deprecated.  Please use
## the describeBy function
## Warning in describe.by(tabaco26$n17b1): no grouping variable requested
describe.by(tabaco26$n17b2)
## Warning in describe.by(tabaco26$n17b2): describe.by is deprecated.  Please use
## the describeBy function
## Warning in describe.by(tabaco26$n17b2): no grouping variable requested
plot_frq(tabaco26$N18)

plot_frq(tabaco26$N21)

plot_frq(tabaco26$N22)

#TEST 1 (TEST DE FAGERSTROM (fag)) Y TEST 2 (TEST DE RICHMOND(rich))

describeBy(tabaco26$fag, na.rm=TRUE)
## Warning in describeBy(tabaco26$fag, na.rm = TRUE): no grouping variable
## requested
describeBy(tabaco26$rich, na.rm = TRUE)
## Warning in describeBy(tabaco26$rich, na.rm = TRUE): no grouping variable
## requested

#DIFERENCIAS DE FAG Y RICH POR SEXO, CURSO, PROCEDENCIA DE ESTUDIOS, ENFERMEDAD Y MEDICACIÓN (NO HAY DIFERENCIAS ESTADÍSTICAS)

describeBy(tabaco26$fag, tabaco26$sexo)
## 
##  Descriptive statistics by group 
## group: hombre
##    vars n mean   sd median trimmed  mad min max range skew kurtosis  se
## X1    1 9 3.44 1.51      3    3.44 1.48   2   5     3 0.09    -2.12 0.5
## ------------------------------------------------------------ 
## group: mujer
##    vars  n mean sd median trimmed  mad min max range skew kurtosis   se
## X1    1 31 2.94  2      3    2.88 2.97   0   7     7 0.18    -1.04 0.36
t.test(fag~sexo, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  fag by sexo
## t = 0.8235, df = 17.045, p-value = 0.4216
## alternative hypothesis: true difference in means between group hombre and group mujer is not equal to 0
## 95 percent confidence interval:
##  -0.7947407  1.8126619
## sample estimates:
## mean in group hombre  mean in group mujer 
##             3.444444             2.935484
describeBy(tabaco26$fag, tabaco26$procer)
## 
##  Descriptive statistics by group 
## group: bachiller
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 20  2.9 1.71      3    2.94 1.48   0   6     6 -0.27    -0.88 0.38
## ------------------------------------------------------------ 
## group: no bachiller
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 20  3.2 2.09    2.5    3.12 2.22   0   7     7 0.24    -1.45 0.47
t.test(fag~procer, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  fag by procer
## t = -0.49603, df = 36.579, p-value = 0.6228
## alternative hypothesis: true difference in means between group bachiller and group no bachiller is not equal to 0
## 95 percent confidence interval:
##  -1.5259286  0.9259286
## sample estimates:
##    mean in group bachiller mean in group no bachiller 
##                        2.9                        3.2
describeBy(tabaco26$fag, tabaco26$antecedentes)
## 
##  Descriptive statistics by group 
## group: no
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 34 2.97 1.93      3    2.93 1.48   0   7     7 0.19    -0.95 0.33
## ------------------------------------------------------------ 
## group: si
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 6  3.5 1.76      4     3.5 1.48   1   5     4 -0.27    -1.97 0.72
t.test(fag~antecedentes, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  fag by antecedentes
## t = -0.66898, df = 7.2965, p-value = 0.5241
## alternative hypothesis: true difference in means between group no and group si is not equal to 0
## 95 percent confidence interval:
##  -2.385398  1.326574
## sample estimates:
## mean in group no mean in group si 
##         2.970588         3.500000
describeBy(tabaco26$fag, tabaco26$medicacion)
## 
##  Descriptive statistics by group 
## group: no
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 36    3 1.91      3    2.97 1.48   0   7     7 0.17    -0.96 0.32
## ------------------------------------------------------------ 
## group: si
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 4  3.5 1.91      4     3.5 1.48   1   5     4 -0.32    -2.08 0.96
t.test(fag~medicacion, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  fag by medicacion
## t = -0.4955, df = 3.6979, p-value = 0.6482
## alternative hypothesis: true difference in means between group no and group si is not equal to 0
## 95 percent confidence interval:
##  -3.394292  2.394292
## sample estimates:
## mean in group no mean in group si 
##              3.0              3.5
describeBy(tabaco26$fag, tabaco26$curso)
## 
##  Descriptive statistics by group 
## group: primero
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 11 2.55 1.86      3    2.56 2.97   0   5     5 -0.06    -1.67 0.56
## ------------------------------------------------------------ 
## group: segundo
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 4    4 1.83      4       4 2.22   2   6     4    0    -2.24 0.91
## ------------------------------------------------------------ 
## group: tercero
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 21 3.33 2.01      3    3.35 2.97   0   7     7 -0.01    -1.15 0.44
## ------------------------------------------------------------ 
## group: cuarto
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 4    2 0.82      2       2 0.74   1   3     2    0    -1.88 0.41
analisis<-aov(fag~curso, data=tabaco26)
summary(analisis)
##             Df Sum Sq Mean Sq F value Pr(>F)
## curso        3  12.51   4.169   1.178  0.332
## Residuals   36 127.39   3.539               
## 234 observations deleted due to missingness
describeBy(tabaco26$rich, tabaco26$sexo)
## 
##  Descriptive statistics by group 
## group: hombre
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 10  4.9 3.11    4.5    4.88 2.97   0  10    10 0.12    -1.35 0.98
## ------------------------------------------------------------ 
## group: mujer
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 32 4.78 3.03      5    4.73 3.71   0  10    10 0.07    -1.16 0.54
t.test(rich~sexo, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  rich by sexo
## t = 0.10607, df = 14.783, p-value = 0.917
## alternative hypothesis: true difference in means between group hombre and group mujer is not equal to 0
## 95 percent confidence interval:
##  -2.270508  2.508008
## sample estimates:
## mean in group hombre  mean in group mujer 
##              4.90000              4.78125
describeBy(tabaco26$rich, tabaco26$procer)
## 
##  Descriptive statistics by group 
## group: bachiller
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 21 4.67 2.99      5    4.65 4.45   0  10    10 0.11    -1.49 0.65
## ------------------------------------------------------------ 
## group: no bachiller
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 21 4.95 3.11      5    4.94 2.97   0  10    10 0.05    -0.95 0.68
t.test(rich~procer, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  rich by procer
## t = -0.30374, df = 39.941, p-value = 0.7629
## alternative hypothesis: true difference in means between group bachiller and group no bachiller is not equal to 0
## 95 percent confidence interval:
##  -2.186910  1.615482
## sample estimates:
##    mean in group bachiller mean in group no bachiller 
##                   4.666667                   4.952381
describeBy(tabaco26$rich, tabaco26$antecedentes)
## 
##  Descriptive statistics by group 
## group: no
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 36 4.64 3.04    4.5    4.57 3.71   0  10    10 0.12    -1.16 0.51
## ------------------------------------------------------------ 
## group: si
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 6 5.83 2.86    5.5    5.83 2.97   2  10     8 0.14    -1.62 1.17
t.test(rich~antecedentes, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  rich by antecedentes
## t = -0.93888, df = 7.0339, p-value = 0.3789
## alternative hypothesis: true difference in means between group no and group si is not equal to 0
## 95 percent confidence interval:
##  -4.199790  1.810901
## sample estimates:
## mean in group no mean in group si 
##         4.638889         5.833333
describeBy(tabaco26$rich, tabaco26$medicacion)
## 
##  Descriptive statistics by group 
## group: no
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis  se
## X1    1 38 4.79 3.09      5    4.75 3.71   0  10    10  0.1    -1.15 0.5
## ------------------------------------------------------------ 
## group: si
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 4    5 2.58      5       5 2.97   2   8     6    0    -2.08 1.29
t.test(rich~medicacion, data=tabaco26)
## 
##  Welch Two Sample t-test
## 
## data:  rich by medicacion
## t = -0.15204, df = 3.9626, p-value = 0.8866
## alternative hypothesis: true difference in means between group no and group si is not equal to 0
## 95 percent confidence interval:
##  -4.069259  3.648206
## sample estimates:
## mean in group no mean in group si 
##         4.789474         5.000000
describeBy(tabaco26$rich, tabaco26$curso)
## 
##  Descriptive statistics by group 
## group: primero
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 11 6.27 2.57      7    6.33 1.48   2  10     8 -0.34    -1.48 0.78
## ------------------------------------------------------------ 
## group: segundo
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 4  5.5 3.11    4.5     5.5 1.48   3  10     7  0.6    -1.78 1.55
## ------------------------------------------------------------ 
## group: tercero
##    vars  n mean sd median trimmed  mad min max range skew kurtosis   se
## X1    1 21 4.29  3      4    4.12 2.97   0  10    10 0.36    -0.98 0.66
## ------------------------------------------------------------ 
## group: cuarto
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 6  3.5 3.33    3.5     3.5 4.45   0   8     8 0.09    -1.97 1.36
analisis<-aov(rich~curso, data=tabaco26)
summary(analisis)
##             Df Sum Sq Mean Sq F value Pr(>F)
## curso        3   41.5   13.84   1.589  0.208
## Residuals   38  331.0    8.71               
## 232 observations deleted due to missingness