Академический Документы
Профессиональный Документы
Культура Документы
Programas comerciales
Gran variedad
oIBM SPSS Statistics
Statistical Software for Social Sciences (SPSS Inc.)
PASW (Predictive Analytic Software)
Desarrollo de una versin libre llamada PSPP
oSAS, MATLAB, Statistica, Stata, InfoStat
PROGRAMAS DE CLCULO ESTADSTICO
Programas libres:
GNU GPL (General Public License) cuyo propsito es
proteger los derechos y libertades de los usuarios
finales (http://www.fsf.org)
Usar, compartir, estudiar, modificar
R es uno de estos programas libres
OBJETIVO DE ESTE CURSO
Pros Contras
oEs libre oAl principio suele ser
oFlexibilidad rido
oProcedimientos oCuesta un poco si se
disponibles est habituado a trabajar
oSe aprende estadstica con otro tipo de
programas
oLos grficos
OBTENER R
http://www.r-project.org
OBTENER R
Seleccionar un servidor
Colombia
http://www.laqee.unal.edu.co/CRAN/ National University of Colombia
Objetos
oFunciones
nombre.de.la.funcin(argumento/s=, opcin/es=)
Espacio o rea de trabajo
Directorio de trabajo
Paquetes
Archivos de comandos o scripts
DESCRIPCIN DE LA INTERFAZ GRFICA DE
USUARIO EN R
Ejecutar el programa o
el acceso directo del
escritorio
R.lnk
Apertura de la consola
de comandos
OTRAS INTERFACES INTERESANTES
El directorio de trabajo
oUsando cdigo
Identificarlo usando la funcin getwd()
Cambiarlo setwd()
oCon RStudio
setwd("w:/Escritorio")
QU SON LOS ARCHIVOS DE CDIGO?
#Por Bloques
c=1
f=2
g=3
DESCRIPCIN DE PAQUETES
Funcin packageDescription()
Funcin library(help="nombre.del.paquete")
CARGAR PAQUETES
La funcin library()
Con la interfaz de RStudio
DESACTIVAR PAQUETES
La funcin detach("package:nombre.del.paquete")
Con RStudio
INSTALAR PAQUETES
La funcin install.packages("nombre.del.paquete")
Con RStudio
ACTUALIZAR PAQUETES
La funcin update.packages()
Con RStudio
DESINSTALAR PAQUETES
La funcin remove.packages("nombre.del.paquete")
Con Rstudio
#GESTIN DE PAQUETES
packageDescription("foreign") #El paquete "foreign" (tiene que ver con la opcin que tiene R de importar archivos de otros
Ejemplo software. Ver Priority, Version, Fecha de creacin, De qu versin Depende, Autores, Descripcin...
library(help="foreign") #Se nos abre una nueva pestaa con la descripcin de los paquetes
#Con comandos
#Desactivar paquetes
#Con Comandos
detach("package:foreign")
#Instalar paquetes
#Con Comandos
#Con RStudio
#Install Packages
#Actualizar Paquetes
#Con Cdigo
update.packages() #Nos busca los paquetes que pueden ser actualizados
#Con RStudio
#Check for Updates
#Desinstalar Paquetes
LOS OBJETOS DE R
#CREACIN DE OBJETOS
A<-46
26->B
C=99
93=D #Produce un error
QU ES UN VECTOR?
Vectores numricos
oLas edades de un grupo de amigos: 20, 25, 22, 21, 27, 28
Vectores lgicos
oTienen novia los amigos?: TRUE, TRUE, FALSE, FALSE,
TRUE, FALSE (se truncan a ceros y unos)
Vectores cualitativos o de caracteres
oNombres: Pedro, Manuel, Jos, Esteban, Ral, Damin
CREACIN DE VECTORES
La funcin c()
La funcin assingn()
Los dos puntos :
La funcin seq()
Distribuciones estadsticas
Ejemplo
#CREACIN DE VECTORES
s
novia<-c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE) ; novia
edad_2<-c(20,25,22,21,27,28) ; edad_2
id<-1:6 ; id
secuencia<-seq(0,60,10) ; secuencia
#Podra ser igual a
sequencia<-seq(from=0,to=60,by=10) ; sequencia
normal.aleatorio<-rnorm(6,mean=3,sd=4); normal.aleatorio
DIFERENCIAS ENTRE MATRICES, ARRAYS Y
TABLAS
Una matriz es la
generalizacin bi-dimensional
de un vector
oContiene vectores fila
oY vectores columna
Un array es la generalizacin
multidimensional de una matriz Tomado de Lpez (2012)
MODOS DE CREAR MATRICES Y ARRAYS
#dim()
Ejemplo v<-1:30; v
dim(v)<-c(10,3); v #el primer nmero de la fundin dim se refiere a las filas y el segundo a las columnas
s v2<-1:30; v2
#matrix()
m1<-matrix(data=46,nr=2,nc=2); m1
m2<-matrix(1:4,2,2); m2
#Array
#Tablas
barplot(n)
La funcin data()
La funcin str()
La funcin head()
La funcin tail()
La funcin View()
La funcin dim()
CREACIN DE BASES DE DATOS
s #Base de datos que contiene informacin (longitud y anchura del sepalo, longitud y anchura del petalo, especies) de 3 especies
de flores
View(iris) #Nos aparece una nueva ventana que nos muestra de forma tabulada la base de datos
id<-1:6; id
peso<-c(80,75,76,73,85,85); peso
correcto<-c(TRUE, FALSE,TRUE, FALSE,TRUE, TRUE);correcto
letras<-c("A","B","C","D","E","F"); letras
mis.datos<-data.frame(id,peso,correcto,letras); mis.datos
mis.datos
View(mis.datos)
mtx<-matrix(1:9,ncol=3,nrow=3);mtx
as.data.frame(mtx)
View(mtx)
LA FUNCIN PLOT()
Ejemplos
Usemos la variable Sepal.Length contenida en la
base de datos iris
Recuerda utilizar attach()
Es decir:
oattach(iris)
LA FUNCIN PLOT()
Argumento y
0 50 100 150
Posicin Index
LA FUNCIN PLOT()
plot(Sepal.Length, type="l")
0 50 100 150
Index
LA FUNCIN PLOT()
plot(Sepal.Length, type="b")
0 50 100 150
Index
LA FUNCIN PLOT()
plot(Sepal.Length, type="o")
0 50 100 150
Index
LA FUNCIN PLOT()
plot(Sepal.Length, type="h")
0 50 100 150
Index
LA FUNCIN PLOT()
plot(Sepal.Length, type="s")
0 50 100 150
Index
GRFICOS DE DISPERSIN
1 2 3 4 5 6 7
Petal.Length
o plot(Sepal.Length,Petal.Length)
8 10
table(Sepal.Length)
6
Frecuencia
4
absoluta
2
0
4.3 4.9 5.5 6 6.5 7 7.6
Sepal.Length
LA FUNCIN HIST()
250
1. h = rnorm(1000, 46, 3)
Frequency
150
2. hist(h)
0 50
40 45 50 55
h
OPCIONES ESPECFICAS DE LOS HISTOGRAMAS
La opcin breaks
hist(h, breaks=15) hist(h, breaks=30) hist(h, breaks=70)
Histogram of h Histogram of h Histogram of h
120
60
30
Frequency
Frequency
Frequency
80
40
20
40
20
10
0
0
40 45 50 55 40 45 50 55 40 45 50 55
h h h
OPCIONES ESPECFICAS DE LOS HISTOGRAMAS
La opcin density
hist(h, density=5) hist(h, density=10) hist(h, density=30)
Histogram of h Histogram of h Histogram of h
250
250
250
Frequency
Frequency
Frequency
150
150
150
0 50
0 50
0 50
40 45 50 55 40 45 50 55 40 45 50 55
h h h
OPCIONES ESPECFICAS DE LOS HISTOGRAMAS
250
250
Frequency
Frequency
Frequency
150
150
150
0 50
0 50
0 50
40 45 50 55 40 45 50 55 40 45 50 55
h h h
OPCIONES ESPECFICAS DE LOS HISTOGRAMAS
colors()
La opcin border
hist(h, border="red") hist(h, border=green") hist(h, border=blue")
250
250
Frequency
Frequency
Frequency
150
150
150
0 50
0 50
0 50
40 45 50 55 40 45 50 55 40 45 50 55
h h h
OPCIONES ESPECFICAS DE LOS HISTOGRAMAS
La opcin col
hist(h, col="pink") hist(h, col="yellow") hist(h, col="turquoise")
250
250
Frequency
Frequency
Frequency
150
150
150
0 50
0 50
0 50
40 45 50 55 40 45 50 55 40 45 50 55
h h h
VARIAS OPCIONES EN UN MISMO HISTOGRAMA
40
45
h
Histograma
50
55
LA FUNCIN PIE()
Peces
barplot(height=c(3,5,7),names.arg=c("Carne","Fruta","Vegetales"))
LA FUNCIN BARPLOT()
6
4
2
0
barplot(table(Type))
LA FUNCIN BARPLOT()
20
15
10
5
0
barplot(table(Type))
DAR COLOR
20
15
10
5
0
20
15
10
5
0
20
15
10
5
0
20
15
10
5
0
20
15
10
5
0
2.5
text(0.8, 1.5, "Un texto")
2.0
2
1.5
Un texto
2.5
y = c(rep(1.5,3)),
2.0
2
pch = 17,
1.5
Un texto
col = "red"
) 0.6 0.8 1.0 1.2 1.4
Index
LA FUNCIN LINES()
2.5
x = c(0.6,0.8,1,1.2,1.4),
y = c(1.5,2,2.3,2.4,2.5),
2.0
2
type = "b",
1.5
Un texto
col = 4,
pch = 11 0.6 0.8 1.0 1.2 1.4
) Index
LA FUNCIN ABLINE()
2.5
b = 0.5,
2.0
2
lwd= 6,
1.5
Un texto
lty = 3,
col = 6 0.6 0.8 1.0 1.2 1.4
) Index
LA FUNCIN ABLINE()
2.5
v = seq(0.6,1.4,0.2),
col = "pink",
2.0
2
h = seq(1.5, 2.5, 0.5)
1.5
Un texto
)
0.6 0.8 1.0 1.2 1.4
Index
LA FUNCIN LEGEND()
2.5
x = "topleft",
legend = "Leyenda",
2.0
2
fill = "yellow"
)
1.5
Un texto
title( Leyenda
2.5
main = "Es una prueba",
sub = "Base",
2.0
2
col.main = "green"
)
1.5
Un texto