R_Language 板


LINE

最近为了改写程式,开始尝试W大先前建议的例外处理, 我把原文的code先包成一个function, ex: functionA<-function(i,j,k) { 原文code.... } 接着利用tryCatch()去执行functionA (这边我不太了解,是在呼叫function时用tryCatch去包, 还是要先把tryCatch写在function里面,我这边做的是前者) z <- tryCatch( { functionA(5,2,5) }, error = function(e) { message("Model not good: ", cat(p,d,q)) ;next }, finally { print("all done") } ) z 接着R就开始output依序的model output,直到某一model无法fitting,就中止 (所以所要的例外处理然後继续loop 是失败了...) error message: Encountered an error: Error in arima(tr_set$ED, order = c(p, d, q)): non-stationary AR part from CSS -->是有告知我中止的原因 错误在value[[3L]](cond) : 没有可中断/下一个的回圈,跳到顶层 此外: 警告讯息: -->代表我例外处理放错地方 所以next跳错loop的位子? In arima(tr_set$ED, order = c(p, d, q)) : possible convergence problem: optim gave code = 1 -->again same error message as usual 以上问题请教 麻烦了 ※ 引述《GTBUG (贾斯伯张)》之铭言: : [问题类型]: : 程式谘询 : [软体熟悉度]: : 入门(写过其他程式,只是对语法不熟悉) : [问题叙述]: : 目前针对一笔3年的daily资料作建模(365*3笔daily count data),已利用过传统 : time-series建模方法,透过ACF, PACF等判断去找model,也利用过auto.arima去找model : ,现在希望透过手写一个loop去run各种model的组合,再由最小AIC来选出较适的模型 : 当我run後,却吐回一个error message给我,然後终止loop而没有任何结果 : : "错误在stats:::arima(x, order = order, seasonal = seasonal, fixed = : par[1:narma], : wrong length for 'fixed' " : : 如果不用loop, 而是一个一个MODEL慢慢try,就可以跑(如下) : ex. : fit<-arimax(x,order=c(3,1,3),seasonal=list(order=c(0,1,1),period=7),xreg=xreg) : fit2<-arimax(x,order=c(3,1,3),seasonal=list(order=c(0,1,2),period=7),xreg=xreg) : .. : .. : [程式范例]: : : count = 0 : for(i in 0:5) { : for(j in 0:2) { : for(k in 0:1) { : for(l in 0:1) { : for(m in 0:2) { : for(n in 0:1) { : for(o in 0:2) { : model = arimax(ed0710$ED, order=c(i,j,k), : seasonal=list(order=c(l,m,n), period=7*o), xreg=xreg1) : if (count == 0) { : aicmin = model$aic : bestmodel = model : } : if ((count != 0)&& (model$aic< aicmin)) { : aicmin = model$aic : bestmodel = model : diff1 = j : diff2 = m : seas = o*7 : } : count = count+1 : } : } : } : } : } : } : print(bestmodel) : print(count) : print(diff1) : print(diff2) : print(seas) : } : : [关键字]: time-series, ARIMA, loop --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.65.71.253 ※ 编辑: GTBUG 来自: 203.65.71.253 (10/08 17:27)







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP