Re: [R] how to automatically create objects with names from a string list?
Or with mapply name - c(foo, bar, baz) val - 1:3 mapply(assign, name, val, pos=1) Cheers, Simon. On Tue, 2008-06-03 at 22:24 -0700, Moshe Olshansky wrote: You can use either assign or eval. Something like name - c(foo, bar, baz) for (i in 1:length(name)) assign(name[i],i) --- On Wed, 4/6/08, Mark Farnell [EMAIL PROTECTED] wrote: From: Mark Farnell [EMAIL PROTECTED] Subject: [R] how to automatically create objects with names from a string list? To: R-help@r-project.org Received: Wednesday, 4 June, 2008, 3:15 PM Suppose I have a string of objects names: name - c(foo, bar, baz) and I would like to use a for loop to automatically create three objects called foo, bar and baz accordingly. Then how can this be done (so that in the workspace, foo = 1, bar = 2 and baz=3) for (i in name) { . } Thanks! Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Simon Blomberg, BSc (Hons), PhD, MAppStat. Lecturer and Consultant Statistician Faculty of Biological and Chemical Sciences The University of Queensland St. Lucia Queensland 4072 Australia Room 320 Goddard Building (8) T: +61 7 3365 2506 http://www.uq.edu.au/~uqsblomb email: S.Blomberg1_at_uq.edu.au Policies: 1. I will NOT analyse your data for you. 2. Your deadline is your problem. The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging two data sets with no column header
Thanks for your reply. In your last step If I create a duplicate ( two similar records ) # create a duplicate vv[8,1] - 7 vv[8,2]-'g' and then I merge vv with vv2 ,both duplicates are merged. Is there a way to tell R to merge only the unique records. -- I don't think merge will do what you are asking. Suspect you would need to do it either before the merge or after. I tried using the Extract operator on a merged dataset, but only succeeded in omitting the duplicated items, not both instances. -- David Winsemius -- View this message in context: http://www.nabble.com/merging-two-data-sets-with-no-column-header-tp17613296p17639592.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ignoring environment value of R_HOME error when installing packages
I am troubled by what appears to be a glitch in the current distribution, or in its installation on our system. I've traced it, and found a work- around. Is this normal? Is there a cleaner solution? The problem: During a package installation, the warning message WARNING: ignoring environment value of R_HOME from line 31 of R_HOME/bin/R is accidentally spliced into the CLINK_CPPFLAGS variable at line 606 of R_HOME/bin/ INSTALL. This prevents the compilation C files. Please note that I have not set the R_HOME environment variable; it is undefined in my shell. - Here are lines 29-32 from R_HOME/bin/R: if test -n ${R_HOME} \ test ${R_HOME} != ${R_HOME_DIR}; then echo WARNING: ignoring environment value of R_HOME fi - Here is line 606 of R_HOME/bin/INSTALL: CLINK_CPPFLAGS=`echo tools:::.find_cinclude_paths(file='DESCRIPTION') | \ ${R_EXE} --vanilla --slave` The work-around: First some background. The command sequence R CMD INSTALL sets in motion a sequence of scripts that collectively manage the installation process. RR_HOME/bin/R calls Rcmd script on line 148 CMD R_HOME/lib/R/bin/Rcmd calls INSTALL script on line 45 INSTALL R_HOME/lib/R/bin/INSTALL encounters the error on line 606 Now, if you are the owner of you installation, then you can probably just edit the INSTALL file directly. Otherwise, if you specify the full path of an executable in place of the word INSTALL on the command line, the Rcmd script will detect this and call your script instead of the normal INSTALL script (see Rcmd line 37). e.g. R CMD path.to.alternate.install.script ... One can just copy the INSTALL script, changing line 606 to CLINK_CPPFLAGS = and hope for the best. If the package you are compiling specifies its own C include files, then you will have to modify the variable accordingly, or else use the ~/.R/Makevars mechanism. But, the question remains, is there an nicer solution? Thanks, - Stu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-2.7.0 make check failure
This indicates a serious problem with your build (a segfault). Unfortunately as R is very well tested on Linux and we have never seen this one reported, we have no clue as to why. You've told us very little (what architecture, what compilers?) so although it seems to be something specific to your OS/machine, you will need to find out what via the debugger. The most likely guess as to the cause is a compiler optimization error, so I would try building without optimization. On Tue, 3 Jun 2008, Gregory Ruchti wrote: Hello, I am fairly new to using R and am trying to install it on my Linux machine, running Scientific Linux. I get through running 'configure' and 'make' OK, but when I run 'make check', I get the following error: make check make[1]: Entering directory `/home/gruchti/Programs/R-2.7.0/tests' make[2]: Entering directory `/home/gruchti/Programs/R-2.7.0/tests' make[3]: Entering directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' make[4]: Entering directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' make[4]: `Makedeps' is up to date. make[4]: Leaving directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' make[4]: Entering directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' running code in 'base-Ex.R' .../bin/sh: line 1: 4233 Segmentation fault ../../bin/R --vanilla base-Ex.R base-Ex.Rout 21 make[4]: *** [base-Ex.Rout] Error 1 make[4]: Leaving directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' make[3]: *** [test-Examples-Base] Error 2 make[3]: Leaving directory `/home/gruchti/Programs/R-2.7.0/tests/Examples' make[2]: *** [test-Examples] Error 2 make[2]: Leaving directory `/home/gruchti/Programs/R-2.7.0/tests' make[1]: *** [test-all-basics] Error 1 make[1]: Leaving directory `/home/gruchti/Programs/R-2.7.0/tests' make: *** [check] Error 2 I took a look at the 'base-Ex.Rout.fail' file to see where the problem occured and get the following at the end of the file: ## R code version of choose() [simplistic; warning for k 0]: mychoose - function(r,k) + ifelse(k = 0, (k==0), +sapply(k, function(k) prod(r:(r-k+1))) / factorial(k)) k - -1:6 cbind(k=k, choose(1/2, k), mychoose(1/2, k)) *** caught segfault *** address 0x200, cause 'memory not mapped' Traceback: 1: doWithOneRestart(return(expr), restart) 2: withOneRestart(expr, restarts[[1]]) 3: withRestarts({.Internal(.signalCondition(simpleWarning(msg, call), msg, call)).Internal(.dfltWarn(msg, call))}, muffleWarning = function() NULL) 4: .signalSimpleWarning(NaNs produced, quote(gamma(x + 1))) 5: factorial(k) 6: ifelse(k = 0, (k == 0), sapply(k, function(k) prod(r:(r - k + 1)))/factorial(k)) 7: mychoose(1/2, k) 8: cbind(k = k, choose(1/2, k), mychoose(1/2, k)) aborting ... I really am not sure how to interpret this, or how to fix it. Any help would be greatly appreciated! Regards, Greg -- Gregory Ruchti Bloomberg Center for Physics and Astronomy Johns Hopkins University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unable to get plot in R
On Tue, 3 Jun 2008, Duncan Murdoch wrote: On 03/06/2008 6:53 PM, Chin-Cheng Su wrote: Hi everyone, I use R to plot my data set (x,y) in Windows XP, but keep getting error message like follows, ... plot(x, y) Error in windows() : unable to start device devWindows How can I solve this problem? Thanks for any suggestion or help. Somehow you appear to have set options(device) to devWindows. If you set it to windows using options(device=windows), things should be fine. I don't think so. windows() is a family of devices, and that is what they report if GADeviceDriver fails. That would seem to mean that either allocation fails (unlikely) or GA_Open fails (which AFAICS only fails if newwindow does). We don't have the 'at a minimum' details requested in the posting guide, and this might be something to do with the locale. I'd suggest starting R in an English locale if that is not already the case (add LC_ALL=en to the target of the shortcut used to start R -- see the rw-FAQ). -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problems with variogram
Hello, I have data at 10 locations, in each location there are time series (T=56). Question is: when Im fitting variogram what happens with those measures in each location? Are they taken as repeated measures? It's very important for my to know this Thanks a lot __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Model simplification using anova()
ChCh jmo101 at student.canterbury.ac.nz writes: Hello all, I've become confused by the output produced by a call to anova(model1,model2). First a brief background. My model used to predict final tree height is summarised here: Df Sum Sq Mean Sq F valuePr(F) Treatment 2 748.35 374.17 21.3096 7.123e-06 *** HeightInitial1 0.31 0.31 0.01780.89519 DiameterInitial 1 0.52 0.52 0.02980.86460 Frost 1 38.2938.292.18070.15392 HeightInitial:Frost1 85.83 85.83 4.88820.03774 * DiameterInitial:Frost 1 97.9097.905.57540.02749 * Residuals22 386.30 17.56 --- Based on this, I should not remove either of the interaction terms, so I turned my attention to the main factors. Based on p-values, I removed HeightInitial and used a call to anova(model1,model2) to see if this resulted in a weaker model. Here is the output: ... Though should never remove main factors in the presence of interactions. Check Bill Venables penitential sermon which quite on top of google when you enter exegeses. http://www.stats.ox.ac.uk/pub/MASS3/Exegeses.pdf The usual way to simplify models in R is based on the AIC, not on p-values. See stepAIC and the chapter in MASS. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] random time serie
Dear all, I would like to create an random time serie of POSIXct elements inside a certain range of dates and time. For example a sequences of date/time of 400 elements, randomly choosen, with all dates between 2002-12-01 and 2002-12-31 and all time between 07:00:00 and 23:00:00. Would anyone know if there is a specific R - function for that ? Many thanks in advance, Jessica _ Jessica Gervais Tel: +352- 425991-628 Mail: [EMAIL PROTECTED] Resource Centre for Environmental Technologies, Public Research Centre Henri Tudor, Technoport Schlassgoart, 66 rue de Luxembourg, P.O. BOX 144, L-4002 Esch-sur-Alzette, Luxembourg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matlab eigs function in R
Thomas As far I can see eig (matlab) and eigen (R) both uses LAPACK as the engine, so no differences apart from rounding errors should be expected. You are not being particular friendly, since you have not told the whole story about how you use eigs in matlab (you are giving some options to eigs). The man page for eigs tells that eigs find largest eigenvalues and eigenvectors of a sparse matrix. However to see how this is done one needs to consult the references (see below) in order to find out. It is some iterative method depending on numerous parameters. If I use eigs with default values for it's options on M = [1.2607 -3.55752.2968 0 0 0 -3.5575 10.1429 -6.5855 0 0 0 2.2968 -6.58554.2887 0 0 0 0 0 02.6359 -4.84892.2130 0 0 0 -4.84898.9217 -4.0728 0 0 02.2130 -4.07281.8598] to find the four eigenvalues closest to 0 I get: [Y,eigenvals] = eigs(M,4,0) Iteration 1: a few Ritz values of the 6-by-6 matrix: 0 0 0 0 Y = 0.77166670795421 -0.7309382085 -0.00 -0.57709401467465 -0.15442436854521 0.00132216402668 -0.01 -0.57751272471495 -0.61675233485287 -0.00113088742149 -0.00 -0.57744396127772 0.00795845605741 -0.68639286168232 0.57735026918974 0.1228756964 -0.01410736097199 -0.03974888299631 0.57735026918963 -0.00011191813149 0.00614890491458 0.72614174467891 0.57735026918951 0.9963056184 eigenvals = 0.02530485525437 0 0 0 0 0.00109157646361 0 0 0 0 -0.00 0 0 0 0 -0.3332911697 Now setting e.g. options.issym = 1 options.p = 6 (number of basis vectors) we now get [Y,eigenvals] = eigs(M,4,0,options) Iteration 1: a few Ritz values of the 6-by-6 matrix: 0 0 0 0 Y = -0.76500157409670 -0.00223987987076 -0.00 -0.57702216553796 0.13515933807820 0.00165998521603 -0.00 -0.57744188181803 0.62913726290127 0.00151722712519 -0.00 -0.57758630415522 -0.00973169974519 -0.68255505830793 0.57735026918973 -0.00048056999418 0.02143072866845 -0.04677389396937 0.57735026918963 0.00017535669432 -0.01169902892326 0.72932895227757 0.57735026918951 0.00030521329984 eigenvals = 0.02542832424752 0 0 0 0 0.00110871605179 0 0 0 0 -0.00 0 0 0 0 -0.3331498129 Different answers!!! What causes the difference the references should explain to us. If you need functions for sparse matrices in R consider the sparseM and Matrix packages. The latter has a eigen() but I don't know which methods it uses to calculate the eigenvalues and -vectors. Best regards Frede Aakmann Tøgersen Scientist UNIVERSITY OF AARHUS Faculty of Agricultural Sciences Dept. of Genetics and Biotechnology Blichers Allé 20, P.O. BOX 50 DK-8830 Tjele Phone: +45 8999 1900 Direct: +45 8999 1878 E-mail: [EMAIL PROTECTED] Web: http://www.agrsci.org This email may contain information that is confidential. Any use or publication of this email without written permission from Faculty of Agricultural Sciences is not allowed. If you are not the intended recipient, please notify Faculty of Agricultural Sciences immediately and delete this email. References for eigs [1] Lehoucq, R.B. and D.C. Sorensen, Deflation Techniques for an Implicitly Re-Started Arnoldi Iteration, SIAM J. Matrix Analysis and Applications, Vol. 17, 1996, pp. 789-821. [2] Lehoucq, R.B., D.C. Sorensen, and C. Yang, ARPACK Users' Guide: Solution of Large-Scale Eigenvalue Problems with Implicitly Restarted Arnoldi Methods, SIAM Publications, Philadelphia, 1998. [3] Sorensen, D.C., Implicit Application of Polynomial Filters in a k-Step Arnoldi Method, SIAM J. Matrix Analysis and Applications, Vol. 13, 1992, pp. 357-385. -Oprindelig meddelelse- Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] På vegne af kayteck_master Sendt: 3. juni 2008 8:22 Til: r-help@r-project.org Emne: Re: [R] matlab eigs function in R Dear Thomas Yes, you're right. But I'm looking for this not only for computational cost reasons. eigen function from R has identical behavior to matlab function eig, but not to eigs. Even in matlab you can check that those function are not giving identical results. Here you have a short example : Suppose we have given a
[R] missing data imputation - simulation
My dataset contains missing data and I would like to do something like an EM algorithm or a Markov Chain Monte Carlo approach to get rid of the missing data. Is there a function for imputation or simulation of missing data apart from those in the randomForest library? Thanks in advance Birgit - The art of living is more like wrestling than dancing. (Marcus Aurelius) -- View this message in context: http://www.nabble.com/missing-data-imputation---simulation-tp17642736p17642736.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] splitting data frame based on a criteria
Hi the other possible option is to use split with suitable graphing technique or with lapply and appropriate function e.g. boxplot(split(X, Y0)) histogram( ~ X|Y) gives Marvin [EMAIL PROTECTED] napsal dne 03.06.2008 21:11:29: ?by may be helpful here eg if dat is your data.frame and yf is a factor (created using ifelse) use by(dat,yf,mean) to compute the means for each level of yf hth, Ingmar On Jun 3, 2008, at 8:37 PM, Marvin Lists wrote: Hi, I have a data frame that I want to split into two based on the values of a variable in it. The variable Y has numeric values ranging between 0 through 70. I want to plot the frequencies of another variable X in two different cases: - When Y = 0 and - When Y 0 How does one go about doing this? In general, I want to do several analyses with this data frame that are a variation of the above situation, i.e. they require splitting the data into different age, gender etc. and then calculating separate means, correlations and so on for the different groups into which the data frame would split. I am struggling with the correct syntax for achieving this. Reading through the documentation suggests that tapply and split may be the functions to use for my purposes but the examples in the documentations didn't help me understand how I could achieve this. I would appreciate any suggestions and help. Thanks, Marvin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: column and row
Hi use str(object) to see what is a structure of object then use standard selecting by [..., ...] In your case you shall probably use extracting function coef(fit1)[1,] for the first row and similarly for the second. Regards Petr [EMAIL PROTECTED] 724008364, 581252140, 581252257 [EMAIL PROTECTED] napsal dne 04.06.2008 03:55:47: -fit1$coefficients y.control y.lowy.high (Intercept)19.628713 21.883999 20.023814 log(1 + (age - 45)/10) -7.383725 -6.017342 -5.084431 here is my outcome,I need one vector say b1=first row without the intercept ,like:(19.628713, 21.883999, 20.023814) and another b2=second row without the log(1 + (age - 45)/10),only the data,how to do this in R? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] data frame titles
I'm new to R so please forgive the newbie question; but i can't seem to find a definitive answer to this. I am wanting to do a PLS regression on some data. Which takes a formula of the type responseACC ~ dataACC where dataACC is multivariate in nature and responseACC is a single value. I have imported my data from a csv file into a dataframe called for arguments sake df. This file has no headers in it so I get column names X1.X83 I then create a new data frame which says data.frame(dataACC = df[1:82], responseACC = df[83]) When I look at the names of this though I get... dataACC.X1 . dataACC.X82 and then X83 When I pass this to the PLS algorithm I get the error variable responseACC not found So a few questions, Am I doing this in the right way in general? why is the responseACC not being associated as the name of df[83]? Thirdly, If I want to generate my own array of values in order to do get a predicted response based on my initial PLS regression, will it matter that the array data will not have header values (eg dataACC.X1 etc)? if so what the best way of appending the header data? Thanks for any help you can lend Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] missing data imputation - simulation
On 6/4/2008 5:32 AM, Birgitle wrote: My dataset contains missing data and I would like to do something like an EM algorithm or a Markov Chain Monte Carlo approach to get rid of the missing data. Is there a function for imputation or simulation of missing data apart from those in the randomForest library? Thanks in advance Birgit RSiteSearch(imputation, restrict=functions) RSiteSearch({multiple imputation}, restrict=functions) return many relevant hits. - The art of living is more like wrestling than dancing. (Marcus Aurelius) -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] missing data imputation - simulation
Birgit, not knowing your data, I would recommend R-package mice or function aregImpute from R-package Hmisc as good multi-purpose tools. Regards, Ulrike -- View this message in context: http://www.nabble.com/missing-data-imputation---simulation-tp17642736p17643601.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] A little test -- please forgive!
Sorry for the noise -- but I want to see what happens to this message when it gets to tyhe archives. Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 04-Jun-08 Time: 11:02:57 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] missing data imputation - simulation
Many thenks to both of you: Will have a look. Birgit Chuck Cleland wrote: On 6/4/2008 5:32 AM, Birgitle wrote: My dataset contains missing data and I would like to do something like an EM algorithm or a Markov Chain Monte Carlo approach to get rid of the missing data. Is there a function for imputation or simulation of missing data apart from those in the randomForest library? Thanks in advance Birgit RSiteSearch(imputation, restrict=functions) RSiteSearch({multiple imputation}, restrict=functions) return many relevant hits. - The art of living is more like wrestling than dancing. (Marcus Aurelius) -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - The art of living is more like wrestling than dancing. (Marcus Aurelius) -- View this message in context: http://www.nabble.com/missing-data-imputation---simulation-tp17642736p17644180.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Comparing two regression lines
Dear R users, Suppose I have two different response variables y1, y2 that I regress separately on the same explanatory variable, x; sample sizes are n1=n2. Is it legitimate to compare the regression slopes (equal variances assumed) by using lm(y~x*FACTOR), where FACTOR gets y1 if y1 is the response, and y2 if y2 is the response? The problem I see here is that the residual degrees of freedom obviously go up (n1-1+n2-1) although there were only n1=n2 true replications. On the other hand, Zar (1984) and some other statistics textbooks base their calculations on a modified version of the t test (mainly using the residual SS from the two regressions), but when I calculated these tests by hand I found that the t-values are almost identical to the one I get using the lm(...) approach. Part of the R script is appended below. How would you proceed? Many thanks for your help! Best wishes, Christoph ## lm1=lm(y1~x) # y1 and y2 are different response variables, scaled to [0;1] using a ranging transform lm2=lm(y2~x) # n is 12 for each regression model3=lm(y~x*FACTOR) summary(model3) sxx1=sum((y1-mean(y1))^2) sxx2=sum((y2-mean(y2))^2) s.pooled=(4805.2+6946.6)/20 SED=sqrt(s.pooled*(1/sxx1+1/sxx2)) t=(528.54-446.004)/SED #residual SS from lm1 and lm2 divided by SED qt(0.025,20) #compare with t distribution at 20 d.f. ## #(using R 2.6.2 on Windows XP) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: data frame titles
Hi [EMAIL PROTECTED] napsal dne 04.06.2008 10:57:26: I'm new to R so please forgive the newbie question; but i can't seem to find a definitive answer to this. I am wanting to do a PLS regression on some data. Which takes a formula of the type responseACC ~ dataACC where dataACC is multivariate in nature and responseACC is a single value. Really? From which package? AFAIK in package pls you have to enter formula plsr(response~terms, data.frame) I have imported my data from a csv file into a dataframe called for arguments sake df. This file has no headers in it so I get column names X1.X83 I then create a new data frame which says data.frame(dataACC = df[1:82], responseACC = df[83]) You probably want data.frame(dataACC = df[,1:82], responseACC = df[,83]) When I look at the names of this though I get... dataACC.X1 . dataACC.X82 and then X83 When I pass this to the PLS algorithm I get the error variable responseACC not found So a few questions, Am I doing this in the right way in general? why is the responseACC not being associated as the name of df[83]? Thirdly, If I want to generate my own array of values in order to do get a predicted response based on my initial PLS regression, will it matter that the array data will not have header values (eg dataACC.X1 etc)? if so what the best way of appending the header data? see ?names Regards Petr Thanks for any help you can lend Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Minimizing the negative log likelihood function...
François Aucoin: I have tried several R's functions for optimization but the results I yield are not correct. Is there anybody who can help me? I couldn't get it to estimate the correct values either, so I guess either your random number generator 'rkappa' is wrong, or your 'Neg.Log.Like' function is wrong. Or possibly both. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using library in an example
Hi all, I've been trying to include a nice example in the Rd file for a function and cannot work out how to get it through R check. If I use: if(require(maps,quietly=TRUE)) { ... Warning message: 'Sys.putenv' is deprecated. Use 'Sys.setenv' instead. See help(Deprecated) The warning message causes R check to get the tremors and assume there is something wrong with the example. This also means that I can't put a little message telling the user that they needed maps to run the example, as the warning message leads to the else being detached from the if (and another tremor and error message). I can't really use the following, even though it doesn't cause the warning (but would be messy if the user didn't have the package). if(library(maps)) { ... If I try: if(library(maps,logical.return=TRUE)) { ... I get the same warning as with require. Does this qualify as a bug in require/library or should I just not bother to test the result of library and let the user suffer? Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] not meaningful for factors
I am trying to define groupings from levels of factor variables and this the warning message that R give not meaningful for factors. The nature of my task is this. I have a variable stage which has the levels (1B, 2A, 2B) - these are the AJCC TNM stages of cancer, and another variable diameter with factor levels (= 4, 4 - 6.5, 6.5; limit values are exclusive). I am trying to define series of groupings based on these variables and others like them. My first attempts were; 1. node1 - data.trt[data.trt$stage==1B data.trt$diameter=== 4] 2. data.trt$stage[data.trt$stage==1B] data.trt$diameter[data.trt$diameter=== 4] The second attempt was purely a fishing exercise. R gave me the waring message: Warning message: In Ops.factor(data.trt$stage[data.trt$stage == 1B], data.trt$diameter[data.trt$diameter == : not meaningful for factors My question is how do I get round this and by implication is there an alternative way of defining a logical operation applicable to factors. Thanks already for the help. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] request: An array declarion problem
When I run your code, I get a different error: j=10; ss=150; r=array(0 , c( j , ss )); rr=array(0 , c( j , ss )); r1=array(0 , c( j-1 , ss )); r2=array(0 , c( j-1 , ss )); r3=array(0 , c( 2 , ss )) for(i in 1:j-1){ +r1[ i , ] - r[ j+1, ]-r[ j, ]; r2[ i , ] - rr[ j+1, ]-rr[ j, ] +r3[ i,]=rbind(r1[ i, ], r2[ i, ]) +} Error: subscript out of bounds This is probably due to 'r' being dimensioned (j,ss) and you are referencing 'r[j+1,]' which is r[11,]. Also I think you want for(i in 1:(j-1)), notice the difference: 1:j-1 [1] 0 1 2 3 4 5 6 7 8 9 1:(j-1) [1] 1 2 3 4 5 6 7 8 9 On Tue, Jun 3, 2008 at 1:58 PM, Muhammad Azam [EMAIL PROTECTED] wrote: Dear R users I tried a lot to solve the following problem but could not. I have two arrays having same order i.e 1 by 150. j=10; ss=150; r=array(0 , c( j , ss )); rr=array(0 , c( j , ss )); r1=array(0 , c( j-1 , ss )); r2=array(0 , c( j-1 , ss )); r3=array(0 , c( 2 , ss )) for(i in 1:j-1){ r1[ i , ] - r[ j+1, ]-r[ j, ]; r2[ i , ] - rr[ j+1, ]-rr[ j, ] } Now i want to rbind the results of r1 and r2 for each time. Now the order of r3[ j, ] will become 2 by 150. I used the following form in the loop r3[ i,]=rbind(r1[ i, ], r2[ i, ]) But there is an error message Error in r3[i, ] = rbind(r1[i, ], r2[i, ]) : number of items to replace is not a multiple of replacement length I am looking for some suggestion to solve the problem. Thanks and best regards Muhammad Azam Ph.D. Student Department of Medical Statistics, Informatics and Health Economics University of Innsbruck, Austria [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] not meaningful for factors
What exactly are you trying to do? In the first case you are making a logical comparison and that is legal for . In the second you are trying to do a logical operation () between two factors and that operation is not defined. This is what the error message is saying. Also you first attempt is probably missing a comma: node1 - data.trt[data.trt$stage==1B data.trt$diameter=== 4, ] On Wed, Jun 4, 2008 at 8:10 AM, Philip Twumasi-Ankrah [EMAIL PROTECTED] wrote: I am trying to define groupings from levels of factor variables and this the warning message that R give not meaningful for factors. The nature of my task is this. I have a variable stage which has the levels (1B, 2A, 2B) - these are the AJCC TNM stages of cancer, and another variable diameter with factor levels (= 4, 4 - 6.5, 6.5; limit values are exclusive). I am trying to define series of groupings based on these variables and others like them. My first attempts were; 1. node1 - data.trt[data.trt$stage==1B data.trt$diameter=== 4] 2. data.trt$stage[data.trt$stage==1B] data.trt$diameter[data.trt$diameter=== 4] The second attempt was purely a fishing exercise. R gave me the waring message: Warning message: In Ops.factor(data.trt$stage[data.trt$stage == 1B], data.trt$diameter[data.trt$diameter == : not meaningful for factors My question is how do I get round this and by implication is there an alternative way of defining a logical operation applicable to factors. Thanks already for the help. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using library in an example
On 6/4/2008 8:09 AM, Jim Lemon wrote: Hi all, I've been trying to include a nice example in the Rd file for a function and cannot work out how to get it through R check. If I use: if(require(maps,quietly=TRUE)) { ... Warning message: 'Sys.putenv' is deprecated. Use 'Sys.setenv' instead. See help(Deprecated) require() doesn't use Sys.putenv, so I'd guess some package that you're loading does. However, the current version of maps doesn't, so I think you must be loading something that's obsolete. sessionInfo() would have helped a lot. Duncan Murdoch The warning message causes R check to get the tremors and assume there is something wrong with the example. This also means that I can't put a little message telling the user that they needed maps to run the example, as the warning message leads to the else being detached from the if (and another tremor and error message). I can't really use the following, even though it doesn't cause the warning (but would be messy if the user didn't have the package). if(library(maps)) { ... If I try: if(library(maps,logical.return=TRUE)) { ... I get the same warning as with require. Does this qualify as a bug in require/library or should I just not bother to test the result of library and let the user suffer? Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] not meaningful for factors
It works. Thanks Jim. I guess this will be a lots of coffee morning kinda day. jim holtman [EMAIL PROTECTED] wrote: What exactly are you trying to do? In the first case you are making a logical comparison and that is legal for . In the second you are trying to do a logical operation () between two factors and that operation is not defined. This is what the error message is saying. Also you first attempt is probably missing a comma: node1 - data.trt[data.trt$stage==1B data.trt$diameter=== 4, ] On Wed, Jun 4, 2008 at 8:10 AM, Philip Twumasi-Ankrah [EMAIL PROTECTED] wrote: I am trying to define groupings from levels of factor variables and this the warning message that R give not meaningful for factors. The nature of my task is this. I have a variable stage which has the levels (1B, 2A, 2B) - these are the AJCC TNM stages of cancer, and another variable diameter with factor levels (= 4, 4 - 6.5, 6.5; limit values are exclusive). I am trying to define series of groupings based on these variables and others like them. My first attempts were; 1. node1 - data.trt[data.trt$stage==1B data.trt$diameter=== 4] 2. data.trt$stage[data.trt$stage==1B] data.trt$diameter[data.trt$diameter=== 4] The second attempt was purely a fishing exercise. R gave me the waring message: Warning message: In Ops.factor(data.trt$stage[data.trt$stage == 1B], data.trt$diameter[data.trt$diameter == : not meaningful for factors My question is how do I get round this and by implication is there an alternative way of defining a logical operation applicable to factors. Thanks already for the help. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problems with variogram
Laura Saltyte wrote: Hello, I have data at 10 locations, in each location there are time series (T=56). Question is: when I’m fitting variogram what happens with those measures in each location? Are they taken as repeated measures? It's very important for my to know this Thanks a lot Hi Laura, I think this depends on which package you use for your variogram function. In variogram in package gstat, you can define your wanted behavior by manipulating the dX-parameter. Generally, the easiest way you can find an answer to your question if you dont get any help from the help-file of your variogram function, is to look at the number of pairs in the calculated sample variogram; - if you have relatively few pairs altogether (45 or less for your 10 locations, depending on the cutoff for the variogram function), the variogram was calculated from the average of the observations, or from one of the values (probably the first) - if the number of pairs is lower than 45*56 (the length of your time series), the variogram was probably calculated as an average of the variograms from each separate time step - if the number of pairs is high, the variogram was probably calculated by comparing all observations independent of time steps with each other. If you realize that your function uses the last method, I would recommend you to switch to one of the first two. Unless the temporal correlation is very high, the spatial correlation is likely to be (strongly) underestimated in this case. For questions about spatial statistics, the list r-sig-geo will often be more useful than r-help. Good luck, Jon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comparing two regression lines
Dear Christoph, If I've understood properly what you intend to do, no, it doesn't make sense. I assume from your description that you don't have two independent samples, but rather you really have n observations and that the variables x, y1, and y2, are measured on the same individuals. If that's correct, then typically y1 and y2 would not be independent. If my understanding is correct, then you should be able to do what you want by fitting a multivariate regression and testing for the difference of the two slopes. Of course, it must make sense to compare the slopes -- e.g., y1 and y2 must be measured in the same units. Here's a nonsense example illustrating how you could proceed using the linear.hypothesis() function in the car package: library(car) mod - lm(cbind(income, education) ~ prestige, data=Duncan) Anova(mod) Type II MANOVA Tests: Pillai test statistic Df test stat approx F num Df den DfPr(F) prestige 1 0.828 101.216 2 42 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 linear.hypothesis(mod, prestige, P=matrix(c(-1, 1), 2, 1)) Response transformation matrix: [,1] income -1 education1 Sum of squares and products for the hypothesis: [,1] [1,] 1048.684 Sum of squares and products for error: [,1] [1,] 17828.96 Multivariate Tests: Df test stat approx F num Df den Df Pr(F) Pillai1 0.017 2.5292235 1 43 0.11908 Wilks 1 0.983 2.5292235 1 43 0.11908 Hotelling-Lawley 1 0.0588192 2.5292235 1 43 0.11908 Roy 1 0.0588192 2.5292235 1 43 0.11908 Note that in this case the multivariate test is really univariate. If you apply your approach to this example, you get: attach(Duncan) y - c(income, education) x - c(prestige, prestige) f - factor(rep(c(income, education), c(45, 45))) mod.univ - lm(y ~ x*f) Anova(mod.univ) Anova Table (Type II tests) Response: y Sum Sq Df F valuePr(F) x 46199 1 214.549 2.2e-16 *** f 2571 1 11.938 0.0008563 *** x:f 524 1 2.435 0.1223237 Residuals 18519 86 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 The sum of squares for the x:f interaction is exactly half the SS for the hypothesis of equal slopes from the multivariate linear model, but the sum of squares for error is off. The net result is a test statistic that is slightly off (and has incorrect df). I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christoph Scherber Sent: June-04-08 7:37 AM To: [EMAIL PROTECTED] Subject: [R] Comparing two regression lines Dear R users, Suppose I have two different response variables y1, y2 that I regress separately on the same explanatory variable, x; sample sizes are n1=n2. Is it legitimate to compare the regression slopes (equal variances assumed) by using lm(y~x*FACTOR), where FACTOR gets y1 if y1 is the response, and y2 if y2 is the response? The problem I see here is that the residual degrees of freedom obviously go up (n1-1+n2-1) although there were only n1=n2 true replications. On the other hand, Zar (1984) and some other statistics textbooks base their calculations on a modified version of the t test (mainly using the residual SS from the two regressions), but when I calculated these tests by hand I found that the t-values are almost identical to the one I get using the lm(...) approach. Part of the R script is appended below. How would you proceed? Many thanks for your help! Best wishes, Christoph ## lm1=lm(y1~x) # y1 and y2 are different response variables, scaled to [0;1] using a ranging transform lm2=lm(y2~x) # n is 12 for each regression model3=lm(y~x*FACTOR) summary(model3) sxx1=sum((y1-mean(y1))^2) sxx2=sum((y2-mean(y2))^2) s.pooled=(4805.2+6946.6)/20 SED=sqrt(s.pooled*(1/sxx1+1/sxx2)) t=(528.54-446.004)/SED #residual SS from lm1 and lm2 divided by SED qt(0.025,20) #compare with t distribution at 20 d.f. ## #(using R 2.6.2 on Windows XP) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sum of unknown number of matrices
Hi R, I have a list of matrices. I need to get the sum of all the matrices in the list. Example: a=b=c=d=matrix(1:4,2,2) l=list(a,b,c,d) I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? I may not be knowing the number of matrices in the list... Thanks, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot with text and symbols on x
Thanks Greg. A useful solution. Birgit Am 02.06.2008 um 23:13 schrieb Greg Snow: An alternative way to draw the symbols (or some approximation of them) is to use the my.symbols function from the TeachingDemos package along with ms.male and ms.female (or your improvement of these, also from the TeachingDemos package). See the 4th example from ?ms.male (or ?ms.female). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Birgit Lemcke Sent: Thursday, May 29, 2008 6:05 AM To: Gabor Grothendieck Cc: R Hilfe Subject: Re: [R] boxplot with text and symbols on x Thanks that was a huge help. Now I am using this: pdf(InfLengMaxVarHomogeneity.pdf) plot(inflorescence_length_Max~Sex,xaxt=n #unterdrückt normale x- Achse , ylab=inflorescence length max, main=Bartletts Homogeneity for inflorescence length Max,data=FemMal_Sex) Homo-bartlett.test(FemMal_Sex$inflorescence_length_Max,FemMal _Sex$Sex) text( 2, 500, Bartlett's K-squared=, col='red',adj = c(1,0) ) text( 2, 500, round(Homo$statistic,digits=5), col='red' ,adj = c(0,0)) text( 2, 480, df=, col='red',adj = c(1,0) ) text( 2, 480, Homo$parameter, col='red' ,adj = c(0,0)) text( 2, 460, p-value=, col='red', adj = c(1,0)) text( 2, 460, round(Homo$p.value,digits=5), col='red', adj = c(0,0)) axis(1,at=c(1,2) #Mache punkte auf Achse in Position 1 und 2 , lab=expression( \u2642, \u2640)) #zeichne dort Mann/Frau Symbole dev.off() But the symbols do not appear in the pdf. What is the reason for that and how can I create a pdf with the symbols. Thanks again Birgit Am 29.05.2008 um 13:13 schrieb Gabor Grothendieck: 1. See ?locator 2. Try this: plot(1:2, pch = c(\u2640, \u2642)) On Thu, May 29, 2008 at 4:40 AM, Birgit Lemcke [EMAIL PROTECTED] wrote: Hello R-user community! I am running R 2.7.0 on a Power Book (Tiger). (I am still R and statistics beginner) I did the following : pdf(InLnegthMaxHomogeneity.pdf) boxplot(inflorescence_length_Max~Sex, main=Bartletts Homogeneity for inflorescence length,data=FemMal_Sex) Homo-bartlett.test(FemMal_Sex$inflorescence_length_Max,FemMal_Sex $Sex) text( 2, 500, Bartlett's K-squared=, col='red',adj = c(1,0) ) text( 2, 500, round(Homo$statistic,digits=5), col='red' ,adj = c (0,0)) text( 2, 480, df=, col='red',adj = c(1,0) ) text( 2, 480, Homo$parameter, col='red' ,adj = c(0,0)) text( 2, 460, p-value=, col='red', adj = c(1,0)) text( 2, 460, round(Homo$p.value,digits=5), col='red', adj = c(0,0)) dev.off() As I am still not very good in R, I guess it is not the easiest way to implement the text and it was kind of fiddling around to find the right position for the text. I would be glad if somebody would have an easier solution. My second question is about adding symbols (usual male and female symbol) to the x-axis to label the boxes. I would be very glad if somebody could help mw with this. Many thanks in advance. Greets Birgit Birgit Lemcke Institut für Systematische Botanik Zollikerstrasse 107 CH-8008 Zürich Switzerland Ph: +41 (0)44 634 8351 [EMAIL PROTECTED] 175 Jahre UZH «staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.» Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. Birgit Lemcke Institut für Systematische Botanik Zollikerstrasse 107 CH-8008 Zürich Switzerland Ph: +41 (0)44 634 8351 [EMAIL PROTECTED] 175 Jahre UZH «staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.» Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Birgit Lemcke Institut für Systematische Botanik Zollikerstrasse 107 CH-8008 Zürich Switzerland Ph: +41 (0)44 634 8351 [EMAIL PROTECTED] 175 Jahre UZH «staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.» Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of unknown number of matrices
try a simple for loop, it will be fast enough in this case, e.g., matSums - function (lis) { out - array(data = 0, dim = dim(lis[[1]])) for (i in seq(along = lis)) out - out + lis[[i]] out } a - b - c - d - matrix(1:4, 2, 2) l - list(a, b ,c, d) matSums(l) I hope it helps. Best, Dimitris Dimitris Rizopoulos 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: Shubha Vishwanath Karanth [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 4:53 PM Subject: [R] sum of unknown number of matrices Hi R, I have a list of matrices. I need to get the sum of all the matrices in the list. Example: a=b=c=d=matrix(1:4,2,2) l=list(a,b,c,d) I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? I may not be knowing the number of matrices in the list... Thanks, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of unknown number of matrices
Shubha Vishwanath Karanth wrote: I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? Because do.call constructs a function call with the elements of l as arguments, so you end up with: +(1:4, 1:4, 1:4, 1:4) but + only takes two arguments. Use 'Reduce': Reduce(+,l) [,1] [,2] [1,]4 12 [2,]8 16 Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of unknown number of matrices
Dear Shubha, This problem was coincidentally used as an illustration in the Help Desk column in the current R News. Actually, the brute-force method of using a loop to accumulate the sum works quite well; a more elegant alternative, recently brought to my attention by Kurt Hornik, uses the Reduce() function. Here's an example: matrices - vector(mode=list, length=1) for (i in 1:1) + matrices[[i]] - matrix(rnorm(1), 100, 100) system.time({ + S - matrix(0, 100, 100) + for (i in 1:1) S - S + matrices[[i]] + }) user system elapsed 0.590.000.59 system.time(S1 - Reduce(+, matrices)) user system elapsed 0.600.000.59 range(S1 - S) [1] 0 0 I hope this helps, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: June-04-08 10:54 AM To: [EMAIL PROTECTED] Subject: [R] sum of unknown number of matrices Hi R, I have a list of matrices. I need to get the sum of all the matrices in the list. Example: a=b=c=d=matrix(1:4,2,2) l=list(a,b,c,d) I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? I may not be knowing the number of matrices in the list... Thanks, Shubha This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of unknown number of matrices
Thanks all...Reduce() is the new function I learnt today... Thanks... BR, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: Barry Rowlingson [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 8:49 PM To: Shubha Vishwanath Karanth Cc: [EMAIL PROTECTED] Subject: Re: [R] sum of unknown number of matrices Shubha Vishwanath Karanth wrote: I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? Because do.call constructs a function call with the elements of l as arguments, so you end up with: +(1:4, 1:4, 1:4, 1:4) but + only takes two arguments. Use 'Reduce': Reduce(+,l) [,1] [,2] [1,]4 12 [2,]8 16 Barry This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sum of unknown number of matrices
G'day Shubha, On Wed, 4 Jun 2008 20:23:35 +0530 Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: Something like do.call(+,l) is not working...why is this? Well, as the error message says, + is either a unary or a binary operator, i.e. it takes either one or two arguments, but not more. I may not be knowing the number of matrices in the list... This is perhaps a bit complicated but it works: R a=b=c=d=matrix(1:4,2,2) R l=list(a,b,c,d) R library(abind) ## may have to install this package first R apply(do.call(abind, list(l, along=3)), 1:2, sum) [,1] [,2] [1,]4 12 [2,]8 16 HTH. Cheers, Berwin === Full address = Berwin A TurlachTel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability+65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: [EMAIL PROTECTED] Singapore 117546http://www.stat.nus.edu.sg/~statba __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Constructing groupedData objects in nlme - a little problem
Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): library(nlme) x2=Rail$travel;x1=Rail$Rail;eg1=data.frame(x1,x2);eg1gd=Rail print(eg1gd) x11();print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x12 x15 x11 x16 x13 x14 31.7 50.0 54.0 82.7 84.7 96.0 ...which works fine. This uses a built-in groupedData object called Rail that is part of the nlme library. I am trying to 'recreate' this groupedData object. Here's what I've done: x1=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6);x2=c(55,53,54,26,37,32,78,91,85,92,100,96,49,51,50,80,85,83) eg1=data.frame(x1,x2);colnames(eg1)=c(Rail,travel);eg1gd=groupedData(travel~1|Rail,data=eg1) print(eg1gd) x11();print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x1 16.49817 ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Can anyone help? I've looked at the ?groupedData man page, but it has no solution to this. Thanks very much for any advice, Toby Pinheiro JC Bates DM (2000). Mixed-Effects Models in S and S-PLUS (1st ed.). Springer, New York. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] wildcard symbol or character
Bill Venables responded and got me what i wanted with this: [EMAIL PROTECTED] wrote: cv - scan( textConnection(CW-W730 CW-W720 CW-W710 CW-W700 CW-W690 CW-W680 CW-W670 CW-W660 CE-W997 CE-W987 CE-W977 CE-W967 CE-W956 CE-W944 CE-W934 CE-W924 7W-W760 7W-W750 7W-967W-941 7W-932 7W-923 7W-914 7W-905 7E-W565 7E-W555 7E-W545 7E-W535 7E-W525 7E-906 7E-850 7E-840), what = ) Read 32 items cv [1] CW-W730 CW-W720 CW-W710 CW-W700 CW-W690 [6] CW-W680 CW-W670 CW-W660 CE-W997 CE-W987 [11] CE-W977 CE-W967 CE-W956 CE-W944 CE-W934 [16] CE-W924 7W-W760 7W-W750 7W-96 7W-941 [21] 7W-932 7W-923 7W-914 7W-905 7E-W565 [26] 7E-W555 7E-W545 7E-W535 7E-W525 7E-906 [31] 7E-850 7E-840 split(cv, substring(cv, 0, 2)) $`7E` [1] 7E-W565 7E-W555 7E-W545 7E-W535 7E-W525 7E-906 [7] 7E-850 7E-840 $`7W` [1] 7W-W760 7W-W750 7W-96 7W-941 7W-932 7W-923 [7] 7W-914 7W-905 $CE [1] CE-W997 CE-W987 CE-W977 CE-W967 CE-W956 CE-W944 [7] CE-W934 CE-W924 $CW [1] CW-W730 CW-W720 CW-W710 CW-W700 CW-W690 CW-W680 [7] CW-W670 CW-W660 john.polo wrote: hello all, i want to split a list into smaller lists. the list looks like this: CW-W730 CW-W720 CW-W710 CW-W700 CW-W690 CW-W680 CW-W670 CW-W660 CE-W997 CE-W987 CE-W977 CE-W967 CE-W956 CE-W944 CE-W934 CE-W924 7W-W760 7W-W750 7W-967W-941 7W-932 7W-923 7W-914 7W-905 7E-W565 7E-W555 7E-W545 7E-W535 7E-W525 7E-906 7E-850 7E-840 ... i want the smaller lists to be based on the first two characters, like CW or 7E. i tried split() where the f variable = c(1E-*,1W-*,2E-*,2W-*,5E-*,5W-*,7E-*,7W-*,CE-*,CW-*), but * doesn't work as a wildcard as i had hoped. can someone tell me the appropriate wildcard character/symbol to use, please? john __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mathematical expression of probability function?
Dear R forum, I have a concern regarding a mathematical expression of the probability function (see below). I know how to write it for only one index i, but we have two : i (country) and j (year). We have a set of N observations of country year ij (or ith country in jth year). Basically, I could replace ij as a one index t and call it as a country year observation. Anyway, how to write this expression correctly for two indices i and j? Or shall we put two product signs instead? The expression is similar to this: Large Mathematical Sign of Product as a function of (Xij), where the low subscript of the Product is ij=1 and an upper subscript is ij=N. Thanks, Julia _ Search that pays you back! Introducing Live Search cashback. rchpaysyouback [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Constructing groupedData objects in nlme - a little problem
HI Toby, I think that the problem is that you have not specified using Rail and travel in the model statement, but rather are still using x1 and x2. It also does not realize that you want x1 to be a factor. Try x1=factor(c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6)) x2=c(55,53,54,26,37,32,78,91,85,92,100,96,49,51,50,80,85,83) eg1=data.frame(x1,x2); colnames(eg1)=c(Rail,travel); eg1gd=groupedData(travel~1|Rail,data=eg1) print(eg1gd) x11(); print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) femodel=lm(travel~Rail-1,data=eg1gd) summary(femodel) Cheers, Hank On Jun 4, 2008, at 10:01 AM, Toby Marthews wrote: Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): library(nlme) x2=Rail$travel;x1=Rail$Rail;eg1=data.frame(x1,x2);eg1gd=Rail print(eg1gd) x11();print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x12 x15 x11 x16 x13 x14 31.7 50.0 54.0 82.7 84.7 96.0 ...which works fine. This uses a built-in groupedData object called Rail that is part of the nlme library. I am trying to 'recreate' this groupedData object. Here's what I've done: x1=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6); x2=c(55,53,54,26,37,32,78,91,85,92,100,96,49,51,50,80,85,83) eg1=data.frame(x1,x2); colnames(eg1)=c(Rail,travel); eg1gd=groupedData(travel~1|Rail,data=eg1) print(eg1gd) x11(); print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x1 16.49817 ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Can anyone help? I've looked at the ?groupedData man page, but it has no solution to this. Thanks very much for any advice, Toby Pinheiro JC Bates DM (2000). Mixed-Effects Models in S and S-PLUS (1st ed.). Springer, New York. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to automatically create objects with names from a string list?
Mark, Others have given answers to the question that you asked, in the spirit of fortune(108) I am going to answer some of the questions that you should have asked: Q1: Should I ever do this? Short answer: No Less short answer: probably not Longer answer: You should only do this once you fully understand why you should never do this. Q2: Why should I not do this? A: There are many reasons, the most important is probably that there are better ways to accomplish what you want to do. Another important reason is doing this tends to lead to bugs that are very difficult to find and debug, these types of constucts lead to accidentally overwriting variables, using a different variable than you intend, using loops where other tools are better, etc. Q3: What is a better method to accomplish this? A: This depends on what all you want to do with these new variables, but for most cases using a list (or sometimes creating a new environment) will accomplish what you want much better. For example: tmp - c('foo','bar','baz') mylist - as.list(1:3) names(mylist) - tmp mylist $foo [1] 1 $bar [1] 2 $baz [1] 3 # or mylist - list() for(i in seq(along=tmp)){ + mylist[[ tmp[i] ]] - i + } mylist $foo [1] 1 $bar [1] 2 $baz [1] 3 # access a specific value mylist$bar [1] 2 # do something to all of them sapply( mylist, function(x) x+5 ) foo bar baz 6 7 8 # use more directly with( mylist, plot(1:10, 1:10, col=bar, pch=baz) ) # compute new variables based on them mylist - within(mylist, foobar - foo + bar + baz) mylist $foo [1] 1 $bar [1] 2 $baz [1] 3 $foobar [1] 6 # save everything save(mylist, file='myfile') # remove everything in one shot rm(mylist) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mark Farnell Sent: Tuesday, June 03, 2008 11:16 PM To: R-help@r-project.org Subject: [R] how to automatically create objects with names from a string list? Suppose I have a string of objects names: name - c(foo, bar, baz) and I would like to use a for loop to automatically create three objects called foo, bar and baz accordingly. Then how can this be done (so that in the workspace, foo = 1, bar = 2 and baz=3) for (i in name) { . } Thanks! Mark __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Constructing groupedData objects in nlme - a little problem
Toby Marthews Toby.Marthews at lsce.ipsl.fr writes: Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): ... ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Hank is right. On the other hand your well-defined query points to a problem using groupedData. I do a lot of my work with nlme and love it, but I admit that I only started to understand it after I totally stopped using groupedData. Which makes reading Pinheiro/Bates sometimes difficult, because many examples give the impression that these must be done with groupedData. Everything can be done by explicitly saying what should be analyzed in lme and friends, there is no need to rely on groupedData. Note that in lme4 that partially re-designs nlme, there is no such thing as groupedData. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Constructing groupedData objects in nlme - a little problem
Hi Dieter, I never really used groupedData objects at all. I can imagine that if you become even more immersed in nlme and lattice, groupedData could reduce your typing, and sometimes simplify your life, but it was not a hurdle I chose willingly. Hank On Jun 4, 2008, at 1:15 PM, Dieter Menne wrote: Toby Marthews Toby.Marthews at lsce.ipsl.fr writes: Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): ... ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Hank is right. On the other hand your well-defined query points to a problem using groupedData. I do a lot of my work with nlme and love it, but I admit that I only started to understand it after I totally stopped using groupedData. Which makes reading Pinheiro/Bates sometimes difficult, because many examples give the impression that these must be done with groupedData. Everything can be done by explicitly saying what should be analyzed in lme and friends, there is no need to rely on groupedData. Note that in lme4 that partially re-designs nlme, there is no such thing as groupedData. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] estimate phase shift between two signals
Hi, Are there any functions in R that could be used to estimate the phase-shift between two semi-sinusoidal vectors? Here is what I have tried so far, using the spectrum() function -- possibly incorrectly: # generate some fake data, normalized to unit circle x - jitter(seq(-2*pi, 2*pi, by=0.1), amount=pi/8) # functions defining two out-of-phase phenomena f1 - function(x) jitter(sin(x), amount=0.25) f2 - function(x, a) jitter(sin(x + a), amount=0.25) # compute y-values # we are setting the phase shift arbitrarily s - pi/1.5632198 y1 - f1(x) y2 - f2(x, s) # plot: plot(x, y1, type='p', col='red', cex=0.5) lines(lowess(x, y1, f=0.25), col='red') points(x, y2, col='blue', cex=0.5) lines(lowess(x, y2, f=0.25), col='blue') # generate time series object comb.ts - ts(matrix(c(y1, y2), ncol=2)) # multivariate spectral decomposition spec - spectrum(comb.ts, detrend=FALSE) # but how to interpret the phase estimate? mean(spec$phase) the mean 'phase' as returned from spectrum() does not seem to match the value used to generate the data... Am I mis-interpreting the use or output from spectrum() here? If so, is there a general procedure for estimating a phase-shift between two noisy signals? Would I first have to fit a smooth function in order to solve this analytically? Thanks in advance, -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] estimate phase shift between two signals
On Wednesday 04 June 2008, Dylan Beaudette wrote: Hi, Are there any functions in R that could be used to estimate the phase-shift between two semi-sinusoidal vectors? Here is what I have tried so far, using the spectrum() function -- possibly incorrectly: # generate some fake data, normalized to unit circle x - jitter(seq(-2*pi, 2*pi, by=0.1), amount=pi/8) # functions defining two out-of-phase phenomena f1 - function(x) jitter(sin(x), amount=0.25) f2 - function(x, a) jitter(sin(x + a), amount=0.25) # compute y-values # we are setting the phase shift arbitrarily s - pi/1.5632198 y1 - f1(x) y2 - f2(x, s) # plot: plot(x, y1, type='p', col='red', cex=0.5) lines(lowess(x, y1, f=0.25), col='red') points(x, y2, col='blue', cex=0.5) lines(lowess(x, y2, f=0.25), col='blue') # generate time series object comb.ts - ts(matrix(c(y1, y2), ncol=2)) # multivariate spectral decomposition spec - spectrum(comb.ts, detrend=FALSE) # but how to interpret the phase estimate? mean(spec$phase) the mean 'phase' as returned from spectrum() does not seem to match the value used to generate the data... Am I mis-interpreting the use or output from spectrum() here? If so, is there a general procedure for estimating a phase-shift between two noisy signals? Would I first have to fit a smooth function in order to solve this analytically? Thanks in advance, I should have thought about this a little bit more. Here is a brute-force method that may suffice for now, using nls() fit to sin(x + a). # generate some fake data, normalized to unit circle x - jitter(seq(-2*pi, 2*pi, by=0.1), amount=pi/8) # functions defining two out-of-phase phenomena f2 - function(x, a) jitter(sin(x + a), amount=0.25) # compute y-values # we are setting the phase shift arbitrarily ps1 - 1.5632198 ps2 - 0.25 y1 - f2(x, ps1) y2 - f2(x, ps2) # plot: plot(x, y1, type='p', col='red', cex=0.5) lines(lowess(x, y1, f=0.25), col='red') points(x, y2, col='blue', cex=0.5) lines(lowess(x, y2, f=0.25), col='blue') # generate time series object comb.ts - ts(matrix(c(y1, y2), ncol=2)) # multivariate spectral decomposition spec - spectrum(comb.ts, detrend=FALSE) # but how to interpret the phase estimate? mean(spec$phase) # fit a simple sine function to each signal fit1 - nls(y1 ~ sin(x + a), start=list(a=0)) fit2 - nls(y2 ~ sin(x + a), start=list(a=0)) # can we determine phase-shift by looking at zero-crossings? # where function == 0 / changes sign x.clean - seq(-2*pi, 2*pi, by=0.01) y1.clean - predict(fit1, data.frame(x=x.clean)) y2.clean - predict(fit2, data.frame(x=x.clean)) plot(x.clean, y1.clean, type='l', col='red') lines(x.clean, y2.clean, type='l', col='blue') points(x, y1, col='red', cex=0.5) points(x, y2, col='blue', cex=0.5) abline(h=0, lty=2) #compute zero-crossings y1.zero.idx - which(abs(diff(sign(y1.clean))) == 2) y2.zero.idx - which(abs(diff(sign(y2.clean))) == 2) points(x.clean[y1.zero.idx], y1.clean[y1.zero.idx], pch=16, col='red') points(x.clean[y2.zero.idx], y2.clean[y2.zero.idx], pch=16, col='blue') # how close are they? # estimated mean(x.clean[y2.zero.idx] - x.clean[y1.zero.idx]) [1] 1.3625 # original phase shift (ps1 - ps2) [1] 1.313220 the results appear to be good enough. Any thoughts on this approach, or ideas on a more elegant / proper implementation? Cheers, -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] estimate phase shift between two signals
Hi, Are there any functions in R that could be used to estimate the phase-shift between two semi-sinusoidal vectors? Here is what I have tried so far, using the spectrum() function -- possibly incorrectly: # generate some fake data, normalized to unit circle x - jitter(seq(-2*pi, 2*pi, by=0.1), amount=pi/8) # functions defining two out-of-phase phenomena f1 - function(x) jitter(sin(x), amount=0.25) f2 - function(x, a) jitter(sin(x + a), amount=0.25) # compute y-values # we are setting the phase shift arbitrarily s - pi/1.5632198 y1 - f1(x) y2 - f2(x, s) # plot: plot(x, y1, type='p', col='red', cex=0.5) lines(lowess(x, y1, f=0.25), col='red') points(x, y2, col='blue', cex=0.5) lines(lowess(x, y2, f=0.25), col='blue') # generate time series object comb.ts - ts(matrix(c(y1, y2), ncol=2)) # multivariate spectral decomposition spec - spectrum(comb.ts, detrend=FALSE) # but how to interpret the phase estimate? mean(spec$phase) the mean 'phase' as returned from spectrum() does not seem to match the value used to generate the data... Am I mis-interpreting the use or output from spectrum() here? If so, is there a general procedure for estimating a phase-shift between two noisy signals? Would I first have to fit a smooth function in order to solve this analytically? Thanks in advance, -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating a simple Radar/Spider Plot from Statgraphics
I'm new to R - and trying to create a plot similiar to the spider plot at http://www.statgraphics.com/eda.htm#radar . I can't figure out several things... most of which I would think would be straightforward How can I change the lines for each series plotted instead of creating a filled area? How can I get the labels for each of the radial axes at the outside of the plot instead of on a small circle in the middle? Is there an easy way to get a legend like the sample plot? Here's my attempt so far, using the USJudgeRating dataset... I'm sure that there's something simple that I'm missing stars(USJudgeRatings[1:2,1:9],locations = 0:1, scale=FALSE, draw.segments=FALSE, col.segments=1:5,col.stars=0,key.loc=0:1, main=Radar/Spider Plot\nSee http://www.statgraphics.com/eda.htm#radar,full=TRUE) What I really want to do is plot a dataset like this one: Year Below Basic Proficient Advanced 2005 10 25 30 35 2006 8 21 41 30 2007 15 24 48 14 2008 14 19 42 25 and get a graphic with 4 superimposed stars of different colors superimposed showing the shape of the distribution for each year. The data is percentsges of students scoring in each category, summing to 100. There are actually scores for Literacy and Math, so I might display 8 radii instead of the 4 above. And the dataset/graph would be repeated for comparing various subpopulations. Any pointers would be welcomed! Thanks! Albert Crosby Springdale Public Schools Springdale, Arkansas [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] possible bug in flexclust
Hi - Writing to see if someone can suggest whether a problem warrants a bug report. It concerns the use of stepFlexclust in the flexclust package. The problem concerns the size of clusters returned. Versions: R-2.7.0 on Windows XP; RODBC_1.2-3 code snippet: r8 - stepFlexclust(df,8,nrep=100,FUN=kcca, family=kccaFamily(kmedians)) summary(r8) ## returns cluster sizes of 51, 115, 218, 73, 118, 140, 311, and 118 trev - data.frame([EMAIL PROTECTED]) sqlSave(ch, trev, rownames=unitid) in MySQL: select r8cluster, count(*) from trev group by 1 order by 1 ## returns cluster sizes of 51, 116, 217, 73, 117, 140, 312, 118 problem: 4 of the 8 clusters differ in sizes. They're close but I'd think they should be exact. So ... bug or not a bug? It'd be nice if I was just doing something wrong. Thanks. Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Lattice + Word: Changing .wmf files to .pdf files
My apriori apologies if this is felt to be the wrong list for this issue - although it starts with R, it's a combination of programs that creates the problem. Currently we are using windows metafile format for in-text tables for reports created in Word. However, we've discovered some artifactual lines being created in our final output once the Word document is changed to PDF. The process is as follows: # Simplest example code that contains all the sample features that create the problem library(lattice) test - expand.grid(type = paste('Type', 1:4), success = c('Yes','No')) test$result - exp(rnorm(nrow(test))) win.metafile('u:\\test.wmf') dotplot( success ~ result | type, data = test, panel = function(...) { panel.xyplot(...) panel.abline(v = 0, lty = 2) }, xlim = c(-10, 10) ) dev.off() This is then imported into Word 2008 (running on XP Pro 2002 with service pack 2) using the import picture tool. The resulting file is then saved as a PDF from Word. Although the .wmf file (and R console output if sent to there) look exactly as you'd expect, there are a series of diagonal lines running from the bottom of the panel.abline created index line to the upper bound of each panel. I confess to being somewhat confused - if windows metafile formats and PDF are both vector graphic formats, I'm not sure where this extra line has come from. I suspect it may be an artifact from Word's PDF creating routine, but have no concrete proof of this. If any one can shed enlightenment (or suggest an alternative approach that preserves decent fidelity - we've struggled with postscript files in the past, but this may be our opportunity to try them out again), it would be much appreciated. sessionInfo() R version 2.7.0 (2008-04-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-6 loaded via a namespace (and not attached): [1] grid_2.7.0 Jim Price. Cardiome Pharma Corp. -- View this message in context: http://www.nabble.com/Lattice-%2B-Word%3A-Changing-.wmf-files-to-.pdf-files-tp17651766p17651766.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dotchart
I am trying to plot the following data using dotchart intersect.data-structure(list(X = structure(c(1L, 3L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 2L, 4L, 5L, 6L, 7L), .Label = c(1-100, 1001-1100, 101-200, 1101-1200, 1201-1300, 1301-1400, 1401-1500, 201-300, 301-400, 401-500, 501-600, 601-700, 701-800, 801-900, 901-1000), class = factor), svmT.mcmT = c(10L, 9L, 5L, 7L, 10L, 6L, 7L, 6L, 7L, 7L, 7L, 7L, 10L, 9L, 8L), svmT.svmCell = c(4L, 5L, 8L, 6L, 3L, 4L, 7L, 10L, 6L, 5L, 6L, 9L, 10L, 8L, 6L), svmT.mcmCell = c(12L, 11L, 4L, 8L, 7L, 11L, 5L, 9L, 5L, 7L, 7L, 6L, 6L, 8L, 5L), mcmT.svmCell = c(1L, 6L, 7L, 7L, 7L, 6L, 5L, 9L, 14L, 4L, 2L, 6L, 3L, 7L, 4L), mcmT.mcmCell = c(6L, 7L, 12L, 9L, 13L, 7L, 11L, 4L, 8L, 11L, 11L, 12L, 4L, 15L, 16L ), svmCell.mcmCell = c(5L, 9L, 7L, 7L, 8L, 6L, 3L, 9L, 4L, 13L, 9L, 10L, 5L, 7L, 7L)), .Names = c(X, svmT.mcmT, svmT.svmCell, svmT.mcmCell, mcmT.svmCell, mcmT.mcmCell, svmCell.mcmCell ), class = data.frame, row.names = c(NA, -15L)) dotchart(intersect.data) It gives me an error saying x must be numeric. I can edit it manually looking at the VADeaths example but is there an easy way to handle this? Thanks ../Murli __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merge two data sets
since they are not in data1 , I do not want them to be in the merge result. Moshe Olshansky-2 wrote: Where do you want to place ID's which are in data2 but NOT in data1? --- On Wed, 4/6/08, kayj [EMAIL PROTECTED] wrote: From: kayj [EMAIL PROTECTED] Subject: [R] merge two data sets To: r-help@r-project.org Received: Wednesday, 4 June, 2008, 9:45 AM I would like to merge “data1 “that contains 100 unique ID’s with another data set “data 2” with 150 ID’s and the age of those individuals ( the ID in data1 is a subset of the ID in data 2) I would like to merge these data1 with data2 and have the result of the merge to have the ID ordered as in data1. Can this be done in R? -- View this message in context: http://www.nabble.com/merge-two-data-sets-tp17636278p17636278.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/merge-two-data-sets-tp17636278p17652782.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging two data sets with no column header
Thanks a lot for your help, I appreciate it. David Winsemius wrote: Thanks for your reply. In your last step If I create a duplicate ( two similar records ) # create a duplicate vv[8,1] - 7 vv[8,2]-'g' and then I merge vv with vv2 ,both duplicates are merged. Is there a way to tell R to merge only the unique records. -- I don't think merge will do what you are asking. Suspect you would need to do it either before the merge or after. I tried using the Extract operator on a merged dataset, but only succeeded in omitting the duplicated items, not both instances. -- David Winsemius -- View this message in context: http://www.nabble.com/merging-two-data-sets-with-no-column-header-tp17613296p17652963.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [Rd] An issue happens Embed R and redirt png file
Wrong list, so re-directing to r-help. Consider r-sig-debian for Debian questions too, but subscribe or else your posts bounce. On 4 June 2008 at 07:18, Rongrong wrote: | | I am a new R user and I have a question of embedding R to generate png | On Debian, I installed R by source code. | | Now I want to embed R in an application which name is MyApp, and run | the following syntax: | png(filename=/tmp/Rplot%03d.png) | example(rect) | dev.off() | | Unfortunately I get the following error message: | | Error in X11(paste(png::, filename, sep = ), width, height, pointsize, | : | unable to start device PNG | Calls: png | In addition: Warning message: | In png(filename = /tmp/test%03d.png) : | unable to open connection to X11 display '' See the R FAQ. | But I could run above syntax from R, and the result is correct, I can get | two png files from /tmp/ folder. | | I try to respectively run same syntax(the syntax is: | capabilities()[[png]]) | under two modes, the result is different: | In R the result is TRUE, but when MyApp embed R the result is FALSE Because in case you have an x11 display, and in the other your don't. No display, no x11. | Then I used bitmap(file=/tmp/test) when embed R in MyApp, but get another | error message: | | Error in bitmap(file = /tmp/test) : sorry, 'gs' cannot be found Fix that via $ sudo apt-get install ghostscript | Besides, I have installed xvfb. What I need do? Almost there. Wrap your call to MyApp in svfb-run, ie do $ xvfb-run MyApp [other parameters] and you get the virtual x11 device that png needs. R 2.7.0 should also alleviate the need for an x11 device due to its new cairo-based device code. While you didn't tell as which R version you are running, I suspect it is not the one the current one. Dirk -- Three out of two people have difficulties with fractions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dotchart
Thanks! I put the labels as follows dotchart(as.matrix(intersect.data[-1]), labels=intersect.data[,1], cex=0.8) Murli From: Henrique Dallazuanna [EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 1:49 PM To: Nair, Murlidharan T Cc: r-help@r-project.org Subject: Re: [R] dotchart Is because your first column and the object is a data.frame: dotchart(as.matrix(intersect.data[-1])) On Wed, Jun 4, 2008 at 3:42 PM, Nair, Murlidharan T [EMAIL PROTECTED]mailto:[EMAIL PROTECTED] wrote: I am trying to plot the following data using dotchart intersect.data-structure(list(X = structure(c(1L, 3L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 2L, 4L, 5L, 6L, 7L), .Label = c(1-100, 1001-1100, 101-200, 1101-1200, 1201-1300, 1301-1400, 1401-1500, 201-300, 301-400, 401-500, 501-600, 601-700, 701-800, 801-900, 901-1000), class = factor), svmT.mcmT = c(10L, 9L, 5L, 7L, 10L, 6L, 7L, 6L, 7L, 7L, 7L, 7L, 10L, 9L, 8L), svmT.svmCell = c(4L, 5L, 8L, 6L, 3L, 4L, 7L, 10L, 6L, 5L, 6L, 9L, 10L, 8L, 6L), svmT.mcmCell = c(12L, 11L, 4L, 8L, 7L, 11L, 5L, 9L, 5L, 7L, 7L, 6L, 6L, 8L, 5L), mcmT.svmCell = c(1L, 6L, 7L, 7L, 7L, 6L, 5L, 9L, 14L, 4L, 2L, 6L, 3L, 7L, 4L), mcmT.mcmCell = c(6L, 7L, 12L, 9L, 13L, 7L, 11L, 4L, 8L, 11L, 11L, 12L, 4L, 15L, 16L ), svmCell.mcmCell = c(5L, 9L, 7L, 7L, 8L, 6L, 3L, 9L, 4L, 13L, 9L, 10L, 5L, 7L, 7L)), .Names = c(X, svmT.mcmT, svmT.svmCell, svmT.mcmCell, mcmT.svmCell, mcmT.mcmCell, svmCell.mcmCell ), class = data.frame, row.names = c(NA, -15L)) dotchart(intersect.data) It gives me an error saying x must be numeric. I can edit it manually looking at the VADeaths example but is there an easy way to handle this? Thanks ../Murli __ R-help@r-project.orgmailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ggplot questions
Hello, A few questions about the following examples: 1. Why do the two plotting versions not produce the same result? 2. Is the 'scale_x_continuous' (or *_y_* or *_*_discrete) geom the best way to setup grids (as in visual guide-lines) in polar (or for that matter, any) coordinate system? 3. Why do these commands appear to generate 3 plot pages each? 4. Perhaps more questions to follow ;-) ### the data test - structure(list(oplt = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), rplt = 1:10, az = c(57L, 94L, 96L, 152L, 182L, 185L, 227L, 264L, 332L, 354L), dist = c(4.09, 2.8, 7.08, 7.09, 3.28, 7.85, 6.12, 1.97, 7.68, 7.9)), .Names = c(oplt, rplt, az, dist ), row.names = c(NA, 10L), class = data.frame) labs - structure(list(oplt = c(0, 0, 0, 0, 0), rplt = structure(c(3L, 1L, 4L, 5L, 2L), .Label = c(E, N, o, S, W), class = factor), az = c(0, 90, 180, 270, 360), dist = c(0, 16, 16, 16, 16)), .Names = c(oplt, rplt, az, dist), row.names = c(NA, -5L), class = data.frame) ### plot version 1, setup plot structure first, add 'data' points later ggplot() + coord_polar() + layer( data = labs, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360)) + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) ### plot version 2, try the same all in one step ggplot() + coord_polar() + layer( data = test, mapping = aes(x = az, y = dist, label = rplt), geom = text) + scale_x_continuous(breaks=c(90, 180, 270, 360), labels=c('90', '180', '270', '360')) ### the scenario I am generating graphics to show the physical layout of a forestry research experiment. There are 54 'cut blocks' (64x64m, 0.4ha) each containing 1 circular 'overstory plot' (16m radius, 0.08ha). Each 'overstory plot' (oplt) contains 10 circular 'regeneration plots' (rplt) (0.56m radius, 1m^2 or 1.13m radius, 4m^2), these are the label data points plotted below, later to have the 1m^2 or 4m^2 rplt outline added. Later, each individual tree will be plotted across each oplt in the views below and each rplt in expanded views. All locations (rplt centers, tree positions) are recorded as azimuth and distance from their respective plot centers, hence my inclination to use polar coordinates. Thanx, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ontario.ca/ofri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to solve a non-linear system of equations using R
Jorge, You can use the package BB to try and solve this problem. I have re-written your functions a little bit. # -- # Constants # -- l=1 m=0.4795 s=0.4795 # -- # Functions to estimate f_i-k_i # -- myfn - function(d){ d1 - d[1] d2 - d[2] d3 - d[3] d4 - d[4] res - rep(NA, 4) res[1] - 2*d1+2*sqrt(2)*d1*d2+2*sqrt(3)*d2*d3+4*d3*d4-l*m*(1+d1^2+d2^2+d3^2+d4^2) res[2] - 2*sqrt(2)*d2+2*d1^2+2*sqrt(6)*d1*d3+4*d2^2+4*sqrt(3)*d2*d4+6*d3^2+8*d4^2-l*( m^2+m^3*s^(-1))*(1+d1^2+d2^2+d3^2+d4^2) res[3] - 6*d1+12*sqrt(2)*d1*d2+18*sqrt(3)*d2*d3+48*d3*d4+2*sqrt(6)*d3+4*sqrt(6)*d1*d4 -l*(m^3+3*m^4*s^(-1)+3*m^6*s^(-2))*(1+d1^2+d2^2+d3^2+d4^2) res[4] - 12*sqrt(2)*d2+12*d1^2+36*d2^2+72*d3^2+120*d4^2+20*sqrt(6)*d1*d3+56*sqrt(3)*d 2*d4+4*sqrt(6)*d4-l*((m^4+6*m^6*s^(-1)+15*m^6*s^(-2)+15*m^7*s^(-3))-3*l^(2)* (m^2+m^3*s^(-1))^2)*(1+d1^2+d2^2+d3^2+d4^2) res } myfn.opt - function(d){ # re-writing myfn to be used for minimization d1 - d[1] d2 - d[2] d3 - d[3] d4 - d[4] res - rep(NA, 4) res[1] - 2*d1+2*sqrt(2)*d1*d2+2*sqrt(3)*d2*d3+4*d3*d4-l*m*(1+d1^2+d2^2+d3^2+d4^2) res[2] - 2*sqrt(2)*d2+2*d1^2+2*sqrt(6)*d1*d3+4*d2^2+4*sqrt(3)*d2*d4+6*d3^2+8*d4^2-l*( m^2+m^3*s^(-1))*(1+d1^2+d2^2+d3^2+d4^2) res[3] - 6*d1+12*sqrt(2)*d1*d2+18*sqrt(3)*d2*d3+48*d3*d4+2*sqrt(6)*d3+4*sqrt(6)*d1*d4 -l*(m^3+3*m^4*s^(-1)+3*m^6*s^(-2))*(1+d1^2+d2^2+d3^2+d4^2) res[4] - 12*sqrt(2)*d2+12*d1^2+36*d2^2+72*d3^2+120*d4^2+20*sqrt(6)*d1*d3+56*sqrt(3)*d 2*d4+4*sqrt(6)*d4-l*((m^4+6*m^6*s^(-1)+15*m^6*s^(-2)+15*m^7*s^(-3))-3*l^(2)* (m^2+m^3*s^(-1))^2)*(1+d1^2+d2^2+d3^2+d4^2) sum(res^2) } library(BB) p0 - runif(4, -1,0) ans1 - dfsane(par=p0, fn=myfn) ans2 - spg(par=p0, fn=myfn.opt) ans1 ans2 Note that the above does not produce a redual of zero, so the system can't be solved exactly. I tried a large number of random starting values without improving upon the solution provided by spg. So, you may want to check your system for its correctness. Hope this helps, Ravi. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jorge Ivan Velez Sent: Tuesday, June 03, 2008 5:09 PM To: R mailing list Subject: [R] How to solve a non-linear system of equations using R Dear R-list members, I've had a hard time trying to solve a non-linear system (nls) of equations which structure for the equation i, i=1,...,4, is as follows: f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0(1) In the expression above, both f_i and k_i are known functions and l, m and s are known constants. I would like to estimate the vector d=(d_1,d_2,d_3,d_4) which is solution of (1). Functions in R to estimate f_i-k_i are at the end of this message. Any help/suggestions/comments would be greatly appreciated. Thanks in advance, Jorge # -- # Constants # -- l=1 m=0.4795 s=0.4795 # -- # Functions to estimate f_i-k_i # -- f1=function(d){ d1=d[1] d2=d[2] d3=d[3] d4=d[4] res=2*d1+2*sqrt(2)*d1*d2+2*sqrt(3)*d2*d3+4*d3*d4-l*m*(1+d1^2+d2^2+d3^2+d4^2) res } f2=function(d){ d1=d[1] d2=d[2] d3=d[3] d4=d[4] res=2*sqrt(2)*d2+2*d1^2+2*sqrt(6)*d1*d3+4*d2^2+4*sqrt(3)*d2*d4+6*d3^2+8*d4^2 -l*(m^2+m^3*s^(-1))*(1+d1^2+d2^2+d3^2+d4^2) res } f3=function(d){ d1=d[1] d2=d[2] d3=d[3] d4=d[4] res=6*d1+12*sqrt(2)*d1*d2+18*sqrt(3)*d2*d3+48*d3*d4+2*sqrt(6)*d3+4*sqrt(6)*d 1*d4-l*(m^3+3*m^4*s^(-1)+3*m^6*s^(-2))*(1+d1^2+d2^2+d3^2+d4^2) res } f4=function(d){ d1=d[1] d2=d[2] d3=d[3] d4=d[4] res=12*sqrt(2)*d2+12*d1^2+36*d2^2+72*d3^2+120*d4^2+20*sqrt(6)*d1*d3+56*sqrt( 3)*d2*d4+4*sqrt(6)*d4-l*((m^4+6*m^6*s^(-1)+15*m^6*s^(-2)+15*m^7*s^(-3))-3*l^ (2)*(m^2+m^3*s^(-1))^2)*(1+d1^2+d2^2+d3^2+d4^2) res } [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] converting a table to a dataframe or a matrix
can someone show me how to convert a table to a data.frame or a matrix ? I tried below and as.data.frame rearranges the columns similarly to a melt from reshape and as.matrix didn't change it. I actually would prefer to change it to a dataframe but if someone can show me how to convert it to a matrix, then as.data.frame will work on that. I was thinking about just changing the class to matrix since table looks very similar to a matrix but I wasn't sure if that would cause side injuries. thanks. temp - structure(c(0.345901639344262, 0.360117302052786, 0.354304635761589, 0.354319180087848, 0.365524402907580, 0.359455958549223, 0.340284360189573, 0.369763205828780, 0.304918032786885, 0.304985337243402, 0.310596026490066, 0.287457296242069, 0.285565939771547, 0.264248704663212, 0.297630331753555, 0.231329690346084, 0.349180327868852, 0.334897360703812, 0.335099337748344, 0.358223523670083, 0.348909657320872, 0.376295336787565, 0.362085308056872, 0.398907103825137), class = table, .Dim = c(8L, 3L), .Dimnames = structure(list( c((-1,-0.75], (-0.75,-0.5], (-0.5,-0.25], (-0.25,0], (0,0.25], (0.25,0.5], (0.5,0.75], (0.75,1]), c(0, 1, 2)), .Names = c(, ))) print(temp) tempa - as.data.frame(temp) tempb - as.matrix(temp) print(str(tempa)) print(str(tempb)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting a table to a dataframe or a matrix
Hi Mark, Try this: as.data.frame.matrix(temp) or as.data.frame(unclass(temp)) On Wed, Jun 4, 2008 at 4:20 PM, [EMAIL PROTECTED] wrote: can someone show me how to convert a table to a data.frame or a matrix ? I tried below and as.data.frame rearranges the columns similarly to a melt from reshape and as.matrix didn't change it. I actually would prefer to change it to a dataframe but if someone can show me how to convert it to a matrix, then as.data.frame will work on that. I was thinking about just changing the class to matrix since table looks very similar to a matrix but I wasn't sure if that would cause side injuries. thanks. temp - structure(c(0.345901639344262, 0.360117302052786, 0.354304635761589, 0.354319180087848, 0.365524402907580, 0.359455958549223, 0.340284360189573, 0.369763205828780, 0.304918032786885, 0.304985337243402, 0.310596026490066, 0.287457296242069, 0.285565939771547, 0.264248704663212, 0.297630331753555, 0.231329690346084, 0.349180327868852, 0.334897360703812, 0.335099337748344, 0.358223523670083, 0.348909657320872, 0.376295336787565, 0.362085308056872, 0.398907103825137), class = table, .Dim = c(8L, 3L), .Dimnames = structure(list( c((-1,-0.75], (-0.75,-0.5], (-0.5,-0.25], (-0.25,0], (0,0.25], (0.25,0.5], (0.5,0.75], (0.75,1]), c(0, 1, 2)), .Names = c(, ))) print(temp) tempa - as.data.frame(temp) tempb - as.matrix(temp) print(str(tempa)) print(str(tempb)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting a table to a dataframe or a matrix
Either of these will do it: head(temp, Inf) class(temp) - matrix On Wed, Jun 4, 2008 at 3:20 PM, [EMAIL PROTECTED] wrote: can someone show me how to convert a table to a data.frame or a matrix ? I tried below and as.data.frame rearranges the columns similarly to a melt from reshape and as.matrix didn't change it. I actually would prefer to change it to a dataframe but if someone can show me how to convert it to a matrix, then as.data.frame will work on that. I was thinking about just changing the class to matrix since table looks very similar to a matrix but I wasn't sure if that would cause side injuries. thanks. temp - structure(c(0.345901639344262, 0.360117302052786, 0.354304635761589, 0.354319180087848, 0.365524402907580, 0.359455958549223, 0.340284360189573, 0.369763205828780, 0.304918032786885, 0.304985337243402, 0.310596026490066, 0.287457296242069, 0.285565939771547, 0.264248704663212, 0.297630331753555, 0.231329690346084, 0.349180327868852, 0.334897360703812, 0.335099337748344, 0.358223523670083, 0.348909657320872, 0.376295336787565, 0.362085308056872, 0.398907103825137), class = table, .Dim = c(8L, 3L), .Dimnames = structure(list( c((-1,-0.75], (-0.75,-0.5], (-0.5,-0.25], (-0.25,0], (0,0.25], (0.25,0.5], (0.5,0.75], (0.75,1]), c(0, 1, 2)), .Names = c(, ))) print(temp) tempa - as.data.frame(temp) tempb - as.matrix(temp) print(str(tempa)) print(str(tempb)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Reading selected lines in an .html file
Dear friend, In an R program running permanently on a server I would like to read hour by hour the temperature in *C and the humidity from a site like this (actually, from many of such sites): http://www.wunderground.com/global/stations/16239.html How can I read the content of the site and select the info I need? Ciao Vittorio __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice book
Il Thursday 01 May 2008 01:07:13 Charilaos Skiadas ha scritto: Actually it's been out for a couple of weeks now at least. I just finished my first reading of it, and I must say it was spectacular. Congratulations Deepayan, the book gave me exactly the kind of lattice knowledge I needed, and then some. The graphics are really impressive and good illustrations of what lattice can do, and I found the writing very clear, with the complexity increasing at just the right speed. I definitely recommend it to anyone who wants to learn how to use lattice, at any level they desire. Ok, I guess I better stop now. Happy reading Mark! Haris Skiadas Department of Mathematics and Computer Science Hanover College I'm half way through the reading of the book and share your view: extremely well done and self-explaining-. The many examples are all very clear. Congratulations Deepayan. Ciao from Rome Vittorio __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Packfor library-problem downloading
Jubilo, I believe we have the same problem. For a hacky solution, please see my post http://groups.google.com/group/r-help-archive/browse_thread/thread/bbd4ef5857dc99ef - Stu On May 22, 11:05 am, Jubilo [EMAIL PROTECTED] wrote: Hello, I'm a new user to R, and I was trying to install packfor in my R console and I always run into an error. I tried to search, in in the forum, someone that already might have made the same question, but all I could find was a general information how to install libraries in R. Pass through all that procedure (PackageData-Package Installer-Local Source Package[because my library was in a folder in my computer]), I have a message that is DONE, but then I do the command library(packfor) and I get an error message: --- --WARNING:ignoringenvironment value ofR_HOME * Installing *binary* package 'packfor' ... * DONE (packfor) library(packfor) packfor: R Package for Forward Selection (Canoco Manual p.49) version 0.0-8Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Library/Frameworks/R.framework/Versions/2.7/Resources/library/packfor/lib s/i386/packfor.so': dlopen(/Library/Frameworks/R.framework/Versions/2.7/Resources/library/packf or/libs/i386/packfor.so, 6): Library not loaded: /usr/local/lib/libgfortran.2.dylib Referenced from: /Library/Frameworks/R.framework/Versions/2.7/Resources/library/packfor/libs /i386/packfor.so Reason: image not found Error in library(packfor) : .First.lib failed for 'packfor' --- --- I have a mac where I installed R2.7.0, and I want to use the packfor_0.0-8_for_R2.7.tar.gz. I already uninstalled R twice and installed it again, I already used another packfor file, from another person... I ran out of ideas so I would like a little bit of help. My R also presents an other error when it starts: - During startup -Warningmessages: 1: Setting LC_CTYPE failed, using C 2: Setting LC_COLLATE failed, using C 3: Setting LC_TIME failed, using C 4: Setting LC_MESSAGES failed, using CWARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work. Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system preferences accordingly. -- I don't know if this is important to solve the issue, but anyway I already done other analysis (which means that I used other libraries) and I didn't have any problem. Besides the section 9 from the Help talks about version previous the one that I have (1.0.1, 2.0 and 2.1). Thanks in advance for any idea that you might have , Ju -- View this message in context:http://www.nabble.com/Packfor-library-problem-downloading-tp17406291p... Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem pasting into Illustrator CS2
To Whom it May Concern: I have been using R version 2.6.2 for awhile now, installed on a PowerMac G5 running OS 10.4.11 I typically get Quartz graphics output from R into Adobe Illustrator CS2 simply by copying and pasting. Upon upgrading to R version 2.7.0, I now receive an error from Illustrator when trying to paste R generated graphics from the Quartz window into Illustrator. I do not have the exact text of the error message, but the general message is that the object I am trying to paste is too large, and won't fit on the Illustrator drawing board. There are no options for reducing the size. I re-installed R 2.6.2 and I am now able to copy and paste my R graphics into Illustrator as before. Any ideas as to why this is happening or what I should do if I want to be able to copy and paste into Illustrator using the current version of R? Cheers, Courtney L. Meier - Mr. Courtney L. Meier, PhD Dept. Ecology Evolutionary Biology, UCB 334 University of Colorado Boulder Boulder, CO 80309-0334 Tel: 303-492-2557 Fax: 303-492-8699 http://ucsu.colorado.edu/~meiercl/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] array of arrays
Dear R users, I want to calculate the bias and variance of an estimator for several values of two parameters a and b. For example : b1 b2 a1 bias bias variance variance a2 bias bias variance variance Can one do array of arrays ? I have tried and it did not work. Actually I would like to get this array for several values of the number of observations. That would be an array of arrays of arrays :-) Maybe there is a better way to do that... Is there also a way to export arrays to Latex ? Thank you very much [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Superscript/Subscript in main title
I have been trying to figure out how to get superscript/subscript in the main title for a plot. I have tried various approaches and suggestions but none of them work. I am trying to get the following as the main title of my plot: Emission of CO2 with time (but note that 2 is subscript.) I have tried plot(main=Emission of Cexpression(O[2]) with time) and I get error message. I have also tried plot(main=Emission of Cquote(O[2]) with time) I have also tried plot(main) mtext(Emission of Cexpression(O[2]) with time) I keep getting errors. I have searched the archives but none of the threads seem to touch upon this. I would appreciate any suggestion. Regards, Tariq [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Superscript/Subscript in main title
Try this: plot(1:10, main = expression(Emission~of~CO[2]~with~time)) On Wed, Jun 4, 2008 at 5:31 PM, Tariq Perwez [EMAIL PROTECTED] wrote: I have been trying to figure out how to get superscript/subscript in the main title for a plot. I have tried various approaches and suggestions but none of them work. I am trying to get the following as the main title of my plot: Emission of CO2 with time (but note that 2 is subscript.) I have tried plot(main=Emission of Cexpression(O[2]) with time) and I get error message. I have also tried plot(main=Emission of Cquote(O[2]) with time) I have also tried plot(main) mtext(Emission of Cexpression(O[2]) with time) I keep getting errors. I have searched the archives but none of the threads seem to touch upon this. I would appreciate any suggestion. Regards, Tariq [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Superscript/Subscript in main title
Hi Tariq, try: plot(x,y,main=expression(Emission of CO[2]* with time)) Cheers, Christoph Wednesday, June 4, 2008, 10:31:08 PM, you wrote: I have been trying to figure out how to get superscript/subscript in the main title for a plot. I have tried various approaches and suggestions but none of them work. I am trying to get the following as the main title of my plot: Emission of CO2 with time (but note that 2 is subscript.) I have tried plot(main=Emission of Cexpression(O[2]) with time) and I get error message. I have also tried plot(main=Emission of Cquote(O[2]) with time) I have also tried plot(main) mtext(Emission of Cexpression(O[2]) with time) I keep getting errors. I have searched the archives but none of the threads seem to touch upon this. I would appreciate any suggestion. Regards, Tariq [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging two data sets with no column header
Perhaps something about like this: merge(vv[-c(which(duplicated(vv))-1, which(duplicated(vv))),], vv2, by=1) On Wed, Jun 4, 2008 at 3:08 PM, kayj [EMAIL PROTECTED] wrote: Thanks a lot for your help, I appreciate it. David Winsemius wrote: Thanks for your reply. In your last step If I create a duplicate ( two similar records ) # create a duplicate vv[8,1] - 7 vv[8,2]-'g' and then I merge vv with vv2 ,both duplicates are merged. Is there a way to tell R to merge only the unique records. -- I don't think merge will do what you are asking. Suspect you would need to do it either before the merge or after. I tried using the Extract operator on a merged dataset, but only succeeded in omitting the duplicated items, not both instances. -- David Winsemius -- View this message in context: http://www.nabble.com/merging-two-data-sets-with-no-column-header-tp17613296p17652963.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] linear model with the repeated data type~
here is the data: y-c(5,2,3,7,9,0,1,4,5) id-c(1,1,6,6,7,8,15,15,19) t-c(50,56,50,56,50,50,50,60,50) table1-data.frame(y,id,t)//longitudinal data the above is only part of data. what I want to do is to use the linear model for each id ,then get the estimate value,like: fit1-lm(y~t,data=table1,subset=(id==1)) but ,you can see the variable id is quite irregular,they are not arranaged in order and many number missing,if I write a loop by using for,it will give me a lot NA, and for sure ,I dont want to type id=## for about 500 times so,how to get all the esimates for each id,and exclude the NA,then record those estimate in one table? great thanks ~~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] linear model with the repeated data type~
Try this: f - function(x)any(is.na(coefficients(x))) models - by(table1[c(y, t)], table1$id, FUN=lm) models[!unlist(lapply(models, f))] On Wed, Jun 4, 2008 at 6:20 PM, Manli Yan [EMAIL PROTECTED] wrote: here is the data: y-c(5,2,3,7,9,0,1,4,5) id-c(1,1,6,6,7,8,15,15,19) t-c(50,56,50,56,50,50,50,60,50) table1-data.frame(y,id,t)//longitudinal data the above is only part of data. what I want to do is to use the linear model for each id ,then get the estimate value,like: fit1-lm(y~t,data=table1,subset=(id==1)) but ,you can see the variable id is quite irregular,they are not arranaged in order and many number missing,if I write a loop by using for,it will give me a lot NA, and for sure ,I dont want to type id=## for about 500 times so,how to get all the esimates for each id,and exclude the NA,then record those estimate in one table? great thanks ~~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem pasting into Illustrator CS2
Dear Courtney, Are you exporting the graphs as postscript files? This is the usual way I do it when moving graphs between R and Illustrator CS2. I´m afraid I do not have a Mac, but I suppose CS2 runs similarly on both systems. Best wishes Christoph To Whom it May Concern: I have been using R version 2.6.2 for awhile now, installed on a PowerMac G5 running OS 10.4.11 I typically get Quartz graphics output from R into Adobe Illustrator CS2 simply by copying and pasting. Upon upgrading to R version 2.7.0, I now receive an error from Illustrator when trying to paste R generated graphics from the Quartz window into Illustrator. I do not have the exact text of the error message, but the general message is that the object I am trying to paste is too large, and won't fit on the Illustrator drawing board. There are no options for reducing the size. I re-installed R 2.6.2 and I am now able to copy and paste my R graphics into Illustrator as before. Any ideas as to why this is happening or what I should do if I want to be able to copy and paste into Illustrator using the current version of R? Cheers, Courtney L. Meier - Mr. Courtney L. Meier, PhD Dept. Ecology Evolutionary Biology, UCB 334 University of Colorado Boulder Boulder, CO 80309-0334 Tel: 303-492-2557 Fax: 303-492-8699 http://ucsu.colorado.edu/~meiercl/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using as.POSIXlt on multiple columns or multiple objects
If I want to convert one column to date and time format that R can understand and manipulate then I would do this initial$Started-as.POSIXlt(initial$Started) But what happens if I have many such columns and I do not want to have my code be stuffed with 10 similar lines (one for each variable aka column aka vector aka object) I thought I could be clear and use the list function and do this. list(initial$Started ,initial$Finished,full.ques$started.ful ,full.ques$finished.ful) - lapply(list(initial$Started ,initial$Finished,full.ques$started.ful ,full.ques$finished.ful),as.POSIXlt) But I got: Error in list(initial$Started, initial$Finished, full.ques$started.ful, : could not find function list- I am clearly missing some basic R issue here. What am I missing? -- Farrel Buchinsky __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] surprising predicting capabilities
On 03-Jun-08 16:16:13, chaogai wrote: Hi, I noticed the following fortune in R 2.7 and 2.6.2: fortune('Spreads') If anything, there should be a Law: Thou Shalt Not Even Think Of Producing A Graph That Looks Like Anything From A Spreadsheet. -- Ted Harding (in a discussion about producing graphics) R-help (August 2008) Just wondering, what function and library gave this detailed prediction? Cheers I suspect that .../site-library/fortunes/fortunes/fortunes.csv was exported from Excel ... Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 04-Jun-08 Time: 23:28:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] array of arrays
Is it possible to have one array for bias and one for variance? such as.. biasAr= b1 b2 a1 biasbias a2 biasbias and varAr= b1 b2 a1 var var a2 var var then you can combine the two in a data frame? thanks y Michael Prince wrote: Dear R users, I want to calculate the bias and variance of an estimator for several values of two parameters a and b. For example : b1 b2 a1 bias bias variance variance a2 bias bias variance variance Can one do array of arrays ? I have tried and it did not work. Actually I would like to get this array for several values of the number of observations. That would be an array of arrays of arrays :-) Maybe there is a better way to do that... Is there also a way to export arrays to Latex ? Thank you very much [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/array-of-arrays-tp17655733p17658264.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] create many variables at one time~
I need to create 100 variable ,whose name is id.1,id.2id.100 then I need to let a vector say id-c(id.1,id.2id.100) any easy way to do this? thanks a lot~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create many variables at one time~
Try this: for(i in 1:100)assign(sprintf(id.%d, i), value = sample(1)) id - ls(patt = id.[0-9]) On Wed, Jun 4, 2008 at 7:52 PM, Manli Yan [EMAIL PROTECTED] wrote: I need to create 100 variable ,whose name is id.1,id.2id.100 then I need to let a vector say id-c(id.1,id.2id.100) any easy way to do this? thanks a lot~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] do multiple anova tests
Hi I think my question might be answered before but i can't find the correct one. Here is the question. I have a data frame from a csv file which contains about 30 variables. lit is like this. (the values are just number I arbitrary created here) id group calorie weight height bmi co2 SBP 1 a 200 160 10030 50 90 2 a 100 100130 35 40 70 3 b60190 110 . . . 4 b30. .. .. 5 c . .. . ... . .. etc I want to use for loop or any other methods to write one anova function to run anova tests for each numeric variable above, so I can get about 30 anova results. Can someone help me on this Thank you -- View this message in context: http://www.nabble.com/do-multiple-anova-tests-tp17657995p17657995.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] trouble installing Rmpi on 64-bit Ubuntu 8.04 with openmpi
The problem here is that the compiler cannot find the include files for mpi. Notice that the first checks that fail are: checking mpi.h usability... no checking mpi.h presence... no checking for mpi.h... no One solution is to create a file named ~/.R/Makevars with the following line: PKG_CPPFLAGS = -I/opt/openmpi/include ... where /opt/openmpi/include/ contains the necessary mpi.h include file. Then, try to recompile. Hope this helps, - Stu On May 6, 12:52 pm, Mark Kimpel [EMAIL PROTECTED] wrote: Subject pretty much says it all. I am running 64-bit Ubuntu 8.04, i.e. Hardy Heron, have openmpi installed, and get the following error message with attempted install of Rmpi. sessionInfo() follows. Mark checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking mpi.h usability... no checking mpi.h presence... no checking for mpi.h... no Try to find libmpi.so or libmpich.a checking for main in -lmpi... yes checking for openpty in -lutil... yes checking for main in -lpthread... yes configure: creating ./config.status config.status: creating src/Makevars ** libs gcc -std=gnu99 -I/home/mkimpel/R_HOME/R-patched/R-build/lib64/R/include -DPACKAGE_NAME=\\ -DPACKAGE_TARNAME=\\ -DPACKAGE_VERSION=\\ -DPACKAGE_STRING=\\ -DPACKAGE_BUGREPORT=\\ -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DUNKNOWN -fPIC -I/usr/local/include -fpic -g -O2 -c conversion.c -o conversion.o In file included from conversion.c:18: Rmpi.h:1:17: error: mpi.h: No such file or directory In file included from conversion.c:18: Rmpi.h:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mpitype' make: *** [conversion.o] Error 1 chmod: cannot access `/home/mkimpel/R_HOME/site-library-2.7.0/Rmpi/libs/*': No such file or directory ERROR: compilation failed for package 'Rmpi' ** Removing '/home/mkimpel/R_HOME/site-library-2.7.0/Rmpi' The downloaded packages are in /tmp/RtmppcK0FI/downloaded_packages Warning message: sessionInfo() R version 2.7.0 Patched (2008-05-04 r45620) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF- 8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_A DDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] graph_1.18.0 loaded via a namespace (and not attached): [1] cluster_1.11.10 tcltk_2.7.0 tools_2.7.0 -- Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, Mobile VoiceMail (317) 663-0513 Home (no voice mail please) ** [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ignoring environment value of R_HOME error when installing packages
This bug has been resolved, after our administrator updated the path of R_HOME in our scripts. I believe that the cause of trouble was the parallel nature of the installation, as mentioned in the following thread: http://groups.google.com/group/r-help-archive/browse_thread/thread/632175125a7c4 16f/6a5220b73d3ac682?lnk=gstq=R_HOME# regards - S. On Jun 4, 12:35 am, tub78 [EMAIL PROTECTED] wrote: I am troubled by what appears to be a glitch in the current distribution, or in its installation on our system. I've traced it, and found a work- around. Is this normal? Is there a cleaner solution? The problem: During a package installation, the warning message WARNING: ignoring environment value of R_HOME from line 31 of R_HOME/bin/R is accidentally spliced into the CLINK_CPPFLAGS variable at line 606 of R_HOME/bin/ INSTALL. This prevents the compilation C files. Please note that I have not set the R_HOME environment variable; it is undefined in my shell. - Here are lines 29-32 from R_HOME/bin/R: if test -n ${R_HOME} \ test ${R_HOME} != ${R_HOME_DIR}; then echo WARNING: ignoring environment value of R_HOME fi - Here is line 606 of R_HOME/bin/INSTALL: CLINK_CPPFLAGS=`echo tools:::.find_cinclude_paths(file='DESCRIPTION') | \ ${R_EXE} --vanilla --slave` The work-around: First some background. The command sequence R CMD INSTALL sets in motion a sequence of scripts that collectively manage the installation process. R R_HOME/bin/R calls Rcmd script on line 148 CMD R_HOME/lib/R/bin/Rcmd calls INSTALL script on line 45 INSTALL R_HOME/lib/R/bin/INSTALL encounters the error on line 606 Now, if you are the owner of you installation, then you can probably just edit the INSTALL file directly. Otherwise, if you specify the full path of an executable in place of the word INSTALL on the command line, the Rcmd script will detect this and call your script instead of the normal INSTALL script (see Rcmd line 37). e.g. R CMD path.to.alternate.install.script ... One can just copy the INSTALL script, changing line 606 to CLINK_CPPFLAGS = and hope for the best. If the package you are compiling specifies its own C include files, then you will have to modify the variable accordingly, or else use the ~/.R/Makevars mechanism. But, the question remains, is there an nicer solution? Thanks, - Stu __ [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ARS function
I am having problem calling ars function in ARS package. My parameter domain does not have upper bound or lower bound, so I did not givevalues to parameters ubx,lbx. But it keeps telling me the starting values I provided didn't have value to the left or to the right of the mode of the target density. I plotted the density function values for the absicssas vs the abscissae, the curve has a mode in the middle. Has anybody have this problem before?Thanks! rhead -- View this message in context: http://www.nabble.com/ARS-function-tp17658712p17658712.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] merging 3 data sets at once
Hi All, I am looking into merging 3 data sets I know how to do that by merging data1 with data2 and then merging the result with data 3. I was wondering if it can be done all at once so I tried, M-merge(data1,data2,data3, by=”ID”) It does not work! Any ideas? -- View this message in context: http://www.nabble.com/merging-3-data-sets-at-once-tp17658873p17658873.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Survey: Commercial R companies
Hello Everyone, In preparation for an upcoming talk, I would like to assemble a list of companies that provide consulting, services, products, or training for R. I am already aware of a number of such companies including (in alphabetical order): BlueReference http://inference.us Insightful http://www.insightful.com Metrum Institute http://www.metruminstitute.org Metrum Research Group, LLC http://www.metrumrg.com Random Technologies LLC http://random-technologies-llc.com REvolution Computing Inc http://revolution-computing.com Statistics.com http://www.statistics.com XLSolutions Corporation http://www.xlsolutions-corp.com If you are aware of a company that provides consulting, services, products, or training for R, please complete the form below and forward it directly to me at [EMAIL PROTECTED] by Wednesday June 11. I will collate all of the responses and post a complete list back to R-help. Thanks, -Greg Gregory R. Warnes, Ph.D. Associate Professor Center for Biodefence Immune Modeling and Department of Biostatistics and Computational Biology University of Rochester === Cut Here, Send to [EMAIL PROTECTED] == Company Name: Address (including country): Web Site: Email Address: Phone Number: Type of Products and Services: [ ] Commercial versions of R Product Name: [ ] General Training (e.g. Introduction to R, Programming in R, etc.) Courses Taught: [ ] Domain-specific Training (e.g. R for PK/PD Modeling, Bayesian Modeling using R, etc.) Domain: [ ] Add-on packages (Off the shelf, not custom) Package Names: [ ] Software/package development (custom) [ ] Parallel Computing Tools [ ] Statistical Consulting utilizing R Area of expertise: [ ] GUI environments Product Name: [ ] Qualification/Validation Services [ ] Other: [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] quite complicated case(the repeated data arranage~)
Hi everyone: I have been struggling with this repeated data type for whole afternoon,I sent two emails to server for help,many people kindly responded , hereby thank you so much,but since I dont want to write to much in email,so I divide the problem in parts,so far this seem did not work out very well,so this is my whole problem~ first I have example of data here: treatment-c(low,high,high,high,high,low,low,low,low) age-c(50,60,50,50,60,50,60,50,60) y-c(20,40,30,11,23,24,56,65,60) id-c(1,1,3,4,4,6,8,9,9) table1-cbind(treatment,id,age,y) *the actual data are way more than this*,the id is from 1~500,and not in regular ,some number missing~ all I want to do is put the cases to variable according the id for example when id =1 we have treatment1 age1 y low 5020 high 6040 this will generate a new matrix for this example I will have 6 new matrix,according to id. it is reasonable to do this in loop for,but the I met some problem: 1:how to automatically generate the new title such as treatment1 and age1 until treatment 500,age500 2:as you see,id is not strictly from 1 to 500,some time it jump from 15 to19,skip 16,17,18, if I write a loop,it will give me lot NA,certainly I need a way to avoid this and one more,say I have 100 vectors like x1x100,x1-c(1,3),x2-x(2,2),...x100-(number,number) I want to combine all this 100 vectors in one new vector say Xall which is Xall-cbind(x1,x2,...x100) //this need to type in 100 variables,take alot time so Xall will be x1x2 x3 .x100 1 2number 3 2number is here any easy way to do this,instead of inputting them one by one? *and Great Thanks for your time~~* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls() newbie convergence problem
I'm sure this must be a nls() newbie question, but I'm stumped. I'm trying to do the example from Draper and Yang (1997). They give this snippet of S-Plus code: Specify the weight function: weight - function(y,x1,x2,b0,b1,b2) { pred - b0+b1*x1 + b2*x2 parms - abs(b1*b2)^(1/3) (y-pred)/parms } Fit the model gmfit -nls(~weight(y,x1,x2,b0,b1,b2), observe,list(starting value)) in converting this to R, I left the weight function alone and replaced the nls() with gmfit - nls(~weight(y,x1,x2,b0,b1,b2),data=dydata,trace=TRUE,start=list(b0=1,b1=1,b2=1)) where dydata is the appropriate data.frame. nls() quickly (6 iterations) finds the exact values from Draper Yang for b0, b1, and b2 but despite reporting a discrepancy of only 3.760596e-29 by the 7th iteration, it merrily goes on to 50 iterations and thinks it never converged. how do I tell nls() that I'm actually quite happy with 3.760596e-29 and it need not work further? thanks for any suggestions. gary mcclelland (aka bernie) univ of colorado [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using barchart in lattice package and conditioning
I have the data structure below and I'm attempting to send it into barchart using the R code below it. I don't get an error but I don't get any output either. Deepyan's new Lattice book is amazing and there are some examples sort of similar to what i'm doing but I couldn't see a way of using the formula interface to condition on what I wanted to condition on so I decided to use split instead. I'm not sure if that's where my problem lies but if anyone has experience in using the barchart function in the lattice package and could take a look at what I'm trying to do, it would really be appreciated. thanks. p.s: my data set is already tallied by proportion so i don't need to use prop.table and i also have other additional columns in my data set. these two issues are complicating matters for me also. i'm a lattice newbie. stocks.all-structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = AVT.NYSE, class = factor), buckets = structure(c(8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L), .Label = c([0,0.25, [-0.25,0], [0.25,0.50], [-0.5,-0.25], [0.5,0.75], [-0.75,-0.50], [0.75,1.0], [-1.0,-0.75]), class = factor), neutral = c(0.345901639344262, 0.360117302052786, 0.354304635761589, 0.354319180087848, 0.365524402907580, 0.359455958549223, 0.340284360189573, 0.369763205828780, 0.265100671140940, 0.250599520383693, 0.264124293785311, 0.257874015748031, 0.2520833, 0.260869565217391, 0.263257575757576, 0.341911764705882, 0.197761194029851, 0.192307692307692, 0.137724550898204, 0.184647302904564, 0.176991150442478, 0.173796791443850, 0.217573221757322, 0.181818181818182, 0.151162790697674, 0.163865546218487, 0.167346938775510, 0.159638554216867, 0.169934640522876, 0.133047210300429, 0.122093023255814, 0.223529411764706), negative = c(0.304918032786885, 0.304985337243402, 0.310596026490066, 0.287457296242069, 0.285565939771547, 0.264248704663212, 0.297630331753555, 0.231329690346084, 0.345637583892617, 0.34652278177458, 0.353107344632768, 0.319881889763780, 0.3416667, 0.329923273657289, 0.348484848484849, 0.301470588235294, 0.365671641791045, 0.384615384615385, 0.38622754491018, 0.369294605809129, 0.371681415929204, 0.382352941176471, 0.338912133891213, 0.340909090909091, 0.406976744186047, 0.399159663865546, 0.355102040816327, 0.355421686746988, 0.398692810457516, 0.450643776824034, 0.337209302325581, 0.282352941176471), positive = c(0.349180327868852, 0.334897360703812, 0.335099337748344, 0.358223523670083, 0.348909657320872, 0.376295336787565, 0.362085308056872, 0.398907103825137, 0.389261744966443, 0.402877697841727, 0.382768361581921, 0.422244094488189, 0.40625, 0.40920716112532, 0.388257575757576, 0.356617647058824, 0.436567164179104, 0.423076923076923, 0.476047904191617, 0.446058091286307, 0.451327433628319, 0.443850267379679, 0.443514644351464, 0.477272727272727, 0.441860465116279, 0.436974789915966, 0.477551020408163, 0.484939759036145, 0.431372549019608, 0.416309012875536, 0.540697674418605, 0.494117647058824), wt = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c(5.0, 10.0, 20.0, 30.0), class = factor)), .Names = c(group, buckets, neutral, negative, positive, wt), row.names = c(NA, 32L), class = data.frame) # R CODE FOR BARCHART # temp-split(stocks.all,list(stocks.all$group,stocks.all$wt)) print(temp) lapply(temp, function(.df){ print(barchart(.df, stack = TRUE, auto.key = list(columns = 3))) }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] warning message for lmer model with poisson family
Hello, I'm trying to run an lmer model with family poisson but receive the following warning message: model-lmer(count~tem+dat+alt+year+tem:dat+tem:alt+tem:year+dat:alt+dat:year+alt:year+(1|id),family=poisson) Error in objective(.par, ...) : Leading minor of order 2 in downdated X'X is not positive definite I'm using the newest version of R and recently installed the following libraries: (lme4, matrix, lattice). I don't understand what the warning message means or know how to fix it, please help! My response variable is a count variable (n=551); 212 with value = 0, and the rest range between 1-3. -- View this message in context: http://www.nabble.com/warning-message-for-lmer-model-with-poisson-family-tp17659512p17659512.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging 3 data sets at once
I could suggest merge(merge(data1,data2), data3). However, one problem I notice is that is assigns age=12 and gender=M to everyone with id=1, and so on. How are we to know that person with id=1 in data1 is the same person with id=1 in data2 and data3? Bill Date: Wed, 4 Jun 2008 16:24:04 -0700 From: [EMAIL PROTECTED] To: r-help@r-project.org Subject: [R] merging 3 data sets at once Hi All, I am looking into merging 3 data sets I know how to do that by merging data1 with data2 and then merging the result with data 3. I was wondering if it can be done all at once so I tried, M-merge(data1,data2,data3, by=ID) It does not work! Any ideas?-- View this message in context: http://www.nabble.com/merging-3-data-sets-at-once-tp17658873p17658873.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Instantly invite friends from Facebook and other social networks to join yo https://www.invite2messenger.net/im/?source=TXT_EML_WLH_InviteFriends [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging 3 data sets at once
By the way, I used age and gender as examples. Plus, I've seen something very similar posted a while ago. If the problem I listed isn't an issue, then that code will work. Best, Bill From: [EMAIL PROTECTED]: [EMAIL PROTECTED]; [EMAIL PROTECTED]: RE: [R] merging 3 data sets at onceDate: Wed, 4 Jun 2008 20:50:34 -0400 I could suggest merge(merge(data1,data2), data3). However, one problem I notice is that is assigns age=12 and gender=M to everyone with id=1, and so on. How are we to know that person with id=1 in data1 is the same person with id=1 in data2 and data3? Bill Date: Wed, 4 Jun 2008 16:24:04 -0700 From: [EMAIL PROTECTED] To: r-help@r-project.org Subject: [R] merging 3 data sets at once Hi All, I am looking into merging 3 data sets I know how to do that by merging data1 with data2 and then merging the result with data 3. I was wondering if it can be done all at once so I tried, M-merge(data1,data2,data3, by=ID) It does not work! Any ideas?-- View this message in context: http://www.nabble.com/merging-3-data-sets-at-once-tp17658873p17658873.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Instantly invite friends from Facebook and other social networks to join you on Windows Live Messenger. Invite friends now! _ Now you can invite friends from Facebook and other groups to join you on Wi https://www.invite2messenger.net/im/?source=TXT_EML_WLH_AddNow_Now [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] nls() newbie convergence problem
dydata x1 x2 y 1 9 27 248 2 9 22 213 3 4 23 190 4 11 16 183 5 -6 25 144 6 11 14 169 7 -4 13 72 8 2 8 73 9 10 13 156 10 8 30 263 11 12 10 147 12 -7 5 -2 13 0 10 75 14 12 0 77 15 9 8 115 16 12 24 245 17 34 23 370 18 12 1 84 19 10 37 324 20 26 30 371 weight - function(y,x1,x2,b0,b1,b2) { pred - b0+b1*x1 + b2*x2 parms - abs(b1*b2)^(1/3) (y-pred)/parms } gmfit - nls(~weight(y,x1,x2,b0,b1,b2),data=dydata,trace=TRUE, start=list(b0=1,b1=1,b2=1), control=list(warnOnly=TRUE)) library(minpack.lm) weight2 - function(p, y,x1,x2) { pred - p[1]+p[2]*x1 + p[3]*x2 parms - abs(p[2]*p[3])^(1/3) (y-pred)/parms } gmfit2 - nls.lm(par = c(1,1,1), fn = weight2, y=dydata$y,x=dydata$x1,x2=dydata$x2, control=list(nprint=1)) dydata is from Norman R. Draper, Yonghong (Fred) Yang, Generalization of the geometric mean functional relationship, Computational Statistics Data AnalysisVolume 23, Issue 3, 9 January 1997, Pages 355-372; I don't think the attachment got through. nls uses an orthogonality convergence criterium. Bates talks about this in the post at https://stat.ethz.ch/pipermail/r-devel/2000-August/021059.html and it's also described in the book by Bates and Watts (Nonlinear regression analysis its applications). Apparently here the residuals are so small they are effectively 0, and this criteria does not work; there is a warning about using zero-residual data in the help page for nls. nls.lm from the package minpack.lm stops if any of a few different criteria are met; in this case it stops at the time you think is right. On Wed, 4 Jun 2008, Bernard Leemon wrote: I'm sure this must be a nls() newbie question, but I'm stumped. I'm trying to do the example from Draper and Yang (1997). They give this snippet of S-Plus code: Specify the weight function: weight - function(y,x1,x2,b0,b1,b2) { pred - b0+b1*x1 + b2*x2 parms - abs(b1*b2)^(1/3) (y-pred)/parms } Fit the model gmfit -nls(~weight(y,x1,x2,b0,b1,b2), observe,list(starting value)) in converting this to R, I left the weight function alone and replaced the nls() with gmfit - nls(~weight(y,x1,x2,b0,b1,b2),data=dydata,trace=TRUE,start=list(b0=1,b1=1,b2=1)) where dydata is the appropriate data.frame. nls() quickly (6 iterations) finds the exact values from Draper Yang for b0, b1, and b2 but despite reporting a discrepancy of only 3.760596e-29 by the 7th iteration, it merrily goes on to 50 iterations and thinks it never converged. how do I tell nls() that I'm actually quite happy with 3.760596e-29 and it need not work further? thanks for any suggestions. gary mcclelland (aka bernie) univ of colorado [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sorting the data~
id-c(1,1,1,1,3,3,3,7,7,7,7,11,11,11) how to sort this kind of data to id:(1,1,1,1,2,2,2,3,3,3,3,4,4,4.) thanks~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging 3 data sets at once
Not following this very carefully, but today I did something similar with Reduce(merge,list(d1,d2,d3)) ... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sorting the data~
Are these the ranks of the data? help.search(rank) Manli Yan wrote: id-c(1,1,1,1,3,3,3,7,7,7,7,11,11,11) how to sort this kind of data to id:(1,1,1,1,2,2,2,3,3,3,3,4,4,4.) thanks~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sorting the data~
no,the id is variable of a table,such as: treatment id age response low 1 50 20 low 1 60 30 high5 50 30 high5 60 40 ... I want to rearranage the table according the id (increasing),since id is not strictly from 1~n,it is in increasing order but sometime jump through many number like 1 1 5 5,I like them to be 1 1 2 2~ 2008/6/4 Erik Iverson [EMAIL PROTECTED]: Are these the ranks of the data? help.search(rank) Manli Yan wrote: id-c(1,1,1,1,3,3,3,7,7,7,7,11,11,11) how to sort this kind of data to id:(1,1,1,1,2,2,2,3,3,3,3,4,4,4.) thanks~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create many variables at one time~
Try also, id- paste('id.',1:100,sep=) HTH, Jorge On Wed, Jun 4, 2008 at 6:52 PM, Manli Yan [EMAIL PROTECTED] wrote: I need to create 100 variable ,whose name is id.1,id.2id.100 then I need to let a vector say id-c(id.1,id.2id.100) any easy way to do this? thanks a lot~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] wildcard symbol or character
Jorge Ivan Velez wrote: Dear John, Assuming that your information is in the list x, does substr(x,1,2) work for you? HTH, Jorge Jorge, i tried split(rtt, substr(rtt,1,3)) and that worked also. (i didn't think to nest it when you first suggested it.) i just have to clean up the levels thing. thanks!! now, i look into regex some... john __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create many variables at one time~
An easy and good way to make a bunch of variables is to store them in a list. For example: mylist - replicate(100, sample(1:100, 10), simplify=FALSE) id - paste('id.',1:100, sep='') names(mylist) - id sapply(mylist, median) id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9 id.10 id.11 23.0 66.0 58.0 42.5 66.5 42.0 52.0 41.0 64.0 55.0 73.5 id.12 id.13 id.14 id.15 id.16 id.17 id.18 id.19 id.20 id.21 id.22 57.0 64.0 62.0 45.0 32.5 44.5 54.5 70.5 57.0 72.5 41.0 id.23 id.24 id.25 id.26 id.27 id.28 id.29 id.30 id.31 id.32 id.33 43.0 44.5 48.5 71.0 68.5 33.5 44.5 62.5 58.5 40.0 47.0 id.34 id.35 id.36 id.37 id.38 id.39 id.40 id.41 id.42 id.43 id.44 45.5 33.5 62.0 69.0 60.5 22.0 69.0 36.0 43.0 64.5 42.5 id.45 id.46 id.47 id.48 id.49 id.50 id.51 id.52 id.53 id.54 id.55 46.0 49.5 47.5 44.5 66.5 65.0 61.0 43.5 39.0 50.0 49.0 id.56 id.57 id.58 id.59 id.60 id.61 id.62 id.63 id.64 id.65 id.66 56.0 31.0 45.5 37.0 68.0 39.5 69.5 47.0 66.0 56.5 55.5 id.67 id.68 id.69 id.70 id.71 id.72 id.73 id.74 id.75 id.76 id.77 42.0 30.5 49.5 32.0 59.5 33.5 38.0 51.0 74.0 39.5 42.0 id.78 id.79 id.80 id.81 id.82 id.83 id.84 id.85 id.86 id.87 id.88 35.0 55.5 51.0 31.5 44.0 41.5 32.5 60.5 58.5 41.5 39.5 id.89 id.90 id.91 id.92 id.93 id.94 id.95 id.96 id.97 id.98 id.99 46.0 51.0 60.0 51.5 43.5 65.5 42.5 38.0 43.0 46.0 53.5 id.100 41.0 Now what do you want to do with all of those variables? From: [EMAIL PROTECTED] [EMAIL PROTECTED] On Behalf Of Manli Yan [EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 4:52 PM To: r-help@r-project.org Subject: [R] create many variables at one time~ I need to create 100 variable ,whose name is id.1,id.2id.100 then I need to let a vector say id-c(id.1,id.2id.100) any easy way to do this? thanks a lot~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quite complicated case(the repeated data arranage~)
For the first question, what do you want to do with all the subsets? There are tools like split, by, lapply, lmList, etc. that make working with all the subsets easy. If you tell us what your final goal is, we may be able to help with a simple solution that does not need the intermediate tables, at least not explicitly. For the 2nd question try: tmp - paste('x',1:100, sep='') tmp2 - lapply(tmp, function(x) get(x) Xall - do.call('cbind', tmp2) From: [EMAIL PROTECTED] [EMAIL PROTECTED] On Behalf Of Manli Yan [EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 6:19 PM To: r-help@r-project.org Subject: [R] quite complicated case(the repeated data arranage~) Hi everyone: I have been struggling with this repeated data type for whole afternoon,I sent two emails to server for help,many people kindly responded , hereby thank you so much,but since I dont want to write to much in email,so I divide the problem in parts,so far this seem did not work out very well,so this is my whole problem~ first I have example of data here: treatment-c(low,high,high,high,high,low,low,low,low) age-c(50,60,50,50,60,50,60,50,60) y-c(20,40,30,11,23,24,56,65,60) id-c(1,1,3,4,4,6,8,9,9) table1-cbind(treatment,id,age,y) *the actual data are way more than this*,the id is from 1~500,and not in regular ,some number missing~ all I want to do is put the cases to variable according the id for example when id =1 we have treatment1 age1 y low 5020 high 6040 this will generate a new matrix for this example I will have 6 new matrix,according to id. it is reasonable to do this in loop for,but the I met some problem: 1:how to automatically generate the new title such as treatment1 and age1 until treatment 500,age500 2:as you see,id is not strictly from 1 to 500,some time it jump from 15 to19,skip 16,17,18, if I write a loop,it will give me lot NA,certainly I need a way to avoid this and one more,say I have 100 vectors like x1x100,x1-c(1,3),x2-x(2,2),...x100-(number,number) I want to combine all this 100 vectors in one new vector say Xall which is Xall-cbind(x1,x2,...x100) //this need to type in 100 variables,take alot time so Xall will be x1x2 x3 .x100 1 2number 3 2number is here any easy way to do this,instead of inputting them one by one? *and Great Thanks for your time~~* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using barchart in lattice package and conditioning
Hi Mark, I get output, after a while, and reams of it. Very likely not what you wanted. Can you describe what you are trying to see in barcharts for these data? It's not obvious to me from the code below. Best Steve McKinney -Original Message- From: [EMAIL PROTECTED] on behalf of [EMAIL PROTECTED] Sent: Wed 6/4/2008 5:26 PM To: r-help@r-project.org Subject: [R] using barchart in lattice package and conditioning I have the data structure below and I'm attempting to send it into barchart using the R code below it. I don't get an error but I don't get any output either. Deepyan's new Lattice book is amazing and there are some examples sort of similar to what i'm doing but I couldn't see a way of using the formula interface to condition on what I wanted to condition on so I decided to use split instead. I'm not sure if that's where my problem lies but if anyone has experience in using the barchart function in the lattice package and could take a look at what I'm trying to do, it would really be appreciated. thanks. p.s: my data set is already tallied by proportion so i don't need to use prop.table and i also have other additional columns in my data set. these two issues are complicating matters for me also. i'm a lattice newbie. stocks.all-structure(list(group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = AVT.NYSE, class = factor), buckets = structure(c(8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L, 8L, 6L, 4L, 2L, 1L, 3L, 5L, 7L), .Label = c([0,0.25, [-0.25,0], [0.25,0.50], [-0.5,-0.25], [0.5,0.75], [-0.75,-0.50], [0.75,1.0], [-1.0,-0.75]), class = factor), neutral = c(0.345901639344262, 0.360117302052786, 0.354304635761589, 0.354319180087848, 0.365524402907580, 0.359455958549223, 0.340284360189573, 0.369763205828780, 0.265100671140940, 0.250599520383693, 0.264124293785311, 0.257874015748031, 0.2520833, 0.260869565217391, 0.263257575757576, 0.341911764705882, 0.197761194029851, 0.192307692307692, 0.137724550898204, 0.184647302904564, 0.176991150442478, 0.173796791443850, 0.217573221757322, 0.181818181818182, 0.151162790697674, 0.163865546218487, 0.167346938775510, 0.159638554216867, 0.169934640522876, 0.133047210300429, 0.122093023255814, 0.223529411764706), negative = c(0.304918032786885, 0.304985337243402, 0.310596026490066, 0.287457296242069, 0.285565939771547, 0.264248704663212, 0.297630331753555, 0.231329690346084, 0.345637583892617, 0.34652278177458, 0.353107344632768, 0.319881889763780, 0.3416667, 0.329923273657289, 0.348484848484849, 0.301470588235294, 0.365671641791045, 0.384615384615385, 0.38622754491018, 0.369294605809129, 0.371681415929204, 0.382352941176471, 0.338912133891213, 0.340909090909091, 0.406976744186047, 0.399159663865546, 0.355102040816327, 0.355421686746988, 0.398692810457516, 0.450643776824034, 0.337209302325581, 0.282352941176471), positive = c(0.349180327868852, 0.334897360703812, 0.335099337748344, 0.358223523670083, 0.348909657320872, 0.376295336787565, 0.362085308056872, 0.398907103825137, 0.389261744966443, 0.402877697841727, 0.382768361581921, 0.422244094488189, 0.40625, 0.40920716112532, 0.388257575757576, 0.356617647058824, 0.436567164179104, 0.423076923076923, 0.476047904191617, 0.446058091286307, 0.451327433628319, 0.443850267379679, 0.443514644351464, 0.477272727272727, 0.441860465116279, 0.436974789915966, 0.477551020408163, 0.484939759036145, 0.431372549019608, 0.416309012875536, 0.540697674418605, 0.494117647058824), wt = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c(5.0, 10.0, 20.0, 30.0), class = factor)), .Names = c(group, buckets, neutral, negative, positive, wt), row.names = c(NA, 32L), class = data.frame) # R CODE FOR BARCHART # temp-split(stocks.all,list(stocks.all$group,stocks.all$wt)) print(temp) lapply(temp, function(.df){ print(barchart(.df, stack = TRUE, auto.key = list(columns = 3))) }) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] warning message for lmer model with poisson family
Looks like you have some independent variables in your model that correlate perfectly so your design matrix is not of full rank, probably because your independent variable data is not balanced. Does a simpler fit such as model-lmer(count~tem+(1|id),family=poisson) give you a result? You might need to build up your model from such a simple one, adding one new term at a time until you find the one that causes the issue. You probably do not have enough balanced data to allow fitting such a complex model. HTH Steve McKinney -Original Message- From: [EMAIL PROTECTED] on behalf of arams Sent: Wed 6/4/2008 5:18 PM To: r-help@r-project.org Subject: [R] warning message for lmer model with poisson family Hello, I'm trying to run an lmer model with family poisson but receive the following warning message: model-lmer(count~tem+dat+alt+year+tem:dat+tem:alt+tem:year+dat:alt+dat:year+alt:year+(1|id),family=poisson) Error in objective(.par, ...) : Leading minor of order 2 in downdated X'X is not positive definite I'm using the newest version of R and recently installed the following libraries: (lme4, matrix, lattice). I don't understand what the warning message means or know how to fix it, please help! My response variable is a count variable (n=551); 212 with value = 0, and the rest range between 1-3. -- View this message in context: http://www.nabble.com/warning-message-for-lmer-model-with-poisson-family-tp17659512p17659512.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sorting the data~
id-c(1,1,1,1,3,3,3,7,7,7,7,11,11,11,2,2,2,4,4,4,4,8,8,8) sort(id) [1] 1 1 1 1 2 2 2 3 3 3 4 4 4 4 7 7 7 7 8 8 8 11 11 11 Quoting Manli Yan [EMAIL PROTECTED]: no,the id is variable of a table,such as: treatment id age response low 1 50 20 low 1 60 30 high5 50 30 high5 60 40 ... I want to rearranage the table according the id (increasing),since id is not strictly from 1~n,it is in increasing order but sometime jump through many number like 1 1 5 5,I like them to be 1 1 2 2~ 2008/6/4 Erik Iverson [EMAIL PROTECTED]: Are these the ranks of the data? help.search(rank) Manli Yan wrote: id-c(1,1,1,1,3,3,3,7,7,7,7,11,11,11) how to sort this kind of data to id:(1,1,1,1,2,2,2,3,3,3,3,4,4,4.) thanks~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] linear model in the repeated data type~
hi:lot thanks,how to use list to extract,I type allFit$coefficents,it came to nothing, such as I need to extract the estimates,how to do it by using list 2008/6/3 Austin, Matt [EMAIL PROTECTED]: How about library(nlme) allFits - lmList(y ~ t|id, data=table1, pool=FALSE) or allFits - by(table1, table1$id, function(x) lm(y ~ t, data=x)) Both ways store the results as a list, so you can access individual results using list extraction. --Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Manli Yan Sent: Tuesday, June 03, 2008 9:07 PM To: r-help@r-project.org Subject: [R] linear model in the repeated data type~ here is the data: y-c(5,2,3,7,9,0,1,4,5) id-c(1,1,6,6,7,8,15,15,19) t-c(50,56,50,56,50,50,50,60,50) table1-data.frame(y,id,t)//longitudinal data what I want to do is to use the linear model for each id ,then get the estimate value,like: fit1-lm(y~t,data=table1,subset=(id==1)) but ,you can see the variable id is quite irregular,they are not arranaged in order and many number missing,if I write a loop by using for,it will give me a lot NA, and for sure ,I dont want to type id=## for about 500 times,any one know how to deal with it? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.