Re: [R] nls convergence problem
Earl F. Glynn efg at stowers-institute.org writes: It's not clear to me why this problem cannot be fixed somehow. You You might try optim instead of nls, which always (well, as far I used it) converges. However, resulting coefficients may be totally off, and you should use profiling to check the reliability. Dieter __ R-help@stat.math.ethz.ch 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] A model for possibly periodic data with varying amp litude [repost, much edited]
Andrew Robinson A.Robinson at ms.unimelb.edu.au writes: I have up to 12 measures of a protein for each of 6 patients, taken every two or three days. The pattern of the protein looks periodic, but the height of the peaks is highly variable. I'm testing for periodicity using a Monte Carlo simulation envelope approach applied to a cumulative periodogram. Now I want to predict the location of the peaks in time. Of course, the peaks might be occurring on unmeasured days. Have you checked one of the methods in Chapter 13. of MASS to obtain a smoothed estimate? Dieter __ R-help@stat.math.ethz.ch 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] Presentation of multiple models in one table using xtable
Ajay Narottam Shah ajayshah at mayin.org writes: Consider this situation: x1 - runif(100); x2 - runif(100); y - 2 + 3*x1 - 4*x2 + rnorm(100) m1 - summary(lm(y ~ x1)) m2 - summary(lm(y ~ x2)) m3 - summary(lm(y ~ x1 + x2)) Now you have estimated 3 different competing models, and suppose you want to present the set of models in one table. xtable(m1) is cool, but doing that thrice would give us 3 different tables. What I want is this one table: --- M1 M2 M3 --- Intercept 0.0816 3.6292 2.2272 (0.5533) (0.2316)***(0.2385)*** .. (my gmane newreader complains when I quote too much, and contrary to the general believe on this list, I think he is right). There is no standard way of doing this, so the first formatting must be done manually. For a nice output, check the R2HTML packages and the latex() derivates in Frank Harrell's Hmisc package. Dieter __ R-help@stat.math.ethz.ch 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] Regular expressions: retrieving matches depending on intervening strings
Dear all I again have a regular expression question. I have this character vector a: a-c(w AT0a w NN1blockage w CJCand w DT0thatc PUN., w AT0a w NN1blockage w CJCand ptr target=KB2LC003w DT0thatc PUN., w AT0a w NN1blockage w CJCandc PUN, w DT0thatc PUN., w AT0a w NN1blockage w CJCand w AJ0hungry w DT0thatc PUN.) I would like to retrieve those elements of a in which w CJC and w DT0 are - directly adjacent, as in a[1] or - not interrupted by [wc] , as in a[2] And, of these elements I would like to consume all characters from the in w CJC to the last character after w DT0 that is not a . For example, if I was only searching a[1], I would like something like this: matches-gregexpr(w CJC[^]+?w DT0[^]+, a[1], perl=TRUE) substr(a[1], unlist(matches), unlist(matches)+unlist(attributes(matches[[1]], match.length))-1) I have been fiddling around with negative lookahead but I really can't get my head around this. Any pointers would be greatly appreciated. Thanks a lot, STG -- Stefan Th. Gries --- University of California, Santa Barbara http://www.linguistics.ucsb.edu/faculty/stgries __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen University of Turku, Finland __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
try something like the following: x - c(3,3,2,4,5,5,3,3,5,1,6,6) # nx - length(x) ind - c(TRUE, (x[1:(nx-1)] - x[2:nx]) != 0) x[ind] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Atte Tenkanen [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, August 16, 2006 9:42 AM Subject: [R] How to remove similar successive objects from a vector? Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen University of Turku, Finland __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6) NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR) NEWVECTOR[!is.na(NEWVECTOR)] [1] 3 2 3 4 5 3 5 1 --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Atte Tenkanen a écrit : Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen University of Turku, Finland __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 remove similar successive objects from a vector?
On Wed, Aug 16, 2006 at 10:42:35AM +0300, Atte Tenkanen wrote: Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 How about rle? rle(VECTOR)$values should do the same thing. Don't know about efficiency, though. -- Jarimatti Valkonen __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
On Wed, 2006-08-16 at 10:42 +0300, Atte Tenkanen wrote: Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen Is this what you mean? x - c(3, 2, 4, 5, 5, 3, 3, 5, 1, 6, 6) x.wanted - c(3, 2, 4, 5, 3, 5, 1, 6) X - x[diff(x) != 0] all.equal(x.wanted, X) # check it works G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% *Note new Address and Fax and Telephone numbers from 10th April 2006* %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC [f] +44 (0)20 7679 0565 UCL Department of Geography Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street London, UK[w] http://www.ucl.ac.uk/~ucfagls/cv/ WC1E 6BT [w] http://www.ucl.ac.uk/~ucfagls/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch 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] Grasper model error
I'm not too familiar with using grasp, but the error is generated from the `mgcv' package while setting up a GAM. The default smooths used for `s' terms by mgcv::gam are thin plate regression splines based on an `eigen approximation' to full thin plate splines. These have some nice properties but become expensive to set up for data sets with more than a few thousand points, in which case it is better to use a different basis for smooths of one variable, e.g. s(x,bs=cr) or for smooths of several variables use either tensor product smooths, e.g. te(x,z) or use the `knots' argument to `gam' in the way shown at the end of the examples in the `gam' help file. Simon On Tuesday 15 August 2006 19:29, Ken Nussear wrote: I tried this over a the grasp users yahoo group and got no responseSo I wonder if anyone here knows about grasper I keep getting this error when trying to run a model. Error in smooth.construct.tp.smooth.spec(object, data, knots) : Too many knots for t.p.r.s term: see `gam.control' to increase limit, or use a different basis, or see large data set help for `gam'. I'm using R for OSX Gui Version 1.16 R-version 2.3.1, running grasper version 0.4-4 My dataset has ~7500 rows of input, and 21 cols of input. Does anyone have an idea how to troubleshoot this? Thanks Ken [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ R-help@stat.math.ethz.ch 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] Regular expressions: retrieving matches depending on intervening strings [Follow-up]
Dear all This is a follow-up to an earlier posting today regarding a regular expression question. In the meantime, this is the best approximation I could come up with and should give you a better idea what I am talking about. a-c(w AT0a w NN1blockage w CJCand w DT0thatc PUN., w AT0a w NN1blockage w CJCand ptr target=KB2LC003w DT0thatc PUN., w AT0a w NN1blockage w CJCandc PUN, w DT0thatc PUN., w AT0a w NN1blockage w CJCand w AJ0hungry w DT0thatc PUN.) matches-gregexpr(w CJC[^]+(?:[^wc].*?.*?)*w DT0that, a, perl=TRUE) starts-unlist(matches) lengths-unlist(sapply(matches, attributes)) stops-starts+lengths-1 substr(a, starts, stops) What is still missing is that the disallowed string is not just [wc] but [wc] and I don't know how to do that. Any ideas (preferably with lookarounds)? Thanks a bunch, STG -- Stefan Th. Gries --- University of California, Santa Barbara http://www.linguistics.ucsb.edu/faculty/stgries --- ORIGINAL MESSAGE Dear all I again have a regular expression question. I have this character vector a: a-c(w AT0a w NN1blockage w CJCand w DT0thatc PUN., w AT0a w NN1blockage w CJCand ptr target=KB2LC003w DT0thatc PUN., w AT0a w NN1blockage w CJCandc PUN, w DT0thatc PUN., w AT0a w NN1blockage w CJCand w AJ0hungry w DT0thatc PUN.) I would like to retrieve those elements of a in which w CJC and w DT0 are - directly adjacent, as in a[1] or - not interrupted by [wc] , as in a[2] And, of these elements I would like to consume all characters from the in w CJC to the last character after w DT0 that is not a . For example, if I was only searching a[1], I would like something like this: matches-gregexpr(w CJC[^]+?w DT0[^]+, a[1], perl=TRUE) substr(a[1], unlist(matches), unlist(matches)+unlist(attributes(matches[[1]], match.length))-1) I have been fiddling around with negative lookahead but I really can't get my head around this. Any pointers would be greatly appreciated. Thanks a lot, STG __ R-help@stat.math.ethz.ch 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] A model for possibly periodic data with varying amplitude [repost, much edited]
Thanks for your response. No, I haven't - I just looked and didn't see anything that looked suitable for 12 data points. Can you be more precise? Cheers Andrew On Wed, Aug 16, 2006 at 06:43:02AM +, Dieter Menne wrote: Andrew Robinson A.Robinson at ms.unimelb.edu.au writes: I have up to 12 measures of a protein for each of 6 patients, taken every two or three days. The pattern of the protein looks periodic, but the height of the peaks is highly variable. I'm testing for periodicity using a Monte Carlo simulation envelope approach applied to a cumulative periodogram. Now I want to predict the location of the peaks in time. Of course, the peaks might be occurring on unmeasured days. Have you checked one of the methods in Chapter 13. of MASS to obtain a smoothed estimate? Dieter __ R-help@stat.math.ethz.ch 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. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: [EMAIL PROTECTED] http://www.ms.unimelb.edu.au __ R-help@stat.math.ethz.ch 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] REML with random slopes and random intercepts giving strange results
Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
On Wed, 2006-08-16 at 13:01 +0300, Atte Tenkanen wrote: Thanks for all respondents! I wasn't precise enough, when I enclosed my example. In fact, I need a version which works with all kinds of symbolic data, not only with numbers. So these versions rle(VECTOR)$values and VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6) NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR) NEWVECTOR[!is.na(NEWVECTOR)] Note that the above is not giving the same answer as rle(VECTOR)$values : VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6) NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR) NEWVECTOR[!is.na(NEWVECTOR)] [1] 3 2 3 4 5 3 5 1 rle(VECTOR)$values [1] 3 2 3 4 5 3 5 1 6 all.equal(NEWVECTOR[!is.na(NEWVECTOR)], rle(VECTOR)$values) [1] Numeric: lengths (8, 9) differ So make sure you use the rle solution. G answered to my needs. I made a test and the first version was 2.5x faster with my data, but both works enough fast. Atte On Wed, 2006-08-16 at 08:58 +0100, Patrick Burns wrote: I think rle(VECTOR)$values will get you what you want. 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) Atte Tenkanen wrote: Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen University of Turku, Finland __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC ENSIS, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/ UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch 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] [SPAM] - RE: REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam
Can you provide the summary(m2) results? -Original Message- From: Simon Pickett [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 7:14 AM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: [SPAM] - RE: [R] REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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 remove similar successive objects from a vector?
- Original Message - From: Gavin Simpson [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, August 16, 2006 1:21 PM Subject: Re: [R] How to remove similar successive objects from a vector? On Wed, 2006-08-16 at 13:01 +0300, Atte Tenkanen wrote: Thanks for all respondents! I wasn't precise enough, when I enclosed my example. In fact, I need a version which works with all kinds of symbolic data, not only with numbers. So these versions rle(VECTOR)$values and VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6) NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR) NEWVECTOR[!is.na(NEWVECTOR)] Note that the above is not giving the same answer as rle(VECTOR)$values : VECTOR=c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6) NEWVECTOR - ifelse(VECTOR[-length(VECTOR)]==VECTOR[-1],NA,VECTOR) NEWVECTOR[!is.na(NEWVECTOR)] [1] 3 2 3 4 5 3 5 1 rle(VECTOR)$values [1] 3 2 3 4 5 3 5 1 6 all.equal(NEWVECTOR[!is.na(NEWVECTOR)], rle(VECTOR)$values) [1] Numeric: lengths (8, 9) differ So make sure you use the rle solution. G interestingly, if speed matters, then the 2nd and 3rd solutions below seem slightly faster than rle(): x - rep(c(3,2,2,3,4,4,5,5,5,3,3,3,5,1,6,6), 5000) system.time(for(i in 1:1000) out1 - rle(x)$values) [1] 55.44 2.08 57.89NANA system.time(for(i in 1:1000) { + nx - length(x) + ind - c(TRUE, (x[1:(nx-1)] - x[2:nx]) != 0) + out2 - x[ind] + }) [1] 27.69 2.28 30.36NANA system.time(for(i in 1:1000) out3 - x[diff(x) != 0]) [1] 22.30 2.32 24.62NANA all.equal(out1, out2) [1] TRUE all.equal(out1, out3) [1] TRUE Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm answered to my needs. I made a test and the first version was 2.5x faster with my data, but both works enough fast. Atte On Wed, 2006-08-16 at 08:58 +0100, Patrick Burns wrote: I think rle(VECTOR)$values will get you what you want. 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) Atte Tenkanen wrote: Is there some (much) more efficient way to do this? VECTOR=c(3,2,4,5,5,3,3,5,1,6,6); NEWVECTOR=VECTOR[1]; for(i in 1:(length(VECTOR)-1)) { if((identical(VECTOR[i], VECTOR[i+1]))==FALSE){ NEWVECTOR=c(NEWVECTOR,VECTOR[i+1])} } VECTOR [1] 3 2 4 5 5 3 3 5 1 6 6 NEWVECTOR [1] 3 2 4 5 3 5 1 6 ___ Atte Tenkanen University of Turku, Finland __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC ENSIS, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/ UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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] [SPAM] - RE: REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam
sure, thanks again. summary(m2) Linear mixed-effects model fit by REML Formula: change.wt ~ newwt + (newwt | id) Data: grow AIC BIC logLik MLdeviance REMLdeviance -6203.178 -6164.462 3107.589 -6239.374-6215.178 Random effects: Groups NameVariance Std.Dev. Corr id (Intercept) 1.0868e-02 0.1042482 newwt 4.7069e-05 0.0068606 -1.000 Residual 1.4236e-02 0.1193136 # of obs: 4688, groups: id, 485 Fixed effects: Estimate Std. Error DF t value Pr(|t|) (Intercept) 5.5692e-01 6.4189e-03 4686 86.761 2.2e-16 *** newwt -3.2382e-02 4.5962e-04 4686 -70.455 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) newwt -0.954 Can you provide the summary(m2) results? -Original Message- From: Simon Pickett [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 7:14 AM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: [SPAM] - RE: [R] REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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] [SPAM] - RE: REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam
Simon Pickett [EMAIL PROTECTED] writes: sure, thanks again. What is the order of magnitude of newwt? If it is large and with a small variance, then the -1 correlation might be an artifact of extrapolating the individual lines to zero. Try centering newwt by subtracting its mean. summary(m2) Linear mixed-effects model fit by REML Formula: change.wt ~ newwt + (newwt | id) Data: grow AIC BIC logLik MLdeviance REMLdeviance -6203.178 -6164.462 3107.589 -6239.374-6215.178 Random effects: Groups NameVariance Std.Dev. Corr id (Intercept) 1.0868e-02 0.1042482 newwt 4.7069e-05 0.0068606 -1.000 Residual 1.4236e-02 0.1193136 # of obs: 4688, groups: id, 485 Fixed effects: Estimate Std. Error DF t value Pr(|t|) (Intercept) 5.5692e-01 6.4189e-03 4686 86.761 2.2e-16 *** newwt -3.2382e-02 4.5962e-04 4686 -70.455 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) newwt -0.954 Can you provide the summary(m2) results? -Original Message- From: Simon Pickett [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 7:14 AM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: [SPAM] - RE: [R] REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Specifying Path Model in SEM for CFA
Dear Rick, There are a couple of problems here: (1) You've fixed the error variance parameters for each of the observed variables to 1 rather than defining each as a free parameter to estimate. For example, use X1 - X1, theta1, NA Rather than X1 - X1, NA, 1 The general principle is that if you give a parameter a name, it's a free parameter to be estimated; if you give the name as NA, then the parameter is given a fixed value (here, 1). (There is some more information on this and on error-variance parameters in ?sem.) (2) I believe that the model you're trying to specify -- in which all variables but X6 load on F1, and all variables but X1 load on F2 -- is underidentified. In addition, you've set the metric of the factors by fixing one loading to 0.20 and another to 0.25. That should work but strikes me as unusual, and makes me wonder whether this was what you really intended. It would be more common in a CFA to fix the variance of each factor to 1, and let the factor loadings be free parameters. Then the factor covariance would be their correlation. You should not have to specify start values for free parameters (such as g11, g22, and g12 in your model), though it is not wrong to do so. I would not, however, specify start values that imply a singular covariance matrix among the factors, as you've done; I'm surprised that the program was able to get by the start values to produce a solution. BTW, the Thurstone example in ?sem is for a confirmatory factor analysis (albeit a slightly more complicated one with a second-order factor). There's also an example of a one-factor CFA in the paper at http://socserv.socsci.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf, though this is for ordinal observed variables. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rick Bilonick Sent: Tuesday, August 15, 2006 11:50 PM To: R Help Subject: [R] Specifying Path Model in SEM for CFA I'm using specify.model for the sem package. I can't figure out how to represent the residual errors for the observed variables for a CFA model. (Once I get this working I need to add some further constraints.) Here is what I've tried: model.sa - specify.model() F1 - X1,l11, NA F1 - X2,l21, NA F1 - X3,l31, NA F1 - X4,l41, NA F1 - X5, NA, 0.20 F2 - X1,l12, NA F2 - X2,l22, NA F2 - X3,l32, NA F2 - X4,l42, NA F2 - X6, NA, 0.25 F1 - F2,g12, 1 F1- F1,g11, 1 F2- F2,g22, 1 X1 - X1, NA, 1 X2 - X2, NA, 1 X3 - X3, NA, 1 X4 - X4, NA, 1 X5 - X5, NA, 1 X6 - X6, NA, 1 This at least converges: summary(fit.sem) Model Chisquare = 2147 Df = 10 Pr(Chisq) = 0 Chisquare (null model) = 2934 Df = 15 Goodness-of-fit index = 0.4822 Adjusted goodness-of-fit index = -0.087387 RMSEA index = 0.66107 90 % CI: (NA, NA) Bentler-Bonnett NFI = 0.26823 Tucker-Lewis NNFI = -0.098156 Bentler CFI = 0.26790 BIC = 2085.1 Normalized Residuals Min. 1st Qu. MedianMean 3rd Qu.Max. -5.990 -0.618 0.192 0.165 1.700 3.950 Parameter Estimates Estimate Std Error z value Pr(|z|) l11 -0.245981 0.21863 -1.12510 0.26054748 X1 --- F1 l21 -0.308249 0.22573 -1.36555 0.17207875 X2 --- F1 l31 0.202590 0.079102.56118 0.01043175 X3 --- F1 l41 -0.235156 0.21980 -1.06985 0.28468885 X4 --- F1 l12 0.839985 0.219623.82476 0.00013090 X1 --- F2 l22 0.828460 0.225483.67418 0.00023862 X2 --- F2 l32 0.066722 0.083690.79725 0.42530606 X3 --- F2 l42 0.832037 0.218403.80963 0.00013917 X4 --- F2 g12 0.936719 0.643311.45609 0.14536647 F2 -- F1 g11 2.567669 1.256082.04418 0.04093528 F1 -- F1 g22 1.208497 0.550402.19567 0.02811527 F2 -- F2 Iterations = 59 And it produces the following path diagram: path.diagram(fit.sem) digraph fit.sem { rankdir=LR; size=8,8; node [fontname=Helvetica fontsize=14 shape=box]; edge [fontname=Helvetica fontsize=10]; center=1; F2 [shape=ellipse] F1 [shape=ellipse] F1 - X1 [label=l11]; F1 - X2 [label=l21]; F1 - X3 [label=l31]; F1 - X4 [label=l41]; F1 - X5 [label=]; F2 - X1 [label=l12]; F2 - X2 [label=l22]; F2 - X3 [label=l32]; F2 - X4 [label=l42]; F2 - X6 [label=]; } But I don't see the residual error terms that go into each of the observed variables X1 - X6. I've tried: model.sa - specify.model() E1 - X1, e1, 1 E2 - X2, e2, 1 E3 - X3, e3, 1 E4 - X4, e4, 1 E5 - X5, e5, 1 E6 - X6, e6, 1 E1 - E1, s1, NA E2 - E2, s2, NA E3 - E3, s3, NA E4 - E4, s4, NA E5 - E5, s5, NA E6 - E6, s6, NA F1 - X1,l11, NA F1 - X2,l21, NA F1 - X3,l31, NA
[R] advice on exporting a distance matrix in the correct format needed please
Hi there Could anyone please tell me how to export a distance matrix to a .csv file please? when I tried write(matrix) I got the values but not in the format of a distance matrix - just a list of numbers in 4 columns - and when I try write.table(matrix, file=distance.csv) I get the following Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class dist into a data.frame Any suggestions much appreciated [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Problem with the special argument '...' within a function
Dear all, I wrote some functions using the special argument '...'. OK, it works. But if I call such a function which also called such a function, then I get an error message about unused arguments. Here's an example: fun1 - function(x,a=1) { print(paste(x=,x)) print(paste(a=,a)) } fun2 - function(y,b=2) { print(paste(y=,y)) print(paste(b=,b)) } myfun - function(c, ...) { print(paste(c=,c)) fun1(x=c,...) fun2(y=c,...) } This is OK. myfun(c=3) [1] c= 3 [1] x= 3 [1] a= 1 [1] y= 3 [1] b= 2 myfun(c=3,a=4) [1] c= 3 [1] x= 3 [1] a= 4 Error in fun2(y = c, ...) : unused argument(s) (a ...) I understand the error message because fun2 has no argument called 'a'. But how can I avoid this??? I want to use this in order to be able to call myfun() with all arguments to control myfun(),fun1(), and fun2(). Please help! Thanks, Hans __ R-help@stat.math.ethz.ch 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] advice on exporting a distance matrix in the correct format needed please
In order to get a table structure out of a dist object use 'as.matrix ()' like 'as.matrix(dist(myMatrix))' and write.table(). Hans On 16 Aug 2006, at 14:46, Ffenics wrote: Hi there Could anyone please tell me how to export a distance matrix to a .csv file please? when I tried write(matrix) I got the values but not in the format of a distance matrix - just a list of numbers in 4 columns - and when I try write.table(matrix, file=distance.csv) I get the following Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class dist into a data.frame Any suggestions much appreciated [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] fitting truncated normal distribution
Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) : nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ R-help@stat.math.ethz.ch 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 convergence problem
Earl F. Glynn wrote: Berton Gunter [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Or, maybe there's something I don't understand about the algorithm being used. Indeed! So before making such comments, why don't you try to learn about it? Doug Bates is a pretty smart guy, and I think you do him a disservice when you assume that he somehow overlooked something that he explicitly warned you about. I am fairly confident that if he could have made the problem go away, he would have. So I think your vent was a bit inconsiderate and perhaps even intemperate. The R Core folks have produced a minor miracle IMO, and we should all be careful before assuming that they have overlooked easily fixable problems. They're certainly not infallible -- but they're a lot less fallible than most of the rest of us when it comes to R. I meant no disrespect to Doug Bates or any of the R Core folks. I thought what I wrote had a neutral tone and was respectful. I am sorry if anyone was offended by my comments and suggestions. I am certainly thankful for all the hard work that has gone into developing R. efg well, just a feedback to that: of course the tone of your mail was by no means inadequate (at least douglas bates did not object...). the tendency on this list to rather harshly rebuke people for some kind of (real or imagined) misconduct and to 'defend' R against 'attacks' is counterproductive and unnecessary. it goes without saying that the people 'behind' R can not and will not (and are not expected to) change the code after each mail on the help list which raises some question. and concerning your `nls' question: sure, the noise requirement is a pitfall in the beginning, but afterwards it's irrelevant: you don't fit noise free data in real life (in the sense that real data never follow you model exactly). and, sure, the convergence decision could be altered (given enough time and knowledge). whether convergence failure on exact data is a bug or a feature is a matter of taste, probably. getting better access to the trace output and especially access to intermediate pre-convergence values of the model parameters (this would 'solve' your problem, too) would really be an improvement, in my mind (I think this is recognized by d. bates, but simply way down his 'to do' list :-(). joerg __ R-help@stat.math.ethz.ch 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] adding multiple fitted curves to xyplot graph
Hello RHelpers, This may already have been answered, but despite days of scouring through the archives I haven't found it. My goal is to add multiple fitted curves to a plot. An example data set (a data frame named df in following code) is: x1 y1 factor1 4 1298.25 0. 1 5 1393.25 0. 1 6 1471.50 0.04597701 1 7 1586.70 2.56908046 1 8 1692.10 11.14080460 1 9 1832.55 45.50459770 1 10 1928.30 65.5600 1 11 2092.40 100. 1 31 1202.90 0. 2 41 1298.25 0. 2 51 1393.25 0.37885057 2 61 1471.50 0.76839080 2 71 1586.70 7.75206897 2 81 1692.10 50.19448276 2 91 1832.55 94.08045977 2 101 1928.30 100. 2 111 2092.40 100. 2 14 1028.50 0. 3 22 1106.40 0.04938272 3 32 1202.90 0.03448276 3 42 1298.25 0.34482759 3 52 1393.25 1.43850575 3 62 1471.50 1.96850575 3 72 1586.70 36.80597701 3 82 1692.10 92.83390805 3 92 1832.55 100. 3 15 1028.50 0.09638554 4 23 1106.40 0.39988506 4 33 1202.90 0.49321839 4 43 1298.25 1.66045977 4 53 1393.25 7.51137931 4 63 1471.50 42.02724138 4 73 1586.70 99.12068966 4 83 1692.10 100. 4 I plot this with xyplot: trellis.par.set(background,white) trellis.par.set(list(superpose.symbol=list(pch=c(15:17,21,25 xyplot(y1 ~ x1, data=df, groups=factor1, type = p, auto.key = list(space = right, points = TRUE, lines = FALSE)) For each level of factor1 I fit a growth curve: fit.curve-function(tab) { res.fit-nls(y1 ~ 100/(1+exp(((-log(81))/a)*(x1-b))), start=list(a=min(tab$x1[tab$y176],na.rm=T)-max(tab$x1[tab$y115],na.rm=T),b=tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)][!is.na(tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)])]),data=tab) coef(res.fit) } by(df,list(df$factor1),fit.curve) I would like to add the 4 curves corresponding to these 4 fits to my graphic. The elegant way would be a custom panel function I suppose, but I haven't been able to write one up... Could someone help me out on this please? In advance thanks very much!!! David Gouache Arvalis - Institut du Végétal Station de La Minière 78280 Guyancourt Tel: 01.30.12.96.22 / Port: 06.86.08.94.32 __ R-help@stat.math.ethz.ch 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] adding multiple fitted curves to xyplot graph
Try this after displaying the xyplot: # this fit.curve returns the whole nls object, not the coefs fit.curve-function(tab) { nls(y1 ~ 100/(1+exp(((-log(81))/a)*(x1-b))), start=list(a=min(tab$x1[tab$y176],na.rm=T)-max(tab$x1[tab$y115],na.rm=T),b=tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)][!is.na(tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)])]),data=tab) } trellis.focus(panel, 1, 1) f - function(x) panel.lines(x$x1, fitted(fit.curve(x)), col = 1) junk - by(df, df$factor1, f) trellis.unfocus() On 8/16/06, GOUACHE David [EMAIL PROTECTED] wrote: Hello RHelpers, This may already have been answered, but despite days of scouring through the archives I haven't found it. My goal is to add multiple fitted curves to a plot. An example data set (a data frame named df in following code) is: x1 y1 factor1 4 1298.25 0. 1 5 1393.25 0. 1 6 1471.50 0.04597701 1 7 1586.70 2.56908046 1 8 1692.10 11.14080460 1 9 1832.55 45.50459770 1 10 1928.30 65.5600 1 11 2092.40 100. 1 31 1202.90 0. 2 41 1298.25 0. 2 51 1393.25 0.37885057 2 61 1471.50 0.76839080 2 71 1586.70 7.75206897 2 81 1692.10 50.19448276 2 91 1832.55 94.08045977 2 101 1928.30 100. 2 111 2092.40 100. 2 14 1028.50 0. 3 22 1106.40 0.04938272 3 32 1202.90 0.03448276 3 42 1298.25 0.34482759 3 52 1393.25 1.43850575 3 62 1471.50 1.96850575 3 72 1586.70 36.80597701 3 82 1692.10 92.83390805 3 92 1832.55 100. 3 15 1028.50 0.09638554 4 23 1106.40 0.39988506 4 33 1202.90 0.49321839 4 43 1298.25 1.66045977 4 53 1393.25 7.51137931 4 63 1471.50 42.02724138 4 73 1586.70 99.12068966 4 83 1692.10 100. 4 I plot this with xyplot: trellis.par.set(background,white) trellis.par.set(list(superpose.symbol=list(pch=c(15:17,21,25 xyplot(y1 ~ x1, data=df, groups=factor1, type = p, auto.key = list(space = right, points = TRUE, lines = FALSE)) For each level of factor1 I fit a growth curve: fit.curve-function(tab) { res.fit-nls(y1 ~ 100/(1+exp(((-log(81))/a)*(x1-b))), start=list(a=min(tab$x1[tab$y176],na.rm=T)-max(tab$x1[tab$y115],na.rm=T),b=tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)][!is.na(tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)])]),data=tab) coef(res.fit) } by(df,list(df$factor1),fit.curve) I would like to add the 4 curves corresponding to these 4 fits to my graphic. The elegant way would be a custom panel function I suppose, but I haven't been able to write one up... Could someone help me out on this please? In advance thanks very much!!! David Gouache Arvalis - Institut du Végétal Station de La Minière 78280 Guyancourt Tel: 01.30.12.96.22 / Port: 06.86.08.94.32 __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 convergence problem
Joerg van den Hoff [EMAIL PROTECTED] wrote on 08/16/2006 08:22:03 AM: Earl F. Glynn wrote: [deleted] efg [deleted] (I think this is recognized by d. bates, but simply way down his 'to do' list :-(). joerg No doubt Doug Bates would gladly accept patches ... . __ R-help@stat.math.ethz.ch 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. Woodrow Setzer, Ph. D. National Center for Computational Toxicology US Environmental Protection Agency Mail Drop B205-01/US EPA/RTP, NC 27711 Ph: (919) 541-0128Fax: (919) 541-1194 __ R-help@stat.math.ethz.ch 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] fitting truncated normal distribution
[EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) : nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ R-help@stat.math.ethz.ch 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. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on data generated from rtnorm (also part of msm) I got warnings related to the NaNs generated in pnorm and qnorm, but no error as you reported. Both of these suggestions are in the posting guide (see signature above). So, to answer your problem, here's a quick example. library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } set.seed(1) ## to others may reproduce my results exactly x - rtnorm(100, lower = 0) fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Note, the help page ?fitdistr suggests additional parameters may be passed to the density function (i.e. dtnorm) or optim. However, this won't work here because lower is an argument for both functions. This is the reason for writing dtnorm0 which has neither a lower or an upper argument. HTH, --sundar __ R-help@stat.math.ethz.ch 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] list to balanced array
I am working with a large data set of arrivals, for each day I have aggregated the arrivals into hrs (1-24) via: apply(x,2,table). On some days there are zero arrivals during some hours of the day, this leaves me with (I believe) a list of vectors of differnt lengths (see below). [[4]] 1 2 3 5 6 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 1 3 2 3 1 1 2 3 4 4 4 3 2 6 2 5 1 2 2 2 1 [[5]] 2 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 2 1 1 2 1 5 3 6 6 3 2 2 1 4 3 3 4 2 1 I would like to be able to create an array with equal numbers of rows (24) for each column, i.e., fill in the gaps with Zeros. [[5]] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0 2 0 0 1 1 0 2 1 5 3 6 6 3 2 2 1 4 3 0 3 4 2 1 Any suggestions? thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Strange behavior with hist function filled with breaks and freq attribute
Hy all, I give example code : connexions_jours-c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,7,7,7,7,7,7,7,7,8,8,8,12,15,19) pas_de_groupe-1 hist(connexions_jours,col=red,xlab=Répartition du nombre de connexions par jours (sans break),main=,ylab=,freq=FALSE) hist(connexions_jours,breaks=(max(connexions_jours)/pas_de_groupe),col=red,xlab=Répartition du nombre de connexions par jours,main=,ylab=,freq=FALSE) pas_de_groupe-5 hist(connexions_jours,breaks=(max(connexions_jours)/pas_de_groupe),col=red,xlab=Répartition du nombre de connexions par jours,main=,ylab=,freq=FALSE) As in the R help for ?hist i have : freq: logical; if 'TRUE', the histogram graphic is a representation of frequencies, the 'counts' component of the result; if 'FALSE', _relative_ frequencies (probabilities), component 'density', are plotted. Defaults to 'TRUE' _iff_ 'breaks' are equidistant (and 'probability' is not specified). So i'm plotting 3 graphs of probabilities, but because of the breaks the « y » values seems to be broken as if i have to multiplicate the values shown by the break range to have the real percent. So i'm wondering why it doesn't show the sum of the probability instead of the average for each values grouped. Did someone see where i'm wrong? I'll have a look to barplot, to see if it can handle it, but i still find that strange for hist... Thks all COMTE Guillaume [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] confusing about contrasts concept
Hi all, Where can I find a thorough explanation of Contrasts and Contrasts Matrices? I read some help but still confused. Thank you, Tian [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list to balanced array
try the following: arrivals - matrix(sample(1:24, 100, TRUE), 10, 10) apply(arrivals, 2, function(x) table(factor(x, levels = 1:24))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Spencer Jones [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, August 16, 2006 5:22 PM Subject: [R] list to balanced array I am working with a large data set of arrivals, for each day I have aggregated the arrivals into hrs (1-24) via: apply(x,2,table). On some days there are zero arrivals during some hours of the day, this leaves me with (I believe) a list of vectors of differnt lengths (see below). [[4]] 1 2 3 5 6 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 1 3 2 3 1 1 2 3 4 4 4 3 2 6 2 5 1 2 2 2 1 [[5]] 2 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 2 1 1 2 1 5 3 6 6 3 2 2 1 4 3 3 4 2 1 I would like to be able to create an array with equal numbers of rows (24) for each column, i.e., fill in the gaps with Zeros. [[5]] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0 2 0 0 1 1 0 2 1 5 3 6 6 3 2 2 1 4 3 0 3 4 2 1 Any suggestions? thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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] fitting truncated normal distribution
Sorry, didn't notice that you *did* mention dtnorm is part of msm. Ignore that part of the advice... --sundar Sundar Dorai-Raj wrote: [EMAIL PROTECTED] wrote: Hello, I am a new user of R and found the function dtnorm() in the package msm. My problem now is, that it is not possible for me to get the mean and sd out of a sample when I want a left-truncated normal distribution starting at 0. fitdistr(x,dtnorm, start=list(mean=0, sd=1)) returns the error message Fehler in [-(`*tmp*`, x = lower x = upper, value = numeric(0)) : nichts zu ersetzen I don't know, where to enter the lower/upper value. Is there a possibility to program the dtnorm function by myself? Thank you very much in advance for your help, markus --- Versendet durch aonWebmail (webmail.aon.at) __ R-help@stat.math.ethz.ch 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. Hi, Markus, You should always supply the package name where dtnorm is located. My guess is most don't know (as I didn't) it is part of the msm package. Also, you should supply a reproducible example so others may understand your particular problem. For example, when I ran your code on data generated from rtnorm (also part of msm) I got warnings related to the NaNs generated in pnorm and qnorm, but no error as you reported. Both of these suggestions are in the posting guide (see signature above). So, to answer your problem, here's a quick example. library(MASS) ## for fitdistr library(msm) ## for dtnorm dtnorm0 - function(x, mean = 0, sd = 1, log = FALSE) { dtnorm(x, mean, sd, 0, Inf, log) } set.seed(1) ## to others may reproduce my results exactly x - rtnorm(100, lower = 0) fitdistr(x, dtnorm0, start = list(mean = 0, sd = 1)) Note, the help page ?fitdistr suggests additional parameters may be passed to the density function (i.e. dtnorm) or optim. However, this won't work here because lower is an argument for both functions. This is the reason for writing dtnorm0 which has neither a lower or an upper argument. HTH, --sundar __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Trend test and test for homogeneity of odd-ratios
Dear r-users, I am looking for some R functions to do Cochran-Armitage trend test for 2*3 tables (binary phenotype vs. genotypes) and for testing the homogeneity of odds ratios within 2*3*k tables (binary phenotype vs. genotypes vs. strata). In R-Help archives, I've found a 2003 script by Eric Lecoutre for Cochran-Armitage trend test and a script for Breslow-Day test for 2*2*k tables. Could someone please tell we if there were some functions available on CRAN to do such tests ? Thanks, jacques __ R-help@stat.math.ethz.ch 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] Problem with the special argument '...' within a function
I'm not sure if this is what you want, but simply add ... to the list of arguments for fun1 and fun2 would eliminate the error. Andy From: Hans-Joerg Bibiko Dear all, I wrote some functions using the special argument '...'. OK, it works. But if I call such a function which also called such a function, then I get an error message about unused arguments. Here's an example: fun1 - function(x,a=1) { print(paste(x=,x)) print(paste(a=,a)) } fun2 - function(y,b=2) { print(paste(y=,y)) print(paste(b=,b)) } myfun - function(c, ...) { print(paste(c=,c)) fun1(x=c,...) fun2(y=c,...) } This is OK. myfun(c=3) [1] c= 3 [1] x= 3 [1] a= 1 [1] y= 3 [1] b= 2 myfun(c=3,a=4) [1] c= 3 [1] x= 3 [1] a= 4 Error in fun2(y = c, ...) : unused argument(s) (a ...) I understand the error message because fun2 has no argument called 'a'. But how can I avoid this??? I want to use this in order to be able to call myfun() with all arguments to control myfun(),fun1(), and fun2(). Please help! Thanks, Hans __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] matching pairs in a Dataframe?
Dear list, I want to extract pairs of values out of a dataframe where one criteria/condition does match. I have an experiment with 3 conditions which were not always applied: e.g.: group cond x A 1 2 A 2 4 A 3 6.5 B 1 3 B 2 4.5 C 1 2.5 C 3 4 D 2 5 D 3 6 E 1 1 E 2 4 E 3 6 Now I wanted to extract the x of those groups where condition 2 and condition 3 do both exist. In this example that would be groups A, D and E and the extracted pairs e.g.: cond2 cond3 4 6.5 5 6 4 6 (I need this for a wilcoxon test) I would be happy if one could give me a hint, probably its very simple... Thanks Stefan Grosse __ R-help@stat.math.ethz.ch 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] Autocompletion
Hi there! I may be guilty of not doing my homework, but still, I've searched. I'm a relative newcomer to R (my forte is at present MATLAB, but for various reasons I'm trying to get literate in R). My question is: Is there an autocompletion feature buried somewhere in R? All the best Óttar [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Specifying Path Model in SEM for CFA
On Wed, 2006-08-16 at 08:47 -0400, John Fox wrote: Dear Rick, There are a couple of problems here: (1) You've fixed the error variance parameters for each of the observed variables to 1 rather than defining each as a free parameter to estimate. For example, use X1 - X1, theta1, NA Rather than X1 - X1, NA, 1 The general principle is that if you give a parameter a name, it's a free parameter to be estimated; if you give the name as NA, then the parameter is given a fixed value (here, 1). (There is some more information on this and on error-variance parameters in ?sem.) (2) I believe that the model you're trying to specify -- in which all variables but X6 load on F1, and all variables but X1 load on F2 -- is underidentified. In addition, you've set the metric of the factors by fixing one loading to 0.20 and another to 0.25. That should work but strikes me as unusual, and makes me wonder whether this was what you really intended. It would be more common in a CFA to fix the variance of each factor to 1, and let the factor loadings be free parameters. Then the factor covariance would be their correlation. You should not have to specify start values for free parameters (such as g11, g22, and g12 in your model), though it is not wrong to do so. I would not, however, specify start values that imply a singular covariance matrix among the factors, as you've done; I'm surprised that the program was able to get by the start values to produce a solution. BTW, the Thurstone example in ?sem is for a confirmatory factor analysis (albeit a slightly more complicated one with a second-order factor). There's also an example of a one-factor CFA in the paper at http://socserv.socsci.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf, though this is for ordinal observed variables. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox Thanks for the information. I think I understand how to handle the residual variance after reading the sem help file more carefully. Now I have to figure out how to constrain each column of the factor matrix to sum to one. Maybe this will fix the problem with being under-identified. Rick B. __ R-help@stat.math.ethz.ch 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] Autocompletion
On 8/16/06, Óttar Ísberg [EMAIL PROTECTED] wrote: I may be guilty of not doing my homework, but still, I've searched. I'm a relative newcomer to R (my forte is at present MATLAB, but for various reasons I'm trying to get literate in R). My question is: Is there an autocompletion feature buried somewhere in R? What do you mean precisely by 'autocompletion'? Are working on MS Windows or on Linux? Paul __ R-help@stat.math.ethz.ch 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] Autocompletion
I mostly use R under Linux and Xemacs with the truly wonderful ESS (Emacs Speaks Statistics). It has numerous features, one of which is a pretty comprehensive auto-completion facility. The few times I have used R under Windows, any auto-completion feature that may be there did not fall readily to hand (translate: I poked a few keys and didn't notice anything auto-completing), and I didn't spend any time looking for one. As there are several platforms on which R runs, and a number of interactive interfaces, you may need to be a bit more specific in the framing of your question to get a more informative response. Regards, Mike On 8/16/06, Óttar Ísberg [EMAIL PROTECTED] wrote: Hi there! I may be guilty of not doing my homework, but still, I've searched. I'm a relative newcomer to R (my forte is at present MATLAB, but for various reasons I'm trying to get literate in R). My question is: Is there an autocompletion feature buried somewhere in R? All the best Óttar [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Regards, Mike Nielsen [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Problem with the special argument '...' within a function
Quoting Liaw, Andy [EMAIL PROTECTED]: I'm not sure if this is what you want, but simply add ... to the list of arguments for fun1 and fun2 would eliminate the error. Andy That's it!! Thank you very much!! Best, Hans Dear all, I wrote some functions using the special argument '...'. OK, it works. But if I call such a function which also called such a function, then I get an error message about unused arguments. Here's an example: fun1 - function(x,a=1) { print(paste(x=,x)) print(paste(a=,a)) } fun2 - function(y,b=2) { print(paste(y=,y)) print(paste(b=,b)) } myfun - function(c, ...) { print(paste(c=,c)) fun1(x=c,...) fun2(y=c,...) } This is OK. myfun(c=3) [1] c= 3 [1] x= 3 [1] a= 1 [1] y= 3 [1] b= 2 myfun(c=3,a=4) [1] c= 3 [1] x= 3 [1] a= 4 Error in fun2(y = c, ...) : unused argument(s) (a ...) I understand the error message because fun2 has no argument called 'a'. But how can I avoid this??? I want to use this in order to be able to call myfun() with all arguments to control myfun(),fun1(), and fun2(). Please help! Thanks, Hans __ R-help@stat.math.ethz.ch 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] Autocompletion
Hi! That was quick, and thanks. I'm afraid I wasn't precise enough. I'm using Windows XP and by autocompletion I mean typing the first few letters of a command and then have the system either complete the command or give you possible options, as in MATLAB or, for that matter, UNIX. Cheers Óttar [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] separate row averages for different parts of an array
I have an array with 44800 columns and 24 rows I would like to compute the row average for the array 100 columns at a time, so I would like to end up with an array of 24 rows x 448 columns. I have tried using apply(dataset, 1, function(x) mean(x[])), but I am not sure how to get it to take the average 100 columns at a time. Any ideas would be welcomed. thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] adding multiple fitted curves to xyplot graph
On 8/16/06, GOUACHE David [EMAIL PROTECTED] wrote: Hello RHelpers, This may already have been answered, but despite days of scouring through the archives I haven't found it. My goal is to add multiple fitted curves to a plot. An example data set (a data frame named df in following code) is: x1 y1 factor1 4 1298.25 0. 1 5 1393.25 0. 1 6 1471.50 0.04597701 1 7 1586.70 2.56908046 1 8 1692.10 11.14080460 1 9 1832.55 45.50459770 1 10 1928.30 65.5600 1 11 2092.40 100. 1 31 1202.90 0. 2 41 1298.25 0. 2 51 1393.25 0.37885057 2 61 1471.50 0.76839080 2 71 1586.70 7.75206897 2 81 1692.10 50.19448276 2 91 1832.55 94.08045977 2 101 1928.30 100. 2 111 2092.40 100. 2 14 1028.50 0. 3 22 1106.40 0.04938272 3 32 1202.90 0.03448276 3 42 1298.25 0.34482759 3 52 1393.25 1.43850575 3 62 1471.50 1.96850575 3 72 1586.70 36.80597701 3 82 1692.10 92.83390805 3 92 1832.55 100. 3 15 1028.50 0.09638554 4 23 1106.40 0.39988506 4 33 1202.90 0.49321839 4 43 1298.25 1.66045977 4 53 1393.25 7.51137931 4 63 1471.50 42.02724138 4 73 1586.70 99.12068966 4 83 1692.10 100. 4 I plot this with xyplot: trellis.par.set(background,white) This doesn't do what you probably think it does. trellis.par.set(list(superpose.symbol=list(pch=c(15:17,21,25 xyplot(y1 ~ x1, data=df, groups=factor1, type = p, auto.key = list(space = right, points = TRUE, lines = FALSE)) For each level of factor1 I fit a growth curve: fit.curve-function(tab) { res.fit-nls(y1 ~ 100/(1+exp(((-log(81))/a)*(x1-b))), start=list(a=min(tab$x1[tab$y176],na.rm=T)-max(tab$x1[tab$y115],na.rm=T),b=tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)][!is.na(tab$x1[abs(tab$y1-50)==min(abs(tab$y1-50),na.rm=T)])]),data=tab) coef(res.fit) } by(df,list(df$factor1),fit.curve) I would like to add the 4 curves corresponding to these 4 fits to my graphic. The elegant way would be a custom panel function I suppose, but I haven't been able to write one up... Could someone help me out on this please? Here's one solution: xyplot(y1 ~ x1, data=df, groups=factor1, type = p, panel = panel.superpose, panel.groups = function(x, y, ...) { panel.xyplot(x, y, ...) fm - nls(y ~ 100 / (1 + exp(((-log(81)) / a) * (x - b))), start = list(a = min(x[y 76], na.rm = TRUE) - max(x[y 15], na.rm = TRUE), b = x[abs(y-50) == min(abs(y - 50), na.rm = TRUE)][ !is.na(x[abs(y - 50) == min(abs(y-50), na.rm = TRUE)])])) fit.fun - function(x) predict(fm, newdata = list(x = x)) panel.curve(fit.fun, ...) }, auto.key = list(space = right, points = TRUE, lines = FALSE)) -Deepayan __ R-help@stat.math.ethz.ch 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 about agnes
Hello. I have the following distance matrix between 8 points: [1,] 0.00 3.162278 7.280110 8.544004 7.071068 9.899495 6.403124 8.062258 [2,] 3.162278 0.00 5.00 6.403124 4.472136 8.944272 6.082763 8.062258 [3,] 7.280110 5.00 0.00 1.414214 1.00 5.00 4.242641 5.830952 [4,] 8.544004 6.403124 1.414214 0.00 2.236068 4.123106 4.472136 5.656854 [5,] 7.071068 4.472136 1.00 2.236068 0.00 6.00 5.00 6.708204 [6,] 9.899495 8.944272 5.00 4.123106 6.00 0.00 3.605551 3.00 [7,] 6.403124 6.082763 4.242641 4.472136 5.00 3.605551 0.00 2.00 [8,] 8.062258 8.062258 5.830952 5.656854 6.708204 3.00 2.00 0.00 I want to apply the cluster algorithm using single linkage procedure. The metric is the euclidean metric. In order to do this, I do: aux=agnes(xMatrix, diss = inherits(xMatrix,dist),metric=euclidean,method=single) Next, I do plot(aux) because I want to view the dendogram. My question is about the graph of the dendogram. What means the number height that appears on the left hand of it? My assumption was it was the distance between clusters but I was wrong because the distance matrices between the clusters are the following: Join clusters {3} and {5} (distance=1) New matrix distance: [1,] 0.00 3.162278 7.071068 8.544004 9.899495 6.403124 8.062258 [2,] 3.162278 0.00 4.472136 6.403124 8.944272 6.082763 8.062258 [3,] 7.071068 4.472136 0.00 1.414214 5.00 4.242641 5.830952 [4,] 8.544004 6.403124 1.414214 0.00 4.123106 4.472136 5.656854 [5,] 9.899495 8.944272 5.00 4.123106 0.00 3.605551 3.00 [6,] 6.403124 6.082763 4.242641 4.472136 3.605551 0.00 2.00 [7,] 8.062258 8.062258 5.830952 5.656854 3.00 2.00 0.00 Join clusters {3,5} and {4} (distance=1.414214). New matrix distance: [1,] 0.00 3.162278 7.071068 9.899495 6.403124 8.062258 [2,] 3.162278 0.00 4.472136 8.944272 6.082763 8.062258 [3,] 7.071068 4.472136 0.00 4.123106 4.242641 5.656854 [4,] 9.899495 8.944272 4.123106 0.00 3.605551 3.00 [5,] 6.403124 6.082763 4.242641 3.605551 0.00 2.00 [6,] 8.062258 8.062258 5.656854 3.00 2.00 0.00 Join clusters {7} and {8} (distance = 2). New matrix distance: [1,] 0.00 3.162278 7.071068 9.899495 6.403124 [2,] 3.162278 0.00 4.472136 8.944272 6.082763 [3,] 7.071068 4.472136 0.00 4.123106 4.242641 [4,] 9.899495 8.944272 4.123106 0.00 3.00 [5,] 6.403124 6.082763 4.242641 3.00 0.00 etc... but in the graph of the dendogram, it appears the following numbers when it joins the clusters: cluster {3} and {5}: more or less 2.3 cluster {3,5} and {4}: more or less 3 cluster {7} and {8}: more or less 4.75. As you can see, these numbers are distint from the distance between clusters (1, 1.414214 and 2). So, can somebody say me what do these numbers represent? Thanks in advance, Arnau. __ R-help@stat.math.ethz.ch 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] matching pairs in a Dataframe?
I found a solution: pairs-merge(subset(data.frame,cond==2,select=c(group,x),subset(data.frame,cond==3,select=c(group,x)),by=c(group)) That yields something like group cond.x cond.y A 4 6.5 D 5 6 E 4 6 now I just need to figure out how I embed this into a function together with the test, so that I don't have to write to much Stefan Grosse Dear list, I want to extract pairs of values out of a dataframe where one criteria/condition does match. I have an experiment with 3 conditions which were not always applied: e.g.: group cond x A 1 2 A 2 4 A 3 6.5 B 1 3 B 2 4.5 C 1 2.5 C 3 4 D 2 5 D 3 6 E 1 1 E 2 4 E 3 6 Now I wanted to extract the x of those groups where condition 2 and condition 3 do both exist. In this example that would be groups A, D and E and the extracted pairs e.g.: cond2 cond3 4 6.5 5 6 4 6 __ R-help@stat.math.ethz.ch 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] separate row averages for different parts of an array
On Wed, 2006-08-16 at 11:36 -0600, Spencer Jones wrote: I have an array with 44800 columns and 24 rows I would like to compute the row average for the array 100 columns at a time, so I would like to end up with an array of 24 rows x 448 columns. I have tried using apply(dataset, 1, function(x) mean(x[])), but I am not sure how to get it to take the average 100 columns at a time. Any ideas would be welcomed. thanks, Spencer Something along the lines of the following, presuming that 'mat' is your 24 * 44800 matrix: sapply(seq(1, 44800, 100), function(x) rowMeans(mat[, x:(x + 99)])) The first argument in sapply() creates a sequence from 1:44800 by increments of 100. sapply() then passes each value in the sequence as the starting index value 'x' to use to subset 'mat' in 100 column sets and gets the rowMeans() for each sub-matrix. The returned object will be a 24 * 448 matrix. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch 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] read.csv issue
I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Autocompletion
From: Óttar Ísberg Hi! That was quick, and thanks. I'm afraid I wasn't precise enough. I'm using Windows XP and by autocompletion I mean typing the first few letters of a command and then have the system either complete the command or give you possible R under Emacs/ESS has autocompletion. I believe JGR also has it. Since you mention Matlab and are using WinXP, JGR is probably closer to what you're expecting. See http://www.rosuda.org/software/JGR/. options, as in MATLAB or, for that matter, UNIX. I guess you meant something like the bash shell, instead of UNIX? Andy Cheers Óttar [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Autocompletion
On 8/16/06, Óttar Ísberg [EMAIL PROTECTED] wrote: That was quick, and thanks. I'm afraid I wasn't precise enough. I'm using Windows XP and by autocompletion I mean typing the first few letters of a command and then have the system either complete the command or give you possible options, as in MATLAB or, for that matter, UNIX. Regarding Windows XP, I do not know. However, on Linux, one presses CTRL+R and R tries to complete the command with a command previously used. Notwithstanding, I am sure that one can use the arrows keys on Windows XP to invoke commands from a list of already used commands. Try both ways. Paul __ R-help@stat.math.ethz.ch 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] read.csv issue
Dear Harold, One thing you can do is to read the file plainly, even if the \ is lost and then, inside R, change the string value with gsub. Sincerely, Carlos J. Gil Bellosta http://www.datanalytics.com http://www.data-mining-blog.com El mié, 16-08-2006 a las 14:43 -0400, Doran, Harold escribió: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] read.csv issue
Try 'gsub' y schidsch_name 1 331-802-7081 School One 2 464-551-7357 School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five levels(y$sch_name) - gsub(, , levels(y$sch_name)) y schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \\ Four 4 388-517-4394 School Five On 8/16/06, Doran, Harold [EMAIL PROTECTED] wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] read.csv issue
On Wed, 2006-08-16 at 14:43 -0400, Doran, Harold wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold Harold, What version of R and OS are you running? Under: Version 2.3.1 Patched (2006-08-06 r38829) on FC5: read.csv(test.csv) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \\ Four 4 388-517-4394 School Five The '\' is doubled. Take note of the impact of the 'allowEscapes' argument: read.csv(test.csv, allowEscapes = TRUE) schidsch_name 1 331-802-7081 School One 2 464-551-7357 School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five The '\' is lost. Try it with 'allowEscapes = FALSE' explicitly. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch 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] read.csv issue
OK, thanks to you and Carlos. I see how this works. Now, I just want 1 \ (miktex doesn't work with \\). I tried tinkering around with what you have for the replacement portion of the function. Is it possible to only have only one \? From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 3:10 PM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: Re: [R] read.csv issue Try 'gsub' y schidsch_name 1 331-802-7081 School One 2 464-551-7357 School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five levels(y$sch_name) - gsub(, , levels(y$sch_name)) y schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \\ Four 4 388-517-4394 School Five On 8/16/06, Doran, Harold [EMAIL PROTECTED] wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Plots Without Displaying
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 R Help Mailing List, I'd like to generate a plot that I could display and/or store it as e.g. jpeg. But unfortunately always a plotting window opens. Is it possible to prevent that? I tried the following: R bp-boxplot( sample(100), plot=FALSE) This works somehow, but it only stores data (as discribed in the help) in bp and it is not possible afaik to display bp later on or store them as a jpeg. The next: R p-plot(sample(100), sample(100), plot=FALSE) ..and also a variant using jpeg() didn't work at all. Is there a way to generally store the plots as object, without displaying them, or perhaps directly saving them to disc as jpeg? A Yes or No or any further help/links are appreciated!!! TIA, Lothar -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE43C1HRf7N9c+X7sRAmCqAKCN9PpAEqnQ1hJHjrDKDat49ulHPQCfRVUW +N9AtKrFxcs/kAdSQ7iV4yk= =Tybe -END PGP SIGNATURE- __ R-help@stat.math.ethz.ch 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] read.csv issue
Set allowEscapes = FALSE when reading. See the help page for more details. There is perhaps an argument for changing the default for allowEscapes under read.csv, especially as people have now changed that for comment.char (in R-devel). On Wed, 16 Aug 2006, Doran, Harold wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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] read.csv issue
On Wed, 16 Aug 2006, Prof Brian Ripley wrote: Set allowEscapes = FALSE when reading. See the help page for more details. There is perhaps an argument for changing the default for allowEscapes under read.csv, especially as people have now changed that for comment.char (in R-devel). Oops, it was already changed in 2.2.0. What version of R is this? On Wed, 16 Aug 2006, Doran, Harold wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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] read.csv issue
Well, for this particular program I am using 2.1.1, though I normally use 2.3.0. Long story about why the old version is used, but I must for this particular program. -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 3:26 PM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: Re: [R] read.csv issue On Wed, 16 Aug 2006, Prof Brian Ripley wrote: Set allowEscapes = FALSE when reading. See the help page for more details. There is perhaps an argument for changing the default for allowEscapes under read.csv, especially as people have now changed that for comment.char (in R-devel). Oops, it was already changed in 2.2.0. What version of R is this? On Wed, 16 Aug 2006, Doran, Harold wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for replication # A sample .csv format schid,sch_name 331-802-7081,School One 464-551-7357,School Two 388-517-7627,School Three \ Four 388-517-4394,School Five Note the third line includes the \ character. However, when I read the data in I get read.csv(file.choose()) schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three Four 4 388-517-4394 School Five It turns out to be very important to read in this character as I have a program that loops through a data set and Sweave's about 30,000 files. The variable sch_name gets dropped into the tex file using \Sexpr{tmp$sch_name}. However, if there is an , the latex file won't compile properly. So, what I need is for the data to be read in as schid sch_name 1 331-802-7081School One 2 464-551-7357School Two 3 388-517-7627 School Three \ Four 4 388-517-4394 School Five I am obligated by a client to include the in the school name, so eliminating that isn't an option. I thought maybe comment.char or quote would be what I needed, but they didn't resolve the issue. I'm certain I'm missing something simple, I just can't see it. Any thoughts? Harold [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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] Plots Without Displaying
Yes, see ?jpeg ?bitmap and as you didn't tell us your OS we don't know if these are available to you. jpeg(file=test.jpg) boxplot(sample(100)) dev.off() may well work. 'An Introduction to R' explains about graphics devices, including these. On Wed, 16 Aug 2006, Lothar Botelho-Machado wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 R Help Mailing List, I'd like to generate a plot that I could display and/or store it as e.g. jpeg. But unfortunately always a plotting window opens. Is it possible to prevent that? I tried the following: R bp-boxplot( sample(100), plot=FALSE) This works somehow, but it only stores data (as discribed in the help) in bp and it is not possible afaik to display bp later on or store them as a jpeg. The next: R p-plot(sample(100), sample(100), plot=FALSE) ..and also a variant using jpeg() didn't work at all. Is there a way to generally store the plots as object, without displaying them, or perhaps directly saving them to disc as jpeg? A Yes or No or any further help/links are appreciated!!! -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch 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] confusing about contrasts concept
Tian Bill Venables wrote an excellent explanation to the S list back in 1997. I saved it as a pdf file and attach it herewith ... Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of T Mu Sent: Thursday, 17 August 2006 3:23 a.m. To: R-Help Subject: [R] confusing about contrasts concept Hi all, Where can I find a thorough explanation of Contrasts and Contrasts Matrices? I read some help but still confused. Thank you, Tian [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. __ The contents of this e-mail are privileged and/or confidential to the named recipient and are not to be used by any other person and/or organisation. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. R-help@stat.math.ethz.ch 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] Autocompletion
For autocompletion in ESS, press the TAB key. __ R-help@stat.math.ethz.ch 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] confusing about contrasts concept [long]
Tian It appears the attachment might not have worked so I'll embed Bill's message at the end. Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Alspach Sent: Thursday, 17 August 2006 8:02 a.m. To: T Mu; R-Help Subject: Re: [R] confusing about contrasts concept Tian Bill Venables wrote an excellent explanation to the S list back in 1997. I saved it as a pdf file and attach it herewith ... Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of T Mu Sent: Thursday, 17 August 2006 3:23 a.m. To: R-Help Subject: [R] confusing about contrasts concept Hi all, Where can I find a thorough explanation of Contrasts and Contrasts Matrices? I read some help but still confused. Thank you, Tian Date sent: Sat, 29 Mar 1997 17:23:31 +1030 From: Bill Venables [EMAIL PROTECTED] To: Wei Qian [EMAIL PROTECTED] Copies to: [EMAIL PROTECTED] Subject:Re: test contrasts [long] Wei Qian writes: I am new to Splus, so please don't be offended if my question is too naive. We're all friends here, Wei. It's not that kind of group...mostly. Does anyone know how to test contrasts in Splus? To be specific, suppose I have a one-way layout experiment with 3 treatments, and I want to test the contrasts of treatment 1 vs. treatment 2, treatment 1 vs. treatment 3, etc. In SAS, I could use the following: proc gim; class trt; model y = trt; contrasts! vs. 2 1-10; contrasts 2 vs. 3 10-1; run; One way I can think of is that to construct my design matrix and obtain the contrast sum of squares through a series of matrix operations, but is there any easy way to do it or any built-in function in Splus can do it? The answer is 'yes' but hardly anyone seems to know how to do it. The explanation in the 'white book' for example, seems a little incomplete to me and not quite adequate to settle the case you raise. (The explanation in the yellow book is also inadequate, but I hope come July we will have fixed that.) Since this is one of the most frequent questions people ask me in direct email, too, let me try (again) to sort it out in some detail. A formula such as y ~ f, where f is a factor in principle generates a single classification model in the form *y_{ij} == mu + phi_i + e_{ij} Write the design matrix in the form X = [1 Xf], where, assuming f has p levels, Xf is the n x p dummy variable (ie binary) matrix corresponding to the phi_i's. So in matrix terms the model is written as *y = 1 mu + Xf phi + e (a) If you remove the intercept term, using y ~ f -1, then Xf is the design matrix you get and the coefficients correspond to the class means; (b) If the intercept term is left in, then the design matrix X does not have full column rank, so an adjustment has to be made to Xf to make it so. The redundancy comes about because the columns of Xf add to the the 1-vector, that is Xf l_p = l_n. So let C be any p x (p -1) matrix such that [1 C] is nonsingular. It can easily be seen that Xc = [1 (Xf C)] will have full column rank and that fitting the model using this model matrix is equivalent to the original redundantly specified model. The matrix C is called the *coding matrix* for the factor f. The linear model is actually fitted in the form *y = 1 mu + (Xf C) alpha + e where alpha has (p-1) components, of course. In order to make sense of the alpha's we need to relate them back to the phi's. For any such C there will be a vector, v, such the v'C = 0' (using ' for transpose). (In fact v spans the orthogonal complement to the column space of C). Clearly phi and alpha are related by *C alpha = phi but since v'C = 0', it follows that an identification constraint applies, namely v'phi = 0. By multiplying both sides by (C'C)^{-1} C', it also follows that *alpha =(C'C)^{-1}C'phi which provides an interpretation for the alpha's in terms of the (constrained) phi's. For example take the Helmert contrasts. contr.helmert(4) [,1][,2][,3] 1 -1 -1 -1 2 1 -1 -1 3 0 2 -1 4 0 0 3 The constraint vector is clearly v= (1,1,1,1), since the columns add to zero. In this case the columns are also mutually orthogonal, so the matrix (C'C^{-l} C' (the generalized inverse of C) has a similar form apart from a few row divisors: fractions(ginverse(contr.helmert(4))) [,1][,2][,3][,4] [1,]-1/21/2 0 0 [2,]-1/6-1/61/3 0 [3,]-1/12 -1/12 -1/12 1/4 (ginverse() will be available in S+4.0 and fractions(), now available in the MASS2 library, simply displays numbers in fractional form so that patterns are more obvious). Thus the phi's are identified by requiring that they add to zero, and *alpha_l = (phi_2 - phi_l )/2, *alpha_2 = [phi_3 - (phi_l + phi_2)/2] / 3 c. When the columns of C are not mutually orthogonal the
Re: [R] confusing about contrasts concept
Thank you. Got both. On 8/16/06, Peter Alspach [EMAIL PROTECTED] wrote: Tian Bill Venables wrote an excellent explanation to the S list back in 1997. I saved it as a pdf file and attach it herewith ... Peter Alspach -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of T Mu Sent: Thursday, 17 August 2006 3:23 a.m. To: R-Help Subject: [R] confusing about contrasts concept Hi all, Where can I find a thorough explanation of Contrasts and Contrasts Matrices? I read some help but still confused. Thank you, Tian [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. __ The contents of this e-mail are privileged and/or confidential to the named recipient and are not to be used by any other person and/or organisation. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Plots Without Displaying
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Prof Brian Ripley wrote: Yes, see ?jpeg ?bitmap and as you didn't tell us your OS we don't know if these are available to you. jpeg(file=test.jpg) boxplot(sample(100)) dev.off() may well work. 'An Introduction to R' explains about graphics devices, including these. On Wed, 16 Aug 2006, Lothar Botelho-Machado wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 R Help Mailing List, I'd like to generate a plot that I could display and/or store it as e.g. jpeg. But unfortunately always a plotting window opens. Is it possible to prevent that? I tried the following: R bp-boxplot( sample(100), plot=FALSE) This works somehow, but it only stores data (as discribed in the help) in bp and it is not possible afaik to display bp later on or store them as a jpeg. The next: R p-plot(sample(100), sample(100), plot=FALSE) ..and also a variant using jpeg() didn't work at all. Is there a way to generally store the plots as object, without displaying them, or perhaps directly saving them to disc as jpeg? A Yes or No or any further help/links are appreciated!!! Thank you for the explanation and your patience in answering me this obviously very simple question!! Originally I tried to store plots directly in a list. So writing them directly to disc was just a good alternative. I knew that that jpeg() provides functionality for that, but didn't use it correctly. Hence, is it also possible to store a plot in a list, somehow? Kind regards, Lothar -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE44S8HRf7N9c+X7sRAgCpAKC3NhjCYwkteksOljUKWrO3166nCwCgsfLI EPGVIoqc2dla5t6s9mmZQqE= =h+Az -END PGP SIGNATURE- __ R-help@stat.math.ethz.ch 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] Specifying Path Model in SEM for CFA
Dear Rick, It's unclear to me what you mean by constraining each column of the factor matrix to sum to one. If you intend to constrain the loadings on each factor to sum to one, sem() won't do that, since it supports only equality constraints, not general linear constraints on parameters of the model, but why such a constraint would be reasonable in the first place escapes me. More common in confirmatory factor analysis would be to constrain more of the loadings to zero. Of course, one would do this only if it made substantive sense in the context of the research. Regards, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -Original Message- From: Rick Bilonick [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 12:07 PM To: John Fox Cc: 'R Help' Subject: Re: [R] Specifying Path Model in SEM for CFA On Wed, 2006-08-16 at 08:47 -0400, John Fox wrote: Dear Rick, There are a couple of problems here: (1) You've fixed the error variance parameters for each of the observed variables to 1 rather than defining each as a free parameter to estimate. For example, use X1 - X1, theta1, NA Rather than X1 - X1, NA, 1 The general principle is that if you give a parameter a name, it's a free parameter to be estimated; if you give the name as NA, then the parameter is given a fixed value (here, 1). (There is some more information on this and on error-variance parameters in ?sem.) (2) I believe that the model you're trying to specify -- in which all variables but X6 load on F1, and all variables but X1 load on F2 -- is underidentified. In addition, you've set the metric of the factors by fixing one loading to 0.20 and another to 0.25. That should work but strikes me as unusual, and makes me wonder whether this was what you really intended. It would be more common in a CFA to fix the variance of each factor to 1, and let the factor loadings be free parameters. Then the factor covariance would be their correlation. You should not have to specify start values for free parameters (such as g11, g22, and g12 in your model), though it is not wrong to do so. I would not, however, specify start values that imply a singular covariance matrix among the factors, as you've done; I'm surprised that the program was able to get by the start values to produce a solution. BTW, the Thurstone example in ?sem is for a confirmatory factor analysis (albeit a slightly more complicated one with a second-order factor). There's also an example of a one-factor CFA in the paper at http://socserv.socsci.mcmaster.ca/jfox/Misc/sem/SEM-paper.pdf, though this is for ordinal observed variables. I hope this helps, John John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox Thanks for the information. I think I understand how to handle the residual variance after reading the sem help file more carefully. Now I have to figure out how to constrain each column of the factor matrix to sum to one. Maybe this will fix the problem with being under-identified. Rick B. __ R-help@stat.math.ethz.ch 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] Plots Without Displaying
Yes, you can do that for lattice-based plots. The functions in the lattice package produce objects of class trellis which can be stored in a list and processed or updated at a later time: library(lattice) attach(barley) plotList - list(length=3) plotList[[1]] - xyplot(yield ~ site, data=barley) plotList[[2]] - xyplot(yield ~ variety, data=barley) plotList[[3]] - xyplot(yield ~ year, data=barley) plotList plotList[[3]] - update(plotList[[3]], yaxis=Yield (bushels/acre)) print(plotList[[3]]) Obviously, you can store any lattice-based plot in the list. HTH. -Christos Christos Hatzis, Ph.D. Nuvera Biosciences, Inc. 400 West Cummings Park Suite 5350 Woburn, MA 01801 Tel: 781-938-3830 www.nuverabio.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lothar Botelho-Machado Sent: Wednesday, August 16, 2006 4:49 PM To: r-help@stat.math.ethz.ch Subject: Re: [R] Plots Without Displaying -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Prof Brian Ripley wrote: Yes, see ?jpeg ?bitmap and as you didn't tell us your OS we don't know if these are available to you. jpeg(file=test.jpg) boxplot(sample(100)) dev.off() may well work. 'An Introduction to R' explains about graphics devices, including these. On Wed, 16 Aug 2006, Lothar Botelho-Machado wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 R Help Mailing List, I'd like to generate a plot that I could display and/or store it as e.g. jpeg. But unfortunately always a plotting window opens. Is it possible to prevent that? I tried the following: R bp-boxplot( sample(100), plot=FALSE) This works somehow, but it only stores data (as discribed in the help) in bp and it is not possible afaik to display bp later on or store them as a jpeg. The next: R p-plot(sample(100), sample(100), plot=FALSE) ..and also a variant using jpeg() didn't work at all. Is there a way to generally store the plots as object, without displaying them, or perhaps directly saving them to disc as jpeg? A Yes or No or any further help/links are appreciated!!! Thank you for the explanation and your patience in answering me this obviously very simple question!! Originally I tried to store plots directly in a list. So writing them directly to disc was just a good alternative. I knew that that jpeg() provides functionality for that, but didn't use it correctly. Hence, is it also possible to store a plot in a list, somehow? Kind regards, Lothar -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE44S8HRf7N9c+X7sRAgCpAKC3NhjCYwkteksOljUKWrO3166nCwCgsfLI EPGVIoqc2dla5t6s9mmZQqE= =h+Az -END PGP SIGNATURE- __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] bwplot in loop doesn't produce any output
Hi, running the following code by itself runs as expected. k - 1 i - 2 j - 3 NumName - varnames[num.cols[k]] FacNames - varnames[fac.cols[c(i,j)]] tmp - paste(FacNames[1],NumName,sep=~) fml - formula(paste(tmp,FacNames[2],sep=|)) bwplot(fml, data = X) But when set into a loop, it doens't produce anything. I've tried sending the output to pdf(file=test.pdf), and the pdf file stays empty. for (i in 1:(lfc-1)) { for (j in (i+1):lfc) { for (k in 1:lnc) { NumName - varnames[num.cols[k]] FacNames - varnames[fac.cols[c(i,j)]] tmp - paste(FacNames[1],NumName,sep=~) fml - formula(paste(tmp,FacNames[2],sep=|)) bwplot(fml, data = X) } } } Any thoughts ? And if you know how to unlock test.pdf for viewing while R is running, I'd appreciate this bit of info too (i've tried dev.off(), windows() and such, and test.pdf can only be viewed after shutting down R). Thank you. Nick. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] bwplot in loop doesn't produce any output
Its a FAQ http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f On 8/16/06, Nick Desilsky [EMAIL PROTECTED] wrote: Hi, running the following code by itself runs as expected. k - 1 i - 2 j - 3 NumName - varnames[num.cols[k]] FacNames - varnames[fac.cols[c(i,j)]] tmp - paste(FacNames[1],NumName,sep=~) fml - formula(paste(tmp,FacNames[2],sep=|)) bwplot(fml, data = X) But when set into a loop, it doens't produce anything. I've tried sending the output to pdf(file=test.pdf), and the pdf file stays empty. for (i in 1:(lfc-1)) { for (j in (i+1):lfc) { for (k in 1:lnc) { NumName - varnames[num.cols[k]] FacNames - varnames[fac.cols[c(i,j)]] tmp - paste(FacNames[1],NumName,sep=~) fml - formula(paste(tmp,FacNames[2],sep=|)) bwplot(fml, data = X) } } } Any thoughts ? And if you know how to unlock test.pdf for viewing while R is running, I'd appreciate this bit of info too (i've tried dev.off(), windows() and such, and test.pdf can only be viewed after shutting down R). Thank you. Nick. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] glmmPQL question!
I don't think there is an easy way to do that. If it were my problem, I think I'd start by trying to the model using 'lmer' associated with the 'lme4' package. I would then try to pass the fit to 'mcmcsamp' to get a random sample of parameter estimates following the posterior distribution. Then I'd convert the simulated parameters into a distribution of predictions for the conditions of interest. While doing this, I'd apply quantile of the distribution of predictions for each set of conditions to get the desired confidence limits. Make sense? If you'd like further help from this listserve, please submit another post. When you do that, however, I strongly urge you to include commented, minimal, self-contained, reproducible code illustrating something you tried that didn't quite work to help people understand what you want (as suggested in the posting guide www.R-project.org/posting-guide.html). Without such a minimal, self contained example, your problem is rarely as clear, and people's replies are less likely to be relevant. Since they know that, they are less likely to reply. Hope this helps. Spencer Graves [EMAIL PROTECTED] wrote: Hello Folks- Is there a way to create confidence bands with 'glmmPQL' ??? I am performing a stroke study for Northwestern University in Chicago, Illinois. I am trying to decide a way to best plot the model which we created with the glmmPQL function in R. I would like to plot my actual averaged data points within 95 % confidence intervals from the model. Plotting the model is easy, but determining confidence bands is not. Here is my model: ratiomodel-glmmPQL(ratio~as.factor(joint)*time, random = ~ 1 | subject, family = Gamma(link = identity),alldata3) I am used to seeing confidence intervals from models that increase, “flair out” in the y direction, at the beginning and ending time points (x values) of the simulated data. If I use 'lm' and pass the command 'int = c ' 'to create this model I can easily find and plot this type of confidence band for 'ratio~time'. But I need to take into account 'as.factor(joint)', and in fact I can produce confidence bands with 'glm' by passing in 'se.fit = TRUE', but the problem is I need to make subject a random variable, and take into account my ratio with the Gamma distribution. Is there a way to create confidence bands with 'glmmPQL' ??? ' as.factor(joint)' has 3 levels, so I would like to produce this linear model with three levels and confidence bands for comparison of the levels of 'joint'. Any Help at all with my problem would be greatly appreciated!! LJ __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] putting the mark for censored time on 1-KM curve or competing risk curve
Hi All, I'm trying to figure out the cumulative incidence curve in R in some limited time. I found in package cmprsk, the command plot.cuminc can get this curve. But I noticed that there is no mark for the censored time there, comparing with the KM curve by plot.survfit. Here are my codes (attached is the data): dat-read.table(F://wendy/BMT data analysis/final data.txt,header=TRUE,sep=\t) library(cmprsk) library(survival) attach(dat) par(mfrow=c(2,1)) curve-cuminc(SURVEFP/365.25,STATREP,Ritux) plot(curve,xlab=years,curvlab=c(No rituximab, Rituximab),lty=1:2,col=c(red,blue),mark.time=TRUE) a-survfit(Surv(SURVEFP/365.25,STATREP)~Ritux,type=kaplan-meier) plot(a,main=OS for whole group,conf.int=F,xlab=years,ylab=probability,lty=1:2,col=c(red,b lue)) --- Could you help me with how to put the mark for censored time on cumulative incidence curve, or maybe how to get the 1-KM curve with the mark for censored time? This will help me a lot! Thank you very much! UPN TYPESTATP SURVP STATNRMPSTATREP STATEFP SURVEFP AGE AGEBMT_med AGEBMT_dec SEX DXCODE DX1 DXBMT? STAGEGRP BSYMDX BMINVDX PS IPIGROUPINITXGRPPRIXRT INICHEMO PRIPURANPRIRITU PRICHOP PRICHEMOPRIRESP DXBMTMON INIDXBMTCON1_3 CON1_2 STATUS BM_PB CELLDOSEBMTSUB3A CMV SURVAG STATAG SURVCG STATCG CGVHD_CISTAT_CGCI AGVHD_CISTAT_AGCI COMPETING_RNSTATUSCODE RESIDUALSCT Ritux 318 AUTO1 41 1 0 1 41 39 0 2 F 2 2 COMPADV 0 0 0 1 2 1 1 0 0 1 0 P 1 1 3 0 1 BM 0 3 9 41 9 41 8 41 3 41 3 1 1 0 0 492 ALLO1 20781 0 1 207844 0 2 M 2 2 DIS ADV 1 1 0 2 2 1 1 0 0 1 0 P 0 0 2 1 1 BM 1 1 4 20780 2078 0 20783 20783 1 1 1 0 625 ALLO1 128 1 0 1 128 41 0 2 M 1 1 TRAN-H ADV 1 1 0 1 1 0 1 0 0 1 1 P 0 1 2 1 1 BM 1 1 1 43 1 101 1 101 1 43 3 1 1 0 0 631 ALLO1 15480 1 1 656 36 0 1 F 2 2 DIS ADV 0 1 0 2 1 0 1 0 0 1 1 P 0 0 1 1 1 BM 1 2 1 15 1 1548 0 656 2 15 1 2 1 0 0 637 ALLO1 16 1 0 1 16 34 0 1 F 2 2 COMPADV 0 1 0 2 1 0 1 0 0 1 0 C 1 1 2 1 1 BM 1 1 4 16 0 16 8 16 3 16 3 1 1 0 0 652 ALLO1 17 1 0 1 17 46 1 2 M 1 1 TRAN-H ADV 0 1 0 2 2 1 1 0 0 1 0 C 0 1 2 1 1 BM 1 1 4 17 0 17 8 17 3 17 3 1 1 0 0 759 ALLO1 156 0 1 1 66 44 0 2 M 1 1 TRAN-H ADV 0 0 0 1 2 1 1 0 0 1 1 C 0 1 1 1 1 BM 0 1 4 156 0 124 1 66 2 66 2 2 1 0 0 826 ALLO1 52 1 0 1 52 36 0 1 F 1 1 TRAN-H ADV 0 1 0 1 2 1 1 0 0 1 0 P 0 1 1 1 1 BM 1 2 3 20 1 52 8 52 3 20 1 1 1 0 0 918 AUTO1 289 0 1 1 121 50 1 3 M 2 2 COMPADV 1 0 0 1 2 1 1 0 0 1 1 P 1 1 2 1 1 PB
Re: [R] Variance Components in R
I used SPSS over 25 years ago, but I don't recall ever fitting a variance components model with it. Are all your random effects nested? If they were, I would recommend you use 'lme' in the 'nlme' package. However, if you have crossed random effects, I suggest you try 'lmer' associated with the 'lme4' package. For 'lmer', documentation is available in Douglas Bates. Fitting linear mixed models in R. /R News/, 5(1):27-30, May 2005 (www.r-project.org - newsletter). I also recommend you try the vignette available with the 'mlmRev' package (see, e.g., http://finzi.psych.upenn.edu/R/Rhelp02a/archive/81375.html). Excellent documentation for both 'lme' (and indirectly for 'lmer') is available in Pinheiro and Bates (2000) Mixed-Effects Models in S and S-Plus (Springer). I have personally recommended this book so many times on this listserve that I just now got 234 hits for RSiteSearch(graves pinheiro). Please don't hesitate to pass this recommendation to your university library. This book is the primary documentation for the 'nlme' package, which is part of the standard R distribution. A subdirectory ~library\nlme\scripts of your R installation includes files named ch01.R, ch02.R, ..., ch06.R, ch08.R, containing the R scripts described in the book. These R script files make it much easier and more enjoyable to study that book, because they make it much easier to try the commands described in the book, one line at a time, testing modifications to check you comprehension, etc. In addition to avoiding problems with typographical errors, it also automatically overcomes a few minor but substantive changes in the notation between S-Plus and R. Also, the MINQUE method has been obsolete for over 25 years. I recommend you use method = REML except for when you want to compare two nested models with different fixed effects; in that case, you should use method = ML, as explained in Pinheiro and Bates (2000). Hope this helps. Spencer Graves Iuri Gavronski wrote: Hi, I'm trying to fit a model using variance components in R, but if very new on it, so I'm asking for your help. I have imported the SPSS database onto R, but I don't know how to convert the commands... the SPSS commands I'm trying to convert are: VARCOMP RATING BY CHAIN SECTOR RESP ASPECT ITEM /RANDOM = CHAIN SECTOR RESP ASPECT ITEM /METHOD = MINQUE (1) /DESIGN = CHAIN SECTOR RESP ASPECT ITEM SECTOR*RESP SECTOR*ASPECT SECTOR*ITEM CHAIN*RESP CHAIN*ASPECT CHAIN*ITEM RESP*ASPECT RESP*ITEM SECTOR*RESP*ASPECT SECTOR*RESP*ITEM CHAIN*RESP*ASPECT /INTERCEPT = INCLUDE. VARCOMP RATING BY CHAIN SECTOR RESP ASPECT ITEM /RANDOM = CHAIN SECTOR RESP ASPECT ITEM /METHOD = REML /DESIGN = CHAIN SECTOR RESP ASPECT ITEM SECTOR*RESP SECTOR*ASPECT SECTOR*ITEM CHAIN*RESP CHAIN*ASPECT CHAIN*ITEM RESP*ASPECT RESP*ITEM SECTOR*RESP*ASPECT SECTOR*RESP*ITEM CHAIN*RESP*ASPECT /INTERCEPT = INCLUDE. Thank you for your help. Best regards, Iuri. ___ Iuri Gavronski - [EMAIL PROTECTED] doutorando UFRGS/PPGA/NITEC - www.ppga.ufrgs.br Brazil __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Setting contrasts for polr() to get same result of SAS
Hi all, I am trying to do a ordered probit regression using polr(), replicating a result from SAS. polr(y ~ x, dat, method='probit') suppose the model is y ~ x, where y is a factor with 3 levels and x is a factor with 5 levels, To get coefficients, SAS by default use the last level as reference, R by default use the first level (correct me if I was wrong), The result I got is a mixture, using first and last for different variables. I tried relevel, reorder, contrasts, but no success. I found what really matters is options(contrasts = c(contr.treatment, contr.poly)) or options(contrasts = c(contr.SAS, contr.poly)) so I guess I can set contrasts= a list of contrasts for each variables in polr(), but I cannot successfuly set the contrasts, what is the syntax? Is there a better way to do this? Thank you very much, Tian [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] garch results is different other soft
I do not believe there are any garch functions in the core R. RSiteSearch(garch, tseries) just returned 21 hits, identifying garch capabilities in three different packages (tseries, fSeries and fOptions), plus mentions of garch in the Ecdat package. I would be interested in a sensible reply to your question, and I believe many others would as well. However, without more specifics, I don't feel I can afford the time to investigate this further. You could help this by providing commented, minimal, self-contained, reproducible code, mentioning which 'garch' function you used in which package and which data readily available to all R users (as suggested in the posting guide www.R-project.org/posting-guide.html). If you do this, please tell us which capability of which other software you used for comparison, and compare the answers obtained from the other software and the R function(s) you used. You might even be able to answer the question yourself by reading the code: R is open source, and you can view the R code for any function just by typing the function name at a command prompt. If part of the work is done in a compiled language, you will be able to see that, and the GNU license guarantees that you can get the source. Moreover, the 'debug' function in R makes it fairly easy to walk through a function line by line, looking at what it does at each step of the way. I know this doesn't answer your question, but I hope it helps. Best Wishes, Spencer Graves Yong Xiao wrote: Hi I compared garch results in R with those give by other software and found that their coefficients are different from each other. So I wondered that a convention the garch funcion in R takes. By testing the output, I noticed it seems that garch function in R by default takes such a convention: y(t) = c + sigma(t) where c=0 and sigma(t) = a(0) + a(1)*epsilon^2 + b(1)*sigma(t-1)^2. I also checked the standard deviation series, i.e., the output$fitted.values, and noticed that the first element (the starting variance) is NA. I feel puzzled because in other software, the starting variance is estimated together with a(0), a(1) and b(1) by ML method. Could any clear this puzzle for me? Many thanks! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] separate row averages for different parts of an array
Spencer Jones a écrit : I have an array with 44800 columns and 24 rows I would like to compute the row average for the array 100 columns at a time, so I would like to end up with an array of 24 rows x 448 columns. I have tried using apply(dataset, 1, function(x) mean(x[])), but I am not sure how to get it to take the average 100 columns at a time. Any ideas would be welcomed. thanks, Spencer ?rowSums, ?rowMeans something like : rowMeans(my_array[,1:100]) (perhaps you'll have to use t() also) hih __ R-help@stat.math.ethz.ch 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.