Documentos de Académico
Documentos de Profesional
Documentos de Cultura
KELMANSKY 13
Llamamos
lote
LECTURA DE DATOS
> Cera
CERA
1 63.78
2 63.34
3 63.36
4 63.51
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 16
5 63.92
........
datos <-
read.csv2(file.choose())#excel en
castellano
datos <- read.csv
(file.choose())#excel en inglés
datos[1:10,]
Escritura de datos
1) A un archivo texto.
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 19
write.table (datos[1:10,],file=
file.choose())# elijo nombre.txt
2) A un archivo csv
write.csv (datos[1:10,],file=
file.choose())# elijo nombre.csv para
excel en inglés
write.csv2 (datos[1:10,],file=
file.choose())# elijo nombre.csv para
excel en castellano
File -> Import Data -> From File -> Browse -> Seleccionar -
OK
Histogramas
hist(Cera$CERA,nclass=25)
hist(Cera$CERA)
hist(Cera$CERA,nclass=4)
Histogram of Cera$CERA
0 1 2 3 4 5
Frequency
Cera$CERA
Histogram of Cera$CERA
15
Frequency
10
5
0
Cera$CERA
Histogram of Cera$CERA
25
Frequency
15
0 5
Cera$CERA
hist(Cera$CERA,nclass=25,probability=T,
main="Histograma de Áreas, nclass=25",
xlab= "Cera"
,xlim=c(62.5,64.5),ylim=c(0,2))
hist(Cera$CERA,probability=T,
main="Histograma de Áreas,Cantidad de
Clases por defecto",
xlab= "Cera"
,xlim=c(62.5,64.5),ylim=c(0,2))
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 23
hist(Cera$CERA,nclass=4,probability=T,
main="Histograma de Áreas, nclass=4",
xlab= "Cera"
,xlim=c(62.5,64.5),ylim=c(0,2))
1.0
0.0
Cera
1.0
0.0
Cera
1.0
0.0
Cera
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 24
Tabla 1
16 12.0 8.0 5
32 15.1 11.3 6
64 18.1 16.0 7
128 21.1 22.6 8
256 24.1 32.0 9
512 27.1 45.3 10
ejex<- seq(10,512)
velle <- 2*sqrt(ejex)
sturges <- 1+logb(ejex,2)
dixkron <- 10*log10(ejex)
par(csi=0.24)
plot(ejex,velle,lty=1, type="l",
xlab="Tamaño de la Muestra",
ylab="Cantidad de Intervalos")
lines(ejex,sturges,lty=1, type="l")
lines(ejex,dixkron,lty=1, type="l")
40
Velleman
Cantidad de Intervalos
30
Dixon y Kronmal
20
Sturges
10
Tamaño de la Muestra
rango(datos) / ( 1 + log2 n)
R es el rango intercuartil.
en R hist(Cera$CERA,nclass=nclass.FD)
Las opciones son
nclass.Sturges
nclass.scott
nclass.FD(x)
en S-plus
hist(x, nclass=<<see below>>, .....)
nclass
recommendation for the number of classes (i.e., bars) the
histogram should have. This may be an integer, a
function to apply to x which returns an integer, or a
character string specifying which built-in method to use.
Available methods for calculating the number of classes
are Sturges ( sturges), Freedman-Diaconis ( fd), and
Scott ( scott).
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 28
0.6
0.0
60 65 70 75 80
ceraloca
0.6
0.0
60 65 70 75 80
ceraloca
0.6
0.0
60 65 70 75 80
ceraloca
n-1/3.
log(n) y n1/2.
Histograma
n
fˆh ( x) = (nh) −1 ∑∑ I ( X i ∈ B j ) I ( x ∈ B j )
i =1 j
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 32
Sesgo
n
−1
fˆh ( x) = (nh) ∑ I(X i ∈ B j )
i =1
∑ E [I ( X i ∈ B j )] =
n
−1
E ( fˆh ( x)) = (nh)
i =1
[
= (nh) −1 nE I ( X ∈ B j ) ]
jh
= h −1 ∫ f (u )du
( j −1) h
E ( fˆh ( x)) − f ( x)
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 33
Luego
f ( x ) = a + cx x ∈ Bj a, c ∈ R
Varianza
I (Xi ∈ B j )
es una variable Bernouilli con varianza p (1-p ) donde
p = P( X i ∈ B j ) = ∫ f (u)du
Bj
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 35
Por lo tanto
n
Var ( fˆh ( x )) = Var ((nh) −1 ∑ I ( X i ∈ B j ))
i =1
n
−2
= (nh) ∑ Var ( I ( X i ∈ B j ))
i =1
−1 − 2
=n h ( ∫ f (u )du )(1 − ∫ f (u )du )
Bj Bj
= (nh) −1 ( f ( x ) + o(1)), h → 0, nh → ∞
[
ECM ( fˆh ( x) = E ( fˆh ( x) − f ( x)) 2 ]
[
= E ( fˆh ( x) − E (( fˆh ( x)) + E (( fˆh ( x)) − f ( x)) 2 ]
= E [( fˆ ( x) − E (( fˆ ( x))) ]
h h
2
[ ][
+ 2 E ( f h ( x) − E (( f h ( x)) E (( f h ( x)) − f ( x)
ˆ ˆ ˆ 2
]
[
+ E (( f h ( x)) − f ( x)
ˆ 2
]
[ ][
= Var f h ( x) + Sesgo( f h ( x))
ˆ ˆ 2
]
Es la suma de la varianza y el sesgo al cuadrado.
[ ][
ECM ( f h ( x) = Var f h ( x) + Sesgo( f h ( x))
ˆ ˆ ˆ 2
]
f ( x) + (( j − 1 / 2)h − x) 2 [ f ' (( j − 1 / 2)h)]2
1
=
nh
1
+ o( h) + o( )
nh
Minimizar el ECM con respecto a h establece un compromiso
en el dilema que presenta el “variance-bias trade-off”, es decir
ANÁLISIS DE DATOS 2009 Dra. Diana M. KELMANSKY 37
1/ 3
⎛ ⎞
⎜
h0 = ⎜
6 ⎟
⎜ n ∫ ( f ' ( x)) 2 dx ⎟⎟
⎝ ⎠
h0 ∝ n −1 / 3