Está en la página 1de 16

DATOS DE MINERALES

> chorSub[1:5,]
Al Ca
Fe
K
Mg
Mn Na
P Si
Ti
190 101 11 -22 -17 -34 -41 27 -36 -58 -28
191 50 129
23 -82
47
33 61 90 -24
9
192
5 65 -22 -96 -33
7 47 49 30 -39
193 -40 -16 -158 -70 -104 -114 53 -61 103 -160
194 -13 30 -82 -113
26 -41 65 -90 43 -130

> summary(princomp(chorSub))###los datos ya fueron estandarizados


Importance of components:
Comp.1
Comp.2
Comp.3
Comp.4
Comp.5
Standard deviation
172.6840406 131.2978867 102.8855171 83.83859858
62.17277832
Proportion of Variance
0.4094813
0.2367256
0.1453577 0.09652009
0.05307992
Cumulative Proportion
0.4094813
0.6462069
0.7915646 0.88808472
0.94116463
Comp.6
Comp.7
Comp.8
Comp.9
Comp.10
Standard deviation
46.32460246 30.92286282 24.735623474 18.153694396
15.523697424
Proportion of Variance 0.02946816 0.01313074 0.008401859 0.004525429
0.003309177
Cumulative Proportion
0.97063280 0.98376353 0.992165394 0.996690823
1.000000000
LAS CARGAS SON:
Loadings:
Comp.1
Al -0.270
Ca -0.168
Fe -0.471
K
Mg -0.345
Mn -0.327
Na 0.127
P -0.191
Si 0.423
Ti -0.465

Comp.2 Comp.3 Comp.4 Comp.5


-0.279 0.741 0.284
0.623
-0.110 0.238
-0.476 -0.501
0.195 0.418
-0.256
-0.451 0.272
0.516 -0.403 -0.222 0.314
0.103 -0.505
-0.782
-0.110
-0.169 -0.105
-0.202
-0.388 0.226

Comp.6 Comp.7 Comp.8 Comp.9 Comp.10


-0.250
0.182 -0.235 -0.240
0.162 -0.707
-0.209
0.185
0.738 -0.325
0.487 -0.221 -0.425
-0.220
0.498 -0.401 0.143 -0.370 -0.189
-0.461 -0.627
0.367
0.443 0.237 -0.139
-0.208
0.186
-0.227
-0.139 -0.825
0.572 0.140 -0.423

> screeplot(princomp(chorSub))

> biplot(princomp(chorSub) )

LOS OUTLIERS PUEDEN CAMBIAR MUCHO EL ANALISIS


>
> chorSub.princomp<-princomp(chorSub)
> help(corr.plot)
> corr.plot( (chorSub[,"Al"]), (chorSub[,"Na"]))
$cor.cla
[1] -0.04144816
$cor.rob
[1] 0.4095245

PARA ESTIMAR DE MANERA ROBUSTA LA MATRIZ DE VARIANZAS Y COVARIANZAS


> covMcd(chorSub)
Minimum Covariance Determinant (MCD) estimator.
Call:
covMcd(x = chorSub)
-> Method: Minimum Covariance Determinant Estimator.
Log(Det.): 67.24
Robust Estimate of Location:
Al
Ca
Fe
K
Mg
Mn
Na
P
Ti
-14.58
8.50 -59.47 -27.39 -41.86 -47.25
42.94 -18.64
51.39
Robust Estimate of Covariance:
Al
Ca
Fe
K
Mg
Mn
Na
Si
Al
9669.9
6112
2770 -2317.4
2567.0
2414.2
3091.05
-6088.97
Ca
6112.1
8393
3972 -4656.4
4633.1
3860.4
3254.65
-5125.31
Fe
2770.4
3972
6816 -1711.5
5960.2
4498.9 -2063.46
-5699.89
K
-2317.4 -4656 -1712
6379.3 -2553.0 -2150.0 -1749.84
1638.17
Mg
2567.0
4633
5960 -2553.0
6072.9
4241.8
-954.58
-5056.64

Si
41.33

4446.7
4865.8
3447.7
-1276.7
2694.2

Mn
2414.2
-3866.36
Na
3091.1
-64.33
P
4446.7
-4116.19
Si -6089.0
6853.57
Ti
770.2
-4435.42
Ti
Al
770.2
Ca
2328.6
Fe
6319.9
K
-818.7
Mg
5441.0
Mn
3897.3
Na -2920.8
P
2518.4
Si -4435.4
Ti
6717.3

3860

4499

-2150.0

4241.8

3496.4

-572.20

2583.1

3255

-2063

-1749.8

-954.6

-572.2

5167.23

799.5

4866

3448

-1276.7

2694.2

2583.1

799.45

6404.8

-5125

-5700

1638.2

-5056.6

-3866.4

-64.33

-4116.2

2329

6320

-818.7

5441.0

3897.3

-2920.78

2518.4

PARA CALCULAR DISTANCIAS Y DISIMILITUDES

> distancias<-daisy(chorSub, metric = "euclidean", stand = FALSE)

ANALISIS DE CONGLOMERADOS JERARQUICOS


>
> chorSub.clust<-agnes(chorSub,diss=FALSE,method = "ward")
> plot(chorSub.clust)
<Enter> para ver el prximo grfico:
<Enter> para ver el prximo grfico:

> grupos<-hclust(distancias,method = "ward")


PARA CORTAR EL DENDOGRAMA Y OBTENER LOS GRUPOS
>
> memb <- cutree(grupos, k = 3)####guardo a que grupo pertenecen

> plot(grupos)
> (x <- identify(grupos))###esta es otra manera de hacerlo a pie.
[[1]]
193 194 198 202 204 207 209 210 217 218 222 224 226 230 231 232 233 234
237 238 244
4
5
9 13 15 18 20 21 28 29 33 35 37 41 42 43 44 45
48 49 55
247 250
58 61
[[2]]
190 191
216 219
1
2
27 30
221 223
32 34

192 195 196 197 199 200 201 203 205 206 208 211 212 213 214 215
220
3
6
7
8 10 11 12 14 16 17 19 22 23 24 25 26
31
225 227 228 229 235 236 239 240 241 242 243 245 246 248 249
36 38 39 40 46 47 50 51 52 53 54 56 57 59 60

[[3]]
190 191 192 197 199 208 215 216 225 227 228 229 236 240 241 243 245 246
249
1
2
3
8 10 19 26 27 36 38 39 40 47 51 52 54 56 57
60
[[4]]
195 196 200 201 203 205 206 211 212 213 214 219 220 221 223 235 239 242
248
6
7 11 12 14 16 17 22 23 24 25 30 31 32 34 46 50 53
59

CONGLOMERADOS NO JERARQUICOS
> ###### Kmeans
>
> conglo1<-kmeans(chorSub,2)
> conglo2<-kmeans(chorSub,3)
>
> ##### cluster por modelos DE MEZCLAS DE DENSIDADES
>
> clustmodelo<-Mclust(chorSub[,1:10])
> plot.Mclust(clustmodelo)
<Enter> para ver el prximo grfico: #################discriminante
lineal
<Enter> para ver el prximo grfico:
<Enter> para ver el prximo grfico:
<Enter> para ver el prximo grfico:

ANALISIS DE DISCRIMINANTE LINEAL


> fit <- lda(memb~ Al+Ca+Fe+K+Mg+Mn+Na+P+Si+Ti,
data=as.data.frame(chorSub),na.action="na.omit", CV=TRUE)
> fit2 <-lda(memb~ Al+Ca+Fe+K+Mg+Mn+Na+P+Si+Ti,
data=as.data.frame(chorSub),na.action="na.omit" )
>
> ct <- table(memb, fit$class)
> ct
memb 1 2 3
1 18 0 1
2 1 22 0
3 1 3 15
> diag(prop.table(ct, 1))
1
2
3
0.9473684 0.9565217 0.7894737
> # total percent correct
> sum(diag(prop.table(ct)))
[1] 0.9016393
>
>
PUEDO USARNOTROS DATOS PARA HACER PREDICION
>
> chorSub2 <- round(100*scale(chorizon[,101:110]))[180:189,]
> storage.mode(chorSub2) <- "integer"
> colnames(chorSub2) <- gsub("_.*", '', colnames(chorSub))
> #write.table(chorSub2,"chorSub2", row.names = FALSE)
> predict(fit2, as.data.frame(chorSub2))$class
[1] 1 1 2 2 1 1 3 3 2 2
Levels: 1 2 3
> datos<-read.table("chorSub2",header=TRUE )
> datos

Al
Ca
Fe
K
Mg
Mn
Na
P Si
Ti
1
24
-1
45 -49
3
7 -86 -20 34
-9
2
-42
60
51 -57 164
7
24 -49 -76
47
3
30
-5
1
58
7 -41
35 21 -11
13
4 -191 -129 -80
66 -121
7 -139 -36 136 -13
5
-48
48 124 -74 121
83 -22 -36 -92 160
6
-1
71
8 -124 249
33
35 -61 -53 -70
7
59 -96
60
54
12 -15 -128 49 -23
13
8
124 -112
90
27
16 -15 -164 -49 -9
47
9
-88 -114 -160 197 -157 -139
44 -36 146 -122
10 -78 -99 -129 192 -118 -114
27 -20 122 -92
COEFICIENTES PARA CREAR LAS FUNCIONES DISCRIMINANTES
> fit2$scaling
LD1
LD2
Al -0.0045555103 0.004667801
Ca -0.0001843901 -0.026015863
Fe 0.0055164242 0.012749097
K
0.0161424676 -0.004420512
Mg 0.0008433545 0.005440859
Mn -0.0011417624 0.006067205
Na 0.0079950044 0.011427042
P -0.0087500452 0.004875888
Si 0.0093702775 0.013853604
Ti -0.0100390981 0.005672175
> coeficientes<-fit2$scaling
CALCULO EL PRODUCTO PARA OBTENER SUS EVALUACIONES EN LAS FUNCIONES
DISCRIMINANTES
> chorSub2%*%coeficientes
LD1
LD2
180 -0.7609801 0.3268802
181 -0.8915436 -0.6710061
182 0.7212448 0.2394921
183 2.0165015 0.5834024
184 -2.6226223 0.8032017
185 -0.7740636 -0.6754421
186 -0.8192857 1.8048060
187 -1.0198853 2.5456509
188 6.0052543 -0.3953322
189 5.2496015 -0.2362607
> ############## otras graficas
plot(chorSub.princomp$scores[,1],chorSub.princomp$scores[,2],col=clustmod
elo$classification)
> plot(chorSub.princomp$scores[,1],chorSub.princomp$scores[,2],col=memb)
>
plot(chorSub.princomp$scores[,1],chorSub.princomp$scores[,2],col=conglo1$
cluster)
>
plot(chorSub.princomp$scores[,1],chorSub.princomp$scores[,2],col=conglo2$
cluster)

Intereses relacionados