R language Learning note-error in TS (x): object is not a matrix problem solved

Source: Internet
Author: User

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

Because: 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 name that is named with it. Otherwise it will not get the correct result.

3. Solve

The workaround is that the function does not have the same name as the reason why the sample () function in the fitted () function is not handled correctly, possibly and the fitted () function itself.

Note: There is also the data () function that can cause confusion.


4, sample command to participate in

Use Help (sample) to see the use of the sample () function.


Sample {Base} R Documentation

Random Samples and Permutationsdescription

sampleTakes 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.


R language Learning note-error in TS (x): object is not a matrix problem solved

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.