Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:14:26+00:00 2026-05-30T13:14:26+00:00

i am making a research in R project. Data is stored in 3 zoo

  • 0

i am making a research in R project. Data is stored in 3 zoo objects with 9 columns each. I want to make granger-test of each column on each and store results (Pr(>F) values) in 3 matrices 9×9.

I try to use for() loop and have the following problem

for(i in 1:ncol(dfvola.pre)) {
   grangertest(order=4, 
       dfvola.pre[,2], 
       dfvola.pre[,i])$'Pr(>F)'[2]
 }

produces error Error in solve(vc[ovar, ovar]) : subscript out of bounds

At the same time

grangertest(order=4, dfvola.pre[,2], 
            dfvola.pre[,3])$'Pr(>F)'[2] 

works fine, i.e. I can store Pr(>F) in variable or matrix cell. But to make 3 matrices 9×9 I had to write 81*3 lines of code and I wanted to know is there more elegant solution in R.
I am new to R and have a feeling that perhaps there should be one, even more elegant that nested loops 🙂

Just in case, this is my data (zoo object):

head(dfvola.pre)
                    CH           HK          SI          RU         EN
2002-02-08 -0.04105356 -0.021797675 -0.03411227 -0.06821175 -0.1728407
2002-02-11 -0.07383230 -0.034095749 -0.05364423 -0.12425684 -0.1656535
2002-02-12 -0.09345455  0.011086639 -0.06846780 -0.14499508 -0.0169436
2002-02-13 -0.09492381  0.009393133 -0.08113240 -0.13592678  2.4487733
2002-02-14 -0.08875820  0.026173698 -0.08273877 -0.07034832  0.4948738
2002-02-15 -0.07895699 -0.041345747 -0.07501171 -0.01333353  0.2248262
                     US          GR          FR          JP
2002-02-08  0.015261541 -0.02886118 -0.01236761 -0.03934752
2002-02-11 -0.102323758 -0.11697662 -0.12982389 -0.08438561
2002-02-12  0.001706797 -0.11818056 -0.14477277 -0.09312417
2002-02-13 -0.085467795 -0.10278221 -0.07810301 -0.11467290
2002-02-14 -0.082738612 -0.13175354 -0.12782784 -0.12296171
2002-02-15 -0.098760674 -0.08439060 -0.08903754 -0.11871091
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:14:28+00:00Added an answer on May 30, 2026 at 1:14 pm

    The problem occurs when i becomes equal to 2. Then you are testing the difference between two identical dataset, which leads to the error:

    x = runif(100)
    grangertest(order=4, x, x)
    Error in solve(vc[ovar, ovar]) : subscript out of bounds
    

    I’m not familiar with grangertest, but it might be that a covariance matrix becomes singular. The solution is to skip i = 2:

    for(i in 1:ncol(dfvola.pre)) {
     if(!i == 2) {
       grangertest(order=4, 
           dfvola.pre[,2], 
           dfvola.pre[,i])$'Pr(>F)'[2]
      }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a research project on search engines, and i am having problems
I have been making some research in the domain of servers for a website
Making an adobe flex ui in which data that is calculated must use proprietary
I like the idea of making research available at multiple levels of detail i.e.,
Context: I'm making a simple solar system simulation in c++/OpenGL. Research: I've tried searching
I'm doing a bit of hands on research surrounding the speed benefits of making
Within an asp webform project I am making a call to a web service
I am making a portal page for a project, and a div contained is
I am working on a project with a group, and we are making an
I'm working on a personal project involving map-making tools for a tabletop game that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.