I'm new to R and don't have much background in statistics, but my graduate study is related to statistics and I'm currently working on constructing an index (similar to constructing standardised precipitation index) and would require fitting a cumulative density function into inverse normal distribution. Seems that R doesn't have built-in inverse normal distribution function. Is there a way to do it?
Here attached is my code. Thanks!
timeScale <- 3
SNOmm_1_3mon <- read.delim('SNOmm_1.txt')
nVal <- nrow(SNOmm_1_3mon)
nYear <- nVal/12
totWindows <- nVal - timeScale +1
SWEI <- matrix(0,totWindows,1)
nWindow <-0
Q <- c(0,0,0,0,0,0,0,0,0,0,0,0)
"fit Pearson Type III distribution and retain its parameters"
for(k in 1:12){
endMonth <- timeScale+k-1
if (endMonth>12){nYear2 <- nYear-1
} else {nYear2 <- nYear
}
precipCum <- list()
for(i in 1:nYear2){
nWindow<-nWindow+1
sumVal<-0
for(j in 1:timeScale){
sumVal <- sumVal+SNOmm_1_3mon[(i-1)*12+endMonth-j+1,1]
}
precipCum[i] <- sumVal
}
precipCumData <- as.numeric(as.character(unlist(precipCum)))
LMOMENT <- samlmu(precipCumData)
PE3PARA <- pelpe3(LMOMENT)
}
"Calcualte SWEI"
startMonth <- 1
for(i in 1:(nVal-timeScale+1)){
if(i<-1){kk<-timeScale
} else {kk<-timeScale+i-1
}
sumVal2 <- 0
for(j in 1:timeScale){
sumVal2 <- sumVal2+SNOmm_1_3mon[kk-j+1,1]
}
if(sumVal2>0){Xn_cdf<-cdfpe3(sumVal2,PE3PARA)
Cum_prob<-Q[startMonth]+(1-Q[startMonth])*Xn_cdf
} else {Cum_prob <- Q[startMonth]
}
**Z<-norminv(Cum_prob)
SWEI[i]<-Z
startMonth <- startMonth+1
if(startMonth>13){startMonth <- 1
}
sumVal3[i] <- sumVal2**
}
The "Z<- norminv part doesn't exist in Rstudio, it's just a way for me to represent what I'd like to do in that part. Thanks!