Dear R users,
I'm new of R, thus I apologize in advance if my following question may
result a little dumb, but I really need some expert advice.
I have a problem in applying someone else's code to my data. The author's
code works perfectly with the examples he provides, and it seems to me I am
doing all the correct steps in my case, but apparently I am not.

The main function is:
grid_boot <- function(dat,name,t,ar,grid,bq,c,all,grph)
and I should simply specify the parameter and then running the code given
in the script, or at least for the author's example this works.
All the specification in the examples are close to my case, except for the
ar parameter.
The ar parameter is the autoregressive order of a time series, so it is
simply a number from 1 to n that you choose. My series requires a simple ar
= 1, but if I run the code with this specification, R give me back the
following error:

" Error in solve.default(t(x) %*% x) :
  system is computationally singular: reciprocal condition number =
6.07898e-34 In addition: Warning messages:
1: In dat[(ar - k + 2):(n - k + 1)] - dat[(ar - k + 1):(n - k)] :
  longer object length is not a multiple of shorter object length
2: In dat[(ar - k + 2):(n - k + 1)] - dat[(ar - k + 1):(n - k)] :
  longer object length is not a multiple of shorter object length"

In the example, the author specifies as follow:
orig <- 2    # set to 1 for original data, set to 2 for extended data #
t <- 2
grid <- 200
bq <- 9999
c <- .9
i <- 7
d <- np[i,]
if (orig==1){
    y <- as.matrix(dat[d[1]:(d[2]-18)])
    if (i==4) y <- y[21:82]
}else{
    y <- as.matrix(dat[d[1]:d[2]])
}
name <- "GNP per Capita: 1869-1988"
ar <- d[3]

What I can't figure out is the indication ar <- d[3] and in general what
precisely he means with specifying i and d. I think this specification is
due to the fact that his dataset is made of several variables all written
in the same column and they are associated with an index.
When I give these inputs to R (I use RStudio), in the environment pane
 appears as ar = 1. When I give the numerical input (ar <- 1) for my
exercise instead, the only result is the error above mentioned.

Below, I report my data (as you can see, it is only a single series with
few observation, so it should be an easy one) and my inputs, while I attach
the script in a text file because it is quite a long one. I also attach the
example and the data used in it.
I hope someone can help me figuring out what am I doing wrong and I will be
very grateful to anyone who is willing to help a newbie like me.

library(pracma)
source(file.choose())
dat <- as.matrix(read.csv(file.choose(), header = TRUE))
print(dat)

USA
 [1,]  0.01075000
 [2,]  0.01116000
 [3,]  0.01214000
 [4,]  0.01309000
 [5,]  0.01668000
 [6,]  0.02991000
 [7,]  0.02776000
 [8,]  0.04218000
 [9,]  0.05415000
[10,]  0.05895000
[11,]  0.04256000
[12,]  0.03306000
[13,]  0.00622000
[14,]  0.11035000
[15,]  0.09132000
[16,]  0.05737000
[17,]  0.06486000
[18,]  0.07647000
[19,]  0.11266000
[20,]  0.13509000
[21,]  0.10316000
[22,]  0.06161000
[23,]  0.03212000
[24,]  0.04317000
[25,]  0.03561000
[26,]  0.01859000
[27,]  0.03741000
[28,]  0.04009000
[29,]  0.04827000
[30,]  0.05398000
[31,]  0.04235000
[32,]  0.03029000
[33,]  0.02952000
[34,]  0.02607000
[35,]  0.02805000
[36,]  0.02931000
[37,]  0.02338000
[38,]  0.01552000
[39,]  0.02188000
[40,]  0.03377000
[41,]  0.02826000
[42,]  0.01586000
[43,]  0.00002270
[44,]  0.02677000
[45,]  0.03393000
[46,]  0.03226000
[47,]  0.02853000
[48,]  0.03839000
[49,] -0.00000356
[50,]  0.00001640
[51,]  0.03157000
[52,]  0.02069000
[53,]  0.01465000
[54,]  0.01622000
[55,]  0.01622000

dat <- dat
name <- "Inflation"
t <- 1
ar <- 1
grid <- 200
bq <- 1999
c <- .9
all <- 0
grph <- 1

out <- grid_boot(dat, name, t, ar, grid, bq, c, all, grph)

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to