Introducción al análisis descriptivo en R
Análisis descriptivo en R
Objetivo del análisis descriptivo Tipos de variables Gráficas básicas
Histograma y estimación de la densidad Diagramas de dispersión Boxplot
Cálculo de índices básicos Discusión de ejemplos
Objetivo del análisis descriptivo
Explorar la estructura de los datos Proponer una interpretación de la
variación observada Valorar la influencia de variables de
confusión Resumir las principales
características de los datos
Tipos de variables
Cuantitativas Discretas: Número de accidentes,
Número de hijos varones, Número de diagnósticos correctos,
Continuas: Edad, Peso, Tiempo, Volumen celular
Cualitativas Nominales: Género (Hombre/Mujer),
Diagnóstico (Sano/Emfermo), Fenotipo (AA/Aa/aa)
Ordinales: Gravedad (0,+,++), Obesidad (Normal/Sobrepeso/Obeso/Obeso Grave)
Base de datos
Utilizaremos la base de datos fat disponible en el paquete UsingR
Algunas cuestiones de interés
¿Qué valores de BMI se han obtenido? Estudiar la distribución de los valores en
la muestra (histograma y densidad). ¿Cómo se relaciona la altura con el
peso? ¿La distribución del BMI depende de la edad? Diagrama de dispersión. Regresión de
cuantiles
¿Qué valores de BMI se han obtenido?
Histogram of fat$BMI
fat$BMI
Fre
qu
en
cy
15 20 25 30 35 40 45 50
02
04
06
08
01
00
12
0
Histograma
BMI
fat$BMI
De
nsi
ty
20 25 30 35 40 45 50
0.0
00
.02
0.0
40
.06
0.0
80
.10
0.1
2
Histograma
Histogram of BMI
BMI
De
nsi
ty
20 25 30 35 40 45 50
0.0
00
.02
0.0
40
.06
0.0
80
.10
0.1
2
Estimación de la densidad
20 30 40 50
0.0
00
.02
0.0
40
.06
0.0
80
.10
0.1
2
Distribución de BMI
BMI
De
nsi
da
d
Estimación de la densidad
20 30 40 50
0.0
00
.02
0.0
40
.06
0.0
80
.10
0.1
2
Distribución de BMI
BMI
De
nsi
da
d
Estimación de la densidadModelo normal
20 30 40 50
0.0
00
.02
0.0
40
.06
0.0
80
.10
0.1
2
Distribución de BMI
BMI
De
nsi
da
d
Estimación de la densidadModelo normal
-3 -2 -1 0 1 2 3
20
25
30
35
40
45
50
Normal Q-Q Plot
Theoretical Quantiles
Sa
mp
le Q
ua
ntil
es
¿Cómo se relaciona la altura con el peso?
30 40 50 60 70
15
02
00
25
03
00
35
0
height
we
igh
t
64 66 68 70 72 74 76 78
15
02
00
25
03
00
35
0
height
we
igh
t
¿Cómo se relaciona la altura con el peso?
64 66 68 70 72 74 76 78
15
02
00
25
03
00
35
0
height
we
igh
t
Cuantil: Valor para el cual un determinado % de individuos tienen valores iguales o inferiores a el.
Ejemplo: Si el cuantil 90 de peso es de 70 kg., entonces un 90% de individuos de esta población tienen valores de peso iguales o inferiores a 70 kg.
La regresión de cuantiles permite estimar cómo varían los cuantiles de una varaible en función de otra(s) variable(s).
¿Depende el BMI de la edad?
20 30 40 50 60 70 80
20
25
30
35
40
45
50
age
BM
I
El análisis descriptivo indica que la variación del BMI con la edad no es muy importante. La dispersión por edades parece mantenerse constante.
Datos de un ensayo clínico hipotético
Los datos AssaigClinic.R estan en formato de tabla. En cada caso, debéis copiar el fichero en un directorio.
Indicar el directorio en la instrucción read.table
El resultado es un data.frame que contiene la información del fichero.
Datos de un ensayo clínico hipotético
Podemos explorar qué variables se han recogido:
Veamos qué tratamientos se han incluido:
Recordad que podemos acceder directamente a las variables de un data.frame mediante attach
Tabulación de datos
Tabulación de datos
Tabulación de datos
Gráfico debarras
A B Control
0.0
0.2
0.4
0.6
0.8
1.0
Gráfico debarras
A B Control
0.0
0.2
0.4
0.6
0.8
1.0
Boxplot
A B Control
24
68
10
12
14
16
Boxplot (subgrupos)
Co
nce
ntr
aci
o
5
10
15
A B Control
No
A B Control
Si
Boxplot (subgrupos)
Co
nce
ntr
aci
o
5
10
15
No Si
A
No Si
B
5
10
15
Control
Histograma (Subgrups)
Concentracio
De
nsi
ty
0.0
0.1
0.2
0.3
5 10 15
NoA
SiA
NoB
0.0
0.1
0.2
0.3
SiB
0.0
0.1
0.2
0.3
NoControl
5 10 15
SiControl
Medias por subgrupos
5
6
7
8
9
10
11
12
Tractament[Millora == "Si"]
A B
Co
ntr
olA B
Co
ntr
ol
#this next command defines a new function which can then be used #for making multiple histograms multi.hist <- function(x) {nvar <- dim(x)[2] #number of variables nsize=trunc(sqrt(nvar))+1 #size of graphic old.par <- par(no.readonly = TRUE) # all par settings which can be changed par(mfrow=c(nsize,nsize)) #set new graphic parameters for (i in 1:nvar) { name=names(x)[i] #get the names for the variables hist(x[,i],main=name,xlab=name) } #draw the histograms for each variable on.exit(par(old.par)) #set the graphic parameters back to the original } #now use the function on the data multi.hist(person.data) #draw the histograms for all variables (see above) #this next command defines a new function which can then be used #for making multiple histograms multi.hist <- function(x) {nvar <- dim(x)[2] #number of variables nsize=trunc(sqrt(nvar))+1 #size of graphic old.par <- par(no.readonly = TRUE) # all par settings which can be changed par(mfrow=c(nsize,nsize)) #set new graphic parameters for (i in 1:nvar) { name=names(x)[i] #get the names for the variables hist(x[,i],main=name,xlab=name) } #draw the histograms for each variable on.exit(par(old.par)) #set the graphic parameters back to the original } #now use the function on the data multi.hist(person.data) #draw the histograms for all variables (see above) #this next command defines a new function which can then be used #for making multiple histograms multi.hist <- function(x) {nvar <- dim(x)[2] #number of variables nsize=trunc(sqrt(nvar))+1 #size of graphic old.par <- par(no.readonly = TRUE) # all par settings which can be changed par(mfrow=c(nsize,nsize)) #set new graphic parameters for (i in 1:nvar) { name=names(x)[i] #get the names for the variables hist(x[,i],main=name,xlab=name) } #draw the histograms for each variable on.exit(par(old.par)) #set the graphic parameters back to the original } #now use the function on the data multi.hist(person.data) #draw the histograms for all variables (see above) #this next command defines a new function which can then be used #for making multiple histograms multi.hist <- function(x) {nvar <- dim(x)[2] #number of variables nsize=trunc(sqrt(nvar))+1 #size of graphic old.par <- par(no.readonly = TRUE) # all par settings which can be changed par(mfrow=c(nsize,nsize)) #set new graphic parameters for (i in 1:nvar) { name=names(x)[i] #get the names for the variables hist(x[,i],main=name,xlab=name) } #draw the histograms for each variable on.exit(par(old.par)) #set the graphic parameters back to the original } #now use the function on the data multi.hist(person.data) #draw the histograms for all variables (see above)
Top Related