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]]
Hi Dalila, is your function a part of a packacke or is it self-written? If you have the code it would be helpful to provide it. Frank
I forgot to attach the website in which there's all what is needed for this procedure, sorry! The text file I attach is the main standard procedure, while in the website there is all the resources for the example. If you can help me, I'd be so grateful! I think it's all self written, by the way because it's the procedure in the author's paper http://www.ssc.wisc.edu/~bhansen/progs/restat_99.html 2016-02-18 14:19 GMT+01:00 Frank Duschek <fd at itsfd.de>:> Hi Dalila, > is your function a part of a packacke or is it self-written? If you > have the code it would be helpful to provide it. > > Frank > > ______________________________________________ > R-help at 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. >
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 >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 at 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.[[alternative HTML version deleted]]
I'm really sorry, I forgot the attachment! I attach the main code as txt file, instead here <http://www.ssc.wisc.edu/~bhansen/progs/restat_99.html> there everything else I mentioned. I apologize if I have not been able to summarize, but I am not so proficient. Yes, the ar parameter is exactly what I said it is; it is an index that shouldn't be found in the data, but you decide it. Even the author specifies it is "the order of the autoregressive parameter", thus I really don't have a clue of why he used indexetion. Np is his dataset, you can find it in the link below, if you want to help me. Yes, I read about indexing but I'm asking for help just because I am sure of what "ar" is. I am not proficient with R, but at least I have knowledge Time series econometrics' theory. No, I am not asking to do my homework for me howeverer. I spent the last two whole weeks on this code trying different inputs and trying to put all my effort in understanding every single detail of this code, otherwise I would never asked for help to unknown people. And it is my master thesis, thus is not really nice to use the word "homework" if you don't know my personal situation. However, I understand you probably receive thousands of silly problems, thus don't get me wrong for what I've just said. All the data and the code are here <http://www.ssc.wisc.edu/~bhansen/progs/restat_99.html>, the main procedure is attached. (When I sent the first mail, I sent it another right after with the attachment, but the moderators discarded it, thus I apologize again for the uncomplete post" 2016-02-18 17:57 GMT+01:00 Jeff Newmiller <jdnewmil at dcn.davis.ca.us>:> 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 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 at 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. >> >>