data
(mtcars)
my_pca <-
prcomp
(mtcars, scale =
TRUE
,
center =
TRUE
, retx = T)
names
(my_pca)
summary
(my_pca)
my_pca
my_pca$rotation
dim
(my_pca$x)
my_pca$x
biplot
(my_pca, main =
"Biplot"
, scale = 0)
my_pca$sdev
my_pca.var <- my_pca$sdev ^ 2
my_pca.var
propve <- my_pca.var /
sum
(my_pca.var)
propve
plot
(propve, xlab =
"principal component"
,
ylab =
"Proportion of Variance Explained"
,
ylim =
c
(0, 1), type =
"b"
,
main =
"Scree Plot"
)
plot
(
cumsum
(propve),
xlab =
"Principal Component"
,
ylab =
"Cumulative Proportion of Variance Explained"
,
ylim =
c
(0, 1), type =
"b"
)
which
(
cumsum
(propve) >= 0.9)[1]
train.data <-
data.frame
(disp = mtcars$disp, my_pca$x[, 1:4])
install.packages
(
"rpart"
)
install.packages
(
"rpart.plot"
)
library
(rpart)
library
(rpart.plot)
rpart.model <-
rpart
(disp ~ .,
data = train.data, method =
"anova"
)
rpart.plot
(rpart.model)