Encoding:
|
| Attachment 1: |
pca_and_lda.R
Notes
#First we need to read in the data
dataSim <- read.table("output.txt.Simulation",sep=" ",header=TRUE)
dataRF <- read.table("output.txt.RFTriggers",sep=" ",header=TRUE)
dataPulser <- read.table("output.txt.CalPulsers",sep=" ",header=TRUE)
#Now we combine them into one data object
data <- rbind(dataRF,dataSim)
#Now we actually have to specify that we
#want to use the first 10 columns
data <- data[,1:10]
#make a principal component analysis object
pca <- prcomp(data,center=TRUE,scale=TRUE,retx=TRUE)
#Load a plotting library
library(ggfortify)
#then can plot
autplot(prcomp(data))
#or, we can plot like this
#to get some color data points
labels<-c(rep(0,nrow(dataSim)),rep(1,nrow(dataRF)))
plot(pca$x[,1],pca$x[,2],col=labels+1)
#we can also do an LDA analysis
#we need to import the MASS library
library(MASS)
#and now we make the lda object
lda(data,grouping=labels)
#didn't write down any plotting unfortunately.
|