if (FALSE) {
# Example data
set.seed(1234)
n <- 2000
p <- 10
mu0 <- as.matrix(runif(p, 0))
sigma0 <- as.matrix(runif(p, 0, 10))
ro <- as.matrix(c(runif(round(p / 2), -1, -0.8), runif(p - round(p / 2), 0.8, 1)))
R0 <- ro %*% t(ro)
diag(R0) <- 1
Sigma0 <- sigma0 %*% t(sigma0) * R0
x <- mvrnorm(n, mu0, Sigma0)
colnames(x) <- paste("x", 1:p, sep = "")
e <- rnorm(n, 0, 1)
B <- sample(1:3, (p + 1), replace = TRUE)
en <- matrix(rep(1, n * 1), ncol = 1)
y <- cbind(en, x) %*% B + e
colnames(y) <- paste("y")
data <- data.frame(cbind(y, x))
# Call the PCR function
result <- PCR(data, threshold = 0.9)
# Access the estimated regression coefficients
print(Bhat <- result$Bhat)
# Access the predicted values
print(yhat <- result$yhat)
# Print the summary of the regression model
print(result$summary)
# Print the RMSE
print(paste("RMSE:", result$RMSE))
}
Run the code above in your browser using DataLab