您的位置:首页
R语言学习笔记-Error in ts(x):对象不是矩阵问题解决
2017-07-07 14:41
621 查看
1、问题
在对时间序列进行拟合操作时,发生:Error in ts(x):对象不是矩阵的错误,而直接在arima()函数中使用时没有问题的。> sample<-c2
> sample
[1] 0.00 0.00 0.00 0.00 0.00 0.00 0.06 0.09 0.20 0.09 0.08 0.14 0.14 0.23
[15] 0.08 0.06 0.12 0.20 0.14 0.11 0.20 0.14 0.17 0.15 0.18 0.15 0.20 0.12
[29] 0.23 0.08 0.12 0.08 0.23 0.12 0.08 0.17 0.18 0.17 0.12 0.17 0.14 0.18
[43] 0.11 0.27 0.06
> fitted(arima(sample,order=c(4,0,3)))
Error in ts(x) : 对象不是矩阵
> arima(sample,order=c(4,0,3))
Call:
arima(x = sample, order = c(4, 0, 3))
Coefficients:
ar1 ar2 ar3 ar4 ma1 ma2 ma3 intercept
0.6740 0.0666 -0.4026 0.4924 -0.6160 0.2129 0.3564 0.1097
s.e. 0.2761 0.3073 0.2510 0.1724 0.3005 0.3112 0.2361 0.0380
sigma^2 estimated as 0.002756: log likelihood = 67.68, aic = -117.37
>
2、原因分析
原由于:数据的变量名与基础包中的sample函数同名,在fitted()函数中未能正确处理。在R语言中sample是基础包中的一个函数,注意在R程序中变量名不要使用与之同名的名称。否则不会得到正确的结果。
3、解决
解决的办法是函数不要与之同名,至于为什么会在fitted()函数中sample()函数没有被正确处理,可能和fitted()函数的本身。注意:还有一可能造成混淆的还有data()函数。
4、sample命令參考
使用help(sample)能够查看sample()函数的使用帮助。sample {base} | R Documentation |
Random Samples and Permutations
Description
sampletakes a sample of the specified size from the elementsof
xusing either with or without replacement.
Usage
sample(x, size, replace = FALSE, prob = NULL) sample.int(n, size = n, replace = FALSE, prob = NULL)
Arguments
x | Either a vector of one or more elements from which to choose,or a positive integer. See ‘Details.’ |
n | a positive number, the number of items to choose from. See‘Details.’ |
size | a non-negative integer giving the number of items to choose. |
replace | Should sampling be with replacement? |
prob | A vector of probability weights for obtaining the elementsof the vector being sampled. |
相关文章推荐
- R语言学习笔记-Error in ts(x):对象不是矩阵问题解决
- R语言学习-问题解决-Error in `[<-.ts`(`*tmp*`,...only replacement of elements is allowed
- R语言学习-问题解决-Error in output$nodeID : $ operator is invalid for atomic vectors
- QTP学习笔记(一):安装篇,解决QTP无法识别控件对象的问题
- Silverlight学习笔记[1] - unhandled error in silverlight application 未将对象引用设置
- TensorFlow学习笔记(UTF-8 问题解决 UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: in
- R语言——解决矩阵内“No data available in table”空矩阵赋值问题
- Python学习笔记:学习爬虫时遇到的问题TypeError: cannot use a string pattern on a bytes-like object 与解决办法
- Linux学习30_configure: error: no acceptable C compiler found in $PATH 问题解决
- C# in Depth Third Edition 学习笔记-- C#2.0: 解决C#1.0的问题 1 泛型
- 学习笔记---递归的代码,解决经典的汉诺塔问题
- 【记录】正则表达式学习第3天(正则学习笔记),又解决了个实际问题。
- 我的嵌入式学习笔记(2)--scanf使用常见问题及解决方法
- vs2008编译时出现问题解决方法:MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tma
- 设计模式学习1—使用单件模式解决对象重复申请问题
- [解决问题][不能更新eclipse]错误提示:Error retrieving "feature.xml". [error in opening zip file]
- 解决Exception starting filter struts2 java.lang.UnsupportedClassVersionError: Bad version number in .class的问题
- 解决A generic error occurred in GDI+的问题
- ASP.NET学习笔记----解决页面中部分验证的问题:validationgroup,爽(20080326)
- struts学习笔记--解决了struts action中的execute方法不执行的问题