I am very new to R so I apologize in advance if this is a trivial questions. I have a large set of data consisting of mortgage loan information icluding date of origination. I need to calculate a moving weighted (by loan amount) average of FICO scores over 3 month windows. The problem that I'm running into, is that I don't know how to account for the fact that there are multiple loans originated in the same month/year, and I know that an average of 3 months of averages is inaccurate.
SO how might I go about doing this if I have the following fields:
funded$loan_amount
funded$fico_score
funded$date
To do moving average it is best to use the package TTR.
library(SMA)
data<-ts(data=cbind(rnorm(10),rexp(10,2)),names=c("value","weight"))
result<-WMA(data[,"value"],wts=data[,"weight"],n=3)
You might need to install the library "SMA" first, if you have never used it before on your R installation.
Instead of moving average, consider exponential smoothing. It has known stochastic properties, which allow compute confidence intervals. See the package forecast
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.