300 likes | 556 Views
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.
E N D
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
¿Cómo se relaciona la altura con el peso? 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? 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.Restan 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
#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)