Se leen los datos saeraq.Rdata
, que provienen del fichero raq.dat
utilizado en (A. Field, Miles, and Field 2012) (disponible en la web del libro).
Y
load( "saeraq.RData" )
tables
Se realizan descriptivos de cada variable con el paquete tables
(Murdoch (2016)).
# library( tables )
op <- booktabs()
# Función para imprimir tablas en latex
tablaLatex <- function( tabla, caption = NULL ){
cat( '\\begin{table} \\centering\n' )
if( !is.null( caption ) ) cat( paste0( '\\caption{', caption, '}\n' ) )
latex( tt )
cat( '\\end{table}' )
}
sexo
tt <- tabular( ~ ( Sexo = sexo ) + ( Total = 1 ), data = df )
# tablaLatex( tt, caption = "Variable \\texttt{sexo}." )
html( tt, options = htmloptions( HTMLcaption = "Variable sexo", pad = TRUE ) )
Sexo | |||
---|---|---|---|
Mujer | Hombre | Total | |
1927 | 644 | 2571 |
actividadS
tt <- tabular( ~ ( `Actividad S` = actividadS ) + ( Total = 1 ), data = df )
# tablaLatex( tt, "Variable \\texttt{actividadS}." )
html( tt, options = htmloptions( HTMLcaption = "Variable actividadS", pad = TRUE ) )
Actividad S | |||||
---|---|---|---|---|---|
Nada | Poco | Mucho | Muchísimo | Total | |
613 | 658 | 669 | 631 | 2571 |
ingresos
ic1 <- function(x){
mean( x ) - qt( 0.975, df = length( x ) - 1 ) * sd( x ) / sqrt( length( x ) )
}
ic2 <- function(x){
mean( x ) + qt( 0.975, df = length( x ) - 1 ) * sd( x ) / sqrt( length( x ) )
}
tt <- tabular( ~ ( Ingresos = ingresos ) * ( ic1 + mean + sd + ic2 + median ) +
( Total = 1 ), data = df )
# tablaLatex( tt, "Variable \\texttt{ingresos}." )
html( tt, options = htmloptions( HTMLcaption = "Variable ingresos", pad = TRUE ) )
Ingresos | ||||||
---|---|---|---|---|---|---|
ic1 | mean | sd | ic2 | median | Total | |
29320 | 29672 | 9095 | 30024 | 27771 | 2571 |
origen
tt <- tabular( ~ ( Origen = origen ) + ( Total = 1 ), data = df )
# tablaLatex( tt, "Variable \\texttt{origen}." )
html( tt, options = htmloptions( HTMLcaption = "Variable origen", pad = TRUE ) )
Origen | ||||
---|---|---|---|---|
Albacete | Murcia | Helsinki | Total | |
1178 | 1112 | 281 | 2571 |
nivelIngles
tt <- tabular( ( `Nivel de inglés` = nivelIngles ) + ( Total = 1 ) ~ ( Frecuencia = 1 ),
data = df )
# tablaLatex( tt, "Variable \\texttt{nivelIngles}." )
html( tt, options = htmloptions( HTMLcaption = "Variable nivelIngles", pad = TRUE ) )
Nivel de inglés | Frecuencia |
---|---|
Nulo | 297 |
CasiNulo | 289 |
A1 | 451 |
A2 | 455 |
B1 | 473 |
B2 | 377 |
C1 | 145 |
C2 | 79 |
IsabelII | 3 |
Shakespeare | 2 |
Total | 2571 |
likert
Se realizan gráficos descriptivos de los datos con el paquete likert
(Bryer and Speerschneider (2015)) que, al estar basados en ggplot2
(Wickham (2009)), permite modificarlos de forma sencilla.
# library( likert )
dfLikert <- df[ , grep( "^Q", colnames( df ) ) ]
colnames( dfLikert ) <- dicc[ grep( "^Q", dicc$item ), "spanish" ]
bloque1 <- 1:8
bloque2 <- 9:17
bloque3 <- 18:23
items1 <- likert( items = dfLikert[ , bloque1 ] )
items2 <- likert( items = dfLikert[ , bloque2 ] )
items3 <- likert( items = dfLikert[ , bloque3 ] )
plot( items1, centered = TRUE, group.order = colnames( items1$items ),
legend.position = "right" ) +
theme( axis.text.x = element_text( size = 10 ),
axis.text.y = element_text( size = 13, hjust = 0 ),
legend.text = element_text( size = 10 ),
legend.title = element_text( size = 10 ) )
Gráfico de barras de los ítems 1 a 8.
plot( items2, centered = TRUE, group.order = colnames( items2$items ),
legend.position = "right" ) +
theme( axis.text.x = element_text( size = 10 ),
axis.text.y = element_text( size = 13, hjust = 0 ),
legend.text = element_text( size = 10 ),
legend.title = element_text( size = 10 ) )