logo资料库

GM(1,1)r代码.pdf

第1页 / 共2页
第2页 / 共2页
资料共2页,全文预览结束
x<-c(1,2,3,4,5,6,7) x0 <- x k = length(x0) # AGO x1 = cumsum(x0) # construct matrix B & Y B = cbind(-0.5*(x1[-k]+x1[-1]),rep(1,times=k-1)) Y = x0[-1] # compute BtB... BtB = t(B)%*%B BtB.inv = solve(BtB) BtY = t(B)%*%Y # estimate alpha = BtB.inv%*%BtY # 建立预测模型 predict <- function(k) { y = (x0[1] - alpha[2]/alpha[1])*exp(-alpha[1]*k)+alpha[2]/alpha[1] return(y) } pre <- sapply(X=0:(k-1),FUN=predict) prediff <- c(pre[1],diff(pre)) # 计算残差 error <- round(abs(prediff-x0),digits=6) phi=error/x0 emax <- max(error) emin <- min(error) # 模型评价 incidence <- function(x) { return((emin + 0.5*emax)/(x+0.5*emax)) } enta=sapply(error,incidence) degree <- mean(sapply(error,incidence)) s1 <- sqrt(sum((x0-mean(x0))^2)/5) s2 <- sqrt(sum((error-mean(error))^2)/5) C <- s2/s1 e <- abs(error-mean(error)) p <- length(e<0.6745)/length(e) result <- list(alpha=alpha,fit = prediff,error=error,phi=phi,enta=enta,degree = degree, s1=s1,s2=s2,C
= C, P = p)
分享到:
收藏