library(ggplot2)
library(mlbench)
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 4.2.1
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
library(corrplot)
## corrplot 0.92 loaded
library (DMwR2)
## Warning: package 'DMwR2' was built under R version 4.2.1
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library (dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## src, summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(Amelia)
## Loading required package: Rcpp
## Warning: package 'Rcpp' was built under R version 4.2.1
## ##
## ## Amelia II: Multiple Imputation
## ## (Version 1.8.0, built: 2021-05-26)
## ## Copyright (C) 2005-2022 James Honaker, Gary King and Matthew Blackwell
## ## Refer to http://gking.harvard.edu/amelia/ for more information
## ##
library(mlbench)
ionosphere <- read.csv("C:/Users/18324/Downloads/ionosphere (1).csv", header= FALSE)
View(ionosphere)
head(ionosphere, 2)
## V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11
## 1 1 0 0.99539 -0.05889 0.85243 0.02306 0.83398 -0.37708 1 0.03760 0.85243
## 2 1 0 1.00000 -0.18829 0.93035 -0.36156 -0.10868 -0.93597 1 -0.04549 0.50874
## V12 V13 V14 V15 V16 V17 V18 V19 V20
## 1 -0.17755 0.59755 -0.44945 0.60536 -0.38223 0.84356 -0.38542 0.58212 -0.32192
## 2 -0.67743 0.34432 -0.69707 -0.51685 -0.97515 0.05499 -0.62237 0.33109 -1.00000
## V21 V22 V23 V24 V25 V26 V27 V28
## 1 0.56971 -0.29674 0.36946 -0.47357 0.56811 -0.51171 0.41078 -0.46168
## 2 -0.13151 -0.45300 -0.18056 -0.35734 -0.20332 -0.26569 -0.20468 -0.18401
## V29 V30 V31 V32 V33 V34 V35
## 1 0.21266 -0.34090 0.42267 -0.54487 0.18641 -0.45300 g
## 2 -0.19040 -0.11593 -0.16626 -0.06288 -0.13738 -0.02447 b
str(ionosphere)
## 'data.frame': 351 obs. of 35 variables:
## $ V1 : int 1 1 1 1 1 1 1 0 1 1 ...
## $ V2 : int 0 0 0 0 0 0 0 0 0 0 ...
## $ V3 : num 0.995 1 1 1 1 ...
## $ V4 : num -0.0589 -0.1883 -0.0336 -0.4516 -0.024 ...
## $ V5 : num 0.852 0.93 1 1 0.941 ...
## $ V6 : num 0.02306 -0.36156 0.00485 1 0.06531 ...
## $ V7 : num 0.834 -0.109 1 0.712 0.921 ...
## $ V8 : num -0.377 -0.936 -0.121 -1 -0.233 ...
## $ V9 : num 1 1 0.89 0 0.772 ...
## $ V10: num 0.0376 -0.0455 0.012 0 -0.164 ...
## $ V11: num 0.852 0.509 0.731 0 0.528 ...
## $ V12: num -0.1776 -0.6774 0.0535 0 -0.2028 ...
## $ V13: num 0.598 0.344 0.854 0 0.564 ...
## $ V14: num -0.44945 -0.69707 0.00827 0 -0.00712 ...
## $ V15: num 0.605 -0.517 0.546 -1 0.344 ...
## $ V16: num -0.38223 -0.97515 0.00299 0.14516 -0.27457 ...
## $ V17: num 0.844 0.055 0.838 0.541 0.529 ...
## $ V18: num -0.385 -0.622 -0.136 -0.393 -0.218 ...
## $ V19: num 0.582 0.331 0.755 -1 0.451 ...
## $ V20: num -0.3219 -1 -0.0854 -0.5447 -0.1781 ...
## $ V21: num 0.5697 -0.1315 0.7089 -0.6997 0.0598 ...
## $ V22: num -0.297 -0.453 -0.275 1 -0.356 ...
## $ V23: num 0.3695 -0.1806 0.4339 0 0.0231 ...
## $ V24: num -0.474 -0.357 -0.121 0 -0.529 ...
## $ V25: num 0.5681 -0.2033 0.5753 1 0.0329 ...
## $ V26: num -0.512 -0.266 -0.402 0.907 -0.652 ...
## $ V27: num 0.411 -0.205 0.59 0.516 0.133 ...
## $ V28: num -0.462 -0.184 -0.221 1 -0.532 ...
## $ V29: num 0.2127 -0.1904 0.431 1 0.0243 ...
## $ V30: num -0.341 -0.116 -0.174 -0.201 -0.622 ...
## $ V31: num 0.4227 -0.1663 0.6044 0.2568 -0.0571 ...
## $ V32: num -0.5449 -0.0629 -0.2418 1 -0.5957 ...
## $ V33: num 0.1864 -0.1374 0.5605 -0.3238 -0.0461 ...
## $ V34: num -0.453 -0.0245 -0.3824 1 -0.657 ...
## $ V35: chr "g" "b" "g" "b" ...
summary(ionosphere)
## V1 V2 V3 V4
## Min. :0.0000 Min. :0 Min. :-1.0000 Min. :-1.00000
## 1st Qu.:1.0000 1st Qu.:0 1st Qu.: 0.4721 1st Qu.:-0.06474
## Median :1.0000 Median :0 Median : 0.8711 Median : 0.01631
## Mean :0.8917 Mean :0 Mean : 0.6413 Mean : 0.04437
## 3rd Qu.:1.0000 3rd Qu.:0 3rd Qu.: 1.0000 3rd Qu.: 0.19418
## Max. :1.0000 Max. :0 Max. : 1.0000 Max. : 1.00000
## V5 V6 V7 V8
## Min. :-1.0000 Min. :-1.0000 Min. :-1.0000 Min. :-1.00000
## 1st Qu.: 0.4127 1st Qu.:-0.0248 1st Qu.: 0.2113 1st Qu.:-0.05484
## Median : 0.8092 Median : 0.0228 Median : 0.7287 Median : 0.01471
## Mean : 0.6011 Mean : 0.1159 Mean : 0.5501 Mean : 0.11936
## 3rd Qu.: 1.0000 3rd Qu.: 0.3347 3rd Qu.: 0.9692 3rd Qu.: 0.44567
## Max. : 1.0000 Max. : 1.0000 Max. : 1.0000 Max. : 1.00000
## V9 V10 V11 V12
## Min. :-1.00000 Min. :-1.00000 Min. :-1.00000 Min. :-1.00000
## 1st Qu.: 0.08711 1st Qu.:-0.04807 1st Qu.: 0.02112 1st Qu.:-0.06527
## Median : 0.68421 Median : 0.01829 Median : 0.66798 Median : 0.02825
## Mean : 0.51185 Mean : 0.18135 Mean : 0.47618 Mean : 0.15504
## 3rd Qu.: 0.95324 3rd Qu.: 0.53419 3rd Qu.: 0.95790 3rd Qu.: 0.48237
## Max. : 1.00000 Max. : 1.00000 Max. : 1.00000 Max. : 1.00000
## V13 V14 V15 V16
## Min. :-1.0000 Min. :-1.00000 Min. :-1.0000 Min. :-1.00000
## 1st Qu.: 0.0000 1st Qu.:-0.07372 1st Qu.: 0.0000 1st Qu.:-0.08170
## Median : 0.6441 Median : 0.03027 Median : 0.6019 Median : 0.00000
## Mean : 0.4008 Mean : 0.09341 Mean : 0.3442 Mean : 0.07113
## 3rd Qu.: 0.9555 3rd Qu.: 0.37486 3rd Qu.: 0.9193 3rd Qu.: 0.30897
## Max. : 1.0000 Max. : 1.00000 Max. : 1.0000 Max. : 1.00000
## V17 V18 V19 V20
## Min. :-1.0000 Min. :-1.000000 Min. :-1.0000 Min. :-1.00000
## 1st Qu.: 0.0000 1st Qu.:-0.225690 1st Qu.: 0.0000 1st Qu.:-0.23467
## Median : 0.5909 Median : 0.000000 Median : 0.5762 Median : 0.00000
## Mean : 0.3819 Mean :-0.003617 Mean : 0.3594 Mean :-0.02402
## 3rd Qu.: 0.9357 3rd Qu.: 0.195285 3rd Qu.: 0.8993 3rd Qu.: 0.13437
## Max. : 1.0000 Max. : 1.000000 Max. : 1.0000 Max. : 1.00000
## V21 V22 V23 V24
## Min. :-1.0000 Min. :-1.000000 Min. :-1.0000 Min. :-1.00000
## 1st Qu.: 0.0000 1st Qu.:-0.243870 1st Qu.: 0.0000 1st Qu.:-0.36689
## Median : 0.4991 Median : 0.000000 Median : 0.5318 Median : 0.00000
## Mean : 0.3367 Mean : 0.008296 Mean : 0.3625 Mean :-0.05741
## 3rd Qu.: 0.8949 3rd Qu.: 0.188760 3rd Qu.: 0.9112 3rd Qu.: 0.16463
## Max. : 1.0000 Max. : 1.000000 Max. : 1.0000 Max. : 1.00000
## V25 V26 V27 V28
## Min. :-1.0000 Min. :-1.00000 Min. :-1.0000 Min. :-1.00000
## 1st Qu.: 0.0000 1st Qu.:-0.33239 1st Qu.: 0.2864 1st Qu.:-0.44316
## Median : 0.5539 Median :-0.01505 Median : 0.7082 Median :-0.01769
## Mean : 0.3961 Mean :-0.07119 Mean : 0.5416 Mean :-0.06954
## 3rd Qu.: 0.9052 3rd Qu.: 0.15676 3rd Qu.: 0.9999 3rd Qu.: 0.15354
## Max. : 1.0000 Max. : 1.00000 Max. : 1.0000 Max. : 1.00000
## V29 V30 V31 V32
## Min. :-1.0000 Min. :-1.00000 Min. :-1.0000 Min. :-1.000000
## 1st Qu.: 0.0000 1st Qu.:-0.23689 1st Qu.: 0.0000 1st Qu.:-0.242595
## Median : 0.4966 Median : 0.00000 Median : 0.4428 Median : 0.000000
## Mean : 0.3784 Mean :-0.02791 Mean : 0.3525 Mean :-0.003794
## 3rd Qu.: 0.8835 3rd Qu.: 0.15407 3rd Qu.: 0.8576 3rd Qu.: 0.200120
## Max. : 1.0000 Max. : 1.00000 Max. : 1.0000 Max. : 1.000000
## V33 V34 V35
## Min. :-1.0000 Min. :-1.00000 Length:351
## 1st Qu.: 0.0000 1st Qu.:-0.16535 Class :character
## Median : 0.4096 Median : 0.00000 Mode :character
## Mean : 0.3494 Mean : 0.01448
## 3rd Qu.: 0.8138 3rd Qu.: 0.17166
## Max. : 1.0000 Max. : 1.00000
dim(ionosphere)
## [1] 351 35
ionosphere$V1<-factor(ionosphere$V1)
prop.table(table(ionosphere$V1))
##
## 0 1
## 0.1082621 0.8917379
ionosphere$V35<-factor(ionosphere$V35, levels=c("b", "g"), labels = c("Bad", "Good"))
cbind(freq=table(ionosphere$V35), percentage=(round(prop.table(table(ionosphere$V35)),2)))
## freq percentage
## Bad 126 0.36
## Good 225 0.64
freqbg<-table(ionosphere$V35)
barplot(freqbg, main=" Frequency of good and bad")

summary(ionosphere$V2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 0 0 0 0 0
## Second attribute is constant.. removing it
#Create a missing map
missmap
## function (obj, vars, legend = TRUE, col, main, y.cex = 0.8, x.cex = 0.8,
## y.labels, y.at, csvar = NULL, tsvar = NULL, rank.order = TRUE,
## margins = c(5, 5), gap.xaxis = 1, x.las = 2, ...)
## {
## if (inherits(obj, "amelia")) {
## vnames <- colnames(obj$imputations[[1]])
## n <- nrow(obj$missMatrix)
## p <- ncol(obj$missMatrix)
## percent.missing <- colMeans(obj$missMatrix)
## pmiss.all <- mean(obj$missMatrix)
## r1 <- obj$missMatrix
## }
## else {
## vnames <- colnames(obj)
## n <- nrow(obj)
## p <- ncol(obj)
## percent.missing <- colMeans(is.na(obj))
## pmiss.all <- mean(is.na(obj))
## r1 <- 1 * is.na(obj)
## }
## if (missing(col))
## col <- c("#eff3ff", "#2171b5")
## if (!missing(vars)) {
## if (is.character(vars)) {
## vars <- match(vars, vnames)
## if (any(is.na(vars))) {
## stop("vars not found in the data")
## }
## }
## if (any(!(vars %in% 1:p))) {
## stop("vars outside range of the data")
## }
## p <- length(vars)
## r1 <- r1[, vars]
## percent.missing <- percent.missing[vars]
## pmiss.all <- mean(r1)
## }
## if (!missing(y.labels) && (missing(y.at) && (length(y.labels) !=
## n))) {
## stop("y.at must accompany y.labels if there is less than onefor each row")
## }
## if (is.null(csvar))
## csvar <- obj$arguments$cs
## if (is.null(tsvar))
## tsvar <- obj$arguments$ts
## if (missing(y.labels)) {
## if (!is.null(csvar)) {
## if (class(obj) == "amelia") {
## cs <- obj$imputations[[1]][, csvar]
## }
## else {
## cs <- obj[, csvar]
## }
## y.labels <- cs
## if (is.factor(y.labels))
## y.labels <- levels(y.labels)[unclass(y.labels)]
## cs.names <- y.labels
## if (!is.numeric(cs))
## cs <- as.numeric(as.factor(cs))
## if (!is.null(tsvar)) {
## if (class(obj) == "amelia") {
## ts <- as.numeric(obj$imputations[[1]][, tsvar])
## }
## else {
## ts <- as.numeric(obj[, tsvar])
## }
## unit.period <- order(cs, ts)
## }
## else {
## unit.period <- 1:n
## }
## y.labels <- y.labels[unit.period]
## r1 <- r1[unit.period, ]
## brks <- c(TRUE, rep(FALSE, times = (n - 1)))
## for (i in 2:n) {
## brks[i] <- (cs[unit.period][i] != cs[unit.period][i -
## 1])
## }
## y.at <- which(brks)
## y.labels <- y.labels[brks]
## }
## else {
## y.labels <- row.names(obj$imputations[[1]])
## y.at <- seq(1, n, by = 15)
## y.labels <- y.labels[y.at]
## }
## }
## else {
## if (missing(y.at))
## y.at <- n:1
## }
## missrank <- rev(order(percent.missing))
## if (rank.order) {
## chess <- t(!r1[n:1, missrank])
## vnames <- vnames[missrank]
## }
## else {
## chess <- t(!r1[n:1, ])
## }
## y.at <- (n:1)[y.at]
## if (missing(main))
## main <- "Missingness Map"
## par(mar = c(margins, 2, 1) + 0.1)
## type <- "data"
## if (legend) {
## graphics::layout(matrix(c(1, 2), nrow = 1), widths = c(0.75,
## 0.25))
## par(mar = c(margins, 2, 0) + 0.1, mgp = c(3, 0.25, 0))
## }
## if (type == "data") {
## col.fix <- col
## if (sum(!chess) == 0) {
## col.fix <- col[2]
## }
## image(x = 1:(p), y = 1:n, z = chess, axes = FALSE, col = col.fix,
## xlab = "", ylab = "", main = main)
## if (getRversion() >= "4.0.0") {
## axis(1, lwd = 0, labels = vnames, las = x.las, at = 1:p,
## cex.axis = x.cex, gap.axis = gap.xaxis)
## }
## else {
## axis(1, lwd = 0, labels = vnames, las = x.las, at = 1:p,
## cex.axis = x.cex)
## }
## axis(2, lwd = 0, labels = y.labels, las = 1, at = y.at,
## cex.axis = y.cex)
## if (legend) {
## pm.lab <- paste("Missing (", round(100 * pmiss.all),
## "%)", sep = "")
## po.lab <- paste("Observed (", 100 - round(100 * pmiss.all),
## "%)", sep = "")
## par(mar = c(0, 0, 0, 0.3))
## plot(0, 0, type = "n", axes = FALSE, ann = FALSE)
## legend("left", col = col, bty = "n", xjust = 0, border = "grey",
## legend = c(pm.lab, po.lab), fill = col, horiz = FALSE)
## }
## }
## else {
## tscsdata <- data.frame(cs.names, ts, rowMeans(r1))
## tscsdata <- reshape(tscsdata, idvar = "cs.names", timevar = "ts",
## direction = "wide")
## rownames(tscsdata) <- tscsdata[, 1]
## colnames(tscsdata) <- unique(ts)
## tscsdata <- as.matrix(tscsdata[, -1])
## cols <- rev(heat.colors(5))
## image(z = t(tscsdata), axes = FALSE, col = cols, main = main,
## ylab = "", xlab = "")
## at.seq <- seq(from = 0, to = 1, length = ncol(tscsdata))
## axis(1, labels = unique(ts), at = at.seq, tck = 0, lwd = 0,
## las = 2)
## axis(2, labels = rownames(tscsdata), at = at.seq, tck = 0,
## lwd = 0, las = 1, cex.axis = 0.8)
## if (legend) {
## leg.names <- c("0-0.2", "0.2-0.4", "0.4-0.6", "0.6-0.8",
## "0.8-1")
## legend(x = 0.95, y = 1.01, col = cols, bty = "n",
## xjust = 1, legend = leg.names, fill = cols, horiz = TRUE)
## }
## }
## invisible(NULL)
## }
## <bytecode: 0x000001a517f04d20>
## <environment: namespace:Amelia>
##NO missing values.
library(stringr)
##ggplot(data=ionosphere)+ geom_point(mapping =aes(x=V3, y=V4, color=V35))
par(mfrow=c(2,2))
for(index in 3:34){
hist(ionosphere[, index],xlab=str_c("V", index))
boxplot(ionosphere[,index], horizontal=TRUE)}
















par(mfrow=c(2,3))
myPlot<-function(index) {plot(ionosphere[,index] ~ ionosphere[,index+1])}
odd<-seq(from=3, to=34, by=2)
lapply(odd,FUN=myPlot)


## [[1]]
## NULL
##
## [[2]]
## NULL
##
## [[3]]
## NULL
##
## [[4]]
## NULL
##
## [[5]]
## NULL
##
## [[6]]
## NULL
##
## [[7]]
## NULL
##
## [[8]]
## NULL
##
## [[9]]
## NULL
##
## [[10]]
## NULL
##
## [[11]]
## NULL
##
## [[12]]
## NULL
##
## [[13]]
## NULL
##
## [[14]]
## NULL
##
## [[15]]
## NULL
##
## [[16]]
## NULL
myplot2<-function(index){
ggplot(data=ionosphere)+ geom_point(mapping=aes(x=ionosphere[,index],y=ionosphere[,index+1], color=V35)) + labs(x=str_c("V", index), y=str_c("V", index+1))}
par(mfrow=c(2,3))

odd<-seq(from=3, to=34, by=2)
lapply(odd,FUN=myplot2)
## [[1]]

##
## [[2]]

##
## [[3]]

##
## [[4]]

##
## [[5]]

##
## [[6]]

##
## [[7]]

##
## [[8]]

##
## [[9]]

##
## [[10]]

##
## [[11]]

##
## [[12]]

##
## [[13]]

##
## [[14]]

##
## [[15]]

##
## [[16]]

acfV3<-acf(ionosphere$V3, lag=80)
acfV4<-acf(ionosphere$V4, lag=80)
acfV3<-acf(ionosphere$V3, lag=80, pl=FALSE)
acfV4<-acf(ionosphere$V4, lag=80, pl=FALSE)
acfV5<-acf(ionosphere$V5, lag=80, pl=FALSE)
acfV6<-acf(ionosphere$V6, lag=80, pl=FALSE)
par(mfrow=c(1,2))

plot(x=acfV3$lag,y=acfV3$acf, type="l")
lines(acfV4$lag,acfV4$acf, col="blue")
par(mfrow=c(1,2))

plot(x=acfV5$lag,y=acfV5$acf, type="l", col="green")
lines(acfV6$lag, acfV6$acf, col="orange")
ionosphereR<-ionosphere[-c(1,2)]
dim(ionosphereR)
## [1] 351 33
library(mlbench)
library(caret)
## Warning: package 'caret' was built under R version 4.2.1
##
## Attaching package: 'caret'
## The following object is masked from 'package:survival':
##
## cluster
YJParams<-preProcess(ionosphereR, method=c("YeoJohnson"))
print(YJParams)
## Created from 351 samples and 31 variables
##
## Pre-processing:
## - ignored (1)
## - Yeo-Johnson transformation (30)
##
## Lambda estimates for Yeo-Johnson transformation:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.9000 0.9744 1.1883 1.5298 2.0467 2.6575
#transform the dataset using the parameters
YJTransformed<-predict(YJParams, ionosphereR)
#summarize the transformed dataset
summary(YJTransformed)
## V3 V4 V5 V6
## Min. :-1.0000 Min. :-0.93767 Min. :-1.0000 Min. :-0.92608
## 1st Qu.: 0.4721 1st Qu.:-0.06439 1st Qu.: 0.4127 1st Qu.:-0.02473
## Median : 0.8711 Median : 0.01633 Median : 0.8092 Median : 0.02285
## Mean : 0.6413 Mean : 0.05757 Mean : 0.6011 Mean : 0.13419
## 3rd Qu.: 1.0000 3rd Qu.: 0.19720 3rd Qu.: 1.0000 3rd Qu.: 0.34503
## Max. : 1.0000 Max. : 1.06765 Max. : 1.0000 Max. : 1.08153
## V7 V8 V9 V10
## Min. :-0.5653 Min. :-0.93707 Min. :-0.61049 Min. :-1.01000
## 1st Qu.: 0.2488 1st Qu.:-0.05459 1st Qu.: 0.09238 1st Qu.:-0.04810
## Median : 1.2157 Median : 0.01473 Median : 1.03099 Median : 0.01829
## Mean : 1.0422 Mean : 0.13878 Mean : 0.88899 Mean : 0.17863
## 3rd Qu.: 1.8631 3rd Qu.: 0.46080 3rd Qu.: 1.64342 3rd Qu.: 0.53106
## Max. : 1.9559 Max. : 1.06836 Max. : 1.76271 Max. : 0.99013
## V11 V12 V13 V14
## Min. :-0.61494 Min. :-0.98743 Min. :-0.6635 Min. :-0.93494
## 1st Qu.: 0.02143 1st Qu.:-0.06520 1st Qu.: 0.0000 1st Qu.:-0.07326
## Median : 0.99131 Median : 0.02826 Median : 0.8835 Median : 0.03035
## Mean : 0.85714 Mean : 0.15856 Mean : 0.6970 Mean : 0.11138
## 3rd Qu.: 1.63991 3rd Qu.: 0.48571 3rd Qu.: 1.4876 3rd Qu.: 0.38611
## Max. : 1.74591 Max. : 1.01277 Max. : 1.5836 Max. : 1.07088
## V15 V16 V17 V18
## Min. :-0.6949 Min. :-0.97629 Min. :-0.6768 Min. :-1.004458
## 1st Qu.: 0.0000 1st Qu.:-0.08150 1st Qu.: 0.0000 1st Qu.:-0.225964
## Median : 0.7816 Median : 0.00000 Median : 0.7798 Median : 0.000000
## Mean : 0.5919 Mean : 0.07653 Mean : 0.6494 Mean :-0.004756
## 3rd Qu.: 1.3381 3rd Qu.: 0.31170 3rd Qu.: 1.4123 3rd Qu.: 0.195079
## Max. : 1.4954 Max. : 1.02444 Max. : 1.5448 Max. : 0.995566
## V19 V20 V21 V22
## Min. :-0.6779 Min. :-1.02270 Min. :-0.7410 Min. :-1.02537
## 1st Qu.: 0.0000 1st Qu.:-0.23616 1st Qu.: 0.0000 1st Qu.:-0.24566
## Median : 0.7548 Median : 0.00000 Median : 0.5971 Median : 0.00000
## Mean : 0.6190 Mean :-0.03027 Mean : 0.5133 Mean : 0.00137
## 3rd Qu.: 1.3366 3rd Qu.: 0.13387 3rd Qu.: 1.2041 3rd Qu.: 0.18768
## Max. : 1.5416 Max. : 0.97793 Max. : 1.3844 Max. : 0.97541
## V23 V24 V25 V26
## Min. :-0.7151 Min. :-1.01132 Min. :-0.6787 Min. :-1.01605
## 1st Qu.: 0.0000 1st Qu.:-0.36865 1st Qu.: 0.0000 1st Qu.:-0.33445
## Median : 0.6587 Median : 0.00000 Median : 0.7182 Median :-0.01505
## Mean : 0.5701 Mean :-0.06068 Mean : 0.6445 Mean :-0.07554
## 3rd Qu.: 1.2808 3rd Qu.: 0.16426 3rd Qu.: 1.3466 3rd Qu.: 0.15629
## Max. : 1.4443 Max. : 0.98884 Max. : 1.5393 Max. : 0.98427
## V27 V28 V29 V30
## Min. :-0.5567 Min. :-1.01822 Min. :-0.6921 Min. :-1.00981
## 1st Qu.: 0.3586 1st Qu.:-0.44721 1st Qu.: 0.0000 1st Qu.:-0.23754
## Median : 1.1852 Median :-0.01770 Median : 0.6206 Median : 0.00000
## Mean : 1.0658 Mean :-0.07524 Mean : 0.6014 Mean :-0.03052
## 3rd Qu.: 1.9977 3rd Qu.: 0.15301 3rd Qu.: 1.2758 3rd Qu.: 0.15379
## Max. : 1.9979 Max. : 0.98219 Max. : 1.5028 Max. : 0.99031
## V31 V32 V33 V34
## Min. :-0.7212 Min. :-1.02677 Min. :-0.7886 Min. :-1.039584
## 1st Qu.: 0.0000 1st Qu.:-0.24446 1st Qu.: 0.0000 1st Qu.:-0.166654
## Median : 0.5283 Median : 0.00000 Median : 0.4605 Median : 0.000000
## Mean : 0.5345 Mean :-0.01097 Mean : 0.4606 Mean : 0.005676
## 3rd Qu.: 1.1748 3rd Qu.: 0.19884 3rd Qu.: 1.0076 3rd Qu.: 0.170272
## Max. : 1.4297 Max. : 0.97411 Max. : 1.2882 Max. : 0.962299
## V35
## Bad :126
## Good:225
##
##
##
##
pcaParams<-preProcess(ionosphereR, method=c("center", "scale","pca"))
print(pcaParams)
## Created from 351 samples and 33 variables
##
## Pre-processing:
## - centered (32)
## - ignored (1)
## - principal component signal extraction (32)
## - scaled (32)
##
## PCA needed 23 components to capture 95 percent of the variance
pcaTransformed<-predict(pcaParams,ionosphereR)
summary(pcaTransformed)
## V35 PC1 PC2 PC3
## Bad :126 Min. :-5.0947 Min. :-7.3626 Min. :-4.58510
## Good:225 1st Qu.:-2.8043 1st Qu.:-0.5513 1st Qu.:-0.88662
## Median :-0.5544 Median : 0.2067 Median : 0.08085
## Mean : 0.0000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.: 2.4557 3rd Qu.: 1.1029 3rd Qu.: 0.72676
## Max. : 7.0938 Max. : 6.0984 Max. : 6.33995
## PC4 PC5 PC6 PC7
## Min. :-4.23063 Min. :-5.341903 Min. :-5.42601 Min. :-3.966608
## 1st Qu.:-0.66808 1st Qu.:-0.517672 1st Qu.:-0.28214 1st Qu.:-0.285192
## Median : 0.03845 Median :-0.005795 Median : 0.06542 Median : 0.002698
## Mean : 0.00000 Mean : 0.000000 Mean : 0.00000 Mean : 0.000000
## 3rd Qu.: 0.77472 3rd Qu.: 0.326079 3rd Qu.: 0.28355 3rd Qu.: 0.259849
## Max. : 5.49614 Max. : 5.666305 Max. : 5.73611 Max. : 5.535006
## PC8 PC9 PC10 PC11
## Min. :-3.36081 Min. :-3.19711 Min. :-4.71606 Min. :-3.759692
## 1st Qu.:-0.43987 1st Qu.:-0.28454 1st Qu.:-0.35184 1st Qu.:-0.166462
## Median :-0.01062 Median : 0.03347 Median :-0.05464 Median : 0.003805
## Mean : 0.00000 Mean : 0.00000 Mean : 0.00000 Mean : 0.000000
## 3rd Qu.: 0.36053 3rd Qu.: 0.26747 3rd Qu.: 0.41891 3rd Qu.: 0.225056
## Max. : 4.53979 Max. : 5.40850 Max. : 4.03947 Max. : 4.091761
## PC12 PC13 PC14 PC15
## Min. :-3.5779 Min. :-3.01884 Min. :-5.25980 Min. :-3.93997
## 1st Qu.:-0.3294 1st Qu.:-0.23879 1st Qu.:-0.14624 1st Qu.:-0.11215
## Median :-0.1104 Median :-0.01737 Median : 0.04298 Median : 0.05564
## Mean : 0.0000 Mean : 0.00000 Mean : 0.00000 Mean : 0.00000
## 3rd Qu.: 0.1600 3rd Qu.: 0.27084 3rd Qu.: 0.19094 3rd Qu.: 0.19565
## Max. : 5.0083 Max. : 2.91457 Max. : 2.84904 Max. : 2.47403
## PC16 PC17 PC18 PC19
## Min. :-3.419924 Min. :-2.48320 Min. :-2.66501 Min. :-2.47685
## 1st Qu.:-0.237788 1st Qu.:-0.19485 1st Qu.:-0.16563 1st Qu.:-0.16233
## Median :-0.008522 Median : 0.03736 Median : 0.03625 Median : 0.00643
## Mean : 0.000000 Mean : 0.00000 Mean : 0.00000 Mean : 0.00000
## 3rd Qu.: 0.154506 3rd Qu.: 0.16089 3rd Qu.: 0.22802 3rd Qu.: 0.23497
## Max. : 2.693009 Max. : 2.96302 Max. : 3.07192 Max. : 3.06526
## PC20 PC21 PC22 PC23
## Min. :-3.05065 Min. :-2.48574 Min. :-3.85029 Min. :-2.35814
## 1st Qu.:-0.14498 1st Qu.:-0.13826 1st Qu.:-0.13445 1st Qu.:-0.17623
## Median : 0.01581 Median : 0.01901 Median : 0.04413 Median :-0.03251
## Mean : 0.00000 Mean : 0.00000 Mean : 0.00000 Mean : 0.00000
## 3rd Qu.: 0.20434 3rd Qu.: 0.14199 3rd Qu.: 0.15220 3rd Qu.: 0.15768
## Max. : 2.03193 Max. : 3.54960 Max. : 2.02512 Max. : 2.66537
pca.ion<-ionosphereR[-33]
pcaComp<-princomp(pca.ion)
loadings(pcaComp)
##
## Loadings:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9 Comp.10
## V3 0.101 0.287 0.209 0.370 0.179 0.117 0.241
## V4 0.149 -0.438 0.189 0.103
## V5 0.151 0.261 0.252 -0.356 0.251 0.205 0.209
## V6 0.209 0.440 0.158 0.143
## V7 0.176 0.157 0.268 -0.234 0.124
## V8 -0.143 0.351 -0.108 -0.271 0.289 -0.241
## V9 0.207 0.178 0.145 0.313 -0.176
## V10 -0.132 0.248 -0.199 -0.140 -0.252 -0.158
## V11 0.251 0.111 0.287 -0.130 0.215 -0.215
## V12 -0.112 0.123 0.255 0.174 -0.132 -0.293
## V13 0.293 0.122 -0.109 0.182 -0.304 0.149
## V14 0.181 0.177 0.242 0.223 -0.287 0.300
## V15 0.329 0.117 -0.109 0.135 -0.222 -0.228 -0.155
## V16 0.199 0.168 -0.103 0.208 -0.523
## V17 0.302 -0.165 0.211 0.130
## V18 0.267 0.377 0.171 0.122 -0.206 -0.190
## V19 0.301 -0.118 0.113 0.182 0.205 -0.201 0.133
## V20 0.362 0.443 0.210 -0.173
## V21 0.300 -0.338 -0.194 0.110
## V22 0.342 0.380 -0.204
## V23 0.276 0.119 -0.162 -0.148 -0.272 0.341 0.124
## V24 0.308 -0.277 -0.255 -0.311 -0.311
## V25 0.228 -0.120 0.197 -0.188 0.174 0.163 -0.227 -0.127 0.176
## V26 0.294 -0.126 -0.169 0.230 -0.169 -0.204
## V27 0.164 -0.109 -0.258 -0.183 0.179 -0.183 -0.117
## V28 0.325 0.128 -0.274 0.114 -0.293 0.193
## V29 0.206 -0.155 0.295 -0.118 0.215 0.182 -0.188 -0.245
## V30 0.257 -0.233 -0.347 0.194 0.109 0.127
## V31 0.206 -0.181 0.252 -0.104 -0.196 -0.338 -0.107
## V32 0.174 0.173 -0.410 0.239 0.107 0.166
## V33 0.200 -0.144 0.208 0.109 0.131 -0.221 0.130 0.125 -0.226 -0.195
## V34 0.145 0.211 -0.331 0.130 0.135
## Comp.11 Comp.12 Comp.13 Comp.14 Comp.15 Comp.16 Comp.17 Comp.18 Comp.19
## V3 0.129 0.199 0.115 0.202 0.262
## V4 0.308 -0.198 -0.182 -0.230
## V5 0.248 -0.247
## V6 0.258 -0.212 0.145 -0.192 -0.149
## V7 0.227 0.114 -0.175 -0.257 0.175 0.108
## V8 -0.255 0.187 -0.260 0.285 -0.148 -0.101 0.163
## V9 0.191 -0.184 0.146 0.113 -0.194
## V10 0.230 -0.345 0.263 0.519 -0.163 0.167
## V11 0.128 -0.112 -0.135 -0.265 -0.192
## V12 0.410 -0.190 -0.232 -0.221 0.339 -0.167 0.180 0.244
## V13 -0.107 -0.170 -0.141 0.147 0.187 -0.113
## V14 -0.146 -0.167 -0.325 0.278 0.145 -0.270 -0.260
## V15 -0.128 0.218
## V16 0.175 -0.113 0.182 -0.219 0.245 -0.246
## V17 -0.406 -0.185 -0.114 -0.151 -0.273
## V18 0.232 -0.308 0.163 -0.398 -0.176
## V19 0.420 0.188 0.228
## V20 -0.139 0.126
## V21 0.183 0.129 0.195 -0.131 -0.179
## V22 -0.162 -0.307 -0.285 -0.138 0.181 0.282
## V23 0.251 0.160 -0.109 0.323
## V24 0.119 0.342 -0.129 -0.406 -0.112
## V25 -0.208 -0.315 -0.148 -0.109 -0.163
## V26 0.180 0.215 0.238 0.396 0.170 -0.227 0.246 -0.117
## V27 0.370 -0.232 -0.326 0.218 0.269 0.277 -0.261
## V28 -0.191 -0.158 0.338 -0.170 0.214 0.106
## V29 0.226 0.112 -0.347 -0.294 0.225
## V30 0.210 0.188 0.258 0.171 -0.427
## V31 -0.299 0.199 -0.327 0.308 -0.160 -0.183
## V32 0.127 -0.279 -0.324 -0.164
## V33 0.112 -0.121 -0.123 0.105
## V34 -0.271 -0.339 0.279 0.221 -0.201
## Comp.20 Comp.21 Comp.22 Comp.23 Comp.24 Comp.25 Comp.26 Comp.27 Comp.28
## V3 0.340 0.188 0.215 0.304
## V4 -0.132 0.268 0.175 0.393
## V5 -0.110 -0.167 -0.174 -0.259 -0.218 -0.233
## V6 -0.234 -0.214 0.433 0.149 -0.113 0.301
## V7 0.222 -0.316 -0.518 -0.213
## V8 0.368 0.295
## V9 -0.123 -0.113 -0.194 0.273 0.247
## V10 -0.138 -0.204 0.129 -0.275
## V11 -0.107 0.199 0.281 -0.178 -0.309 0.128 -0.118 0.150
## V12 0.231 -0.158 -0.180 0.108 -0.258
## V13 -0.184 0.257 -0.230 0.335 0.199
## V14 -0.124 0.256 -0.137 0.219 0.133 0.100 -0.193
## V15 0.153 -0.182 -0.192 0.325 -0.232 0.401
## V16 -0.321 -0.257 0.165 0.151 -0.114
## V17 0.150 0.396 -0.133 -0.138
## V18 0.163 0.141 -0.133 0.253 -0.148 0.144 -0.232
## V19 -0.277 -0.292 0.125 0.139 -0.126 -0.175 -0.368
## V20 -0.240 -0.262 -0.310 -0.376 0.152 0.214
## V21 0.227 -0.175 0.299
## V22 0.134 -0.206 0.130 0.283 -0.173
## V23 0.166 -0.105 0.167 0.344 0.112 -0.140 0.232
## V24 -0.137 0.137 -0.160 -0.183 0.190
## V25 0.386 -0.339 -0.222 -0.169 0.109 0.119
## V26 0.224 0.195 0.174 0.181 -0.212 0.126 -0.129
## V27 0.144 -0.212 0.142
## V28 -0.486 -0.157 0.127 0.202 -0.112 0.207
## V29 -0.246 0.284 -0.191 -0.175
## V30 -0.357 -0.151 0.276 -0.130
## V31 0.117 0.162 0.248 -0.236 -0.189 -0.103 0.153
## V32 0.327 -0.301 -0.264 0.238 -0.105
## V33 -0.195 -0.100 0.137 -0.172 0.418 0.311
## V34 0.312 0.112 -0.188 0.147 -0.154 -0.201
## Comp.29 Comp.30 Comp.31 Comp.32
## V3 0.300 0.138
## V4 -0.432 0.117
## V5 -0.171 0.371
## V6 -0.108 0.255
## V7 -0.123 -0.310
## V8 -0.244
## V9 -0.338 -0.323 -0.174 -0.360
## V10
## V11 -0.243 0.343 0.220
## V12 -0.100
## V13 0.255 0.201 0.302 -0.251
## V14
## V15 -0.136 -0.305 0.320
## V16 0.217 0.191
## V17 0.276 -0.204 -0.333
## V18 0.134 0.132
## V19 0.144 0.147 0.151
## V20 -0.178 -0.111 -0.167
## V21 -0.344 0.432 0.238
## V22 -0.106 -0.167 0.156 0.228
## V23 0.126 -0.126 -0.345
## V24 0.224
## V25 -0.157 0.207 -0.101
## V26 -0.184
## V27 -0.133 0.263
## V28
## V29 0.187 -0.228
## V30 0.169 0.142
## V31 -0.114 0.128 -0.139
## V32 0.119 -0.188 -0.150
## V33 0.170 0.226 -0.381 0.151
## V34 -0.185 0.235 -0.114 0.216
##
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.031 0.031 0.031 0.031 0.031 0.031 0.031 0.031 0.031
## Cumulative Var 0.031 0.063 0.094 0.125 0.156 0.188 0.219 0.250 0.281
## Comp.10 Comp.11 Comp.12 Comp.13 Comp.14 Comp.15 Comp.16 Comp.17
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.031 0.031 0.031 0.031 0.031 0.031 0.031 0.031
## Cumulative Var 0.312 0.344 0.375 0.406 0.438 0.469 0.500 0.531
## Comp.18 Comp.19 Comp.20 Comp.21 Comp.22 Comp.23 Comp.24 Comp.25
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.031 0.031 0.031 0.031 0.031 0.031 0.031 0.031
## Cumulative Var 0.562 0.594 0.625 0.656 0.688 0.719 0.750 0.781
## Comp.26 Comp.27 Comp.28 Comp.29 Comp.30 Comp.31 Comp.32
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.031 0.031 0.031 0.031 0.031 0.031 0.031
## Cumulative Var 0.812 0.844 0.875 0.906 0.938 0.969 1.000
##Independent components
icaParams<-preProcess(ionosphereR, method=c("center", "scale", "ica"), n.comp=10)
print(icaParams)
## Created from 351 samples and 33 variables
##
## Pre-processing:
## - centered (32)
## - independent component signal extraction (32)
## - ignored (1)
## - scaled (32)
##
## ICA used 10 components
icaTransformed<-predict(icaParams, ionosphereR)
summary(icaTransformed)
## V35 ICA1 ICA2 ICA3
## Bad :126 Min. :-6.80506 Min. :-5.03337 Min. :-4.02108
## Good:225 1st Qu.:-0.06377 1st Qu.:-0.18222 1st Qu.:-0.29605
## Median : 0.06058 Median : 0.06153 Median :-0.01298
## Mean : 0.00000 Mean : 0.00000 Mean : 0.00000
## 3rd Qu.: 0.22216 3rd Qu.: 0.22224 3rd Qu.: 0.24645
## Max. : 5.06412 Max. : 4.62935 Max. : 5.32322
## ICA4 ICA5 ICA6 ICA7
## Min. :-4.3132 Min. :-4.2841 Min. :-5.352607 Min. :-5.36395
## 1st Qu.:-0.1297 1st Qu.:-0.2942 1st Qu.:-0.171286 1st Qu.:-0.21945
## Median : 0.1320 Median : 0.1471 Median : 0.004297 Median :-0.01657
## Mean : 0.0000 Mean : 0.0000 Mean : 0.000000 Mean : 0.00000
## 3rd Qu.: 0.5253 3rd Qu.: 0.4238 3rd Qu.: 0.169835 3rd Qu.: 0.17317
## Max. : 2.8664 Max. : 4.4416 Max. : 7.562039 Max. : 4.46450
## ICA8 ICA9 ICA10
## Min. :-3.4779 Min. :-1.78268 Min. :-3.6599
## 1st Qu.:-0.4665 1st Qu.:-0.98100 1st Qu.:-0.3416
## Median :-0.2174 Median :-0.04417 Median : 0.1077
## Mean : 0.0000 Mean : 0.00000 Mean : 0.0000
## 3rd Qu.: 0.1969 3rd Qu.: 0.87848 3rd Qu.: 0.4100
## Max. : 3.4861 Max. : 2.64143 Max. : 3.8295

myplot3<-function(index){
ggplot(data=icaTransformed)+ geom_point(mapping=aes(x=icaTransformed[,index],y=icaTransformed[,index+1], color=V35)) + labs(x=str_c("ICA", index), y=str_c("ICA", index+1))}
par(mfrow=c(2,3))
odd<-seq(from=2, to=11, by=2)
lapply(odd,FUN=myplot3)
## [[1]]

##
## [[2]]

##
## [[3]]

##
## [[4]]

##
## [[5]]
