Re: [R] SVAR: error message
I had no problem using svar () I think you should try the code examples in the var package PDF by the authors, the research has since been quoted successfully Amit Mittal PhD in Finance and Accounting (tbd) IIM Lucknow http://ssrn.com/author=2665511 *Top 10%, downloaded author since July 2017 Sent from my Outlook for Android https://aka.ms/ghei36 From: R-help on behalf of John Sent: Wednesday, October 24, 2018 6:25:17 AM To: William Dunlap Cc: r-help; bernh...@pfaffikus.de Subject: Re: [R] SVAR: error message If it is an A model, then should I just set B = NULL or skip the entry B? William Dunlap $B1w(B 2018$BG/(B10$B7n(B24$BF|(B $B=5;0(B $B>e8a(B4:14$BUmF;!'(B > The immediate problem is in svartype=="AB-model" part of SVAR: > > pos <- which(is.na(rb)) > cols <- length(pos) > Rb <- matrix(0, nrow = Ksq, ncol = cols) > for (i in 1:cols) Rb[pos[i], i] <- 1 > > Your Bmat has no NA's, so cols is 0. Then 1:cols is c(1,0), causing > an error in the for loop when it tries to reference column 1 of a 0-column > matrix. The code should use seq_len(cols) instead of 1:cols (or give > an error telling the user that Bmat should contain some NA's). > > This is the sort of question one should send to the maintainer of the > package > that SVAR is in: > > maintainer("vars") > [1] "Bernhard Pfaff " > > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Mon, Oct 22, 2018 at 8:15 PM, John wrote: > >> Hi, >> >> I have a bi-variate VAR model and would like to convert it to SVAR but >> get an error message. Could someone pinpoint anything wrong and correct my >> code? Thanks, >> >> John >> >> >> amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) >> df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) >> var1<-VAR(df1, type = "const", ic="BIC") >> svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), >> max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) >> >> > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) >> > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) >> > var1<-VAR(df1, type = "const", ic="BIC") >> > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = >> diag(2), >> + max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) >> Error in `[<-`(`*tmp*`, pos[i], i, value = 1) : subscript out of bounds >> >> [[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. >> > > [[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. [[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.
Re: [R] SVAR: error message
If it is an A model, then should I just set B = NULL or skip the entry B? William Dunlap 於 2018年10月24日 週三 上午4:14寫道: > The immediate problem is in svartype=="AB-model" part of SVAR: > > pos <- which(is.na(rb)) > cols <- length(pos) > Rb <- matrix(0, nrow = Ksq, ncol = cols) > for (i in 1:cols) Rb[pos[i], i] <- 1 > > Your Bmat has no NA's, so cols is 0. Then 1:cols is c(1,0), causing > an error in the for loop when it tries to reference column 1 of a 0-column > matrix. The code should use seq_len(cols) instead of 1:cols (or give > an error telling the user that Bmat should contain some NA's). > > This is the sort of question one should send to the maintainer of the > package > that SVAR is in: > > maintainer("vars") > [1] "Bernhard Pfaff " > > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Mon, Oct 22, 2018 at 8:15 PM, John wrote: > >> Hi, >> >> I have a bi-variate VAR model and would like to convert it to SVAR but >> get an error message. Could someone pinpoint anything wrong and correct my >> code? Thanks, >> >> John >> >> >> amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) >> df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) >> var1<-VAR(df1, type = "const", ic="BIC") >> svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), >> max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) >> >> > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) >> > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) >> > var1<-VAR(df1, type = "const", ic="BIC") >> > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = >> diag(2), >> + max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) >> Error in `[<-`(`*tmp*`, pos[i], i, value = 1) : subscript out of bounds >> >> [[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. >> > > [[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.
Re: [R] SVAR: error message
The immediate problem is in svartype=="AB-model" part of SVAR: pos <- which(is.na(rb)) cols <- length(pos) Rb <- matrix(0, nrow = Ksq, ncol = cols) for (i in 1:cols) Rb[pos[i], i] <- 1 Your Bmat has no NA's, so cols is 0. Then 1:cols is c(1,0), causing an error in the for loop when it tries to reference column 1 of a 0-column matrix. The code should use seq_len(cols) instead of 1:cols (or give an error telling the user that Bmat should contain some NA's). This is the sort of question one should send to the maintainer of the package that SVAR is in: > maintainer("vars") [1] "Bernhard Pfaff " Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Oct 22, 2018 at 8:15 PM, John wrote: > Hi, > > I have a bi-variate VAR model and would like to convert it to SVAR but > get an error message. Could someone pinpoint anything wrong and correct my > code? Thanks, > > John > > > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) > var1<-VAR(df1, type = "const", ic="BIC") > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), > max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) > > > amat <- matrix(c(NA, 0, NA, NA), nrow = 2, ncol = 2, byrow = TRUE) > > df1<-data.frame(x=c(1,4,5,6,7,8,9,3,5,3), y=c(4,7,1,2,3,9,3,4,5,7)) > > var1<-VAR(df1, type = "const", ic="BIC") > > svar2<-SVAR(x = var1, estmethod = "scoring", Amat = amat, Bmat = diag(2), > + max.iter = 100, conv.crit = 0.1e-6, maxls = 1000) > Error in `[<-`(`*tmp*`, pos[i], i, value = 1) : subscript out of bounds > > [[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. > [[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.
Re: [R] Ignoring the domain of RV in punif()
Well, as a final (I hope!) clarification: It is not the case that "the bigger cube does not exists (because the Q is the reference space)". It does exist! Simply, the probability of the random point being in the bigger cube, and NOT in the cube Q, is 0. Hence "the cumulative probability of reaching a point outside the cube (u or v or w > A) is 1" is badly phrased. The "cumulative probability" is not the probability of *reaching* a point, but of being (in the case of a real random variable) less than or equal to the given value. If Prob[X <= x1] = 1, then Prob[X > x1] = 0. Hence if x0 is the minimum value such that Prob[X <= x0] = 1, then X "can reach" x0. But for any x1 > x0, Prob[x0 < X <= x1] = 0. Therefore, since X cannot be greater than x0, X *cannot reach* x1! Best wishes, Ted. On Tue, 2018-10-23 at 12:06 +0100, Hamed Ha wrote: > Hi Ted, > > Thanks for the explanation. > > I am convinced at least more than average by Eric and your answer. But > still have some shadows of confusion that is definitely because I have > forgotten some fundamentals in probabilities. > > In your cube example, the cumulative probability of reaching a point > outside the cube (u or v or w > A) is 1 however, the bigger cube does not > exists (because the Q is the reference space). Other words, I feel that we > extend the space to accommodate any cube of any size! Looks a bit weird to > me! > > > Hamed. > > On Tue, 23 Oct 2018 at 11:52, Ted Harding wrote: > > > Sorry -- stupid typos in my definition below! > > See at ===*** below. > > > > On Tue, 2018-10-23 at 11:41 +0100, Ted Harding wrote: > > Before the ticket finally enters the waste bin, I think it is > > necessary to explicitly explain what is meant by the "domain" > > of a random variable. This is not (though in special cases > > could be) the space of possible values of the random variable. > > > > Definition of (real-valued) Random Variable (RV): > > Let Z be a probability space, i.e. a set {z} of entities z > > on which a probability distribution is defined. The entities z > > do not need to be numeric. A real-valued RV X is a function > > X:Z --> R defined on Z such that, for any z in Z, X(z) is a > > real number. The set Z, in tthis context, is (by definitipon) > > the *domain* of X, i.e. the space on which X is defined. > > It may or may not be (and usually is not) the same as the set > > of possible values of X. > > > > Then. given any real value x0, the CDF of X at x- is Prob[X <= X0]. > > The distribution function of X does not define the domain of X. > > > > As a simple exam[ple: Suppose Q is a cube of side A, consisting of > > points z=(u,v,w) with 0 <= u,v,w <= A. Z is the probability space > > of points z with a uniform distribution of position within Q. > > Define the random variable X:Q --> [0,1] as > > ===*** > > X[u,v,w) = x/A > > > > Wrong! That should have been: > > > > X[u,v,w) = w/A > > ===*** > > Then X is uniformly distributed on [0,1], the domain of X is Q. > > Then for x <= 0 _Prob[X <= x] = 0, for 0 <= x <= 1 Prob(X >=x] = x, > > for x >= 1 Prob(X <= x] = 1. These define the CDF. The set of poaaible > > values of X is 1-dimensional, and is not the same as the domain of X, > > which is 3-dimensional. > > > > Hopiong this helps! > > Ted. > > > > On Tue, 2018-10-23 at 10:54 +0100, Hamed Ha wrote: > > > > Yes, now it makes more sense. > > > > > > > > Okay, I think that I am convinced and we can close this ticket. > > > > > > > > Thanks Eric. > > > > Regards, > > > > Hamed. > > > > > > > > On Tue, 23 Oct 2018 at 10:42, Eric Berger > > wrote: > > > > > > > > > Hi Hamed, > > > > > That reference is sloppy. Try looking at > > > > > https://en.wikipedia.org/wiki/Cumulative_distribution_function > > > > > and in particular the first example which deals with a Unif[0,1] r.v. > > > > > > > > > > Best, > > > > > Eric > > > > > > > > > > > > > > > On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha > > wrote: > > > > > > > > > >> Hi Eric, > > > > >> > > > > >> Thank you for your reply. > > > > >> > > > > >> I should say that your justification makes sense to me. However, I > > am in > > > > >> doubt that CDF defines by the Pr(x <= X) for all X? that is the > > domain of > > > > >> RV is totally ignored in the definition. > > > > >> > > > > >> It makes a conflict between the formula and the theoretical > > definition. > > > > >> > > > > >> Please see page 115 in > > > > >> > > > > >> > > https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false > > > > >> The > > > > >> > > > > >> > > > > >> Thanks. > > > > >> Hamed. > > > > >> > > > > >> > > > > >> > > > > >> On Tue, 23 Oct 2018 at 10:21, Eric Berger > > wrote: > > > > >> > > > > >>> Hi Hamed, > > > > >>> I disagree with your criticism. > > > > >>> For a random variable X > > > > >>> X: D - - - > R > > > > >>> its CDF F is defined by > > > > >>> F: R - - - > [0,1] > > > > >>>
Re: [R] Ignoring the domain of RV in punif()
Hi Ted, Thanks for the explanation. I am convinced at least more than average by Eric and your answer. But still have some shadows of confusion that is definitely because I have forgotten some fundamentals in probabilities. In your cube example, the cumulative probability of reaching a point outside the cube (u or v or w > A) is 1 however, the bigger cube does not exists (because the Q is the reference space). Other words, I feel that we extend the space to accommodate any cube of any size! Looks a bit weird to me! Hamed. On Tue, 23 Oct 2018 at 11:52, Ted Harding wrote: > Sorry -- stupid typos in my definition below! > See at ===*** below. > > On Tue, 2018-10-23 at 11:41 +0100, Ted Harding wrote: > Before the ticket finally enters the waste bin, I think it is > necessary to explicitly explain what is meant by the "domain" > of a random variable. This is not (though in special cases > could be) the space of possible values of the random variable. > > Definition of (real-valued) Random Variable (RV): > Let Z be a probability space, i.e. a set {z} of entities z > on which a probability distribution is defined. The entities z > do not need to be numeric. A real-valued RV X is a function > X:Z --> R defined on Z such that, for any z in Z, X(z) is a > real number. The set Z, in tthis context, is (by definitipon) > the *domain* of X, i.e. the space on which X is defined. > It may or may not be (and usually is not) the same as the set > of possible values of X. > > Then. given any real value x0, the CDF of X at x- is Prob[X <= X0]. > The distribution function of X does not define the domain of X. > > As a simple exam[ple: Suppose Q is a cube of side A, consisting of > points z=(u,v,w) with 0 <= u,v,w <= A. Z is the probability space > of points z with a uniform distribution of position within Q. > Define the random variable X:Q --> [0,1] as > ===*** > X[u,v,w) = x/A > > Wrong! That should have been: > > X[u,v,w) = w/A > ===*** > Then X is uniformly distributed on [0,1], the domain of X is Q. > Then for x <= 0 _Prob[X <= x] = 0, for 0 <= x <= 1 Prob(X >=x] = x, > for x >= 1 Prob(X <= x] = 1. These define the CDF. The set of poaaible > values of X is 1-dimensional, and is not the same as the domain of X, > which is 3-dimensional. > > Hopiong this helps! > Ted. > > On Tue, 2018-10-23 at 10:54 +0100, Hamed Ha wrote: > > > Yes, now it makes more sense. > > > > > > Okay, I think that I am convinced and we can close this ticket. > > > > > > Thanks Eric. > > > Regards, > > > Hamed. > > > > > > On Tue, 23 Oct 2018 at 10:42, Eric Berger > wrote: > > > > > > > Hi Hamed, > > > > That reference is sloppy. Try looking at > > > > https://en.wikipedia.org/wiki/Cumulative_distribution_function > > > > and in particular the first example which deals with a Unif[0,1] r.v. > > > > > > > > Best, > > > > Eric > > > > > > > > > > > > On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha > wrote: > > > > > > > >> Hi Eric, > > > >> > > > >> Thank you for your reply. > > > >> > > > >> I should say that your justification makes sense to me. However, I > am in > > > >> doubt that CDF defines by the Pr(x <= X) for all X? that is the > domain of > > > >> RV is totally ignored in the definition. > > > >> > > > >> It makes a conflict between the formula and the theoretical > definition. > > > >> > > > >> Please see page 115 in > > > >> > > > >> > https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false > > > >> The > > > >> > > > >> > > > >> Thanks. > > > >> Hamed. > > > >> > > > >> > > > >> > > > >> On Tue, 23 Oct 2018 at 10:21, Eric Berger > wrote: > > > >> > > > >>> Hi Hamed, > > > >>> I disagree with your criticism. > > > >>> For a random variable X > > > >>> X: D - - - > R > > > >>> its CDF F is defined by > > > >>> F: R - - - > [0,1] > > > >>> F(z) = Prob(X <= z) > > > >>> > > > >>> The fact that you wrote a convenient formula for the CDF > > > >>> F(z) = (z-a)/(b-a) a <= z <= b > > > >>> in a particular range for z is your decision, and as you noted this > > > >>> formula will give the wrong value for z outside the interval [a,b]. > > > >>> But the problem lies in your formula, not the definition of the CDF > > > >>> which would be, in your case: > > > >>> > > > >>> F(z) = 0 if z <= a > > > >>>= (z-a)/(b-a) if a <= z <= b > > > >>>= 1 if 1 <= z > > > >>> > > > >>> HTH, > > > >>> Eric > > > >>> > > > >>> > > > >>> > > > >>> > > > >>> On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha > wrote: > > > >>> > > > Hi All, > > > > > > I recently discovered an interesting issue with the punif() > function. > > > Let > > > X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for > (a<= x<= > > > b). > > > The important fact here is the domain of the random variable X. > Having > > > said > > > that, R returns CDF for any value in the real domain. > > > >
Re: [R] Ignoring the domain of RV in punif()
Sorry -- stupid typos in my definition below! See at ===*** below. On Tue, 2018-10-23 at 11:41 +0100, Ted Harding wrote: Before the ticket finally enters the waste bin, I think it is necessary to explicitly explain what is meant by the "domain" of a random variable. This is not (though in special cases could be) the space of possible values of the random variable. Definition of (real-valued) Random Variable (RV): Let Z be a probability space, i.e. a set {z} of entities z on which a probability distribution is defined. The entities z do not need to be numeric. A real-valued RV X is a function X:Z --> R defined on Z such that, for any z in Z, X(z) is a real number. The set Z, in tthis context, is (by definitipon) the *domain* of X, i.e. the space on which X is defined. It may or may not be (and usually is not) the same as the set of possible values of X. Then. given any real value x0, the CDF of X at x- is Prob[X <= X0]. The distribution function of X does not define the domain of X. As a simple exam[ple: Suppose Q is a cube of side A, consisting of points z=(u,v,w) with 0 <= u,v,w <= A. Z is the probability space of points z with a uniform distribution of position within Q. Define the random variable X:Q --> [0,1] as ===*** X[u,v,w) = x/A Wrong! That should have been: X[u,v,w) = w/A ===*** Then X is uniformly distributed on [0,1], the domain of X is Q. Then for x <= 0 _Prob[X <= x] = 0, for 0 <= x <= 1 Prob(X >=x] = x, for x >= 1 Prob(X <= x] = 1. These define the CDF. The set of poaaible values of X is 1-dimensional, and is not the same as the domain of X, which is 3-dimensional. Hopiong this helps! Ted. On Tue, 2018-10-23 at 10:54 +0100, Hamed Ha wrote: > > Yes, now it makes more sense. > > > > Okay, I think that I am convinced and we can close this ticket. > > > > Thanks Eric. > > Regards, > > Hamed. > > > > On Tue, 23 Oct 2018 at 10:42, Eric Berger wrote: > > > > > Hi Hamed, > > > That reference is sloppy. Try looking at > > > https://en.wikipedia.org/wiki/Cumulative_distribution_function > > > and in particular the first example which deals with a Unif[0,1] r.v. > > > > > > Best, > > > Eric > > > > > > > > > On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha wrote: > > > > > >> Hi Eric, > > >> > > >> Thank you for your reply. > > >> > > >> I should say that your justification makes sense to me. However, I am in > > >> doubt that CDF defines by the Pr(x <= X) for all X? that is the domain of > > >> RV is totally ignored in the definition. > > >> > > >> It makes a conflict between the formula and the theoretical definition. > > >> > > >> Please see page 115 in > > >> > > >> https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false > > >> The > > >> > > >> > > >> Thanks. > > >> Hamed. > > >> > > >> > > >> > > >> On Tue, 23 Oct 2018 at 10:21, Eric Berger wrote: > > >> > > >>> Hi Hamed, > > >>> I disagree with your criticism. > > >>> For a random variable X > > >>> X: D - - - > R > > >>> its CDF F is defined by > > >>> F: R - - - > [0,1] > > >>> F(z) = Prob(X <= z) > > >>> > > >>> The fact that you wrote a convenient formula for the CDF > > >>> F(z) = (z-a)/(b-a) a <= z <= b > > >>> in a particular range for z is your decision, and as you noted this > > >>> formula will give the wrong value for z outside the interval [a,b]. > > >>> But the problem lies in your formula, not the definition of the CDF > > >>> which would be, in your case: > > >>> > > >>> F(z) = 0 if z <= a > > >>>= (z-a)/(b-a) if a <= z <= b > > >>>= 1 if 1 <= z > > >>> > > >>> HTH, > > >>> Eric > > >>> > > >>> > > >>> > > >>> > > >>> On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: > > >>> > > Hi All, > > > > I recently discovered an interesting issue with the punif() function. > > Let > > X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= > > b). > > The important fact here is the domain of the random variable X. Having > > said > > that, R returns CDF for any value in the real domain. > > > > I understand that one can justify this by extending the domain of X and > > assigning zero probabilities to the values outside the domain. However, > > theoretically, it is not true to return a value for the CDF outside the > > domain. Then I propose a patch to R function punif() to return an error > > in > > this situations. > > > > Example: > > > punif(10^10) > > [1] 1 > > > > > > Regards, > > Hamed. > > > > [[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 p
Re: [R] Ignoring the domain of RV in punif()
Before the ticket finally enters the waste bin, I think it is necessary to explicitly explain what is meant by the "domain" of a random variable. This is not (though in special cases could be) the space of possible values of the random variable. Definition of (real-valued) Random Variable (RV): Let Z be a probability space, i.e. a set {z} of entities z on which a probability distribution is defined. The entities z do not need to be numeric. A real-valued RV X is a function X:Z --> R defined on Z such that, for any z in Z, X(z) is a real number. The set Z, in tthis context, is (by definitipon) the *domain* of X, i.e. the space on which X is defined. It may or may not be (and usually is not) the same as the set of possible values of X. Then. given any real value x0, the CDF of X at x- is Prob[X <= X0]. The distribution function of X does not define the domain of X. As a simple exam[ple: Suppose Q is a cube of side A, consisting of points z=(u,v,w) with 0 <= u,v,w <= A. Z is the probability space of points z with a uniform distribution of position within Q. Define the random variable X:Q --> [0,1] as X(u,v,w) = x/A Then X is uniformly distributed on [0,1], the domain of X is Q. Then for x <= 0 _Prob[X <= x] = 0, for 0 <= x <= 1 Prob(X >=x] = x, for x >= 1 Prob(X <= x] = 1. These define the CDF. The set of poaaible values of X is 1-dimensional, and is not the same as the domain of X, which is 3-dimensional. Hopiong this helps! Ted. On Tue, 2018-10-23 at 10:54 +0100, Hamed Ha wrote: > Yes, now it makes more sense. > > Okay, I think that I am convinced and we can close this ticket. > > Thanks Eric. > Regards, > Hamed. > > On Tue, 23 Oct 2018 at 10:42, Eric Berger wrote: > > > Hi Hamed, > > That reference is sloppy. Try looking at > > https://en.wikipedia.org/wiki/Cumulative_distribution_function > > and in particular the first example which deals with a Unif[0,1] r.v. > > > > Best, > > Eric > > > > > > On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha wrote: > > > >> Hi Eric, > >> > >> Thank you for your reply. > >> > >> I should say that your justification makes sense to me. However, I am in > >> doubt that CDF defines by the Pr(x <= X) for all X? that is the domain of > >> RV is totally ignored in the definition. > >> > >> It makes a conflict between the formula and the theoretical definition. > >> > >> Please see page 115 in > >> > >> https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false > >> The > >> > >> > >> Thanks. > >> Hamed. > >> > >> > >> > >> On Tue, 23 Oct 2018 at 10:21, Eric Berger wrote: > >> > >>> Hi Hamed, > >>> I disagree with your criticism. > >>> For a random variable X > >>> X: D - - - > R > >>> its CDF F is defined by > >>> F: R - - - > [0,1] > >>> F(z) = Prob(X <= z) > >>> > >>> The fact that you wrote a convenient formula for the CDF > >>> F(z) = (z-a)/(b-a) a <= z <= b > >>> in a particular range for z is your decision, and as you noted this > >>> formula will give the wrong value for z outside the interval [a,b]. > >>> But the problem lies in your formula, not the definition of the CDF > >>> which would be, in your case: > >>> > >>> F(z) = 0 if z <= a > >>>= (z-a)/(b-a) if a <= z <= b > >>>= 1 if 1 <= z > >>> > >>> HTH, > >>> Eric > >>> > >>> > >>> > >>> > >>> On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: > >>> > Hi All, > > I recently discovered an interesting issue with the punif() function. > Let > X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= > b). > The important fact here is the domain of the random variable X. Having > said > that, R returns CDF for any value in the real domain. > > I understand that one can justify this by extending the domain of X and > assigning zero probabilities to the values outside the domain. However, > theoretically, it is not true to return a value for the CDF outside the > domain. Then I propose a patch to R function punif() to return an error > in > this situations. > > Example: > > punif(10^10) > [1] 1 > > > Regards, > Hamed. > > [[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. > > >>> > > [[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,
Re: [R] Transformations in Tidyverse (renaming and ordering columns)
I am impressed. Upon playing with factor, I took it a step further to commonize (and this could very well be simpified): > > testset$Observation <- factor(testset$Order, levels=testset$Order, labels=testset$Observation) > testset$Label <- factor(testset$Seq, levels=testset$Seq, labels=testset$Label) > > testset %>% select(Observation, Label, Value) %>% spread(key=Observation, value=Value) # A tibble: 4 x 4 Label One Two Three 1 Western163 147 119 2 Northern 105 10082 3 Eastern121 10690 4 Southern747065 > All I see left now is to replace "Label" heading value with the appropriate testset$Section value provided for the situation. In this case... # A tibble: 4 x 4 For Reporting Quarter One Two Three ... FWIW, before sending this I cleared all formatting and dismissed the formatting toolbar (been doing only the latter before) in the Gmail client, which I presume will finally strip HTML from the message. -- Cheers, Joel Maxuel On Mon, Oct 22, 2018 at 10:48 PM John Laing wrote: > I don't know much about the Tidyverse, but more generally the way to > represent ordered categorical data is with a factor. This seems to work: > > > testset$Observation <- factor(testset$Observation, levels=c("One", > "Two", "Three")) > > testset$Label <- factor(testset$Label, levels=c("Western", "Northern", > "Eastern", "Southern")) > > testset %>% select(Observation, Label, Value) %>% > spread(key=Observation, value=Value) > # A tibble: 4 x 4 > Label One Two Three > > 1 Western163 147 119 > 2 Northern 105 10082 > 3 Eastern121 10690 > 4 Southern747065 > >> >> [[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.
Re: [R] Ignoring the domain of RV in punif()
Yes, now it makes more sense. Okay, I think that I am convinced and we can close this ticket. Thanks Eric. Regards, Hamed. On Tue, 23 Oct 2018 at 10:42, Eric Berger wrote: > Hi Hamed, > That reference is sloppy. Try looking at > https://en.wikipedia.org/wiki/Cumulative_distribution_function > and in particular the first example which deals with a Unif[0,1] r.v. > > Best, > Eric > > > On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha wrote: > >> Hi Eric, >> >> Thank you for your reply. >> >> I should say that your justification makes sense to me. However, I am in >> doubt that CDF defines by the Pr(x <= X) for all X? that is the domain of >> RV is totally ignored in the definition. >> >> It makes a conflict between the formula and the theoretical definition. >> >> Please see page 115 in >> >> https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false >> The >> >> >> Thanks. >> Hamed. >> >> >> >> On Tue, 23 Oct 2018 at 10:21, Eric Berger wrote: >> >>> Hi Hamed, >>> I disagree with your criticism. >>> For a random variable X >>> X: D - - - > R >>> its CDF F is defined by >>> F: R - - - > [0,1] >>> F(z) = Prob(X <= z) >>> >>> The fact that you wrote a convenient formula for the CDF >>> F(z) = (z-a)/(b-a) a <= z <= b >>> in a particular range for z is your decision, and as you noted this >>> formula will give the wrong value for z outside the interval [a,b]. >>> But the problem lies in your formula, not the definition of the CDF >>> which would be, in your case: >>> >>> F(z) = 0 if z <= a >>>= (z-a)/(b-a) if a <= z <= b >>>= 1 if 1 <= z >>> >>> HTH, >>> Eric >>> >>> >>> >>> >>> On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: >>> Hi All, I recently discovered an interesting issue with the punif() function. Let X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= b). The important fact here is the domain of the random variable X. Having said that, R returns CDF for any value in the real domain. I understand that one can justify this by extending the domain of X and assigning zero probabilities to the values outside the domain. However, theoretically, it is not true to return a value for the CDF outside the domain. Then I propose a patch to R function punif() to return an error in this situations. Example: > punif(10^10) [1] 1 Regards, Hamed. [[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. >>> [[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.
Re: [R] Ignoring the domain of RV in punif()
Hi Hamed, That reference is sloppy. Try looking at https://en.wikipedia.org/wiki/Cumulative_distribution_function and in particular the first example which deals with a Unif[0,1] r.v. Best, Eric On Tue, Oct 23, 2018 at 12:35 PM Hamed Ha wrote: > Hi Eric, > > Thank you for your reply. > > I should say that your justification makes sense to me. However, I am in > doubt that CDF defines by the Pr(x <= X) for all X? that is the domain of > RV is totally ignored in the definition. > > It makes a conflict between the formula and the theoretical definition. > > Please see page 115 in > > https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false > The > > > Thanks. > Hamed. > > > > On Tue, 23 Oct 2018 at 10:21, Eric Berger wrote: > >> Hi Hamed, >> I disagree with your criticism. >> For a random variable X >> X: D - - - > R >> its CDF F is defined by >> F: R - - - > [0,1] >> F(z) = Prob(X <= z) >> >> The fact that you wrote a convenient formula for the CDF >> F(z) = (z-a)/(b-a) a <= z <= b >> in a particular range for z is your decision, and as you noted this >> formula will give the wrong value for z outside the interval [a,b]. >> But the problem lies in your formula, not the definition of the CDF which >> would be, in your case: >> >> F(z) = 0 if z <= a >>= (z-a)/(b-a) if a <= z <= b >>= 1 if 1 <= z >> >> HTH, >> Eric >> >> >> >> >> On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: >> >>> Hi All, >>> >>> I recently discovered an interesting issue with the punif() function. >>> Let >>> X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= >>> b). >>> The important fact here is the domain of the random variable X. Having >>> said >>> that, R returns CDF for any value in the real domain. >>> >>> I understand that one can justify this by extending the domain of X and >>> assigning zero probabilities to the values outside the domain. However, >>> theoretically, it is not true to return a value for the CDF outside the >>> domain. Then I propose a patch to R function punif() to return an error >>> in >>> this situations. >>> >>> Example: >>> > punif(10^10) >>> [1] 1 >>> >>> >>> Regards, >>> Hamed. >>> >>> [[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. >>> >> [[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.
Re: [R] Ignoring the domain of RV in punif()
Hi Eric, Thank you for your reply. I should say that your justification makes sense to me. However, I am in doubt that CDF defines by the Pr(x <= X) for all X? that is the domain of RV is totally ignored in the definition. It makes a conflict between the formula and the theoretical definition. Please see page 115 in https://books.google.co.uk/books?id=FEE8D1tRl30C&printsec=frontcover&dq=statistical+distribution&hl=en&sa=X&ved=0ahUKEwjp3PGZmJzeAhUQqxoKHV7OBJgQ6AEIKTAA#v=onepage&q=uniform&f=false The Thanks. Hamed. On Tue, 23 Oct 2018 at 10:21, Eric Berger wrote: > Hi Hamed, > I disagree with your criticism. > For a random variable X > X: D - - - > R > its CDF F is defined by > F: R - - - > [0,1] > F(z) = Prob(X <= z) > > The fact that you wrote a convenient formula for the CDF > F(z) = (z-a)/(b-a) a <= z <= b > in a particular range for z is your decision, and as you noted this > formula will give the wrong value for z outside the interval [a,b]. > But the problem lies in your formula, not the definition of the CDF which > would be, in your case: > > F(z) = 0 if z <= a >= (z-a)/(b-a) if a <= z <= b >= 1 if 1 <= z > > HTH, > Eric > > > > > On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: > >> Hi All, >> >> I recently discovered an interesting issue with the punif() function. Let >> X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= b). >> The important fact here is the domain of the random variable X. Having >> said >> that, R returns CDF for any value in the real domain. >> >> I understand that one can justify this by extending the domain of X and >> assigning zero probabilities to the values outside the domain. However, >> theoretically, it is not true to return a value for the CDF outside the >> domain. Then I propose a patch to R function punif() to return an error in >> this situations. >> >> Example: >> > punif(10^10) >> [1] 1 >> >> >> Regards, >> Hamed. >> >> [[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. >> > [[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.
Re: [R] Ignoring the domain of RV in punif()
Hi Hamed, I disagree with your criticism. For a random variable X X: D - - - > R its CDF F is defined by F: R - - - > [0,1] F(z) = Prob(X <= z) The fact that you wrote a convenient formula for the CDF F(z) = (z-a)/(b-a) a <= z <= b in a particular range for z is your decision, and as you noted this formula will give the wrong value for z outside the interval [a,b]. But the problem lies in your formula, not the definition of the CDF which would be, in your case: F(z) = 0 if z <= a = (z-a)/(b-a) if a <= z <= b = 1 if 1 <= z HTH, Eric On Tue, Oct 23, 2018 at 12:05 PM Hamed Ha wrote: > Hi All, > > I recently discovered an interesting issue with the punif() function. Let > X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= b). > The important fact here is the domain of the random variable X. Having said > that, R returns CDF for any value in the real domain. > > I understand that one can justify this by extending the domain of X and > assigning zero probabilities to the values outside the domain. However, > theoretically, it is not true to return a value for the CDF outside the > domain. Then I propose a patch to R function punif() to return an error in > this situations. > > Example: > > punif(10^10) > [1] 1 > > > Regards, > Hamed. > > [[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. > [[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.
[R] Ignoring the domain of RV in punif()
Hi All, I recently discovered an interesting issue with the punif() function. Let X~Uiform[a,b] then the CDF is defined by F(x)=(x-a)/(b-a) for (a<= x<= b). The important fact here is the domain of the random variable X. Having said that, R returns CDF for any value in the real domain. I understand that one can justify this by extending the domain of X and assigning zero probabilities to the values outside the domain. However, theoretically, it is not true to return a value for the CDF outside the domain. Then I propose a patch to R function punif() to return an error in this situations. Example: > punif(10^10) [1] 1 Regards, Hamed. [[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.
Re: [R] Cannot use R on Windows when installed to an external drive with a space in the path
On 10/22/2018 07:15 PM, Ivan Krylov wrote: This is a bin\R.exe + bin\Rscript.exe bug. Please note this has been fixed in later versions of R, quoting has been added. If you can find some corner case in which the current quoting (R-devel) is incorrect on Windows, in the front-ends or anywhere else, please send a bug report with a reproducible example. But please keep in mind my comment that some packages will not be working with space in the name of R home directory. Some packages will not build from source. CRAN has been checking for the most obvious cause of this (certain use of include directives in make files), but it is still not safe to use R on file systems without SFN. Best, Tomas On Windows, where the system call to create a process only takes one command line string instead of an array of command line parameters[0] (and the C runtimes usually call CommandLineToArgvW[1] behind the scenes to get an array back), execv() does nothing to prepare a properly-quoted command line and just concatenates its arguments[2]. Moreover, Windows version of execv() is effectively undocumented[3], nor there is any information about the suggested replacement[4]. (You can call it a Windows bug instead.) Short file names are not a guaranteed solution, because they may not be available at all on some filesystems[5] (which is how this error has been encountered). In the general case, "argument quoting hell"[6] is unavoidable on Windows, but the code from [2] implements the proper conversion from an array of strings to a single quoted command line, ready to be parsed by the launched process. char* getRHOME(int m) in src/gnuwin32/rhome.c tries to return a short path (assuming it won't contain spaces). This is used by rcmdfn() from src/gnuwin32/front-ends/rcmdfn.c to system() a command line built with no quoting, causing the error. rcmdfn() is called from src/gnuwin32/front-ends/R.c, which seems to contain the entry point for R\R-3.3.3\bin\R.exe. Fortunately, in src/unix/Rscript.c the whole mess seems to be avoided by having it directly include rterm.c and then call AppMain() on Windows, passing the command line parameter array. Same goes for src/gnuwin32/front-ends/graphappmain.c. The corresponding executables reside in the architecture-specific subdirectory of ...\bin\. So if you run Rgui.exe, Rterm.exe or Rscript.exe from R-3.3.3\bin\i386 instead of R-3.3.3\bin, no extra cmd.exe processes should be spawned and the badly-formed system() should be avoided. __ 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.
[R] quantmod::chart_Series() how to simplify x-axis labels?
Is there a way to easily simplify the x-axis labels for quantmod::chart_Series() https://stackoverflow.com/questions/52910667/quantmodchart-series-how-to-simplify-x-axis-labels [[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.