[R] Problem in adapting a script I have not written.
jdnewmil at dcn.davis.ca.us
Thu Feb 18 17:57:20 CET 2016
d[ 3 ] means indexing some vector-like object called "d" to extract the third value. (You really need to read the Introduction to R document that comes with R, particularly about indexing. There are actually four ways to do indexing that may come up as you read other people's code.) "d" is the contents of the seventh row of some matrix-like object called "np" which you have given no definition for. Without that information "ar" could be almost anything. If you are right and their example works then you have not given us the whole example. You mention attaching code... the mailing list strips off most attachments to avoid spreading viruses, but if they have the extension ".txt" they usually get through okay.
If the ar parameter really is what you say it is supposed to be, giving it the value 1 should be perfectly acceptable. However, you may not have specified the arguments to that function in the correct order, or the problem may be in other arguments.
Do be warned that this list is here to help you through rough spots... not to do your work for you. The Posting Guide mentioned at the bottom of every R-help email asks you to post minimal examples rather than long complicated code files, so you are at best near the edge of acceptable use in this request, so at least be sure we can reproduce your error. (Posting your email in plain text rather than HTML is another important step in communicating clearly by avoiding corruption of your code in the mailing list.)
Sent from my phone. Please excuse my brevity.
On February 17, 2016 1:19:07 PM PST, Dalila Zolarsi <dalila.zolarsi at gmail.com> wrote:
>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
>code works perfectly with the examples he provides, and it seems to me
>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
>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 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
>= 1, but if I run the code with this specification, R give me back the
>" 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,]
> y <- as.matrix(dat[d:(d-18)])
> if (i==4) y <- y[21:82]
> y <- as.matrix(dat[d:d])
>name <- "GNP per Capita: 1869-1988"
>ar <- d
>What I can't figure out is the indication ar <- d and in general
>precisely he means with specifying i and d. I think this specification
>due to the fact that his dataset is made of several variables all
>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
>few observation, so it should be an easy one) and my inputs, while I
>the script in a text file because it is quite a long one. I also attach
>example and the data used in it.
>I hope someone can help me figuring out what am I doing wrong and I
>very grateful to anyone who is willing to help a newbie like me.
>dat <- as.matrix(read.csv(file.choose(), header = TRUE))
> [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
>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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help