## 

# Creation:  4/2018
# Authors: Veronica torralba
#
# Aim: function for projecting a PC on a variable with the regression method
#
# Assumption: none
#
# Branch: teleconnections
#
# Example:
#
## Compute rotated PCs truncating the loadings to 30:
# test <- REOF(ano=anom, lat, lon, ntrunc=30)
#
## Visualize the first four rotated PCs:
# ProjEOF(anom, lat, lon, test$RPCs[,1:4])
#

regressionMaps<-function(anom, index){
    postime <- which(dim(anom) == length(index))
    lm_fun <- function(x,y) lm(y~x)$coefficients[[2]]                                  
    regress_map <- apply(anom,(1:length(dim(anom)))[-postime], lm_fun, x=index)
    return(regress_map)
}

