Biomedical Engineering Reference
In-Depth Information
Alternatively, if scaling to unit variance is required the following code
may be used.
R<-scale(R, center = TRUE,scale = TRUE)
R<-scale(R, center = TRUE,scale = TRUE)
Next, PCA scores are calculated using the NIPALS algorithm using
pcaMethods.
#-------------------------------------
# PCA Scores Node (Snippet Node)
#-------------------------------------
require(pcaMethods)
results=pca(R, method='nipals', centre=FALSE, nPcs=3)
t1=results@scores[,1]
t2=results@scores[,2]
t3=results@scores[,3]
R<-cbind(t1,t2,t3)
R<-R
#-------------------------------------
# PCA Scores Node (Snippet Node)
#-------------------------------------
require(pcaMethods)
results=pca(R, method='nipals', centre=FALSE, nPcs=3)
t1=results@scores[,1]
t2=results@scores[,2]
t3=results@scores[,3]
R<-cbind(t1,t2,t3)
R<-R
The R View node provides the ability to produce R plots. The code below
sets up a graph, colours the points according to class and plots the fi rst
two scores from the PCA node output.
#-------------------------------------------
# Scores Plot (RView Node)
#-------------------------------------------
#-------------------------------------------
# Scores Plot (RView Node)
#-------------------------------------------
#calculate axis limits for X
mnX=min(R$'t1')
mxX=max(R$'t1')
plotrangeX=1.2*(max(abs(mnX),abs(mxX))) # add 20%
#calculate axis limits for X
mnX=min(R$'t1')
mxX=max(R$'t1')
plotrangeX=1.2*(max(abs(mnX),abs(mxX))) # add 20%
￿ ￿ ￿ ￿ ￿
#calculate axis limits for Y
mnY=min(R$'t2')
mxY=max(R$'t2')
plotrangeY=1.2*(max(abs(mnY),abs(mxY))) # add 20%
#calculate axis limits for Y
mnY=min(R$'t2')
mxY=max(R$'t2')
plotrangeY=1.2*(max(abs(mnY),abs(mxY))) # add 20%
A=substr(row.names(R), 1, 2) # extract fi rst 2 characters
B=factor(A) # change to a factor
A=substr(row.names(R), 1, 2) # extract fi rst 2 characters
B=factor(A) # change to a factor
# Plot the scores
plot(R$t1, R$t2,
main= 'Scores Plot', sub='First two components',
xlab='t1',
ylab='t2',
xlim = c(-plotrangeX, +plotrangeX),
ylim = c(-plotrangeY, +plotrangeY),
# Plot the scores
plot(R$t1, R$t2,
main= 'Scores Plot', sub='First two components',
xlab='t1',
ylab='t2',
xlim = c(-plotrangeX, +plotrangeX),
ylim = c(-plotrangeY, +plotrangeY),
 
Search WWH ::




Custom Search