# Imputation of missing values in PCA - 2: 32 missing values
# Random replacement of 32 values (out of the 319) by NA
rnd <- matrix(sample(c(rep(1, 32), rep(0, 287))), 29, 11)
env.miss32 <- env
env.miss32[rnd == 1] <- NA
# How many NA in each site?
summary(t(env.miss32))
# Imputation
env.imp2 <- imputePCA(env.miss32)
# PCA on the imputed data
env.imp32 <- env.imp2$completeObs
env.imp32.pca <- rda(env.imp32, scale = TRUE)
# Procrustes comparison of original PCA and PCA on imputed data
pca.proc32 <- procrustes(env.pca, env.imp32.pca, scaling = 1)
par(mfrow = c(1, 2))
plot(pca.proc,
main = "Procrustes rotation of original and imputed PCA\n
3 missing values")
points(pca.proc, display = "target", col = "red")
text(
pca.proc,
display = "target",
col = "red",
pos = 4,
cex = 0.6
)
plot(pca.proc32,
main = "Procrustes rotation of original and imputed PCA\n
32 missing values")
points(pca.proc32, display = "target", col = "red")
text(
pca.proc32,
display = "target",
col = "red",
pos = 4,
cex = 0.6
)
Hint In some of the plot titles above, the use of \n allows one to split a (long) title in
two parts that are written on successive lines.
In this second example, we removed 32 values randomly. Of course, in the real
world, nobody does that. We did it for demonstration purposes only.
174
5 Unconstrained Ordination
# Random replacement of 32 values (out of the 319) by NA
rnd <- matrix(sample(c(rep(1, 32), rep(0, 287))), 29, 11)
env.miss32 <- env
env.miss32[rnd == 1] <- NA
# How many NA in each site?
summary(t(env.miss32))
# Imputation
env.imp2 <- imputePCA(env.miss32)
# PCA on the imputed data
env.imp32 <- env.imp2$completeObs
env.imp32.pca <- rda(env.imp32, scale = TRUE)
# Procrustes comparison of original PCA and PCA on imputed data
pca.proc32 <- procrustes(env.pca, env.imp32.pca, scaling = 1)
par(mfrow = c(1, 2))
plot(pca.proc,
main = "Procrustes rotation of original and imputed PCA\n
3 missing values")
points(pca.proc, display = "target", col = "red")
text(
pca.proc,
display = "target",
col = "red",
pos = 4,
cex = 0.6
)
plot(pca.proc32,
main = "Procrustes rotation of original and imputed PCA\n
32 missing values")
points(pca.proc32, display = "target", col = "red")
text(
pca.proc32,
display = "target",
col = "red",
pos = 4,
cex = 0.6
)
Hint In some of the plot titles above, the use of \n allows one to split a (long) title in
two parts that are written on successive lines.
In this second example, we removed 32 values randomly. Of course, in the real
world, nobody does that. We did it for demonstration purposes only.
174
5 Unconstrained Ordination
