if (FALSE) {
## Example
## This is Koopman's Table 2 Example
R.X <- matrix(c(1.00, .69, .49, .39,
.69, 1.00, .38, .19,
.49, .38, 1.00, .27,
.39, .19, .27, 1.00),4,4)
b <- c(.39, .22, .02, .43)
rxy <- R.X %*% b
OLSRSQ <- t(b) %*% R.X %*% b
theta <- .02
r.yhata.yhatb <- sqrt( 1 - (theta)/OLSRSQ)
Converged = FALSE
SEED = 1234
MaxTries = 100
iter = 1
while( iter <= MaxTries){
SEED <- SEED + 1
cat("\nCurrent Seed = ", SEED, "\n")
output <- fungibleExtrema(R.X, rxy,
r.yhata.yhatb,
Nstarts = 5,
MaxMin = "Min",
Seed = SEED,
maxGrad = 1E-05,
PrintLevel = 1)
Converged <- output$converged
if(Converged) break
iter = iter + 1
}
print( output )
## Scale to replicate Koopman
a <- output$a
a.old <- a
aRa <- t(a) %*% R.X %*% a
## Scale a such that a' R a = .68659
## vc = variance of composite
vc <- aRa
## sf = scale factor
sf <- .68659/vc
a <- as.numeric(sqrt(sf)) * a
cat("\nKoopman Scaling\n")
print(round(a,2))
}
Run the code above in your browser using DataLab