Re: [R] feed cut() output into goodness-of-fit tests
Andrei - Looking inside the code for cut, it looks like you could retrieve the breaks as follows: getbreaks = function(x,nbreaks){ nb = nbreaks + 1 dx = diff(rx <- range(x,na.rm=TRUE)) seq.int(rx[1] - dx/1000,rx[2] + dx/1000,length.out=nb) } The dx/1000 is what makes cut()'s break different than a simple call to seq(). - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 15 Oct 2010, Andrei Zorine wrote: Hello, My question is assuming I have cut()'ed my sample and look at the table() of it, how can I compute probabilities for the bins? Do I have to parse table's names() to fetch bin endpoints to pass them to p[distr-name] functions? i really don't want to input arguments to PDF functions by hand (nor copy-and-paste way). x.fr <- table(cut(x,10)) x.fr (0.0617,0.549] (0.549,1.04](1.04,1.52](1.52,2.01] (2.01,2.5] 16 28 26 18 6 (2.5,2.99](2.99,3.48](3.48,3.96](3.96,4.45](4.45,4.94] 3 2 0 0 1 names(x.fr) [1] "(0.0617,0.549]" "(0.549,1.04]" "(1.04,1.52]""(1.52,2.01]" [5] "(2.01,2.5]" "(2.5,2.99]" "(2.99,3.48]""(3.48,3.96]" [9] "(3.96,4.45]""(4.45,4.94]" -- Andrei Zorine __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] feed cut() output into goodness-of-fit tests
On Fri, Oct 15, 2010 at 10:22 AM, Andrei Zorine wrote: > Hello, > My question is assuming I have cut()'ed my sample and look at the > table() of it, how can I compute probabilities for the bins? I actually don't know what you mean by this (my own ignorance probably). Do I have > to parse table's names() to fetch bin endpoints For equal-width bins you can use seq(min(x), max(x), by = (max(x) - min(x))/10) HTH, Ista to pass them to > p[distr-name] functions? i really don't want to input arguments to PDF > functions by hand (nor copy-and-paste way). > >> x.fr <- table(cut(x,10)) >> x.fr > > (0.0617,0.549] (0.549,1.04] (1.04,1.52] (1.52,2.01] (2.01,2.5] > 16 28 26 18 6 > (2.5,2.99] (2.99,3.48] (3.48,3.96] (3.96,4.45] (4.45,4.94] > 3 2 0 0 1 > >> names(x.fr) > [1] "(0.0617,0.549]" "(0.549,1.04]" "(1.04,1.52]" "(1.52,2.01]" > [5] "(2.01,2.5]" "(2.5,2.99]" "(2.99,3.48]" "(3.48,3.96]" > [9] "(3.96,4.45]" "(4.45,4.94]" > > > -- > > Andrei Zorine > > __ > R-help@r-project.org mailing list > 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. > -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list 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] feed cut() output into goodness-of-fit tests
Hello, My question is assuming I have cut()'ed my sample and look at the table() of it, how can I compute probabilities for the bins? Do I have to parse table's names() to fetch bin endpoints to pass them to p[distr-name] functions? i really don't want to input arguments to PDF functions by hand (nor copy-and-paste way). > x.fr <- table(cut(x,10)) > x.fr (0.0617,0.549] (0.549,1.04](1.04,1.52](1.52,2.01] (2.01,2.5] 16 28 26 18 6 (2.5,2.99](2.99,3.48](3.48,3.96](3.96,4.45](4.45,4.94] 3 2 0 0 1 > names(x.fr) [1] "(0.0617,0.549]" "(0.549,1.04]" "(1.04,1.52]""(1.52,2.01]" [5] "(2.01,2.5]" "(2.5,2.99]" "(2.99,3.48]""(3.48,3.96]" [9] "(3.96,4.45]""(4.45,4.94]" -- Andrei Zorine __ R-help@r-project.org mailing list 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.