Re: [R] Sum(Random Numbers)=100
Hi, I am afraid there is no other way except using brute force, that is , loop until their sum reaches your expectation. it is easy to figure out this probability by letting their sum to be a new random variable Z and Z = X_1 + \ldots + X_n where X_i ~ Poisson({\lambda}_i) . By calculating their moment generate function we can find the pmf of Z which is a new Poisson random variable with the parameter \sum_{i}{{\lambda}_i}. and Moshe Olshansky's method is also correct except it is based on the conditioning. On 2008-7-8, at 下午1:58, Shubha Vishwanath Karanth wrote: On 2008-7-8, at 下午2:39, Moshe Olshansky wrote: If they are really random you can not expect their sum to be 100. However, it is not difficult to get that given that the sum of n independent Poisson random variables equals N, any individual one has the conditional binomial distribution with size = N and p = 1/n, i.e. P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = k1 then the sum of the rest 49 must equal 100 - k1, so now you generate X2 binomial with size = 100-k1 and p = 1/49; if X2 = k2 then generate X3 binomial with size = 100 -(k1+k2) and p = 1/48, etc. Why do you need this? --- On Tue, 8/7/08, Shubha Vishwanath Karanth <[EMAIL PROTECTED] > wrote: From: Shubha Vishwanath Karanth <[EMAIL PROTECTED]> Subject: [R] Sum(Random Numbers)=100 To: [EMAIL PROTECTED] Received: Tuesday, 8 July, 2008, 3:58 PM Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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. --- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ 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] Survey questions
Farley, Robert wrote: I found and loaded the "survey" package. ?rake and ?postStratify seem promising. Are there other packages/procedures I've missed? Are there online references that an R newbie could use to feel comfortable applying these procedures to a survey? How about a reference discussing the details of designing a "post survey survey" to generate additional weights? There is quite some material on the package homepage at http://faculty.washington.edu/tlumley/survey/ including a page on post-stratification and calibration http://faculty.washington.edu/tlumley/survey/example-poststrat.html Maybe the exemplars of the PEAS project are helpful as well: http://www2.napier.ac.uk/depts/fhls/peas/about.asp HTH, Tobias Thanks in advance, Robert Farley Metro www.Metro.net From: Farley, Robert Sent: Thursday, June 26, 2008 15:48 To: 'r-help@r-project.org' Subject: Survey questions First the R question. I have the results of a rather large survey (thousands of forms, each with dozens of questions) with some existing weights and expansion factors. I wish to add additional weighting factors, based on new information that elements of certain variables should appear in certain proportions. Where should I look in R to develop what is essentially an N-dimensional balancing process. I'd like to develop new weighting factors, without disturbing the existing weightings/expansion. Now the statistics question. Is this appropriate? Where can I find a nearly entry level discussion of the statistical ramifications of this? Is it possible (proper) to re-survey a population to obtain new weights (for previously un-weighted responses) for an original survey? Thanks in advance, Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax:(213)922-2868 www.Metro.net [[alternative HTML version deleted]] __ 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] Sum(Random Numbers)=100
For arbitrary lambda_i it can take years until the sum of 50 such random variables is 100! But if one makes lambda_i = 2, then the probability that the sum of 50 of them equals 100 is about 1/sqrt(2*pi*100), so on average that sequence of 50 numbers must be generated about sqrt(2*pi*100)) ~ 25 times, which is very reasonable. --- On Tue, 8/7/08, Peng Jiang <[EMAIL PROTECTED]> wrote: > From: Peng Jiang <[EMAIL PROTECTED]> > Subject: Re: [R] Sum(Random Numbers)=100 > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED], "Shubha Vishwanath Karanth" <[EMAIL PROTECTED]> > Received: Tuesday, 8 July, 2008, 4:56 PM > Hi, >I am afraid there is no other way except using brute > force, that > is , loop until their sum reaches your expectation. > it is easy to figure out this probability by letting > their sum to be > a new random variable Z and Z = X_1 + \ldots + X_n > where X_i ~ Poisson({\lambda}_i) . By calculating > their moment > generate function we can find the pmf of Z which is > a new Poisson random variable with the parameter > \sum_{i}{{\lambda}_i}. > > and Moshe Olshansky's method is also correct except > it is based on > the conditioning. > On 2008-7-8, at 下午1:58, Shubha Vishwanath Karanth > wrote: > On 2008-7-8, at 下午2:39, Moshe Olshansky wrote: > > > If they are really random you can not expect their sum > to be 100. > > However, it is not difficult to get that given that > the sum of n > > independent Poisson random variables equals N, any > individual one > > has the conditional binomial distribution with size = > N and p = 1/n, > > i.e. > > P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). > > So you can generate X1 binomial with size = 100 and p > = 1/50; if X1 > > = k1 then the sum of the rest 49 must equal 100 - k1, > so now you > > generate X2 binomial with size = 100-k1 and p = 1/49; > if X2 = k2 > > then generate X3 binomial with size = 100 -(k1+k2) and > p = 1/48, etc. > > > > Why do you need this? > > > > > > --- On Tue, 8/7/08, Shubha Vishwanath Karanth > <[EMAIL PROTECTED] > > > wrote: > > > >> From: Shubha Vishwanath Karanth > <[EMAIL PROTECTED]> > >> Subject: [R] Sum(Random Numbers)=100 > >> To: [EMAIL PROTECTED] > >> Received: Tuesday, 8 July, 2008, 3:58 PM > >> Hi R, > >> > >> > >> > >> I need to generate 50 random numbers (preferably > poisson), > >> such that > >> their sum is equal to 100. How do I do this? > >> > >> > >> > >> > >> > >> Thank you, > >> > >> Shubha > >> > >> > >> > >> This e-mail may contain confidential and/or > privileged > >> i...{{dropped:13}} > >> > >> __ > >> 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. > > --- > Peng Jiang 江鹏 ,Ph.D. Candidate > Antai College of Economics & Management > 安泰经济管理学院 > Department of Mathematics > 数学系 > Shanghai Jiaotong University (Minhang Campus) > 800 Dongchuan Road > 200240 Shanghai > P. R. China __ 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] Sum(Random Numbers)=100
what you could (what I suggest) is not technically clean because your draw is not strictly random any more. But if you want to distribute 100 on 50 units with a Poisson-distributed variable x, then your lambda must be 100/50=2. You could then sample Poisson distribution ( rpois(50,2) ), sum over all 50 values and stop as soon as the sum is exactly 100. This may take a while though. And again, this is not strictly random as you are discarding lots of distributions to achieve that. Cheers, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Shubha Vishwanath Karanth Gesendet: Tuesday, July 08, 2008 2:54 AM An: [EMAIL PROTECTED]; [EMAIL PROTECTED] Betreff: Re: [R] Sum(Random Numbers)=100 ...actually I need to allocate certain amount of money (here I mentioned it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being divided among 50 stocks and preferably all are integer allocations(i.e., 5 8 56 12 etc without any decimals)... Thank you, Shubha -Original Message- From: Moshe Olshansky [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 08, 2008 12:09 PM To: [EMAIL PROTECTED]; Shubha Vishwanath Karanth Subject: Re: [R] Sum(Random Numbers)=100 If they are really random you can not expect their sum to be 100. However, it is not difficult to get that given that the sum of n independent Poisson random variables equals N, any individual one has the conditional binomial distribution with size = N and p = 1/n, i.e. P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = k1 then the sum of the rest 49 must equal 100 - k1, so now you generate X2 binomial with size = 100-k1 and p = 1/49; if X2 = k2 then generate X3 binomial with size = 100 -(k1+k2) and p = 1/48, etc. Why do you need this? --- On Tue, 8/7/08, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: > From: Shubha Vishwanath Karanth <[EMAIL PROTECTED]> > Subject: [R] Sum(Random Numbers)=100 > To: [EMAIL PROTECTED] > Received: Tuesday, 8 July, 2008, 3:58 PM Hi R, > > > > I need to generate 50 random numbers (preferably poisson), such that > their sum is equal to 100. How do I do this? > > > > > > Thank you, > > Shubha > > > > This e-mail may contain confidential and/or privileged > i...{{dropped:13}} > > __ > 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] Sum(Random Numbers)=100
sum.x=sum(x) while(sum.x!=100) x=rpois(50,2) I have tried this, but this can really take some time. In fact, I would suggest an similarly "fraudulent" activity, draw 49 values, and set the last nonrandomly to the difference between 100 and the sum of the 49 values if this difference is a.) nonnegative and b.) not too extreme (say more than three lambdas out). This is "as random" as the previous approach, maybe even more. Best, Daniel - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Shubha Vishwanath Karanth Gesendet: Tuesday, July 08, 2008 1:59 AM An: [EMAIL PROTECTED] Betreff: [R] Sum(Random Numbers)=100 Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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] Sum(Random Numbers)=100
For some reason, the while-loop I sent did not work. It was running forever although I don't know why. Anyway, using repeat works fast: repeat{x=rpois(50,2) if(sum(x)==100) break } - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Shubha Vishwanath Karanth Gesendet: Tuesday, July 08, 2008 1:59 AM An: [EMAIL PROTECTED] Betreff: [R] Sum(Random Numbers)=100 Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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] Sum(Random Numbers)=100
Shubha Does table(ceiling(runif(100,0,50))) give you something like you want? Richard. Shubha Vishwanath Karanth wrote: ...actually I need to allocate certain amount of money (here I mentioned it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being divided among 50 stocks and preferably all are integer allocations(i.e., 5 8 56 12 etc without any decimals)... Thank you, Shubha -Original Message- From: Moshe Olshansky [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 08, 2008 12:09 PM To: [EMAIL PROTECTED]; Shubha Vishwanath Karanth Subject: Re: [R] Sum(Random Numbers)=100 If they are really random you can not expect their sum to be 100. However, it is not difficult to get that given that the sum of n independent Poisson random variables equals N, any individual one has the conditional binomial distribution with size = N and p = 1/n, i.e. P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = k1 then the sum of the rest 49 must equal 100 - k1, so now you generate X2 binomial with size = 100-k1 and p = 1/49; if X2 = k2 then generate X3 binomial with size = 100 -(k1+k2) and p = 1/48, etc. Why do you need this? --- On Tue, 8/7/08, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: From: Shubha Vishwanath Karanth <[EMAIL PROTECTED]> Subject: [R] Sum(Random Numbers)=100 To: [EMAIL PROTECTED] Received: Tuesday, 8 July, 2008, 3:58 PM Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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. -- Richard D. Pearson [EMAIL PROTECTED] School of Computer Science,http://www.cs.man.ac.uk/~pearsonr University of Manchester, Tel: +44 161 275 6178 Oxford Road, Mob: +44 7971 221181 Manchester M13 9PL, UK.Fax: +44 161 275 6204 __ 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] Change in behaviour of sd()
Hi I have just upgraded from R2.6.0 to R2.7.1 (running on Windows) and a part of my code that previously ran ok now gives an error. The following is a simple example to demonstrate my problem. > a <- array(c(1,2,3,4,5,6,rep(NA,6)),dim=c(6,2)) > apply(a,2,sd,na.rm=T) In R2.6.0 this gives (which is what I would like) [1] 1.870829 NA In R2.7.1 it gives the following error "Error in var(x, na.rm = na.rm) : no complete element pairs" As my columns are always either all NA or all numbers, I could get around it by replacing the NA's with 0's but if someone could shed some light on why the behaviour has changed in the new version or a better work around it would be much appreciated. I want to keep the columns of NA's because ultimately I am plotting the results with contour and the NA's refer to grid cells not on land where I don't want to have contours. Thanks for your help Fiona _ Fiona Johnson PhD Candidate, UNSW Water Research Centre School of Civil & Environmental Engineering The University of New South Wales, Sydney, NSW, 2052, Australia Email: fiona.johnson (at) student.unsw.edu.au __ 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] How to change labels in a histogram
Hi everyone I am trying to add a percent sign to my labels in a hist() plot. "labels = TRUE" gives me the values, but I don't know how to add the percent sign. I would prefer to annote the plot after drawing it, e.g. using text(), but don't know how to address the positions in a standard histogram. A lattice approach would work too. Best regards, LY -- View this message in context: http://www.nabble.com/How-to-change-labels-in-a-histogram-tp18333955p18333955.html Sent from the R help mailing list archive at Nabble.com. __ 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] Sum(Random Numbers)=100
> x <- rmultinom(1, 100, rep(1/50, 50)) > as.vector(x) [1] 4 0 5 4 2 2 4 4 3 2 4 1 1 1 2 0 0 0 2 1 0 4 3 3 2 4 2 2 2 0 1 1 4 2 2 2 0 1 1 1 2 3 2 2 4 1 [47] 3 1 3 0 > sum(x) [1] 100 Bill Venables CSIRO Laboratories PO Box 120, Cleveland, 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary): +61 7 3826 7304 Mobile: +61 4 8819 4402 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Malter Sent: Tuesday, 8 July 2008 5:32 PM To: 'Shubha Vishwanath Karanth'; [EMAIL PROTECTED] Subject: Re: [R] Sum(Random Numbers)=100 For some reason, the while-loop I sent did not work. It was running forever although I don't know why. Anyway, using repeat works fast: repeat{x=rpois(50,2) if(sum(x)==100) break } - cuncta stricte discussurus - -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von Shubha Vishwanath Karanth Gesendet: Tuesday, July 08, 2008 1:59 AM An: [EMAIL PROTECTED] Betreff: [R] Sum(Random Numbers)=100 Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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. __ 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] Sum(Random Numbers)=100
Richard Pearson wrote: Shubha Does table(ceiling(runif(100,0,50))) give you something like you want? That's a neat(-ish) solution of Moshe's multinomial formulation. More generally, if p is a vector of probabilities you can simulate independent indicators with cut(runif(N), c(0,cumsum(p)) and then multinomials by tabulation. However, it is inefficient for large N, and awkward if you want replicates, which is why we have rmultinom(). In the present case use rmultinom(1, 100, rep(1/50,50)) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] what does this warning mean ?
Hi , dear R experts . I use the package mclust to do some cluster analysis . doing the example that the document provides > faithfulModel <- Mclust( faithful ) > plot( faithfulModel ) I remember in R 2.7.0 I can get several figures using the plot command, but after I update R, using the same statements, after I get the first figure and I press enter as R tells and I get "Warning message:In plot.Mclust(faithfulMclust) : data not supplied". I tried other data set , the warning message still exists . what does it mean? how can i do to avoid it ? is there any resource that I can find solution to specific warning like some IDE(like Xcodes in mac or Eclipse , etc.) does??? thanks in advance. best regards. --- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ 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] How to change labels in a histogram
> I am trying to add a percent sign to my labels in a hist() plot. "labels = > TRUE" gives me the values, but I don't know how to add the percent sign. I > would prefer to annote the plot after drawing it, e.g. using text() This is probably a good starting point: x <- rnorm(100) h <- hist(x) text(h$mids, h$counts+0.5, paste(format(h$counts/sum(h$counts) * 100, digits=2), "%") ) cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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] package segmented problem
Hi, while using package "segmented" (version 0.2-4) by Vita Muggeo to investigate a possible change point (around time = 222) in admissions for a specific medical condition I had the following error message: fit2.seg<-segmented(fit2, seg.Z=~time,psi=222) Error in segmented.lm(fit2, seg.Z = ~time, psi = 222) : (Some) estimated psi out of its range "fit2" is a simple lm fit to time. I have used this package successfully for related analyses without this error. Having tried many alternatives to "psi=222" but with the same error, I wondered if anyone can assist? Many thanks, Alan Kelly __ 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] Sum(Random Numbers)=100
So really you want random portfolios. While your specification may satisfy the demands of your current application, in general generating random portfolios is more complicated. There can be a large number of constraints required to make the portfolios conform to a realistic situation. Two example constraints are that each position should have no more than 5% weight, and the volatility should be no more than 15%. More on random portfolios can be found at http://www.burns-stat.com/pages/Finance/random_portfolios.html Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Shubha Vishwanath Karanth wrote: ...actually I need to allocate certain amount of money (here I mentioned it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being divided among 50 stocks and preferably all are integer allocations(i.e., 5 8 56 12 etc without any decimals)... Thank you, Shubha -Original Message- From: Moshe Olshansky [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 08, 2008 12:09 PM To: [EMAIL PROTECTED]; Shubha Vishwanath Karanth Subject: Re: [R] Sum(Random Numbers)=100 If they are really random you can not expect their sum to be 100. However, it is not difficult to get that given that the sum of n independent Poisson random variables equals N, any individual one has the conditional binomial distribution with size = N and p = 1/n, i.e. P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = k1 then the sum of the rest 49 must equal 100 - k1, so now you generate X2 binomial with size = 100-k1 and p = 1/49; if X2 = k2 then generate X3 binomial with size = 100 -(k1+k2) and p = 1/48, etc. Why do you need this? --- On Tue, 8/7/08, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: From: Shubha Vishwanath Karanth <[EMAIL PROTECTED]> Subject: [R] Sum(Random Numbers)=100 To: [EMAIL PROTECTED] Received: Tuesday, 8 July, 2008, 3:58 PM Hi R, I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this? Thank you, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] Can R do this ?
On Tue, Jul 8, 2008 at 6:59 AM, Daren Tan <[EMAIL PROTECTED]> wrote: > > I have a folder full of pngs and jpgs, and would like to consolidate them > into a pdf with appropriate title and labels. Can this be done via R ? I do not know whether R can do that. However, you can accomplish that easily with LyX or with OpenOffice. Paul __ 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] Can R do this ?
If this is about more than a handful files, then it is really painful to do it with OpenOffice.org or LyX, I guess. You can use imagemagick, this is fairly standard on Linux. Then it is something like this, assuming you have bash: for f in *.png; do convert $f ${f%png}pdf; done for f in *.jpg; do convert $f ${f%jpg}pdf; done Of course this does not vectorise the files Gabor On Tue, Jul 08, 2008 at 10:05:59AM +0100, Paul Smith wrote: > On Tue, Jul 8, 2008 at 6:59 AM, Daren Tan <[EMAIL PROTECTED]> wrote: > > > > I have a folder full of pngs and jpgs, and would like to consolidate them > > into a pdf with appropriate title and labels. Can this be done via R ? > > I do not know whether R can do that. However, you can accomplish that > easily with LyX or with OpenOffice. > > Paul > > __ > 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. -- Csardi Gabor <[EMAIL PROTECTED]>UNIL DGM __ 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] Can R do this ?
Hi Daren, Can R (out)do Emacs? I think you just need to ?Sweave a little. Mark. Daren Tan wrote: > > > I have a folder full of pngs and jpgs, and would like to consolidate them > into a pdf with appropriate title and labels. Can this be done via R ? > _ > Easily publish your photos to your Spaces with Photo Gallery. > > [[alternative HTML version deleted]] > > __ > 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. > > -- View this message in context: http://www.nabble.com/Can-R-do-this---tp18332407p18335253.html Sent from the R help mailing list archive at Nabble.com. __ 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] Can R do this ?
Ooops, please ignore my previous mail, I did not read the question carefully enough. Gabor On Tue, Jul 08, 2008 at 02:27:51AM -0700, Mark Difford wrote: > > Hi Daren, > > Can R (out)do Emacs? I think you just need to ?Sweave a little. > > Mark. > > > Daren Tan wrote: > > > > > > I have a folder full of pngs and jpgs, and would like to consolidate them > > into a pdf with appropriate title and labels. Can this be done via R ? > > _ > > Easily publish your photos to your Spaces with Photo Gallery. > > > > [[alternative HTML version deleted]] > > > > __ > > 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. > > > > > > -- > View this message in context: > http://www.nabble.com/Can-R-do-this---tp18332407p18335253.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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. -- Csardi Gabor <[EMAIL PROTECTED]>UNIL DGM __ 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] attributing values to dataframe positions following eval
Hi everybody, I've been looking around, but can't seem to find the answer. I get a list of names (which vary, so I never know them in advance), and transform them into variables, each of which is a dataframe, using assign: polyList <- c("rs123", "rs124", "rs555", "rs000") numPoly <- length(polyList) for (k in 1:numPoly) { assign(polyList[k], data.frame(matrix(NA, ncol=3, nrow=3))) } polyList <- lapply(polyList, as.name) I can see the resulting dataframe associated to rs123 (for example) using: > eval(polyList[[1]]) X1 X2 X3 1 NA NA NA 2 NA NA NA 3 NA NA NA And see the value in row 1, column 1 with: > eval(polyList[[1]])[1,1] [1] NA Now, I want to change the values in the dataframe... that's what I can't manage to do: > eval(polyList[[1]])[1,1] <- 5 Error in eval(polyList[[1]])[1, 1] <- 5 : could not find function "eval<-" Anybody has an idea on how to do that? Thank you, Stephane PS: yes, I'm aware that using arrays and dataframes instead of going through the creation of variables may be more practical, but the context is much more complex than the presented example (and in that specific case, having these variables is a requirement) -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a compa ny registered in England with number 2742969, whose registered office is 2 15 Euston Road, London, NW1 2BE. [[alternative HTML version deleted]] __ 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] Problems with lm()
Hi Daniel, Thanks for the info., I read the wiki link and it made sense Chibisi On Tue, Jul 8, 2008 at 1:42 AM, Daniel Malter <[EMAIL PROTECTED]> wrote: > If that is so, i.e. x1=-x2, then they do not convey different meaning and > cannot be estimated. Think about it that way you leave the house 8 hours > after midnight. This is identical to saying that you leave the house 16 > hours before midnight. This conveys the exact (!) same information and > neither measure is better than the other. Therefore you do not gain > anything > by including both. You need variation in the measures so that both can be > meaningfully estimates. Be aware though that even if there is variation, > but > when this variation is marginal, then your model may suffer from > "multicollinearity" and you may find "weird" results (e.g. unexpected, > "crazy" coefficients; "wrong" signs on your coefficients; insignificance > when you would expect significance). Then excluding one of the regressors > may still be necessary because despite their variation (i.e. x1 is slightly > different from -x2), the difference in information convey by them is > marginal. Multicollinearity violates the model assumptions of OLS. > > http://en.wikipedia.org/wiki/Multicollinearity > > Cheers, > Daniel > > - > cuncta stricte discussurus > - > > -Ursprüngliche Nachricht- > Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im > Auftrag von Chibisi Chima-Okereke > Gesendet: Monday, July 07, 2008 8:09 PM > An: r-help@r-project.org > Betreff: [R] Problems with lm() > > Dear all, > > I am trying to fit a multiple linear regression model to a table of data. > My > data.frame is like this ... > > fit.data <- data.frame(y, x1, x2, x3, x4, x5, x6), then I use the linea > regression command ... > > lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6, data = fit.data) > > however, for some tables the data in column x1 is equal to -x2, so I get NA > values for both coefficients of x1 and x2. I need to have real fitted > coefficients for all the parameters or the physical meaning of the > parameters is lost. Is there any way of forcing R to fit all the > parameters? > I have seen the contrast option but I don't really understand it (I am not > a > statistician) so I would be greatful if anyone could explain that. > > Kind Regards > > Chibisi > > [[alternative HTML version deleted]] > > __ > 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. > > [[alternative HTML version deleted]] __ 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] Constrained optimization
i have a function like 1+sin(a+bx) where -pi/2<=a+bx<=pi/2 i made a progrom using constrOptim() function but it is not giving good result. it depends on the initial value. but when i am doing simulation it is impossible of find the best initial value for every step. also i am not exactly sure how to input the restriction though i have read the help file of the function. here x is a set of values. would u please send me some instruction to find the best result from the obtimization. Kanak Choudhury sutdent of Jahangirnagar university Bangladesh mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ 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] forecast & xreg
Dear all, I am fitting an arimax (arima with some extra explanatory variables) model to a time series. Say, I have a Y (dependent variable) and an X (explanatory). Y is 100 observations (time series) and X is 100 + 20 (20 to use for the forecast horizon). I can not make xreg work with the forecast function for an arima fit. The "predict" function seems to be working but the "forecast" returns > Error in predict.Arima(object, n.ahead = h) : 'xreg' and 'newxreg' have different numbers of columns... Xreg is a time series of explanatory variables of the same length of the dependent and newxreg should be as long as the forecast horizon (same number of explanatory variables). Is this right? Or should xreg be: X[1:100] and newxreg X[101:20], i.e. use different segments of the same regressor ??? In other words, can/should newxreg and xreg be different variables as long as their lengths are according to the forecast horizon specs? This doesn't seem to work... Any scripts/demos would be extremely welcome. Thanks, COstas P Think before you print. Disclaimer: This e-mail is confidential. If you are not the intended recipient, you should not copy it, re-transmit it, use it or disclose its contents, but should return it to the sender immediately and delete the copy from your system. EFG Eurobank Ergasias S.A. is not responsible for, nor endorses, any opinion, recommendation, conclusion, solicitation, offer or agreement or any information contained in this communication. EFG Eurobank Ergasias S.A. cannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. If you suspect that the message may have been intercepted or amended, please call the sender. [[alternative HTML version deleted]] __ 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] Change legend in the 'hydrogeo' package
At first sorry for the possibly dumb question of a newbie. I am using the hydrogeo package to visualize approx. 300 data within the Piper-Hill diagrams. The package is using a dataframe with 6 columns, first of them is containing the row.names, next four with the data itself. The last column contains "WaterTypes" dividing data to several categories. The diagram is created by the piper function, assigning different symbols following the row.names (I don't need id, however I can assign one symbol for the whole dataset using pch ) and assigmning colours following WaterTypes. Untill now it's working very well, what I need however is to change the legend, as it is showing all the 300 rows, even I assigned only one symbol. For me it is more appropriate to show the categories from the "WaterTypes" columns assigned to the colours. Could somebody give me a hint how to change the code to give me an appropriate result? The answer is probably in the help assigned to the "legend" of the graphics package, but it's quite unclear to me. Many thanks in advance Tomas The piece of code from the hydrogeo package creating the legend is here: ylegend <- X plotlegend <- function(dd, X, ...) { xid <- c(X + p) yid <- c(ylegend - (X/30) * 1:nrow(dd)) text(xid, yid, labels = row.names(dd), vfont = c("serif", "plain"), cex = 0.7) if (is.character(dd$pch)) { text(xid - (X/15), yid, labels = c(1:nrow(dd)), vfont = c("serif", "plain"), cex = 0.7) } else { points(rep(xid - (X/15), length(yid)), yid, pch = dd$pch, col = dd$col) } return(min(yid)) } __ 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] one-site competition data // curve fitting
On Mon, Jul 07, 2008 at 11:15:57AM +0200, Thiemo Schreiber wrote: > Hello everyone, > > I have biological data from a competition experiment where a free ligand is > titrated against the binding of a protein. > > Now, I would like to fit a standard on-site binding curve to this data in > order to obtain the IC50 and Kd values. > Unfortunately I have not been able to find a package/function which allows > such a fitting and calculates the results. > > > Does anyone know if there is a suitable package available and which function > to apply? > > Thanks a lot. > > Cheers > Thiemo Schreiber > [[alternative HTML version deleted]] this is probably what you are looking for: let x = vector of free ligand concenctrations y = vector of correspondng spec. protein bindings be defined in the R workspace. than use res <- nls( y ~ (x * Bmax) / (x + Kd), start = list(Bmax=, Kd=)) (providing some sensible start values for the free parameters , of course) cf. `nls' manpage for details __ 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] Histogram with colors according to factor
Given a data frame with a continuous variable and a factor. I would like to generate a histogram of the continuous variable, where each bar is filled with different colors according to the percentage of factor values falling into this region of the continuous variable. I looked into packages like 'lattice' and 'ggplot2'. Searching R-help revealed that 'histogram' is spelled 'histogramm' in almost 2% of the time. I now know how to color whole bars, but did not find a solution for this specific kind of visualization. Many thanks in advance, Hans Werner Borchers Hans W. Borchers ABB Corporate Research - Hans W. Borchers ABB Corporate Research Germany -- View this message in context: http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18336930.html Sent from the R help mailing list archive at Nabble.com. __ 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] Need ideas on how to show spikes in my data and how to code it in R
Hi! Sorry for bothering you again but I can't seem to get it right. When i multiply the density with the number of observations it seems to be way to high, The reference curve is drawn at maybe 20 times higher frequency count than it should be. I use the following code where "weights$Weight" is my weights data and "reference" is my reference dataset. # calucate the right breakpoints breakpoints <- seq(min(weights), max(weights), by=binwidth) #scale density dens <- density(reference) dens$y <- dens$y * (length(weights$Weight)) #graph it hist(weights$Weight, freq=TRUE, breaks=breakpoints, main=wfiles[i]) lines(dens) Any ideas are greatly appreciated. /Thomas On Fri, Jun 27, 2008 at 10:54 PM, Daniel Folkinshteyn <[EMAIL PROTECTED]> wrote: > if you want the "frequency" scale rather than density scale, then leave hist > as is (by default it uses the frequency scale), and rescale the density by > multiplying it by the appropriate NOBS. > > on 06/27/2008 01:16 PM Thomas Frööjd said the following: >> >> Hi >> >> Thank you very much for taking time to answer. >> >> The solution of using hist(data) for the main dataset and adding >> lines(density(refdata)) for the reference data seem to work great. I >> forgot to mention one thing however, I need to have frequency on the y >> azis instead of density as now. >> >> I know this is not a "real" histogram but since the audience is not >> very statistically experienced I would prefer to do it this way. >> Anyone have an idea? >> >> Thanks again for your help. >> >> Thomas Fröjd >> >> On Wed, Jun 25, 2008 at 6:16 PM, Daniel Folkinshteyn <[EMAIL PROTECTED]> >> wrote: I don't understand this. Why not just get hist() to plot on the density scale, thereby making its output commensurate with the output of density()? The hist() function will plot on the density scale if you ask it to. Set freq=FALSE (or prob=TRUE) in the call to hist. >>> >>> ehrm... because i didn't realize that option existed :) that certainly is >>> easier than manually scaling hist output by NOBS - thanks for the tip! >>> >> > > __ 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] shading an area in a edf
Hi, I've got the following edf: *** x = c(1.6,1.8,2.4,2.7,2.9,3.3,3.4,3.4,4,5.2) F2.5 <- ecdf(x) plot(F2.5, verticals= TRUE, do.p = TRUE, lwd=3, ylab = "", xlab = "", xlim = c(1,5.5)) abline(h= (0:5)*0.2) #mean abline(v=mean(x), lwd=2) mtext(text=expression(bar(x) == 3.07), side=1, adj=0.462, padj=3, cex=1) *** Now I would like to shade the two areas: http://www.nabble.com/file/p18334136/ecdf.gif Is it possible to do this without too much effort? Thanks for any suggestion Tobias -- View this message in context: http://www.nabble.com/shading-an-area-in-a-edf-tp18334136p18334136.html Sent from the R help mailing list archive at Nabble.com. __ 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] Multiple Plots and y Axis Labels
Hi, I'm using the mfrow parameter in par() to plot several timeseries with a common time x axis as a sequence of plots one below the other. I reduced the top and bottom margins to zero to get a very nice looking plot but sometimes the labels on the y axes from one plot overlap with the y axis labels on the plot above or below. Any ideas how I can prevent this without losing the look of the plots? ie I don't want gaps between the plots. Below is some example code. rain<-ts(scan("rain.csv"),start=1996, frequency=12) fire<-ts(scan("fire.csv"),start=1996,frequency=12) op<-par(mar=c(0,0,0,0), oma=c(2,5,3,1), mfrow=c(2,1)) xl <- c(1996,2008) plot(rain, xlim=xl, axes=F, col="blue"); axis(2, las=1); axis(1, labels=F); box(); abline(v=1996:2008, lty=3) mtext("Rainfall", side=2, line=line1, cex=mtex); mtext(expression(paste("mm ",month^{-1})), side=2, line=line2, cex=mtex); plot(fire*100, xlim=xl, axes=F, col="red"); axis(2, las=1); axis(1, labels=F); box(); abline(v=1996:2008, lty=3) mtext("Fire", side=2, line=line1, cex=mtex); mtext(expression(paste("% Area Burned ",month^{-1})), side=2, line=line2, cex=mtex); par(op) mtext(plottitle, line=3, font=2, cex=1.5) -- View this message in context: http://www.nabble.com/Multiple-Plots-and-y-Axis-Labels-tp18337207p18337207.html Sent from the R help mailing list archive at Nabble.com. __ 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] Need ideas on how to show spikes in my data and how to code it in R
Two thoughts: i) If you have a narrow distribution, the density can be higher than 1. The area comes out at 1 for density, and n for the frequency. ii) hist() will not show the same frequencies as density() unless hist has unit bin sizes. density*length is showing number per unit change in Weight; hist shows number per bin width. Try plotting a histogram first, then plot the density on top of that. If they disagree >>> "Thomas Fröjd" <[EMAIL PROTECTED]> 07/08/08 12:29 PM >>> Hi! Sorry for bothering you again but I can't seem to get it right. When i multiply the density with the number of observations it seems to be way to high, The reference curve is drawn at maybe 20 times higher frequency count than it should be. I use the following code where "weights$Weight" is my weights data and "reference" is my reference dataset. # calucate the right breakpoints breakpoints <- seq(min(weights), max(weights), by=binwidth) #scale density dens <- density(reference) dens$y <- dens$y * (length(weights$Weight)) #graph it hist(weights$Weight, freq=TRUE, breaks=breakpoints, main=wfiles[i]) lines(dens) Any ideas are greatly appreciated. /Thomas On Fri, Jun 27, 2008 at 10:54 PM, Daniel Folkinshteyn <[EMAIL PROTECTED]> wrote: > if you want the "frequency" scale rather than density scale, then leave hist > as is (by default it uses the frequency scale), and rescale the density by > multiplying it by the appropriate NOBS. > > on 06/27/2008 01:16 PM Thomas Frööjd said the following: >> >> Hi >> >> Thank you very much for taking time to answer. >> >> The solution of using hist(data) for the main dataset and adding >> lines(density(refdata)) for the reference data seem to work great. I >> forgot to mention one thing however, I need to have frequency on the y >> azis instead of density as now. >> >> I know this is not a "real" histogram but since the audience is not >> very statistically experienced I would prefer to do it this way. >> Anyone have an idea? >> >> Thanks again for your help. >> >> Thomas Fröjd >> >> On Wed, Jun 25, 2008 at 6:16 PM, Daniel Folkinshteyn <[EMAIL PROTECTED]> >> wrote: I don't understand this. Why not just get hist() to plot on the density scale, thereby making its output commensurate with the output of density()? The hist() function will plot on the density scale if you ask it to. Set freq=FALSE (or prob=TRUE) in the call to hist. >>> >>> ehrm... because i didn't realize that option existed :) that certainly is >>> easier than manually scaling hist output by NOBS - thanks for the tip! >>> >> > > __ 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. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Manipulate Data (with regular expressions)
Dear Everyone, I try to automatically manipulate the data of a variable (class = factor) like x 220 220a 221 221b B221 Into two variables (class = numeric) like x y 220 0 220 1 221 0 221 1 221 1 y has to carry the information about the class (number or string) of the former x-Variable. I could do it by hand like x[x == "220a"] <- 220 y[x == "220a"] <- 1 but x has way to many expressions. So I wondered if I could use a regular expression like OR ANY OTHER WAY x[x == [0-9]{3}a] <- regular expression y[x == [0-9]{3}] <- 1 Thanks a lot [[alternative HTML version deleted]] __ 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] Histogram with colors according to factor
Is this what you want? dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y = gl(3, 100, labels = LETTERS[1:3])) ggplot(dataset, aes(x = x, fill = y)) + geom_histogram() ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "dodge") HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Hans W. Borchers Verzonden: dinsdag 8 juli 2008 13:23 Aan: r-help@r-project.org Onderwerp: [R] Histogram with colors according to factor Given a data frame with a continuous variable and a factor. I would like to generate a histogram of the continuous variable, where each bar is filled with different colors according to the percentage of factor values falling into this region of the continuous variable. I looked into packages like 'lattice' and 'ggplot2'. Searching R-help revealed that 'histogram' is spelled 'histogramm' in almost 2% of the time. I now know how to color whole bars, but did not find a solution for this specific kind of visualization. Many thanks in advance, Hans Werner Borchers Hans W. Borchers ABB Corporate Research - Hans W. Borchers ABB Corporate Research Germany -- View this message in context: http://www.nabble.com/Histogram-with-colors-according-to-factor-tp183369 30p18336930.html Sent from the R help mailing list archive at Nabble.com. __ 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] How to change labels in a histogram
>>> Lord Yo <[EMAIL PROTECTED]> 07/08/08 9:00 AM >>> >I am trying to add a percent sign to my labels in a hist() plot. ?hist says "labels: logical or character. " This should be a clue; labels could be a character vector. Try x<-rlnorm(128, 1) h<-hist(x, plot=F) plot(h, labels=paste(round(100*h$counts/sum(h$counts),1),"%",sep="")) Steve E *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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 with eigenvectors
Hi everybody, I have some problems with the function eigen. I have a square matrix and I want to calculate the eigenvalues and eigenvectors. I apply the function eigen and I get it, however when I solve the same problem in Statistica software, I realise that some eigenvectors are the opposite. How can I get the same values? Thanks in advance [[alternative HTML version deleted]] __ 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] Sum(Random Numbers)=100
Hi Peng, Does this help? sum(diff(c(0,sort(sample(seq(1,99,1),50,replace=T)),100))) Regards Alex -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peng Jiang Sent: July 8, 2008 3:57 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: [R] Sum(Random Numbers)=100 Hi, I am afraid there is no other way except using brute force, that is , loop until their sum reaches your expectation. it is easy to figure out this probability by letting their sum to be a new random variable Z and Z = X_1 + \ldots + X_n where X_i ~ Poisson({\lambda}_i) . By calculating their moment generate function we can find the pmf of Z which is a new Poisson random variable with the parameter \sum_{i}{{\lambda}_i}. and Moshe Olshansky's method is also correct except it is based on the conditioning. On 2008-7-8, at 下午1:58, Shubha Vishwanath Karanth wrote: On 2008-7-8, at 下午2:39, Moshe Olshansky wrote: > If they are really random you can not expect their sum to be 100. > However, it is not difficult to get that given that the sum of n > independent Poisson random variables equals N, any individual one has > the conditional binomial distribution with size = N and p = 1/n, i.e. > P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k). > So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = > k1 then the sum of the rest 49 must equal 100 - k1, so now you > generate X2 binomial with size = 100-k1 and p = 1/49; if X2 = k2 then > generate X3 binomial with size = 100 -(k1+k2) and p = 1/48, etc. > > Why do you need this? > > > --- On Tue, 8/7/08, Shubha Vishwanath Karanth > <[EMAIL PROTECTED] > > wrote: > >> From: Shubha Vishwanath Karanth <[EMAIL PROTECTED]> >> Subject: [R] Sum(Random Numbers)=100 >> To: [EMAIL PROTECTED] >> Received: Tuesday, 8 July, 2008, 3:58 PM Hi R, >> >> >> >> I need to generate 50 random numbers (preferably poisson), >> such that >> their sum is equal to 100. How do I do this? >> >> >> >> >> >> Thank you, >> >> Shubha >> >> >> >> This e-mail may contain confidential and/or privileged >> i...{{dropped:13}} >> >> __ >> 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. --- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ 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.
[R] RES: Sum(Random Numbers)=100
One of possible solutions is: generate all the numbers. num <- rpois(...) num <- round(num/sum(num)*100,0) sum(num) I don't know if it is the best solution, but is one! Leandro Marino -Mensagem original- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] nome de Peter Dalgaard Enviada em: terça-feira, 8 de julho de 2008 05:12 Para: Richard Pearson Cc: [EMAIL PROTECTED] Assunto: Re: [R] Sum(Random Numbers)=100 Richard Pearson wrote: > Shubha > > Does table(ceiling(runif(100,0,50))) give you something like you want? That's a neat(-ish) solution of Moshe's multinomial formulation. More generally, if p is a vector of probabilities you can simulate independent indicators with cut(runif(N), c(0,cumsum(p)) and then multinomials by tabulation. However, it is inefficient for large N, and awkward if you want replicates, which is why we have rmultinom(). In the present case use rmultinom(1, 100, rep(1/50,50)) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] Histogram with colors according to factor
No; thanks for your try, but this is not what I want. Here each bar has one single color. I would like to render each bar with several colors according to the distribution of a factor. I now learned that this is called "stacked histogram" (damned Excel). In the following entry https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html Deepayan Sarkar has provided a solution though he doubts its value. Still, I find "stacked histograms" a vuable tool during exploratory data analysis. Hans Werner Is this what you want? dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y = gl(3, 100, labels = LETTERS[1:3])) ggplot(dataset, aes(x = x, fill = y)) + geom_histogram() ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "dodge") HTH, Thierry - Hans W. Borchers ABB Corporate Research Germany -- View this message in context: http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18337935.html Sent from the R help mailing list archive at Nabble.com. __ 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] Help with eigenvectors
Francisco Javier Santos Alamillos ujaen.es> writes: > > Hi everybody, > > I have some problems with the function eigen. I have a square matrix and I > want to calculate the eigenvalues and eigenvectors. I apply the function > eigen and I get it, however when I solve the same problem in Statistica > software, I realise that some eigenvectors are the opposite. How can I get > the same values? > > Thanks in advance > Multiply by -1 :-) Seriously, though, the eigenvectors can be multiplied by any constant (if L.M = aL, then (cL).M = a(cL)). (They are usually scaled to have norm 1, i.e. L.L=1.) If you are trying to match something from a previous problem, you can check the sign of one particular variable and adjust the eigenvector appropriately. Ben Bolker __ 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] Histogram with colors according to factor
After reading your question again I came up with these plots. dataset <- data.frame(x = c(rnorm(1000), rnorm(200, mean = 1)), y = gl(2, 100, labels = LETTERS[1:2])) ggplot(dataset, aes(x = x, group = y)) + stat_bin(aes(fill = ..count..), width = 0.2) + scale_fill_gradient(low = "red", high = "green") ggplot(dataset, aes(x = x)) + stat_bin(aes(fill = ..ncount..), width = 0.2) + scale_fill_gradient(low = "red", high = "green") + facet_grid(. ~ y) ggplot(dataset, aes(x = x)) + stat_bin(aes(fill = ..count..), width = 0.2) + scale_fill_gradient(low = "red", high = "green") + facet_grid(. ~ y) HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Hans W. Borchers Verzonden: dinsdag 8 juli 2008 14:23 Aan: r-help@r-project.org Onderwerp: Re: [R] Histogram with colors according to factor No; thanks for your try, but this is not what I want. Here each bar has one single color. I would like to render each bar with several colors according to the distribution of a factor. I now learned that this is called "stacked histogram" (damned Excel). In the following entry https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html Deepayan Sarkar has provided a solution though he doubts its value. Still, I find "stacked histograms" a vuable tool during exploratory data analysis. Hans Werner Is this what you want? dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y = gl(3, 100, labels = LETTERS[1:3])) ggplot(dataset, aes(x = x, fill = y)) + geom_histogram() ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "dodge") HTH, Thierry - Hans W. Borchers ABB Corporate Research Germany -- View this message in context: http://www.nabble.com/Histogram-with-colors-according-to-factor-tp183369 30p18337935.html Sent from the R help mailing list archive at Nabble.com. __ 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] one-site competition data // curve fitting
Check out the drc package. On Mon, Jul 7, 2008 at 5:15 AM, Thiemo Schreiber <[EMAIL PROTECTED]> wrote: > Hello everyone, > > I have biological data from a competition experiment where a free ligand is > titrated against the binding of a protein. > > Now, I would like to fit a standard on-site binding curve to this data in > order to obtain the IC50 and Kd values. > Unfortunately I have not been able to find a package/function which allows > such a fitting and calculates the results. > > > Does anyone know if there is a suitable package available and which function > to apply? > > Thanks a lot. > > Cheers > Thiemo Schreiber >[[alternative HTML version deleted]] > > __ > 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] one-site competition data // curve fitting
Joerg van den Hoff fzd.de> writes: > > > res <- nls( y ~ (x * Bmax) / (x + Kd), start = list(Bmax=, Kd=)) > > (providing some sensible start values for the free parameters , of course) > > cf. `nls' manpage for details There are also "self-starting" models -- SSmicmen I think? Maybe in nlme package? Ben Bolker __ 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 for xvalid with external data
Hi, as usual I have a problem with R functions! I formulated a geostatistical model with geoR. I decided to include some covariates in my model, and I estimated all the parameters (linear model and covariance function parameters) by the likfit function as follows: mod1<-likfit(geodata, ini=varfitmodel, trend=~cov1 +cov2, lambda=0.5, cov.model="matern",kappa=0.5) Once I obtained my best model, I'd like to validate it using an external dataset by using the function xvalid. First of all, I transformed the external dataset in a geodata object, as usual, named "validation_data" ,where also covariates were included. Then I tried the following syntax: Validation<-xvalid(geodata, model=mod1, locations.xvalid=validation_data$coords, data.xvalid= validation_data$data) Bur R says: Trend elements not found. My question is: how can I specify the trend structure within the xvalid function? Thank a lot [[alternative HTML version deleted]] __ 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] about EM algorithm
Hi, dear R experts . is there any package contain an universal EM procedure, that is , for arbitrary d.f. , not just the one in mclust . thanks in advance best regards --- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ 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] Specific question on LDheatmap
Dear R-friends, I am stuck making an LD plot of a small genotype set: An exert of my data (genotypes) >tempped.exert V27/V28 V33/V34 V39/V40 V41/V42 1 B/B B/B A/A B/B 2 B/A B/B A/B B/B 3 B/B B/B A/A B/B 4 B/A B/A A/B B/A 5 B/B B/B A/A B/B The command: >LDheatmap(tempped.exert) Gives me the desired LD map of the first two columns only. How do I make it to take all 4 SNP's/colomns? Your help is highly appreciated, Thanks, Marco __ 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] Histogram with colors according to factor
> Given a data frame with a continuous variable and a factor. I would like to > generate a histogram of the continuous variable, where each bar is filled > with different colors according to the percentage of factor values falling > into this region of the continuous variable. How exactly do you want the bar coloured? I can see that this might possibly work if the factor has only two levels, but how is a colour supposed to encode the a categorical distribution? Or do you mean: dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y = gl(3, 100, labels = LETTERS[1:3])) ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position = "fill") Hadley -- http://had.co.nz/ __ 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] attributing values to dataframe positions following eval
Does not just polyList[[1]])[1, 1] <- 5 work? --- On Tue, 7/8/08, Stephane Bourgeois <[EMAIL PROTECTED]> wrote: > From: Stephane Bourgeois <[EMAIL PROTECTED]> > Subject: [R] attributing values to dataframe positions following eval > To: r-help@r-project.org > Received: Tuesday, July 8, 2008, 5:40 AM > Hi everybody, > > > > I've been looking around, but can't seem to find > the answer. > > > > I get a list of names (which vary, so I never know them in > advance), and > transform them into variables, each of which is a > dataframe, using > assign: > > > > polyList <- c("rs123", "rs124", > "rs555", "rs000") > > numPoly <- length(polyList) > > > > for (k in 1:numPoly) { > > assign(polyList[k], data.frame(matrix(NA, ncol=3, > nrow=3))) > > } > > > > polyList <- lapply(polyList, as.name) > > > > I can see the resulting dataframe associated to rs123 (for > example) > using: > > > > > eval(polyList[[1]]) > > X1 X2 X3 > > 1 NA NA NA > > 2 NA NA NA > > 3 NA NA NA > > > > And see the value in row 1, column 1 with: > > > > > eval(polyList[[1]])[1,1] > > [1] NA > > > > Now, I want to change the values in the dataframe... > that's what I can't > manage to do: > > > > > eval(polyList[[1]])[1,1] <- 5 > > Error in eval(polyList[[1]])[1, 1] <- 5 : > > could not find function "eval<-" > > > > Anybody has an idea on how to do that? > > > > Thank you, > > > > Stephane > > > > PS: yes, I'm aware that using arrays and dataframes > instead of going > through the creation of variables may be more practical, > but the context > is much more complex than the presented example (and in > that specific > case, having these variables is a requirement) > > > > > > > -- > The Wellcome Trust Sanger Institute is operated by Genome > Research > > Limited, a charity registered in England with number > 1021457 and a > compa > ny registered in England with number 2742969, whose > registered > office is 2 > 15 Euston Road, London, NW1 2BE. > > > > [[alternative HTML version deleted]] > > __ > 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] about EM algorithm
I don't think there can be. The EM algorithm isn't really an algorithm -- it's an outline for an algorithm. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Peng Jiang wrote: Hi, dear R experts . is there any package contain an universal EM procedure, that is , for arbitrary d.f. , not just the one in mclust . thanks in advance best regards --- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ 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.
[R] R package
Hello, I have tried to create a package, and I have got it. I checked the files and I built the package. Nevertheless, I want a .pdf file with the package's documentation. Anyone know what I have to do? Thanks in advance, Sergi Martínez [[alternative HTML version deleted]] __ 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] Manipulate Data (with regular expressions)
Check out sedit() in the Hmisc package Cheers! --- On Tue, 7/8/08, Kunzler, Andreas <[EMAIL PROTECTED]> wrote: > From: Kunzler, Andreas <[EMAIL PROTECTED]> > Subject: [R] Manipulate Data (with regular expressions) > To: r-help@r-project.org > Date: Tuesday, July 8, 2008, 7:11 AM > Dear Everyone, > > > > I try to automatically manipulate the data of a variable > (class = > factor) like > > > > x > > 220 > > 220a > > 221 > > 221b > > B221 > > > > Into two variables (class = numeric) like > > > > x y > > 220 0 > > 220 1 > > 221 0 > > 221 1 > > 221 1 > > > > y has to carry the information about the class (number or > string) of the > former x-Variable. > > > > I could do it by hand like > > > > x[x == "220a"] <- 220 > > y[x == "220a"] <- 1 > > > > but x has way to many expressions. > > > > So I wondered if I could use a regular expression like OR > ANY OTHER WAY > > > > x[x == [0-9]{3}a] <- regular expression > > y[x == [0-9]{3}] <- 1 > > > > > > Thanks a lot > > > > > [[alternative HTML version deleted]] > > __ > 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] Manipulate Data (with regular expressions)
Try this: x <- factor(c("220", "220a", "221", "221b", "B221")) pat <- "[^0-9]+" # match non-digits nums <- as.numeric(gsub(pat, "", x)) has.lets <- as.numeric(regexpr(pat, x) > 0) On Tue, Jul 8, 2008 at 7:11 AM, Kunzler, Andreas <[EMAIL PROTECTED]> wrote: > Dear Everyone, > > > > I try to automatically manipulate the data of a variable (class = > factor) like > > > > x > > 220 > > 220a > > 221 > > 221b > > B221 > > > > Into two variables (class = numeric) like > > > > x y > > 220 0 > > 220 1 > > 221 0 > > 221 1 > > 221 1 > > > > y has to carry the information about the class (number or string) of the > former x-Variable. > > > > I could do it by hand like > > > > x[x == "220a"] <- 220 > > y[x == "220a"] <- 1 > > > > but x has way to many expressions. > > > > So I wondered if I could use a regular expression like OR ANY OTHER WAY > > > > x[x == [0-9]{3}a] <- regular expression > > y[x == [0-9]{3}] <- 1 > > > > > > Thanks a lot > > > > >[[alternative HTML version deleted]] > > __ > 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] R package
On 7/8/2008 10:53 AM, Sergi M.Garrido wrote: Hello, I have tried to create a package, and I have got it. I checked the files and I built the package. Nevertheless, I want a .pdf file with the package's documentation. Anyone know what I have to do? In a shell in Windows, R CMD Rd2dvi.sh --pdf pkgdirname In Unix, I believe you use just Rd2dvi, no ".sh". Duncan Murdoch Thanks in advance, Sergi Martínez [[alternative HTML version deleted]] __ 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.
[R] workspace platform potabillity
Hi, Can I save a workspace under a 64bit machine in a way that allows reading it correctly on a 32bit machine? Will the normal procedure of save.image() or save(#object#) produce errors here, because the data is stored in a binary mode? Regards, Benjamin == Benjamin Otto University Hospital Hamburg-Eppendorf Institute For Clinical Chemistry Martinistr. 52 D-20246 Hamburg Tel.: +49 40 42803 1908 Fax.: +49 40 42803 4971 == -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf Körperschaft des öffentlichen Rechts Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender) Dr. Alexander Kirstein Ricarda Klein Prof. Dr. Dr. Uwe Koch-Gromus __ 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] Can I do regression by steps?
I saw this type of models in some of my company projects. To simplify: Y is regressed on X1 and X2. But the regression is done by two steps: First Y is regressed on X1 with intercept, and the residuals from the first step are used to regress on X2, without the constant. The reason to do so is some observations have X1 data but do not have X2, so I guess the person wants to use as much information as he can to get the coef. for X1, and then use part of the residuals (that have X2 data) to catch what is left to be explained by X2. But my concern is, should we consider the correlation between X1 and X2? If residuals from the first step are used, then X1 effect has been removed. Then what does it really mean by regressing residuals on X2, which has some X1 effect correlated with?? should X2 be adjusted by X1, too (regress X2 on X1 and use the residuals)? What if both X1 and X2 are dummy variables? Dummy variables can have a meaningful correlation, too, right? Thanks a lot! -- View this message in context: http://www.nabble.com/Can-I-do-regression-by-steps--tp18338562p18338562.html Sent from the R help mailing list archive at Nabble.com. __ 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] attributing values to dataframe positions following eval
In the long run it will probably be easier/simpler to work in a list (or a new environment) rather than doing everything in the global environment. For example you can do some of what you are trying below with code like: > polyList <- c("rs123", "rs124", "rs555", "rs000") > mylist <- sapply( polyList, function(x) data.frame(matrix(NA,3,3)), > USE.NAMES=TRUE, simplify=FALSE) Now you can print out rs123 using: > mylist[['rs123']] Or > mylist[[ polyList[1] ]] Or > mylist[[1]] Looking at the first row, first column of the first element is > mylist[[1]][1,1] And changing it is just: > mylist[[1]][1,1] <- 5 You can also use the elements of mylist by name using the with and within functions: > with(mylist, rs124) > mylist <- within(mylist, rs123[1,1] <- 5) Changing or extracting from all the data frames becomes much easier using lapply or sapply and you don't need to mess around with the eval and assign functions. You also have all your data in a single object to make it easier to save/load/delete/rename/etc. and you are much less likely to accidentally overwrite a variable of interest. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Stephane Bourgeois > Sent: Tuesday, July 08, 2008 3:41 AM > To: r-help@r-project.org > Subject: [R] attributing values to dataframe positions following eval > > Hi everybody, > > > > I've been looking around, but can't seem to find the answer. > > > > I get a list of names (which vary, so I never know them in > advance), and transform them into variables, each of which is > a dataframe, using > assign: > > > > polyList <- c("rs123", "rs124", "rs555", "rs000") > > numPoly <- length(polyList) > > > > for (k in 1:numPoly) { > > assign(polyList[k], data.frame(matrix(NA, ncol=3, nrow=3))) > > } > > > > polyList <- lapply(polyList, as.name) > > > > I can see the resulting dataframe associated to rs123 (for example) > using: > > > > > eval(polyList[[1]]) > > X1 X2 X3 > > 1 NA NA NA > > 2 NA NA NA > > 3 NA NA NA > > > > And see the value in row 1, column 1 with: > > > > > eval(polyList[[1]])[1,1] > > [1] NA > > > > Now, I want to change the values in the dataframe... that's > what I can't manage to do: > > > > > eval(polyList[[1]])[1,1] <- 5 > > Error in eval(polyList[[1]])[1, 1] <- 5 : > > could not find function "eval<-" > > > > Anybody has an idea on how to do that? > > > > Thank you, > > > > Stephane > > > > PS: yes, I'm aware that using arrays and dataframes instead > of going through the creation of variables may be more > practical, but the context is much more complex than the > presented example (and in that specific case, having these > variables is a requirement) > > > > > > > -- > The Wellcome Trust Sanger Institute is operated by Genome Research > > Limited, a charity registered in England with number 1021457 > and a compa ny registered in England with number 2742969, > whose registered office is 2 > 15 Euston Road, London, NW1 2BE. > > > > [[alternative HTML version deleted]] > > __ > 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.
[R] Question: Beginner stuck in a R cycle
Dear All, I have a database of 200 observations named myD. In the dataframe there are a column named code (with codes varying from 1 to 77), a column named "prevalence" with some quantitative measurements are given and an column named Pr_mean, with no values. I would like to set a cycle to compute the average of prevalence values for each different code and store the averages under the empty field Pr_mean. This is what I wrote: # Set a cycle for (i in 1:nrow(myD)) { mycode = myD$code[i] mymean[i] = mean(prevalence) myD$Pr_mean[i] = mymean[i] } With the above cycle I am able to compute the average of all 200 observations which is then written in every cell. I understand that a condition is missing, that indicates that the average has to be computed amongst the observations showing the same codes values. Could you please help me ? D. Posta, news, sport, oroscopo: tutto in una sola pagina. Crea l'home page che piace a te! www.yahoo.it/latuapagina [[alternative HTML version deleted]] __ 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] Need ideas on how to show spikes in my data and how to code it in R
Hi thanks for your answer. > ii) hist() will not show the same frequencies as density() unless hist has > unit bin sizes. density*length is showing number per unit change in Weight; > hist shows number per bin width. I belive this is what is confounding me. I have a bin width of 0.1 in the histogram. Changing dens$y <- dens$y * (length(weights$Weight)) to dens$y <- dens$y * (length(weights$Weight)*binwidth) where binwidth=0.1 seems to output correct graphs. Can someone verify this is the right approach? On Tue, Jul 8, 2008 at 1:45 PM, S Ellison <[EMAIL PROTECTED]> wrote: > Two thoughts: > i) If you have a narrow distribution, the density can be higher than 1. The > area comes out at 1 for density, and n for the frequency. > > ii) hist() will not show the same frequencies as density() unless hist has > unit bin sizes. density*length is showing number per unit change in Weight; > hist shows number per bin width. > > > > > > > Try plotting a histogram first, then plot the density on top of that. If they > disagree >>> "Thomas Fröjd" <[EMAIL PROTECTED]> 07/08/08 12:29 PM >>> > Hi! > > Sorry for bothering you again but I can't seem to get it right. > > When i multiply the density with the number of observations it seems > to be way to high, The reference curve is drawn at maybe 20 times > higher frequency count than it should be. > > I use the following code where "weights$Weight" is my weights data and > "reference" is my reference dataset. > > # calucate the right breakpoints > breakpoints <- seq(min(weights), max(weights), by=binwidth) > > > #scale density > dens <- density(reference) > dens$y <- dens$y * (length(weights$Weight)) > > #graph it > hist(weights$Weight, freq=TRUE, breaks=breakpoints, main=wfiles[i]) > > lines(dens) > > Any ideas are greatly appreciated. > > /Thomas > > > > On Fri, Jun 27, 2008 at 10:54 PM, Daniel Folkinshteyn > <[EMAIL PROTECTED]> wrote: >> if you want the "frequency" scale rather than density scale, then leave hist >> as is (by default it uses the frequency scale), and rescale the density by >> multiplying it by the appropriate NOBS. >> >> on 06/27/2008 01:16 PM Thomas Frööjd said the following: >>> >>> Hi >>> >>> Thank you very much for taking time to answer. >>> >>> The solution of using hist(data) for the main dataset and adding >>> lines(density(refdata)) for the reference data seem to work great. I >>> forgot to mention one thing however, I need to have frequency on the y >>> azis instead of density as now. >>> >>> I know this is not a "real" histogram but since the audience is not >>> very statistically experienced I would prefer to do it this way. >>> Anyone have an idea? >>> >>> Thanks again for your help. >>> >>> Thomas Fröjd >>> >>> On Wed, Jun 25, 2008 at 6:16 PM, Daniel Folkinshteyn <[EMAIL PROTECTED]> >>> wrote: > > I don't understand this. Why not just get hist() to plot on the > density scale, > thereby making its output commensurate with the output of density()? > The hist() function will plot on the density scale if you ask it to. > Set freq=FALSE > (or prob=TRUE) in the call to hist. ehrm... because i didn't realize that option existed :) that certainly is easier than manually scaling hist output by NOBS - thanks for the tip! >>> >> >> > > __ > 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. > > *** > This email and any attachments are confidential. Any u...{{dropped:8}} __ 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] time series by calendar week
hello, i cant find a solution on this (might be) easy problem: i have a time serie by carlandar weeks, so for every carlendar week i have a value. now i would like to use the functions for time series, so i change structur to a time serie with cam <- ts(number,start=c(2001,1),deltat=7/365) or cam <- ts(number,start=c(2001,1),frequency=52) the problem on it is, that 2004 had 53 calendar weeks, which is not recognized there. it follows with using a saisonal structure the weeks are shifting. f.e. first week in 2005 is conected with the second week in 2004. with the first function leap years are not recognized. is there another function which is recognizing irregularities in the calendar? thanks a lot, collonil -- View this message in context: http://www.nabble.com/time-series-by-calendar-week-tp18340479p18340479.html Sent from the R help mailing list archive at Nabble.com. __ 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] simulate data for lme
hi. i did some research first, but didn't find what i was looking for... the thing is: i generated data with correlated errors and simulated the power with using aov(). what i wanna do now is something similar while using lme(), so that the corr-structure will be paid attention to. i'm not quite sure how to do that... i hope someone can help me. thanks in advance. mel code: ee<-mvrnorm(n=100, mu=rep(0,N),Omega.block) #omega.block describes the corr-structure mu<-c(1,2,3) (group<-factor(rep(1:k,n))) eval.simu<-function(e) { y<-mu[group]+e fit<-aov(y~group) s.fit<-summary(fit)[[1]] s.fit$P[1] } p<-apply(ee,1,"eval.simu") #then count number of p≤alpha to get power -- View this message in context: http://www.nabble.com/simulate-data-for-lme-tp18342119p18342119.html Sent from the R help mailing list archive at Nabble.com. __ 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] Change language in Rcmdr
On Monday 07 July 2008, Philippe Grosjean wrote: > Hello, > > As far as I know, Rcmdr is already translated in French. It is thus just > a question of switching R to French. Alternatively, you could switch the language after R starts: Sys.putenv(LANGUAGE="fr") After this, Rcmdr will be opened in French. Best, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 signature.asc Description: This is a digitally signed message part. __ 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] How to draw dot plots for 2 vectors seperately
Hi all, I want to draw dot plots for 2 rows in a matrix separately but want to have them close to each other. For example, I have a matrix a: > dim(a) [1] 319 2 and then transpose it to matrix b > b<-t(a) > dim(b) [1] 2 319 So I want to draw dot plots for these two rows separately but want them close to each other so that I am able to cross-compare each other. If they can only be drawn in a single figure, I want them be represented by different colors so that I could distinguish them. I tried: dotchart(b,xlim=c(0,100)) but it is not what I want actually. Thanks for your suggestions! Best, Allen [[alternative HTML version deleted]] __ 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] Question: Beginner stuck in a R cycle
Try: > myD <- transform(myD, Pr_mean = ave(prevalence, codes)) See ?ave and ?transform for details. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Daniela Ottaviani > Sent: Tuesday, July 08, 2008 7:18 AM > To: r-help@r-project.org > Subject: [R] Question: Beginner stuck in a R cycle > > Dear All, > > I have a database of 200 observations named myD. > In the dataframe there are a column named code (with codes > varying from 1 to 77), a column named "prevalence" with some > quantitative measurements are given and an column named > Pr_mean, with no values. > > I would like to set a cycle to compute the average of > prevalence values for each different code and store the > averages under the empty field Pr_mean. > > This is what I wrote: > > # Set a cycle > for (i in 1:nrow(myD)) { > mycode = myD$code[i] > mymean[i] = mean(prevalence) > myD$Pr_mean[i] = mymean[i] > } > > With the above cycle I am able to compute the average of all > 200 observations which is then written in every cell. > I understand that a condition is missing, that indicates that > the average has to be computed amongst the observations > showing the same codes values. > > Could you please help me ? > > > D. > > > > Posta, news, sport, oroscopo: tutto in una sola pagina. > Crea l'home page che piace a te! > www.yahoo.it/latuapagina > [[alternative HTML version deleted]] > > __ > 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] Question: Beginner stuck in a R cycle
On 08-Jul-08 13:18:13, Daniela Ottaviani wrote: > Dear All, > I have a database of 200 observations named myD. > In the dataframe there are a column named code (with codes varying > from 1 to 77), a column named "prevalence" with some quantitative > measurements are given and an column named Pr_mean, with no values. > > I would like to set a cycle to compute the average of prevalence values > for each different code and store the averages under the empty field > Pr_mean. I think something on the following lines would do what you want (I think it is wise to call the final column "Pr.mean", as below, rather than "Pr_mean"): for( Code in unique(myD$code) ){ ix <- (myD$code == Code ) myD$Pr.mean[ix] <- mean(myD$prevalence[ix]) } Ted. > This is what I wrote: > ># Set a cycle > for (i in 1:nrow(myD)) { > mycode = myD$code[i] > mymean[i] = mean(prevalence) > myD$Pr_mean[i] = mymean[i] > } > > With the above cycle I am able to compute the average of all 200 > observations which is then written in every cell. > I understand that a condition is missing, that indicates that the > average has to be computed amongst the observations showing the same > codes values. > > Could you please help me ? > > > D. > > > > Posta, news, sport, oroscopo: tutto in una sola pagina. > Crea l'home page che piace a te! > www.yahoo.it/latuapagina > [[alternative HTML version deleted]] > > __ > 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. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 08-Jul-08 Time: 17:01:38 -- XFMail -- __ 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] Question: Beginner stuck in a R cycle
On Tue, Jul 8, 2008 at 3:18 PM, Daniela Ottaviani <[EMAIL PROTECTED]> wrote: > Dear All, > > I have a database of 200 observations named myD. > In the dataframe there are a column named code (with codes varying from 1 to > 77), a column named "prevalence" with some quantitative measurements are > given and an column named Pr_mean, with no values. > > I would like to set a cycle to compute the average of prevalence values for > each different code and store the averages under the empty field Pr_mean. > > This is what I wrote: > > # Set a cycle > for (i in 1:nrow(myD)) { > mycode = myD$code[i] > mymean[i] = mean(prevalence) > myD$Pr_mean[i] = mymean[i] > } > > With the above cycle I am able to compute the average of all 200 observations > which is then written in every cell. > I understand that a condition is missing, that indicates that the average has > to be computed amongst the observations showing the same codes values. > > Could you please help me ? > > > D. > > The easiest thing to do is to use ?by: myD<-data.frame(code=sample(letters[1:5],200,replace=T),value=rnorm(200)) by(myD$value,myD$code,mean) but that won't get you the the group means in the empty column without some more lines of code. Another way is to use ?lapply and ?unlist: myD$Pr_mean<-unlist(lapply(as.character(myD$code),function(x) mean(myD$value[myD$code==x]))) Regards, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik __ 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] time series by calendar week
I don't know if this will help, but look at the zoo, chron, and Posix Date Time packages/classes. On Tue, Jul 8, 2008 at 10:25 AM, collonil <[EMAIL PROTECTED]> wrote: > > hello, > > i cant find a solution on this (might be) easy problem: > > i have a time serie by carlandar weeks, so for every carlendar week i have > a > value. now i would like to use the functions for time series, so i change > structur to a time serie with > > cam <- ts(number,start=c(2001,1),deltat=7/365) > or > cam <- ts(number,start=c(2001,1),frequency=52) > > the problem on it is, that 2004 had 53 calendar weeks, which is not > recognized there. > it follows with using a saisonal structure the weeks are shifting. f.e. > first week in 2005 is conected with the second week in 2004. > with the first function leap years are not recognized. > > is there another function which is recognizing irregularities in the > calendar? > > thanks a lot, collonil > > -- > View this message in context: > http://www.nabble.com/time-series-by-calendar-week-tp18340479p18340479.html > Sent from the R help mailing list archive at Nabble.com. > > __ > 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. > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] Constrained optimization
On Tue, Jul 8, 2008 at 11:28 AM, Kanak Choudhury <[EMAIL PROTECTED]> wrote: > i have a function like > > 1+sin(a+bx) where -pi/2<=a+bx<=pi/2 > > i made a progrom using constrOptim() function but it is not giving good > result. it depends on the initial value. but when i am doing simulation it > is impossible of find the best initial value for every step. also i am not > exactly sure how to input the restriction though i have read the help file > of the function. here x is a set of values. would u please send me some > instruction to find the best result from the obtimization. Actually, there is no need to use R to optimize such a function. In truth, the analytical solution for your problem, in case you are wanting to maximize, is: a + b x = pi/2; in case of minimization, the solution is: a + b x = - pi/2. Paul __ 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] time series by calendar week
Or look at the fame package, which has ti (TimeIndex) and tis (TimeIndexedSeries) classes that handle this kind of problem. I think it's simpler and faster than the zoo stuff, but then I would say that, since I wrote it. Jeff "stephen sefick" <[EMAIL PROTECTED]> writes: > I don't know if this will help, but look at the zoo, chron, and Posix Date > Time packages/classes. > > On Tue, Jul 8, 2008 at 10:25 AM, collonil <[EMAIL PROTECTED]> wrote: > >> >> hello, >> >> i cant find a solution on this (might be) easy problem: >> >> i have a time serie by carlandar weeks, so for every carlendar week i have >> a >> value. now i would like to use the functions for time series, so i change >> structur to a time serie with >> >> cam <- ts(number,start=c(2001,1),deltat=7/365) >> or >> cam <- ts(number,start=c(2001,1),frequency=52) >> >> the problem on it is, that 2004 had 53 calendar weeks, which is not >> recognized there. >> it follows with using a saisonal structure the weeks are shifting. f.e. >> first week in 2005 is conected with the second week in 2004. >> with the first function leap years are not recognized. >> >> is there another function which is recognizing irregularities in the >> calendar? >> >> thanks a lot, collonil >> >> -- >> View this message in context: >> http://www.nabble.com/time-series-by-calendar-week-tp18340479p18340479.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> 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. >> > > > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis > > [[alternative HTML version deleted]] > > __ > 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. > -- Jeff __ 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] fisher.test
Hi! I am Marta Colombo, student in Mathematical Engineering at "Politecnico di Milano". For my master degree thesis I have to analyze some categorical data. My dataset is composed by 327 individuals and 16 variables. I am using Fisher exact test to test independence on IxJ contingency tables, but I have a problem with one variable. R gives me this error message: FEXACT error 7. LDSTP is too small for this problem. Try increasing the size of the workspace. or also this one: FEXACT error 6. LDKEY is too small for this problem. Try increasing the size of the workspace. Do you know what these error messages mean? What can I do? Thank you in advance for your kindness and attention! Best regards, Marta Colombo __ 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] Question: Beginner stuck in a R cycle
Would ave() do what you want? Rashid On Tue, 8 Jul 2008, Daniela Ottaviani wrote: > Dear All, > > I have a database of 200 observations named myD. > In the dataframe there are a column named code (with codes varying from 1 to > 77), a column named "prevalence" with some quantitative measurements are > given and an column named Pr_mean, with no values. > > I would like to set a cycle to compute the average of prevalence values for > each different code and store the averages under the empty field Pr_mean. > > This is what I wrote: > > # Set a cycle > for (i in 1:nrow(myD)) { > mycode = myD$code[i] > mymean[i] = mean(prevalence) > myD$Pr_mean[i] = mymean[i] > } > > With the above cycle I am able to compute the average of all 200 observations > which is then written in every cell. > I understand that a condition is missing, that indicates that the average has > to be computed amongst the observations showing the same codes values. > > Could you please help me ? > > > D. > > > > Posta, news, sport, oroscopo: tutto in una sola pagina. > Crea l'home page che piace a te! > www.yahoo.it/latuapagina > [[alternative HTML version deleted]] > > __ > 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.
[R] R crash with ATLAS precompiled Rblas.dll on Windows XP Core2 Duo
I noticed a problem using R 2.7.1 on Windows XP SP2 with the precompiled Atlas Rblas.dll. Running the code below causes R to crash. I started R using Rgui --vanilla and am using the precompiled Atlas Rblas.dll from cran.fhcrc.org dated 17-Jul-2007 05:04 for Core2 Duo. The code that causes the crash: x <- rnorm(100) y <- rnorm(100) z <- rnorm(100) loess(z ~ x * y) loess(z ~ x) does not cause a crash using the Atlas BLAS and neither does running the above code with the Rblas.dll that came with R 2.7.1. In addition, the code runs fine using the Atlas BLAS under R 2.6.2. The windows error information that is printed to the screen when R closes: AppName: rgui.exeAppVer: 2.71.45970.0ModName: rblas.dll ModVer: 2.51.42199.0 Offset: 000501cc sessionInfo returns: R version 2.7.1 (2008-06-23) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base I checked the R FAQ, R for Windows FAQ, and the README associated with the Atlas BLAS on CRAN and couldn't find any information related to possible crash causes. I've used the ATLAS BLAS for about 6 months on this machine (it's a new machine) with R 2.6.2. Using debug(stats:::simpleLoess), I've found that the crash occurs on the first iteration of the line: z <- .C(R_loess_raw, as.double(y), as.double(x), as.double(weights), as.double(robust), as.integer(D), as.integer(N), as.double(span), as.integer(degree), as.integer(nonparametric), as.integer(order.drop.sqr), as.integer(sum.drop.sqr), as.double(span * cell), as.character(surf.stat), fitted.values = double(N), parameter = integer(7), a = integer(max.kd), xi = double(max.kd), vert = double(2 * D), vval = double((D + 1) * max.kd), diagonal = double(N), trL = double(1), delta1 = double(1), delta2 = double(1), as.integer(surf.stat == "interpolate/exact")) After that, I'm kind of stuck in terms of tracking it down. Thanks for any input, Jason Law City of Portland, OR __ 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] Gage R & R
Hello, Could you let me know if there any R packages available for performing Gage R & R studies. Thank you! Sincerely, Isabella Isabella R. Ghement, Ph.D. Ghement Statistical Consulting Company 301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5 Tel: 604-767-1250 Fax: 604-270-3922 E-mail: [EMAIL PROTECTED] Web: www.ghement.ca __ 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] How I count the all possible samples??
Dear Members, I am facing a problem during counting a sample. I have 4 characters i.e. A,C,G,T of DNA sequence and code this sequence by 1,2,3,4 respectively. [1] "41" "12" "22" "23" "32" "22" "23" "32" "22" "21" "12" "22" "23" "31" "12" [16] "21" "11" "11" "14" "43" "32" "22" "23" "34" "41" "13" "33" "32" "21" "12" [31] "22" "24" "44" "42" "21" "12" "23" "31" "12" "23" "33" "32" "22" "22" "21" [46] "13" "31" "11" "12" "22" "21" "14" "43" "33" "32" "23" "34" "43" "32" "23" [61] "33" "34" "41" "13" "34" "44" "42" "23" "33" "32" "24" "44" "44" "43" "33" [76] "31" "14" "43" "32" "22" "22" "21" "12" "22" "21" "13" "32" "23" "33" "32" [91] "21" "12" "23" "34" "43" "32" "21" "12" "21" "11" and i want to count all possible sample i.e. 11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44 from the above sequence?? How i can calculate please help me I would be very thank full to you. Regards, ++ MUHAMMAD FAISAL Department of Statistics and Decion Support system, University of Vienna,Austria Res. # +4314796696104 Cell # +436503605156 Office # +431427738662 +++ [[alternative HTML version deleted]] __ 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] Question: Beginner stuck in a R cycle
Dear Daniela, Try this: set.seed(123) myD<-data.frame(code=sample(letters[1:5],200,replace=T),value=rnorm(200)) tapply(myD$value,myD$code,mean) a b c d e 0.04401465 0.07813648 0.07018791 -0.14508544 -0.02369875 See ?tapply for more information. HTH, Jorge On Tue, Jul 8, 2008 at 9:18 AM, Daniela Ottaviani <[EMAIL PROTECTED]> wrote: > Dear All, > > I have a database of 200 observations named myD. > In the dataframe there are a column named code (with codes varying from 1 > to 77), a column named "prevalence" with some quantitative measurements are > given and an column named Pr_mean, with no values. > > I would like to set a cycle to compute the average of prevalence values for > each different code and store the averages under the empty field Pr_mean. > > This is what I wrote: > > # Set a cycle > for (i in 1:nrow(myD)) { > mycode = myD$code[i] > mymean[i] = mean(prevalence) > myD$Pr_mean[i] = mymean[i] > } > > With the above cycle I am able to compute the average of all 200 > observations which is then written in every cell. > I understand that a condition is missing, that indicates that the average > has to be computed amongst the observations showing the same codes values. > > Could you please help me ? > > > D. > > > > Posta, news, sport, oroscopo: tutto in una sola pagina. > Crea l'home page che piace a te! > www.yahoo.it/latuapagina >[[alternative HTML version deleted]] > > __ > 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. > [[alternative HTML version deleted]] __ 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] How I count the all possible samples??
Dear Muhammad, Does it work for you? x=scan() 41 12 22 23 32 22 23 32 22 21 12 22 23 31 12 21 11 11 14 43 32 22 23 34 41 13 33 32 21 12 22 24 44 42 21 12 23 31 12 23 33 32 22 22 21 13 31 11 12 22 21 14 43 33 32 23 34 43 32 23 33 34 41 13 34 44 42 23 33 32 24 44 44 43 33 31 14 43 32 22 22 21 12 22 21 13 32 23 33 32 21 12 23 34 43 32 21 12 21 11 table(x) See ?table for more information. HTH, Jorge On Tue, Jul 8, 2008 at 1:23 PM, muhammad faisal <[EMAIL PROTECTED]> wrote: > > Dear Members, > > I am facing a problem during counting a sample. > I have 4 characters i.e. A,C,G,T of DNA sequence and code this sequence by > 1,2,3,4 respectively. > > > [1] "41" "12" "22" "23" "32" "22" "23" "32" "22" "21" "12" "22" "23" "31" > "12" > [16] "21" "11" "11" "14" "43" "32" "22" "23" "34" "41" "13" "33" "32" "21" > "12" > [31] "22" "24" "44" "42" "21" "12" "23" "31" "12" "23" "33" "32" "22" "22" > "21" > [46] "13" "31" "11" "12" "22" "21" "14" "43" "33" "32" "23" "34" "43" "32" > "23" > [61] "33" "34" "41" "13" "34" "44" "42" "23" "33" "32" "24" "44" "44" "43" > "33" > [76] "31" "14" "43" "32" "22" "22" "21" "12" "22" "21" "13" "32" "23" "33" > "32" > [91] "21" "12" "23" "34" "43" "32" "21" "12" "21" "11" > > and i want to count all possible sample i.e. > 11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44 > > from the above sequence?? > > How i can calculate please help me > I would be very thank full to you. > > > > Regards, > ++ > MUHAMMAD FAISAL Department of Statistics and Decion Support system, > University of Vienna,Austria Res. # +4314796696104 > Cell # +436503605156 > Office # +431427738662 > +++ > > > > >[[alternative HTML version deleted]] > > > __ > 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. > > [[alternative HTML version deleted]] __ 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] How I count the all possible samples??
?unique --- On Tue, 7/8/08, muhammad faisal <[EMAIL PROTECTED]> wrote: > From: muhammad faisal <[EMAIL PROTECTED]> > Subject: [R] How I count the all possible samples?? > To: r-help@r-project.org > Received: Tuesday, July 8, 2008, 1:23 PM > Dear Members, > > I am facing a problem during counting a sample. > I have 4 characters i.e. A,C,G,T of DNA sequence and code > this sequence by 1,2,3,4 respectively. > > > [1] "41" "12" "22" > "23" "32" "22" "23" > "32" "22" "21" "12" > "22" "23" "31" "12" > [16] "21" "11" "11" > "14" "43" "32" "22" > "23" "34" "41" "13" > "33" "32" "21" "12" > [31] "22" "24" "44" > "42" "21" "12" "23" > "31" "12" "23" "33" > "32" "22" "22" "21" > [46] "13" "31" "11" > "12" "22" "21" "14" > "43" "33" "32" "23" > "34" "43" "32" "23" > [61] "33" "34" "41" > "13" "34" "44" "42" > "23" "33" "32" "24" > "44" "44" "43" "33" > [76] "31" "14" "43" > "32" "22" "22" "21" > "12" "22" "21" "13" > "32" "23" "33" "32" > [91] "21" "12" "23" > "34" "43" "32" "21" > "12" "21" "11" > > and i want to count all possible sample i.e. > 11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44 > > from the above sequence?? > > How i can calculate please help me > I would be very thank full to you. > > > > Regards, > ++ > MUHAMMAD FAISAL Department of Statistics and Decion > Support system, > University of Vienna,Austria Res. # +4314796696104 > Cell # +436503605156 > Office # +431427738662 > +++ > > > > > [[alternative HTML version > deleted]]__ > 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. __ [[elided Yahoo spam]] __ 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] Plot
Hello everyone, I am trying to plot an MvA plot with the following code: dat<-read.table(file="C:\\Documents and Settings\\.txt",header=T) file.show(file="C:\\Documents and Settings\\Ow...txt") library(sma) data(MouseArray) dat.o<-as.list(dat) dat.o$R.2<-as.matrix(dat[,c(1:5)]) dat.o$G.2<-as.matrix(dat[,c(6:10)]) dat.o$Gb.2<-as.matrix(dat[,c(11:15)]) dat.o$Rb.2<-as.matrix(dat[,c(16:20)]) dat.o<-dat.o[c(c(1:5)[5],c(6:10)[5],c(11:15)[5],c(16:20)[5])] dim(dat.o$R.2);dim(dat.o$G.2);dim(dat.o$Rb.2);dim(dat.o$Gb.2) plot.mva(dat.o,layout=mouse.setup,norm="n",plot.type="n",image.id=5) But I get the following error message: "error in plot window--need finite 'xlim' values" 2.In min(x) : no non missing argument to min---returning inf 3.In mas(x) : no non missing arguments to max---returning -inf 4.In min(x0 : no non missing arguments to min--returning inf 5.In max(x) :no non missing arguments to max--returning -inf Any help would be appreciated Thanks Paul [[alternative HTML version deleted]] __ 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] making zoo objects with zoo without format argument?
#this is a subset of a larger data frame and I am okay with subsetting it as there are redundant time stamps, but I would like to create a zoo object out of this and I am having a hard #time figuring out how to do this the date structure is year and then month x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" ), class = "data.frame", row.names = c(NA, 23L)) #thanks Stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] Plot
are any of the subsets all NA? On Tue, Jul 8, 2008 at 1:39 PM, Paul Adams <[EMAIL PROTECTED]> wrote: > Hello everyone, > I am trying to plot an MvA plot with the following code: > dat<-read.table(file="C:\\Documents and Settings\\.txt",header=T) > file.show(file="C:\\Documents and Settings\\Ow...txt") > library(sma) > data(MouseArray) > dat.o<-as.list(dat) > dat.o$R.2<-as.matrix(dat[,c(1:5)]) > dat.o$G.2<-as.matrix(dat[,c(6:10)]) > dat.o$Gb.2<-as.matrix(dat[,c(11:15)]) > dat.o$Rb.2<-as.matrix(dat[,c(16:20)]) > dat.o<-dat.o[c(c(1:5)[5],c(6:10)[5],c(11:15)[5],c(16:20)[5])] > dim(dat.o$R.2);dim(dat.o$G.2);dim(dat.o$Rb.2);dim(dat.o$Gb.2) > plot.mva(dat.o,layout=mouse.setup,norm="n",plot.type="n",image.id=5) > But I get the following error message: > "error in plot window--need finite 'xlim' values" > 2.In min(x) : no non missing argument to min---returning inf > 3.In mas(x) : no non missing arguments to max---returning -inf > 4.In min(x0 : no non missing arguments to min--returning inf > 5.In max(x) :no non missing arguments to max--returning -inf > Any help would be appreciated > Thanks > Paul > > > >[[alternative HTML version deleted]] > > > __ > 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. > > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] extracting index list when using tapply()
Hello, The quick version of my question is how can I extract a matrix instead of a vector using tapply()? I would like to be able to access both the results of tapply() and also the index variables. In case further explanation would help: I am analyzing a large (3million rows x 9 columns) spatial/temporal dataset and am attempting to calculate the number of unique years containing any data within each geographic area (10 degree cells in this case). I can do this, but I also want to extract a subset vector of the index variable (area). My script to calculate the number of unique years containing any data for each area is: x<-tapply(years, area, function(x) length(unique(x))) Now, I want to extract the vector of areas where the number of unique years containing any data is >20, but tapply() only returns a vector of unique years and I was a matrix. I could use a looping function to do this, but tapply() is much faster with large datasets and so I would like to use it if possible. Any help is appreciated. Thanks. -- View this message in context: http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18345794.html Sent from the R help mailing list archive at Nabble.com. __ 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] Automatic placement of Legends
Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Many thanks in advance, Tolga Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[alternative HTML version deleted]] __ 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] time series by calendar week
On Tue, Jul 8, 2008 at 10:25 AM, collonil <[EMAIL PROTECTED]> wrote: > > hello, > > i cant find a solution on this (might be) easy problem: > > i have a time serie by carlandar weeks, so for every carlendar week i have a > value. now i would like to use the functions for time series, so i change > structur to a time serie with > > cam <- ts(number,start=c(2001,1),deltat=7/365) > or > cam <- ts(number,start=c(2001,1),frequency=52) > > the problem on it is, that 2004 had 53 calendar weeks, which is not > recognized there. > it follows with using a saisonal structure the weeks are shifting. f.e. > first week in 2005 is conected with the second week in 2004. > with the first function leap years are not recognized. > > is there another function which is recognizing irregularities in the > calendar? > I assume the main problem is that you want to convert it to a series that has an integral number of cycles per year.To do that some approximation will be required such as: - omit anything past 52 weeks from each year, or - create a grid of freq points per year and then take the last point in each grid section or the mean of all points in each grid section Here is an example using a grid of 52 points per year: # Suppose we have this data: library(zoo) set.seed(1) z <- zooreg(1:100 + rnorm(100), start = as.Date("2001-01-01"), deltat = 7) # new.freq() converts dates to a grid of freq points per year # yd is sequence of dates of firsts of years # yy is years of the same sequence # last line interpolates so dates, d, are transformed to year + frac of year new.freq <- function(d, freq = 52) { y <- as.Date(cut(range(d), "years")) + c(0, 367) yd <- seq(y[1], y[2], "year") yy <- as.numeric(format(yd, "%Y")) ceiling(freq * approx(yd, yy, xout = d)$y) / freq } # take last point in each period aggregate(z, new.freq, tail, 1) # or, take mean of all points in each period aggregate(z, new.freq, mean) __ 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] making zoo objects with zoo without format argument?
There is no data in your data frame, just index info, so I assume you want a zero width time series: zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) This also works but then you are left with a character date which you may not want: zoo(, x$Yearmonth) On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > #this is a subset of a larger data frame and I am okay with subsetting it as > there are redundant time stamps, but I would like to create a zoo object out > of this and I am having a hard #time figuring out how to do this the date > structure is year and then month > > x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, > 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, > 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", > "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", > "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", > "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", > "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, > 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, > 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" > ), class = "data.frame", row.names = c(NA, 23L)) > > #thanks Stephen > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis > >[[alternative HTML version deleted]] > > __ > 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] making zoo objects with zoo without format argument?
On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > There is no data in your data frame, just index info, so I assume you > want a zero width time series: > > zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) > > This also works but then you are left with a character date which you > may not want: > > zoo(, x$Yearmonth) This last one should have been: zoo(, as.character(x$Yearmon)) since your data frame holds a factor rather than character column. > > > On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> wrote: >> #this is a subset of a larger data frame and I am okay with subsetting it as >> there are redundant time stamps, but I would like to create a zoo object out >> of this and I am having a hard #time figuring out how to do this the date >> structure is year and then month >> >> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, >> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, >> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", >> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", >> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", >> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", >> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, >> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, >> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" >> ), class = "data.frame", row.names = c(NA, 23L)) >> >> #thanks Stephen >> >> -- >> Let's not spend our time and resources thinking about things that are so >> little or so large that all they really do for us is puff us up and make us >> feel like gods. We are mammals, and have not exhausted the annoying little >> problems of being mammals. >> >> -K. Mullis >> >>[[alternative HTML version deleted]] >> >> __ >> 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] making zoo objects with zoo without format argument?
#this is the whole data frame and I tried the suggested and it looks like it is working but will not plot. thanks agian x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", "2007-11", "2007-12", "2008-01"), class = "factor"), Site = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("301", "520", "Betty's Branch", "Butler Creek", "CLYO", "Downstream", "Horse Creek", "IP", "North Augusta", "Stan's", "Stevens Creek", "Vogtle"), class = "factor"), River.Mile = c(215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215), Lagrangian = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("No", "Yes"), class = "factor"), EventType = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Regular", "Stormwater"), class = "factor"), Month = c(1L, 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L), Year = c(2007L, 2008L, 2006L, 2007L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L, 2006L, 2007L), DCAA = c(87, 0, 95, 0, 96, 0, 0, 0, 93, 0, 0, 0, 0, 0, 0, 79, 82, 0, 0, 0, 0, 0, 86), Decachlorobiphenyl = c(79, 0, 65, 0, 83, 0, 0, 0, 74, 0, 0, 0, 0, 0, 0, 93, 76, 0, 0, 0, 0, 0, 74), Tetrachloro.m.xylene = c(90, 0, 86, 0, 83, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 95, 91, 0, 0, 0, 0, 0, 85), Alkalinity = c(15, 13, 12, 14, 13, 16, 13, 16, 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), BOD..5.day = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Carbonaceous.BOD..5.day = c(0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Chloride = c(2.6, 2.7, 3, 2.9, 2.8, 2.6, 2.7, 2.5, 3, 2.4, 2.8, 2.5, 2.7, 2.3, 2.7, 2.5, 2.7, 3, 2.7, 2.6, 2.8, 2.6, 2.7), COD = c(0, 8.8, 0, 0, 0, 13, 0, 0, 7.9, 5.9, 0, 0, 0, 0, 0, 0, 0, 6.6, 6.5, 0, 0, 0, 12), Dissolved.Ammonia...N..phenate. = c(0, 0.095, 0, 0, 0.072, 0.1, 0.17, 0.11, 0.12, 0, 0.055, 0, 0, 0.11, 0, 0, 0.1, 0.15, 0.072, 0.078, 0.073, 0, 0.065), Dissolved.Chloride = c(2.7, 2.7, 0, 2.9, 3.4, 2.6, 2.7, 2.5, 2.9, 2.5, 0, 2.5, 2.7, 2.5, 2.7, 2.4, 2.7, 2.4, 2.8, 2.7, 2.8, 2.6, 2.8), Dissolved.Mercury = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00013, 0, 0, 0, 0, 0, 0, 0, 0, 0), Dissolved.Nitrate.Nitrite...N = c(0.092, 0.16, 0.13, 0.14, 0.16, 1.4, 0.15, 0.18, 0.17, 0.21, 0.17, 0.2, 0.19, 0.16, 0.18, 0.069, 0.048, 0.022, 0.2, 0.056, 0.068, 0.082, 0.051), Dissolved.Nitrite...N = c(0, 0.0097, 0, 0.015, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0046, 0, 0.0051, 0.0034, 0, 0.009, 0.0066, 0.016, 0, 0), Dissolved.Sulfate = c(2.7, 3.3, 0, 3, 3, 2.5, 2.8, 1.7, 3.1, 2.1, 0.18, 2.5, 3, 2.3, 2.9, 2.2, 2.8, 2.3, 2.7, 2.6, 5.8, 2.5, 2.8), DOC = c(2.1, 2, 2.5, 2.1, 2.8, 2.4, 2.3, 2.3, 3.5, 2.1, 2.8, 2, 2.5, 1.9, 2.4, 2, 2.2, 2.1, 2.2, 2.9, 2.2, 2.6, 2.2), Hardness..total. = c(0, 0, 9.6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Mercury = c(0, 0, 9.1e-05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Ortho.phosphorus = c(0, 0, 0.057, 0.008, 0.016, 0.009, 0.028, 0.04, 0.039, 0.044, 0.01, 0.038, 0, 0.089, 0, 0.046, 0.023, 0.019, 0.03, 0.074, 0, 0.027, 0), Phosphorus = c(0, 0.011, 0.042, 0.013, 0.0092, 0.015, 0.0085, 0.0057, 0.01, 0.01, 0.0068, 0.0099, 0.0073, 0.0085, 0.008, 0.0072, 0.01, 0, 0.0086, 0, 0.014, 0.011, 0.011), Silica..calculation. = c(0, 0, 9.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Sulfate = c(2.5, 2.3, 2.5, 2.7, 3, 0.26, 2.9, 2.4, 3.5, 2.4, 3.1, 2.4, 3.1, 2.2, 3, 2.5, 2.8, 2.4, 2.6, 4.1, 2.8, 2.4, 3.4), TDS = c(38, 0, 21, 25, 46, 32, 46, 38, 27, 34, 64, 39, 57, 24, 33, 0, 39, 37, 40, 29, 44, 32, 28), TIC = c(1.1, 3.6, 1.2, 0.99, 1.6, 3.4, 2.4, 4.6, 1.2, 2.7, 2.2, 0.73, 3.5, 1.9, 1.6, 2.2, 2.3, 2.4, 2, 2.2, 0.78, 2, 3.8), TKN = c(0.86, 0.42, 0.42, 0.17, 0.12, 0.2, 0, 0.32, 0.2, 0.46, 0.24, 0, 0.35, 0.2, 0.37, 0.54, 0.2, 0.18, 0.1, 0.25, 0, 0, 0.39), TOC = c(2, 1.9, 2.2, 2, 2.3, 2.2, 2.3, 2.4, 2.8, 2.2, 2.6, 1.8, 2.7, 2.2, 2.2, 2, 2.2, 1.9, 2.5, 2, 2.2, 2, 2.1), TSS = c(0.8, 5.7, 0, 1, 1.8, 0, 1.4, 0, 1.1, 0, 8, 0.6, 1.3, 0.77, 0.5, 1.1, 1, 1.3, 0.8, 1.1, 2.6, 0.4, 0.8), TVSS = c(0, 0, 0, 0, 0, 3.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), pH = c(6.28, 7.11, 7.2, 6.6,
Re: [R] Automatic placement of Legends
legend will accept locator() which would not automate it but would get closer On Tue, Jul 8, 2008 at 2:31 PM, <[EMAIL PROTECTED]> wrote: > Dear R-Users, > > I am looking for a way to get legends placed automagically in an empty > spot on a graph. Additional complication comes through my useage of > multiple graphs on the same plot through mfrow. > > Is there a way to achieve this in R ? I have legends for each of the > sub-plots. > > Many thanks in advance, > Tolga > > Generally, this communication is for informational purposes only > and it is not intended as an offer or solicitation for the purchase > or sale of any financial instrument or as an official confirmation > of any transaction. In the event you are receiving the offering > materials attached below related to your interest in hedge funds or > private equity, this communication may be intended as an offer or > solicitation for the purchase or sale of such fund(s). All market > prices, data and other information are not warranted as to > completeness or accuracy and are subject to change without notice. > Any comments or statements made herein do not necessarily reflect > those of JPMorgan Chase & Co., its subsidiaries and affiliates. > > This transmission may contain information that is privileged, > confidential, legally privileged, and/or exempt from disclosure > under applicable law. If you are not the intended recipient, you > are hereby notified that any disclosure, copying, distribution, or > use of the information contained herein (including any reliance > thereon) is STRICTLY PROHIBITED. Although this transmission and any > attachments are believed to be free of any virus or other defect > that might affect any computer system into which it is received and > opened, it is the responsibility of the recipient to ensure that it > is virus free and no responsibility is accepted by JPMorgan Chase & > Co., its subsidiaries and affiliates, as applicable, for any loss > or damage arising in any way from its use. If you received this > transmission in error, please immediately contact the sender and > destroy the material in its entirety, whether in electronic or hard > copy format. Thank you. > Please refer to http://www.jpmorgan.com/pages/disclosures for > disclosures relating to UK legal entities. >[[alternative HTML version deleted]] > > __ > 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. > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] making zoo objects with zoo without format argument?
x.zoo <- zoo(x,as.yearmon(as.character(x$Yearmonth), "%Y-%m")) plot(x.zoo[,25]) #Error in plot.window(...) : invalid 'ylim' value #there are values On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: > > There is no data in your data frame, just index info, so I assume you > > want a zero width time series: > > > > zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) > > > > This also works but then you are left with a character date which you > > may not want: > > > > zoo(, x$Yearmonth) > > This last one should have been: > > zoo(, as.character(x$Yearmon)) > > since your data frame holds a factor rather than character column. > > > > > > > > On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> > wrote: > >> #this is a subset of a larger data frame and I am okay with subsetting > it as > >> there are redundant time stamps, but I would like to create a zoo object > out > >> of this and I am having a hard #time figuring out how to do this the > date > >> structure is year and then month > >> > >> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, > >> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, > >> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", > >> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", > >> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", > >> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", > >> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, > >> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, > >> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" > >> ), class = "data.frame", row.names = c(NA, 23L)) > >> > >> #thanks Stephen > >> > >> -- > >> Let's not spend our time and resources thinking about things that are so > >> little or so large that all they really do for us is puff us up and make > us > >> feel like gods. We are mammals, and have not exhausted the annoying > little > >> problems of being mammals. > >> > >> -K. Mullis > >> > >>[[alternative HTML version deleted]] > >> > >> __ > >> 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. > >> > > > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] making zoo objects with zoo without format argument?
That worked fine- now one more question- plot(x.zoo[,25]) produces a graph with True as the first label on the x-axis 1. why? 2. is it wrong to assume this is february 2006? thanks stephen R2.7.1 Windows XP (I updated zoo last week when I installed 2.7.1) On Tue, Jul 8, 2008 at 3:17 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > On Tue, Jul 8, 2008 at 2:59 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > > x.zoo <- zoo(x,as.yearmon(as.character(x$Yearmonth), "%Y-%m")) > > plot(x.zoo[,25]) > > > 1. You are trying to pass data frame to zoo whereas it must be a numeric > vector, > matrix or a factor. See ?zoo and try this: > > x.zoo <- zoo(data.matrix(x), as.yearmon(x$Yearmonth, format = "%Y-%m")) > > 2. You don't need as.character (it won't hurt but its unnecessary) since > as.yearmon has a factor method. You only need as.character in the > situation cited in the last post. > > > > > > #Error in plot.window(...) : invalid 'ylim' value > > #there are values > > > > On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck < > [EMAIL PROTECTED]> > > wrote: > >> > >> On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck > >> <[EMAIL PROTECTED]> wrote: > >> > There is no data in your data frame, just index info, so I assume you > >> > want a zero width time series: > >> > > >> > zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) > >> > > >> > This also works but then you are left with a character date which you > >> > may not want: > >> > > >> > zoo(, x$Yearmonth) > >> > >> This last one should have been: > >> > >> zoo(, as.character(x$Yearmon)) > >> > >> since your data frame holds a factor rather than character column. > >> > >> > >> > > >> > > >> > On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> > >> > wrote: > >> >> #this is a subset of a larger data frame and I am okay with > subsetting > >> >> it as > >> >> there are redundant time stamps, but I would like to create a zoo > >> >> object out > >> >> of this and I am having a hard #time figuring out how to do this the > >> >> date > >> >> structure is year and then month > >> >> > >> >> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, > >> >> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, > >> >> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", > >> >> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", > >> >> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", > >> >> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", > >> >> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, > >> >> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, > >> >> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" > >> >> ), class = "data.frame", row.names = c(NA, 23L)) > >> >> > >> >> #thanks Stephen > >> >> > >> >> -- > >> >> Let's not spend our time and resources thinking about things that are > >> >> so > >> >> little or so large that all they really do for us is puff us up and > >> >> make us > >> >> feel like gods. We are mammals, and have not exhausted the annoying > >> >> little > >> >> problems of being mammals. > >> >> > >> >> -K. Mullis > >> >> > >> >>[[alternative HTML version deleted]] > >> >> > >> >> __ > >> >> 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. > >> >> > >> > > > > > > > > > -- > > Let's not spend our time and resources thinking about things that are so > > little or so large that all they really do for us is puff us up and make > us > > feel like gods. We are mammals, and have not exhausted the annoying > little > > problems of being mammals. > > > > -K. Mullis > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ 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] extracting index list when using tapply()
Hi, How about using "subset"? x1<-tapply(subset(years, length(area)>20), function(x) length(unique(x))) I hope this works Chunhao Quoting hesicaia <[EMAIL PROTECTED]>: Hello, The quick version of my question is how can I extract a matrix instead of a vector using tapply()? I would like to be able to access both the results of tapply() and also the index variables. In case further explanation would help: I am analyzing a large (3million rows x 9 columns) spatial/temporal dataset and am attempting to calculate the number of unique years containing any data within each geographic area (10 degree cells in this case). I can do this, but I also want to extract a subset vector of the index variable (area). My script to calculate the number of unique years containing any data for each area is: x<-tapply(years, area, function(x) length(unique(x))) Now, I want to extract the vector of areas where the number of unique years containing any data is >20, but tapply() only returns a vector of unique years and I was a matrix. I could use a looping function to do this, but tapply() is much faster with large datasets and so I would like to use it if possible. Any help is appreciated. Thanks. -- View this message in context: http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18345794.html Sent from the R help mailing list archive at Nabble.com. __ 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] making zoo objects with zoo without format argument?
On Tue, Jul 8, 2008 at 2:59 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > x.zoo <- zoo(x,as.yearmon(as.character(x$Yearmonth), "%Y-%m")) > plot(x.zoo[,25]) 1. You are trying to pass data frame to zoo whereas it must be a numeric vector, matrix or a factor. See ?zoo and try this: x.zoo <- zoo(data.matrix(x), as.yearmon(x$Yearmonth, format = "%Y-%m")) 2. You don't need as.character (it won't hurt but its unnecessary) since as.yearmon has a factor method. You only need as.character in the situation cited in the last post. > > #Error in plot.window(...) : invalid 'ylim' value > #there are values > > On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck <[EMAIL PROTECTED]> > wrote: >> >> On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck >> <[EMAIL PROTECTED]> wrote: >> > There is no data in your data frame, just index info, so I assume you >> > want a zero width time series: >> > >> > zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) >> > >> > This also works but then you are left with a character date which you >> > may not want: >> > >> > zoo(, x$Yearmonth) >> >> This last one should have been: >> >> zoo(, as.character(x$Yearmon)) >> >> since your data frame holds a factor rather than character column. >> >> >> > >> > >> > On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> >> > wrote: >> >> #this is a subset of a larger data frame and I am okay with subsetting >> >> it as >> >> there are redundant time stamps, but I would like to create a zoo >> >> object out >> >> of this and I am having a hard #time figuring out how to do this the >> >> date >> >> structure is year and then month >> >> >> >> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, >> >> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, >> >> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", >> >> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", >> >> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", >> >> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", >> >> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, >> >> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, >> >> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" >> >> ), class = "data.frame", row.names = c(NA, 23L)) >> >> >> >> #thanks Stephen >> >> >> >> -- >> >> Let's not spend our time and resources thinking about things that are >> >> so >> >> little or so large that all they really do for us is puff us up and >> >> make us >> >> feel like gods. We are mammals, and have not exhausted the annoying >> >> little >> >> problems of being mammals. >> >> >> >> -K. Mullis >> >> >> >>[[alternative HTML version deleted]] >> >> >> >> __ >> >> 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. >> >> >> > > > > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis __ 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] nls and "plinear" algorithm
hello all i havnt had a chance to read through the references provided for the "nls" function (since the libraries are closed now). can anyone shed some light on how the "plinear" algorithm works? also, how are the fitted values obtained? also, WHAT DOES THE ".lin" below REPRESENT? thanking you in advance ## i have a quick example: (data below) f1=nls(r~242*(p+exp(-a1*p)/a1-1/a1)*(1-exp(-a2*o))/( (100+exp(-a1*100)/a1-1/a1)*(1-exp(-a2*50)) ) , data = X.m, algorithm="plinear",start = list(a1=0.01,a2=.01),trace = TRUE) > summary(f1) Formula: r ~ 242 * (p + exp(-a1 * p)/a1 - 1/a1) * (1 - exp(-a2 * o))/((100 + exp(-a1 * 100)/a1 - 1/a1) * (1 - exp(-a2 * 50))) Parameters: Estimate Std. Error t value Pr(>|t|) a1 0.027017 0.003493 7.735 6.34e-10 *** a2 0.154967 0.012214 12.688 < 2e-16 *** .lin 1.042452 0.008010 130.140 < 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.979 on 47 degrees of freedom Number of iterations to convergence: 13 Achieved convergence tolerance: 8.91e-06 p r o 98.96338287 241.2828283 50 97.55260431 237.6262626 49 95.63989983 233.0606061 48 93.91802748 229.3232323 47 92.31404009 224.7575758 46 90.03746768 220.7878788 45 89.30649329 216.6868687 44 87.64125166 212.2020202 43 86.68123643 207.4646465 42 85.25030371 203.3939394 41 83.64465743 198.5252525 40 82.60251377 193.8787879 39 81.62361512 189.1717172 38 80.71350574 185.111 37 79.15697699 180.7171717 36 78.11234178 176.5858586 35 76.60248492 172.7272727 34 76.03845076 168.5353535 33 74.32556341 164.6060606 32 73.3639895 160.3939394 31 72.35840786 156.7272727 30 70.90629218 152.5454545 29 69.88235864 148.6161616 28 68.69538137 144.1818182 27 67.6875564 140.5151515 26 67.16355934 135.7373737 25 66.90502437 131.3636364 24 65.63480302 126.8484848 23 64.63355769 122.111 22 63.5529748 117.4040404 21 62.65320004 113.444 20 61.31100803 109.0505051 19 60.59542007 105.1836735 18 58.43200533 100.244898 17 57.13903832 96.68041237 16 56.46953877 92.4583 15 54.79475954 87.5208 14 53.85049475 82.2187513 52.50164551 77.84210526 12 51.04072849 72.87234043 11 49.64840803 68.22580645 10 48.24666285 62.76344086 9 46.36813455 58.0989011 8 44.40690015 51.85714286 7 42.8855932 45.1333 6 40.93434063 39.34090909 5 37.84871552 32.39772727 4 36.10687426 25.8372093 3 32.74320593 18.26829268 2 28.03072554 9.922077922 1 __ 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] Automatic placement of Legends
You may want to look at locator(1) for manual placements; legend(locator(),...) BW Marco -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] namens [EMAIL PROTECTED] Verzonden: di 8-7-2008 20:31 Aan: r-help@r-project.org Onderwerp: [R] Automatic placement of Legends Dear R-Users, I am looking for a way to get legends placed automagically in an empty spot on a graph. Additional complication comes through my useage of multiple graphs on the same plot through mfrow. Is there a way to achieve this in R ? I have legends for each of the sub-plots. Many thanks in advance, Tolga Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[alternative HTML version deleted]] __ 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.
[R] fisher.test
Hi! I am Marta Colombo, student in Mathematical Engineering at "Politecnico di Milano". For my master degree thesis I have to analyze some categorical data. My dataset is composed by 327 individuals and 16 variables. I am using Fisher exact test to test independence on IxJ contingency tables, but I have a problem with one variable. R gives me this error message: FEXACT error 7. LDSTP is too small for this problem. Try increasing the size of the workspace. or also this one: FEXACT error 6. LDKEY is too small for this problem. Try increasing the size of the workspace. Do you know what these error messages mean? What can I do? Thank you in advance for your kindness and attention! Best regards, Marta Colombo __ 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] making zoo objects with zoo without format argument?
Its a bug in axis.zoo. I have just fixed it in the svn repository so try this: source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/R/yearmon.R?rev=485&root=zoo";) plot(x.zoo[, 25]) axis.zoo uses the same algorithm as axis.Date in R and so it gives similar results: # uses axis.Date plot(aggregate(x.zoo[, 25], as.Date, force)) You may wish to try a custom axis: plot(x.zoo[, 25], xaxt = "n") rng <- range(time(x.zoo)) axis(1, at = seq(rng[1], rng[2], 1/12), labels = FALSE, tcl = -0.3) axis(1, at = seq(floor(rng[1]), floor(rng[2]))) On Tue, Jul 8, 2008 at 3:34 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > That worked fine- now one more question- > plot(x.zoo[,25]) > produces a graph with True as the first label on the x-axis > 1. why? > 2. is it wrong to assume this is february 2006? > > thanks > > stephen > R2.7.1 Windows XP (I updated zoo last week when I installed 2.7.1) > > On Tue, Jul 8, 2008 at 3:17 PM, Gabor Grothendieck <[EMAIL PROTECTED]> > wrote: >> >> On Tue, Jul 8, 2008 at 2:59 PM, stephen sefick <[EMAIL PROTECTED]> wrote: >> > x.zoo <- zoo(x,as.yearmon(as.character(x$Yearmonth), "%Y-%m")) >> > plot(x.zoo[,25]) >> >> >> 1. You are trying to pass data frame to zoo whereas it must be a numeric >> vector, >> matrix or a factor. See ?zoo and try this: >> >> x.zoo <- zoo(data.matrix(x), as.yearmon(x$Yearmonth, format = "%Y-%m")) >> >> 2. You don't need as.character (it won't hurt but its unnecessary) since >> as.yearmon has a factor method. You only need as.character in the >> situation cited in the last post. >> >> >> > >> > #Error in plot.window(...) : invalid 'ylim' value >> > #there are values >> > >> > On Tue, Jul 8, 2008 at 2:55 PM, Gabor Grothendieck >> > <[EMAIL PROTECTED]> >> > wrote: >> >> >> >> On Tue, Jul 8, 2008 at 2:43 PM, Gabor Grothendieck >> >> <[EMAIL PROTECTED]> wrote: >> >> > There is no data in your data frame, just index info, so I assume you >> >> > want a zero width time series: >> >> > >> >> > zoo(, as.yearmon(x$Yearmonth, "%Y-%m")) >> >> > >> >> > This also works but then you are left with a character date which you >> >> > may not want: >> >> > >> >> > zoo(, x$Yearmonth) >> >> >> >> This last one should have been: >> >> >> >> zoo(, as.character(x$Yearmon)) >> >> >> >> since your data frame holds a factor rather than character column. >> >> >> >> >> >> > >> >> > >> >> > On Tue, Jul 8, 2008 at 1:43 PM, stephen sefick <[EMAIL PROTECTED]> >> >> > wrote: >> >> >> #this is a subset of a larger data frame and I am okay with >> >> >> subsetting >> >> >> it as >> >> >> there are redundant time stamps, but I would like to create a zoo >> >> >> object out >> >> >> of this and I am having a hard #time figuring out how to do this >> >> >> the >> >> >> date >> >> >> structure is year and then month >> >> >> >> >> >> x <- structure(list(Yearmonth = structure(c(12L, 24L, 1L, 13L, 14L, >> >> >> 3L, 15L, 4L, 16L, 5L, 17L, 6L, 18L, 7L, 19L, 8L, 20L, 9L, 21L, >> >> >> 10L, 22L, 11L, 23L), .Label = c("2006-02", "2006-03", "2006-04", >> >> >> "2006-05", "2006-06", "2006-07", "2006-08", "2006-09", "2006-10", >> >> >> "2006-11", "2006-12", "2007-01", "2007-02", "2007-03", "2007-04", >> >> >> "2007-05", "2007-06", "2007-07", "2007-08", "2007-09", "2007-10", >> >> >> "2007-11", "2007-12", "2008-01"), class = "factor"), Month = c(1L, >> >> >> 1L, 2L, 2L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, >> >> >> 10L, 10L, 11L, 11L, 12L, 12L)), .Names = c("Yearmonth", "Month" >> >> >> ), class = "data.frame", row.names = c(NA, 23L)) >> >> >> >> >> >> #thanks Stephen >> >> >> >> >> >> -- >> >> >> Let's not spend our time and resources thinking about things that >> >> >> are >> >> >> so >> >> >> little or so large that all they really do for us is puff us up and >> >> >> make us >> >> >> feel like gods. We are mammals, and have not exhausted the annoying >> >> >> little >> >> >> problems of being mammals. >> >> >> >> >> >> -K. Mullis >> >> >> >> >> >>[[alternative HTML version deleted]] >> >> >> >> >> >> __ >> >> >> 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. >> >> >> >> >> > >> > >> > >> > >> > -- >> > Let's not spend our time and resources thinking about things that are so >> > little or so large that all they really do for us is puff us up and make >> > us >> > feel like gods. We are mammals, and have not exhausted the annoying >> > little >> > problems of being mammals. >> > >> > -K. Mullis > > > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis __
[R] calculation of entropy in R???
i want to calculate shannon entropy which is H1,H2,H3upto H7? if there is any function or any package in which i can find this entropy directly. do you have any information please share this and i will be very thankful to you. Regards, ++ MUHAMMAD FAISAL Department of Statistics and Decion Support system, University of Vienna,Austria Res. # +4314796696104 Cell # +436503605156 Office # +431427738662 +++ [[alternative HTML version deleted]] __ 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] Fwd: Re: extracting index list when using tapply()
The following message is provided by Erik Please provide the reproducible code to do this. Generate a sample data set using the random data generating functions and show us what you'd like, we can then more easily help. [EMAIL PROTECTED] wrote: Hi, How about using "subset"? x1<-tapply(subset(years, length(area)>20), function(x) length(unique(x))) I hope this works Chunhao Quoting hesicaia <[EMAIL PROTECTED]>: Hello, The quick version of my question is how can I extract a matrix instead of a vector using tapply()? I would like to be able to access both the results of tapply() and also the index variables. In case further explanation would help: I am analyzing a large (3million rows x 9 columns) spatial/temporal dataset and am attempting to calculate the number of unique years containing any data within each geographic area (10 degree cells in this case). I can do this, but I also want to extract a subset vector of the index variable (area). My script to calculate the number of unique years containing any data for each area is: x<-tapply(years, area, function(x) length(unique(x))) Now, I want to extract the vector of areas where the number of unique years containing any data is >20, but tapply() only returns a vector of unique years and I was a matrix. I could use a looping function to do this, but tapply() is much faster with large datasets and so I would like to use it if possible. Any help is appreciated. Thanks. -- View this message in context: http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18345794.html Sent from the R help mailing list archive at Nabble.com. __ 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. - End forwarded message - __ 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] nls and "plinear" algorithm
On 7/8/2008 2:33 PM, Allan Clark wrote: hello all i havnt had a chance to read through the references provided for the "nls" function (since the libraries are closed now). can anyone shed some light on how the "plinear" algorithm works? Nonlinear regression is least squares. There are standard linear algebra methods for solving least squares problems which are linear in the parameters. plinear models are linear in some of the parameters for fixed values of the others, so the nonlinear search only needs to optimize the linear fit over the nonlinear parts of the model: it's much faster than a fully nonlinear search over all the parameters. > also, how are the fitted values obtained? also, WHAT DOES THE ".lin" below REPRESENT? It's a linear multiplier applied to the whole expression you give, essentially changing the formula to r ~ .lin * 242 * (p + exp(-a1 * p)/a1 - 1/a1) * (1 - exp(-a2 * o))/((100 + exp(-a1 * 100)/a1 - 1/a1) * (1 - exp(-a2 * 50))) You can also compare the two DNase1 examples in the ?nls page. In the second one, Asym plays the role of .lin. Duncan Murdoch thanking you in advance ## i have a quick example: (data below) f1=nls(r~242*(p+exp(-a1*p)/a1-1/a1)*(1-exp(-a2*o))/( (100+exp(-a1*100)/a1-1/a1)*(1-exp(-a2*50)) ) , data = X.m, algorithm="plinear",start = list(a1=0.01,a2=.01),trace = TRUE) summary(f1) Formula: r ~ 242 * (p + exp(-a1 * p)/a1 - 1/a1) * (1 - exp(-a2 * o))/((100 + exp(-a1 * 100)/a1 - 1/a1) * (1 - exp(-a2 * 50))) Parameters: Estimate Std. Error t value Pr(>|t|) a1 0.027017 0.003493 7.735 6.34e-10 *** a2 0.154967 0.012214 12.688 < 2e-16 *** .lin 1.042452 0.008010 130.140 < 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.979 on 47 degrees of freedom Number of iterations to convergence: 13 Achieved convergence tolerance: 8.91e-06 p r o 98.96338287 241.2828283 50 97.55260431 237.6262626 49 95.63989983 233.0606061 48 93.91802748 229.3232323 47 92.31404009 224.7575758 46 90.03746768 220.7878788 45 89.30649329 216.6868687 44 87.64125166 212.2020202 43 86.68123643 207.4646465 42 85.25030371 203.3939394 41 83.64465743 198.5252525 40 82.60251377 193.8787879 39 81.62361512 189.1717172 38 80.71350574 185.111 37 79.15697699 180.7171717 36 78.11234178 176.5858586 35 76.60248492 172.7272727 34 76.03845076 168.5353535 33 74.32556341 164.6060606 32 73.3639895 160.3939394 31 72.35840786 156.7272727 30 70.90629218 152.5454545 29 69.88235864 148.6161616 28 68.69538137 144.1818182 27 67.6875564 140.5151515 26 67.16355934 135.7373737 25 66.90502437 131.3636364 24 65.63480302 126.8484848 23 64.63355769 122.111 22 63.5529748 117.4040404 21 62.65320004 113.444 20 61.31100803 109.0505051 19 60.59542007 105.1836735 18 58.43200533 100.244898 17 57.13903832 96.68041237 16 56.46953877 92.4583 15 54.79475954 87.5208 14 53.85049475 82.2187513 52.50164551 77.84210526 12 51.04072849 72.87234043 11 49.64840803 68.22580645 10 48.24666285 62.76344086 9 46.36813455 58.0989011 8 44.40690015 51.85714286 7 42.8855932 45.1333 6 40.93434063 39.34090909 5 37.84871552 32.39772727 4 36.10687426 25.8372093 3 32.74320593 18.26829268 2 28.03072554 9.922077922 1 __ 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] nls and "plinear" algorithm
Allan Clark wrote: hello all i havnt had a chance to read through the references provided for the "nls" function (since the libraries are closed now). can anyone shed some light on how the "plinear" algorithm works? also, how are the fitted values obtained? also, WHAT DOES THE ".lin" below REPRESENT? Essentially it gets multiplied onto the 242 (if I got the parenthesis count right). The whole thing is probably better explained using a simpler example: y ~ A*exp(-a*x) + B*exp(-b*x) is partially linear. If you fix a and b, finding A and B is a linear regression problem. So you can say y ~ cbind(exp(-a*x), exp(-b*x)), algorithm="plinear", start=c(.5, .05) (notice that the left hand side is a matrix if there is more than one linear parameter) thanking you in advance ## i have a quick example: (data below) f1=nls(r~242*(p+exp(-a1*p)/a1-1/a1)*(1-exp(-a2*o))/( (100+exp(-a1*100)/a1-1/a1)*(1-exp(-a2*50)) ) , data = X.m, algorithm="plinear",start = list(a1=0.01,a2=.01),trace = TRUE) summary(f1) Formula: r ~ 242 * (p + exp(-a1 * p)/a1 - 1/a1) * (1 - exp(-a2 * o))/((100 + exp(-a1 * 100)/a1 - 1/a1) * (1 - exp(-a2 * 50))) Parameters: Estimate Std. Error t value Pr(>|t|) a1 0.027017 0.003493 7.735 6.34e-10 *** a2 0.154967 0.012214 12.688 < 2e-16 *** .lin 1.042452 0.008010 130.140 < 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.979 on 47 degrees of freedom Number of iterations to convergence: 13 Achieved convergence tolerance: 8.91e-06 p r o 98.96338287 241.2828283 50 97.55260431 237.6262626 49 95.63989983 233.0606061 48 93.91802748 229.3232323 47 92.31404009 224.7575758 46 90.03746768 220.7878788 45 89.30649329 216.6868687 44 87.64125166 212.2020202 43 86.68123643 207.4646465 42 85.25030371 203.3939394 41 83.64465743 198.5252525 40 82.60251377 193.8787879 39 81.62361512 189.1717172 38 80.71350574 185.111 37 79.15697699 180.7171717 36 78.11234178 176.5858586 35 76.60248492 172.7272727 34 76.03845076 168.5353535 33 74.32556341 164.6060606 32 73.3639895 160.3939394 31 72.35840786 156.7272727 30 70.90629218 152.5454545 29 69.88235864 148.6161616 28 68.69538137 144.1818182 27 67.6875564 140.5151515 26 67.16355934 135.7373737 25 66.90502437 131.3636364 24 65.63480302 126.8484848 23 64.63355769 122.111 22 63.5529748 117.4040404 21 62.65320004 113.444 20 61.31100803 109.0505051 19 60.59542007 105.1836735 18 58.43200533 100.244898 17 57.13903832 96.68041237 16 56.46953877 92.4583 15 54.79475954 87.5208 14 53.85049475 82.2187513 52.50164551 77.84210526 12 51.04072849 72.87234043 11 49.64840803 68.22580645 10 48.24666285 62.76344086 9 46.36813455 58.0989011 8 44.40690015 51.85714286 7 42.8855932 45.1333 6 40.93434063 39.34090909 5 37.84871552 32.39772727 4 36.10687426 25.8372093 3 32.74320593 18.26829268 2 28.03072554 9.922077922 1 __ 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. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] Automatic placement of Legends
You may be able to use the coordinates returned from emptyspace() in plotrix package as coordinates for the legend in legend(). tolga.i.uzuner wrote: > > ... > I am looking for a way to get legends placed automagically in an empty > spot on a graph. Additional complication comes through my useage of > multiple graphs on the same plot through mfrow. > > Is there a way to achieve this in R ? I have legends for each of the > sub-plots. > ... > -- View this message in context: http://www.nabble.com/Automatic-placement-of-Legends-tp18346098p18348418.html Sent from the R help mailing list archive at Nabble.com. __ 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] aggregate() function and na.rm = TRUE
All, I've been using aggregate() to compute means and standard deviations at time/treatment combinations for a longitudinal dataset, using na.rm = TRUE for missing data. This was working fine before, but now when I re-run some old code it isn't. I've backtracked my steps and can't seem to find out why it was working before but not now. In any event, below is a reproducible example of the current problem, viz., calculating the standard deviation via aggregate and employing na.rm = TRUE is not working. Thanks, David dat = data.frame( Hour = c(0, 0, 0, 0, 1, 1,1, 1), Drug = factor(c("P", "D", "P", "D", "P", "D", "P", "D")), Y1 = rnorm(8, 0), Y2 = c(NA, NA, NA, NA, 1, 2, 3, 4) ) > aggregate(dat[c(3,4)], dat[c(1,2)], mean) Hour Drug Y1 Y2 10D -0.75534554 NA 21D 0.27529835 3 30P -0.03949923 NA 41P 0.02627489 2 > aggregate(dat[c(3,4)], dat[c(1,2)], sd) Error in var(x, na.rm = na.rm) : missing observations in cov/cor > aggregate(dat[c(3,4)], dat[c(1,2)], sd, na.rm = TRUE) Error in var(x, na.rm = na.rm) : no complete element pairs > sessionInfo() R version 2.7.1 (2008-06-23) i386-apple-darwin8.10.1 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] grid_2.7.1 lattice_0.17-8 nlme_3.1-89 > __ 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] Change in behaviour of sd()
On 8/07/2008, at 7:38 PM, Fiona Johnson wrote: Hi I have just upgraded from R2.6.0 to R2.7.1 (running on Windows) and a part of my code that previously ran ok now gives an error. The following is a simple example to demonstrate my problem. a <- array(c(1,2,3,4,5,6,rep(NA,6)),dim=c(6,2)) apply(a,2,sd,na.rm=T) In R2.6.0 this gives (which is what I would like) [1] 1.870829 NA In R2.7.1 it gives the following error "Error in var(x, na.rm = na.rm) : no complete element pairs" As my columns are always either all NA or all numbers, I could get around it by replacing the NA's with 0's but if someone could shed some light on why the behaviour has changed in the new version or a better work around it would be much appreciated. I want to keep the columns of NA's because ultimately I am plotting the results with contour and the NA's refer to grid cells not on land where I don't want to have contours. I just scanned through the release announcements (from Peter Dalgaard) about new versions of R (R home page --> What's new? --> Archive of important announcements) and found nothing about new behaviour for sd/var/cov. So I cannot contribute to enlightenment about ``why''. The following function might provide a suitable workaround: my.sd <- function (x, na.rm = FALSE) { if (is.matrix(x)) apply(x, 2, my.sd, na.rm = na.rm) else if (is.vector(x)) { if(na.rm) x <- x[!is.na(x)] if(length(x) == 0) return(NA) sqrt(var(x, na.rm = na.rm)) } else if (is.data.frame(x)) sapply(x, my.sd, na.rm = na.rm) else { x <- as.vector(x) my.sd(x,na.rm=na.rm) } } It seems to work on your toy example at least. Note that my.sd (numeric(0)) returns NA, but my.sd(NULL) throws an error. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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] Sum(Random Numbers)=100
On Tue, Jul 8, 2008 at 9:53 AM, Shubha Vishwanath Karanth < [EMAIL PROTECTED]> wrote: > ...actually I need to allocate certain amount of money (here I mentioned > it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being > divided among 50 stocks and preferably all are integer allocations(i.e., > 5 8 56 12 etc without any decimals)... so perhaps you can reformulate your problem: instead of generating random numbers with their sum constrained to be 100, it could be dividing 100 units randomly between 50 "bins", which is, essentially, random sampling with replacement stocks <- 1:50 money <- 100 allocations <- sample(stocks, money, replace=TRUE) # here you can add a prob argument to sample() # especially if you expect the results to be something like " 5 8 56 12 etc " allocations <- table(factor(allocations, levels=stocks)) # or, equivalently, colSums(outer(allocations, stocks, "==")) I don't know if this solves your problem but at least it's guaranteed to sum to 100 and give you only integer values. Kenn [[alternative HTML version deleted]] __ 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.