Extract only value from the hypothesis test for an object

Asked

Viewed 23 times

2

Good night

I am performing the KPSS hypothesis test for time series stationarity, through the following commands.

#Todos os pacotes necessários para o desenvolvimento do curso
library(forecast)
library(ggplot2)
library(urca)
library(lmtest)
library(seasonal)
library(seasonalview)

x<-ur.kpss(AirPassengers)
print(x)

The Airpassengers base is already native to R

after performing the test I can’t just extract the p-value number from the x-object, which makes it impossible for me to scale to a list of many matrices I have

I would like help to extract the value of p-valeu for another object in number form, I thank you already.

1 answer

3


The result of ur.kpss is a class object S4. To extract elements we use the operator @:

library(forecast)
library(ggplot2)
library(urca)
library(lmtest)
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric

x<-ur.kpss(AirPassengers)
print(x)
#> 
#> ####################################### 
#> # KPSS Unit Root / Cointegration Test # 
#> ####################################### 
#> 
#> The value of the test statistic is: 2.7395

x@teststat
#> [1] 2.739474

Created on 2019-03-14 by the reprex package (v0.2.1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.