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 8707691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:55:58+00:00 2026-06-13T03:55:58+00:00

After trying several variations of coding from the function I’m trying to make, still

  • 0

After trying several variations of coding from the function I’m trying to make, still I’m not success. Here’s the equation below that I wish to make a function of it in R,

enter image description here

Edit: s here is of course less than T.

Also, here’s the two matrix that shows where the wij, zj(t), and zi(t+s) be taken from.

enter image description here

Hence, wij = w12 is equal to w1,2 in wmatrix. Similarly, zj(t) = z2(1) is equal to a2,1 in datamat. Again, i=j. Thus if i=1, t=1 and s = 1, then we have zi(t+s) = z1(1+1) = z1(2) which is equal to a1,2 in datamat matrix.

Now, Here’s the code that I ended up with,

st.acf <- function(datamat, wmatrix,ss){
          a = dim(datamat)[1]
          b = dim(datamat)[2]
          sumn <- 0 
          for(i in 1:a){
             for(j in 1:a){
                for(t in 1:b-ss){
                    sumn <- sumn + wmatrix[i,j]*datamat[j,t]*datamat[i,t+ss]
                }
             }
          }
          print(sumn/sqrt(sum((wmatrix%*%datamat)^2)*sum(datamat^2)))
      }

I used an example which I computed manually, and here’s the data of it,

DataMatrix <- rbind(c(54, 55, 51), c(52, 51, 57))
WeightsMatrix <- rbind(c(0, 1), c(1, 0)) 

The answer of this should be 0.66389. But, when I use my function, the output of it says numeric(0).

st.acf(DataMatrix, WeightsMatrix, 1)
numeric(0)

I can’t understand this, all the codes in my function is correct, when I run the loop, and the
sqrt(sum((wmatrix%*%datamat)^2)*sum(datamat^2)) separately, I got the correct answer. But, when I try to merge them and make a function, I always got numeric(0). Anyone can help me on this.

I’ll appreciate it very much!

  • 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-06-13T03:55:59+00:00Added an answer on June 13, 2026 at 3:55 am

    In R, the : operator has higher precedence than the binary -. Which means that 1:b-ss is equivalent to (1:b)-ss, when you meant to use 1:(b-ss). Make that change in your code and you will get the expected result.

    For more details on operator precedence, see ?Syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After trying several .bst files I am still mostly satisfied with the layout of
After using several non compatible barcode generators gems in rails 3.2, i am trying
After trying to make a while(bool) loop and it failing because I couldn't see
I have read several articles/questions/forums discussing the best auto-complete plugin for jQuery. After trying
I am so frustrated right now after several hours trying to find where shared_ptr
I am trying to accomplish a task but not successful even after trying for
I'm totally confused after trying to solve my problem for several hours for myself,
I'm trying to call Gtk3's GtkTreeRowReference() function without any success. I'm trying to delete
I'm posting here after trying to resolve my problem on my own for a
I have a Rails 2.3.5 application and Im trying to render several Partials from

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.