1. Questions
When a time series is fitted, it occurs: Error in TS (x): The object is not a matrix error and is not a problem when used directly in the Arima () function.
> 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): object is not a matrix
> 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. Cause analysis
The reason for this is that the variable name of the data has the same name as the sample function in the base package and is not handled correctly in the fitted () function.
In the R language, sample is a function in the base package, and note that in R programs, the variable name does not use the same name, otherwise it will not get the correct result.
3. Solve
The solution is that the function does not have the same name as the reason why the sample () function is not handled correctly in the fitted () function, and the fitted () function itself
4, sample Command reference
Use Help (sample) to see the use of the sample () function.
Sample {Base} |
R Documentation |
Random Samples and Permutationsdescription
sample
Takes a sample of the specified size from the elementsof x
using 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 is with replacement? |
prob |
A vector of probability weights for obtaining the elementsof the vector being sampled. |
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
R language Learning note-error in TS (x): object is not a matrix problem solved