# Independent Component Analysis in R

#### kennywhite

##### New Member
Hello everyone.
I am trying to apply ICA to Consumer Price Index. I have 10 variables that represent different consumer price indices for different sector of the Nigeria economy.
Each variable consists of 168 samples. I preprocessed the data by taking the first difference in order to satisfy stationarity after which I randomly generated
an orthogonal matrix to be used as the mixing matrix. After then, I called on the fastICA function to do the rest.

I am new to ICA. I was not thought but I am trying to work out something with it in order to understand it as an alternative to PCA as I learnt.

I am not so sure of the steps I took, so I decided to share it here with the code and dat for vetting and possible correction. Your input will be higjly appreciated.

I am also confused about the interpretation. Below is the code. I need to know if steps taken are right and the interpretation.

library(fastICA)
library(ggplot2)
library(dplyr)
library(tidyr)
library(tidyverse)
library(ggfortify)
library(pracma)
library(BBmisc)
library(ica)

# Source matrix

#Transform to Time Series
S=ts(S)

#Taking the Difference to ensure stationarity
S=diff(S)

#Generating Random Orthogonal Mix Matrix
Q=randortho(10)

#Mixing the signals
X <- S%*%Q

#Transforming Mixed Signals to Time Series
X=ts(X)

#Applying fastICA
a <- fastICA(X, 10, alg.typ = "deflation", fun = "logcosh", alpha = 1, method = "R", row.norm = FALSE, maxit = 200, tol = 0.0001, verbose = FALSE)

par(mar=c(1,3,2,2), mfcol = c(10, 3))

plot(1:167, S[,1 ], type = "l", main = "Original Signals",xlab = "", ylab = "")
plot(1:167, S[,2 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,3 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,4 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,5 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,6 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,7 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,8 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,9 ], type = "l", xlab = "", ylab = "")
plot(1:167, S[,10 ], type = "l", xlab = "", ylab = "")

plot(1:167, X[,1 ], type = "l", main = "Mixed Signals",xlab = "", ylab = "")
plot(1:167, X[,2 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,3 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,4 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,5 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,6 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,7 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,8 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,8 ], type = "l", xlab = "", ylab = "")
plot(1:167, X[,10 ], type = "l", xlab = "", ylab = "")

plot(1:167, a$S[, 1], type = "l", main = "ICA source estimates",xlab = "", ylab = "") plot(1:167, a$S[, 2], type = "l", xlab = "", ylab = "")
plot(1:167, a$S[, 3], type = "l", xlab = "", ylab = "") plot(1:167, a$S[, 4], type = "l", xlab = "", ylab = "")
plot(1:167, a$S[, 5], type = "l", xlab = "", ylab = "") plot(1:167, a$S[, 6], type = "l", xlab = "", ylab = "")
plot(1:167, a$S[, 7], type = "l", xlab = "", ylab = "") plot(1:167, a$S[, 8], type = "l", xlab = "", ylab = "")
plot(1:167, a$S[, 9], type = "l", xlab = "", ylab = "") plot(1:167, a$S[, 10], type = "l", xlab = "", ylab = "")