getwd()
## [1] "C:/Users/skirmantas/OneDrive/Desktop/Duomenys"
setwd("C:/Users/skirmantas/OneDrive/Desktop")
duom <- read.csv2("C:/Users/skirmantas/OneDrive/Desktop/Duomenys/DPP1.csv", header = TRUE, sep = ";", dec = ".")
library(stats)
pc.cr <- princomp(duom, cor = TRUE)
pc.cr
## Call:
## princomp(x = duom, cor = TRUE)
## 
## Standard deviations:
##    Comp.1    Comp.2    Comp.3    Comp.4    Comp.5    Comp.6    Comp.7 
## 2.1826394 1.1339612 0.8311506 0.4168373 0.2007666 0.1815120 0.1113495 
## 
##  7  variables and  53940 observations.
plot(pc.cr$scores[,1], pc.cr$scores[,2], pch=18)

op = par(cex.main=0.53, cex.axis=1, cex.lab=0.7, cex=0.83)
biplot(pc.cr) 

pc <- prcomp(duom, center = TRUE, scale = TRUE)

prcomp(duom, scale = FALSE)
## Standard deviations (1, .., p=7):
## [1] 3.989440e+03 2.283217e+00 1.335150e+00 8.202770e-01 1.948531e-01
## [6] 1.256807e-01 7.795305e-02
## 
## Rotation (n x k) = (7 x 7):
##                                    PC1           PC2           PC3
## Carat.Weight.of.Daimond.  1.095002e-04 -1.268053e-02 -3.095226e-02
## Depth                    -3.823523e-06  2.855246e-01 -9.546313e-01
## Table                     7.120789e-05 -9.562977e-01 -2.805972e-01
## Price.in.US.dollars.      9.999999e-01  9.340588e-05  4.969435e-05
## X.length.                 2.486877e-04 -4.450580e-02 -3.885860e-02
## Y.width.                  2.477609e-04 -4.173598e-02 -3.277768e-02
## Z.Depth.                  1.523479e-04 -9.328059e-03 -8.001227e-02
##                                    PC4           PC5           PC6
## Carat.Weight.of.Daimond. -0.1881334278  1.693347e-01 -2.727369e-01
## Depth                     0.0616683380 -3.426591e-02 -4.147808e-02
## Table                     0.0817901805 -6.533849e-03  3.927639e-03
## Price.in.US.dollars.      0.0003884624 -1.965194e-05  1.540157e-05
## X.length.                -0.6063073272  4.761949e-01 -5.189888e-01
## Y.width.                 -0.6626667125 -7.420649e-01  8.266921e-02
## Z.Depth.                 -0.3838975099  4.389613e-01  8.047951e-01
##                                    PC7
## Carat.Weight.of.Daimond.  0.9275922119
## Depth                    -0.0213840864
## Table                    -0.0034998183
## Price.in.US.dollars.     -0.0000282091
## X.length.                -0.3644031583
## Y.width.                  0.0237073198
## Z.Depth.                  0.0758383874
princomp(duom, cor = FALSE, scores = TRUE)
## Call:
## princomp(x = duom, cor = FALSE, scores = TRUE)
## 
## Standard deviations:
##       Comp.1       Comp.2       Comp.3       Comp.4       Comp.5       Comp.6 
## 3.989403e+03 2.283196e+00 1.335138e+00 8.202694e-01 1.948513e-01 1.256795e-01 
##       Comp.7 
## 7.795232e-02 
## 
##  7  variables and  53940 observations.
#install.packages("factoextra")
library(factoextra)
## Įkeliamas reikalingas paketas: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
res.pca <- prcomp(duom, scale = TRUE)
fviz_eig(res.pca)

fviz_pca_ind(res.pca,
             col.ind = "cos2", # Color by the quality of representation
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE     # Avoid text overlapping
)
## Warning: ggrepel: 53939 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps

fviz_pca_var(res.pca,
             col.var = "contrib", # Color by contributions to the PC
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE     # Avoid text overlapping
)

fviz_pca_biplot(res.pca, repel = TRUE,
                col.var = "#2E9FDF", # Variables color
                col.ind = "#696969"  # Individuals color
)
## Warning: ggrepel: 53939 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps