require(lolR)require(ggplot2)require(MASS)n=400d=30r=3Data for this notebook will ben=400 examples ofd=30 dimensions.
We first visualize the first2 dimensions:
testdat <-lol.sims.cigar(n, d)X <-testdat$XY <-testdat$Ydata <-data.frame(x1=X[,1],x2=X[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Simulated Data")Projecting with LR-CCA to3 dimensions and visualizing the first2:
result <-lol.project.rp(X, r)data <-data.frame(x1=result$Xr[,1],x2=result$Xr[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Projected Data using LR-CCA")Projecting with LDA toK-1=1 dimensions:
liney <-MASS::lda(result$Xr, Y)result <-predict(liney, result$Xr)lhat <-1-sum(result$class==Y)/length(Y)data <-data.frame(x1=result$x[,1],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,fill=y))+geom_density(adjust=1.5,alpha=0.6)+xlab("x1")+ylab("Density")+ggtitle(sprintf("LR-CCA - LDA, L = %.2f", lhat))We visualize the first2 dimensions:
testdat <-lol.sims.rtrunk(n, d)X <-testdat$XY <-testdat$Ydata <-data.frame(x1=X[,1],x2=X[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Simulated Data")Projecting with LR-CCA to3 dimensions and visualizing the first2:
result <-lol.project.rp(X, r)data <-data.frame(x1=result$Xr[,1],x2=result$Xr[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Projected Data using LR-CCA")Projecting with LDA toK-1=1 dimensions:
liney <-MASS::lda(result$Xr, Y)result <-predict(liney, result$Xr)lhat <-1-sum(result$class==Y)/length(Y)data <-data.frame(x1=result$x[,1],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,fill=y))+geom_density(adjust=1.5,alpha=0.6)+xlab("x1")+ylab("Density")+ggtitle(sprintf("RP-LDA, L = %.2f", lhat))We visualize the first2 dimensions:
testdat <-lol.sims.rtrunk(n, d,rotate=TRUE)X <-testdat$XY <-testdat$Ydata <-data.frame(x1=X[,1],x2=X[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Simulated Data")Projecting with RP to3 dimensions and visualizing the first2:
result <-lol.project.rp(X, r)data <-data.frame(x1=result$Xr[,1],x2=result$Xr[,2],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,y=x2,color=y))+geom_point()+xlab("x1")+ylab("x2")+ggtitle("Projected Data using LR-CCA")Projecting with LDA toK-1=1 dimensions:
liney <-MASS::lda(result$Xr, Y)result <-predict(liney, result$Xr)lhat <-1-sum(result$class==Y)/length(Y)data <-data.frame(x1=result$x[,1],y=Y)data$y <-factor(data$y)ggplot(data,aes(x=x1,fill=y))+geom_density(adjust=1.5,alpha=0.6)+xlab("x1")+ylab("Density")+ggtitle(sprintf("RP-LDA, L = %.2f", lhat))