[R] errors with lme4
Dear R-users, i need help for this topic! I'm trying to determine if the reproductive success (0=fail, 1=success) of a species of bird is related to a list of covariates. These are the covariates: §elev: elevation of nest (meters) §seadist: distance from the sea (meters) §meanterranova: records of temperature §minpengS1: records of temperature §wchillpengS1: records of temperature §minpengS2: records of temperature §wchillpengS2: records of temperature §nnd: nearest neighbour distance §npd: nearest penguin distance §eggs: numbers of eggs §lay: laying date (julian calendar) §hatch: hatching date (julian calendar) I have some NAs in the data. I want to test the model with all the variable then i want to remove some, but the ideal model: GLM.1 -lmer(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 +(1|territory), family=binomial(logit), data=fledge) doesn't work because of these errors: 'Warning message: In mer_finalize(ans) : gr cannot be computed at initial par (65)'. matrix is not symmetric [1,2] If i delete one or more of the T records (i.e. minpengS2 +wchillpengS2) the model works...below and example: GLM.16 -lmer(fledgesucc ~ lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +(1|territory), family=binomial(logit), data=fledge) summary(GLM.16) Generalized linear mixed model fit by the Laplace approximation Formula: fledgesucc ~ lay + hatch + elev + seadist + nnd + npd + meanterranova + minpengS1 + (1 | territory) Data: fledge AIC BIC logLik deviance 174 204.2-77 154 Random effects: GroupsNameVariance Std.Dev. territory (Intercept) 0.54308 0.73694 Number of obs: 152, groups: territory, 96 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) 14.136846 14.510089 0.9740.330 lay -0.007642 0.267913 -0.0280.977 hatch -0.025947 0.267318 -0.0970.923 elev 0.007481 0.027765 0.2700.788 seadist -0.004277 0.004550 -0.9400.347 nnd -0.035535 0.026504 -1.3410.180 npd0.003788 0.005521 0.6860.493 meanterranova 1.242570 1.426158 0.8710.384 minpengS1 -0.399852 0.418722 -0.9550.340 Correlation of Fixed Effects: (Intr) layhatch elev seadst nndnpdmntrrn lay 0.411 hatch -0.515 -0.993 elev-0.015 0.141 -0.135 seadist -0.003 -0.023 0.019 -0.440 nnd -0.061 0.066 -0.059 -0.020 0.231 npd 0.033 -0.108 0.100 0.298 -0.498 -0.338 meanterranv 0.459 -0.118 0.075 -0.061 0.014 -0.048 0.130 minpengS1 -0.540 0.015 0.035 0.032 0.000 0.039 -0.086 -0.970 I try also with glmer() but the error are the same. I've attached an example of my dataset only 15 rows just to see the dataset. Let me know if you need more informations. I'm a new R user, so I apologize if the topic is already being addressed by some other user. Thanks in advance for your help and advices! regards -- Alessio Franceschi Phd student Dipartimento di Scienze Ambientali G. Sarfatti Università di Siena Via P.A. Mattioli, 8 - 53100 Siena (Italy) Cell. +393384431806 email: francesc...@unisi.it; alfrances...@alice.it id spedcat spedcodnest territory elevseadist meanterranova minpengS1 wchillpengS1minpengS2 wchillpengS2nnd npd eggslay hatch hatchsucc fledgesucc 1 A 14 1 104 5,8228,57 -3,31 -3,70 -14,03 -1,24 -11,47 32 31 1 0 0 2 A 14 17 154 36,00 79,49 -3,31 -3,70 -14,03 -1,24 -11,47 35 143 2 334 363 1 0 3 A 14 18 125 36,33 93,29 -3,31 -3,70 -14,03 -1,24 -11,47 27 59 2 338 366 1 0 4 A 14 19 126 38,31 95,52 -3,31 -3,70 -14,03 -1,24 -11,47 32 78 2 331 360 1 0 123 B 16 50 37 26,30 213,50 -4,53 -7,10 -26,23 -11,22 -27,40 7 54 1 331 360 1 0 124 B 16 51 33 24,81 252,01 -4,53 -7,10 -26,23 -11,22 -27,40 18 55 2 330 359 1 0 125 B 16 52 31 26,62 268,04 -4,53 -7,10 -26,23 -11,22 -27,40 23 83 2 332 360 1 0 126 B 16 53 29 28,27 293,42 -4,53 -7,10 -26,23 -11,22 -27,40 40 119 2 334 363 1 1 193 C 18 19 126 38,00 95,72 -5,23 -11,29 -21,56 -5,44 -15,42
Re: [R] Looping and paste
Hi: There are two good reasons why the loop solution is not efficient in this (and related) problem(s): (i) There is more code and less transparency; (ii) the vectorized solution is four times faster. Here are the two proposed functions: # Vectorized version m1 - function(v) paste(v, ' to ', v + 50, ' mN', sep = '') # Loop version: m2 - function(v) { out - rep(NA, length(v)) for(i in seq_along(v)) out[i] - paste(v[i], ' to ', v[i] + 50, ' mN', sep = '') out } BndY - seq(from = 18900, to = 19700, by = 50) identical(m1(BndY), m2(BndY)) [1] TRUE # Put them to the test: system.time(replicate(1, m1(BndY))) user system elapsed 0.670.000.67 system.time(replicate(1, m2(BndY))) user system elapsed 2.670.002.67 The vectorized version is four times faster and produces the same output as the loop version. Experiments with a longer test vector (501 elements) maintained the timing ratio. Dennis On Wed, Nov 23, 2011 at 7:00 PM, markm0705 markm0...@gmail.com wrote: Thank you On Thu, Nov 24, 2011 at 7:31 AM, B77S [via R] ml-node+s789695n4102066...@n4.nabble.com wrote: out - vector(list) Ylab - for(i in 1:length(BndY)) { out[i] - paste(BndY[i], to ,BndY[i],mN) } Ylab - do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.html To unsubscribe from Looping and paste, click herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4101892code=bWFya20wNzA1QGdtYWlsLmNvbXw0MTAxODkyfDExNDQyODMxMDM= . NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102553.html Sent from the R help mailing list archive at Nabble.com. [[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] AlgDesign - $D $A $Ge $Dea
See ?AlgDesign::optFederov and look for the 'Value' section, where these elements of the output list are defined. Dennis On Wed, Nov 23, 2011 at 7:15 PM, 蓁蓁 李 tszhenzh...@hotmail.com wrote: Hi, I am wondering how I should interpreate the output of optFederov() in AlgDesign. Specially I want to know what is $D, $A, $Ge and $Dea, which one I can use as an efficiency to say how good the optimal design is. I only know when a orthogonal design comes, $D = 1. I red the pdf document -- vignette(AlgDesign) [Just type: vignette(AlgDesign) in R, you will get this pdf document] On page 20 section 4.2.1.3, it says: the D and G efficiencies of the following ... are 98% and 89%. I tried the code as shown on page 20 a few times and output showed different designs but the figure of $D, $A, $Ge and $Dea are similar. I don't see $D is close to 0.98, but $Ge is 0.89. One of the output as below: dat = gen.factorial(3, 3, center = T, varNames = c(A, B, C)) desC = optFederov(~quad(A,B,C), dat, nT = 14, evaluateI = T, nR = 100) desC $D [1] 0.4630447 $A [1] 3.22 $I [1] 9.945833 $Ge [1] 0.893 $Dea [1] 0.887 $design A B C 1 -1 -1 -1 3 1 -1 -1 5 0 0 -1 7 -1 1 -1 9 1 1 -1 11 0 -1 0 13 -1 0 0 15 1 0 0 17 0 1 0 19 -1 -1 1 21 1 -1 1 23 0 0 1 25 -1 1 1 27 1 1 1 $rows [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 Thanks very much! J [[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] First read (was: Re: Looping and paste)
It's very seldom that I disagree with Bert, but here is one time. I don't think An Introduction to R is a suitable first read for people with little computational experience. Better (I modestly suggest) would be: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html which includes some other references. 'Hints' is imperfect and incomplete but it suffers slightly less from the curse of knowledge than a lot of other R documentation. Pat On 24/11/2011 00:15, Bert Gunter wrote: ... and you can of course do the assignment: Bndy- paste (BndY,to,50+seq_len(BndY), mN, sep = ) An Introduction to R tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunterbgun...@gene.com wrote: Don't do this! paste() is vectorized. paste (BndY,to,50+seq_len(BndY), mN, sep = ) Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77Sbps0...@auburn.edu wrote: out- vector(list) Ylab- for(i in 1:length(BndY)) { out[i]- paste(BndY[i], to ,BndY[i],mN) } Ylab- do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] what is wrong with this dataset?
I (and probably everyone who has looked at your email) have literally no clue what you are trying to do. Take a look at this first. And for your âquestionâ I assume you have tried to aggregate the data frame you have called dataset â what you have produced is a new data frame that has all of the combinations gender and position, it has then simply filled the category and salary with counts of how many female managers, female sales reps... and so on. If you are trying to show average category and salaries for each of the combinations use: dataset2-aggregate(dataset[,c(3:4)],by = dataset[,c(1:2), drop = F], mean) But, please actually enlighten us as to the nature of your problem. Rob -Original Message- From: Carl Witthoft Sent: Thursday, November 24, 2011 3:08 AM To: r-help@r-project.org Subject: Re: [R] what is wrong with this dataset? As the Kroger Data Munger Guru would say, What is the problem you are trying to solve? The datasets look just fine from a structural point of view. What do you want to do and what is wrong with the results you get? quote From: Kaiyin Zhong kindlychung_at_gmail.com Date: Thu, 24 Nov 2011 09:39:20 +0800 d = data.frame(gender=rep(c('f','m'), 5), pos=rep(c('worker', 'manager', 'speaker', 'sales', 'investor'), 2), lot1=rnorm(10), lot2=rnorm(10)) d gender pos lot1 lot2 1 f worker 1.1035316 0.8710510 2 m manager -0.4824027 -0.2595865 3 f speaker 0.8933589 -0.5966119 4 msales 0.4489920 0.4971199 5 f investor 0.9246900 -0.7531117 6 m worker 0.2777642 -0.3338369 7 f manager -1.0890828 0.7073686 8 m speaker -1.3045821 0.4373199 9 fsales 0.3092965 -2.6441382 10 m investor -0.5770073 -1.5200347 cast(melt(d)) Using gender, pos as id variables gender pos lot1 lot2 1 f investor 0.9246900 -0.7531117 2 f manager -1.0890828 0.7073686 3 fsales 0.3092965 -2.6441382 4 f speaker 0.8933589 -0.5966119 5 f worker 1.1035316 0.8710510 6 m investor -0.5770073 -1.5200347 7 m manager -0.4824027 -0.2595865 8 msales 0.4489920 0.4971199 9 m speaker -1.3045821 0.4373199 10 m worker 0.2777642 -0.3338369 dataset = read.csv('datalist.csv') dataset Gender Title Category Salary 1 M Manager3 27000 2 F Manager2 22500 3 M Sales Rep1 18000 4 M Sales Rep3 27000 5 F Manager3 27000 6 M Secretary4 31500 7 M Sales Rep2 22500 8 M Secretary2 22500 9 MWorker4 40500 10 M Manager4 37100 11 F Secretary2 22500 12 F Manager3 27000 13 MWorker2 2 14 M Manager4 32000 15 F Sales Rep2 22900 16 M Sales Rep3 27000 17 F Sales Rep2 22500 18 M Manager1 18000 19 M Secretary3 27000 20 F Sales Rep3 27000 21 M Secretary4 31500 22 MWorker2 22500 23 M Manager2 22500 24 MWorker4 40500 25 MWorker4 37100 26 F Secretary2 22500 27 F Manager3 27000 28 MWorker2 2 29 M Manager4 32000 30 F Sales Rep2 22900 cast(melt(dataset)) Using Gender, Title as id variables Aggregation requires fun.aggregate: length used as default Gender Title Category Salary 1 F Manager4 4 2 F Sales Rep4 4 3 F Secretary2 2 4 M Manager6 6 5 M Sales Rep4 4 6 M Secretary4 4 7 MWorker6 6 The content of datalist.xls is here: http://paste.pound-python.org/show/15098/ -- Sent from my Cray XK6 Pendeo-navem mei anguillae plena est. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Installing rJava from source on Mac
Hi Everybody I am trying to install the latest version of JavaGD from source but get the following error. trying URL 'http://cran.za.r-project.org/src/contrib/JavaGD_0.5-4.tar.gz' Content type 'application/x-gzip' length 102242 bytes (99 Kb) opened URL == downloaded 99 Kb * installing *source* package JavaGD ... /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: no acceptable C compiler found in $PATH See `config.log' for more details. ERROR: configuration failed for package JavaGD line 143, 144 and 220 reads as follows: 143: LIBR=`eval $query VAR=LIBR` 144: STATIC_LIBR=`eval $query VAR=STATIC_LIBR` 220: eval ${query} VAR=${var} I do have gcc installed: (from terminal) $ which gcc /Developer/usr/bin/gcc Can anyone guide me on how to resolve this. sessionInfo below thanks in advance Christiaan sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 Warning messages: [[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] glmulti fails because of rJava
On 23.11.2011 14:43, Toby Marthews wrote: Dear R, The glmulti package no longer loads through the library() command, apparently because of a problem with rJava. I have today reinstalled R from scratch (updated to v2.14.0) and reinstalled all packages from scratch and updated them all too. The problem is the same as I found on v2.13.2. See session below for the error. I tried install.packages(rJava) as advised by the error report but it didn't help (see session below). Please read more carefully: Try re-installing Java and make sure R and Java have matching architectures. It does not ask you to reinstall *r*Java but to reinstall Java. Have you done that? So which architecture is your running R version and which architecture is your Java version? Best, Uwe Ligges Any advice would be much appreciated: I can now not use glmulti at all and I can't see how to solve this! Thank you very much R Help! Best, Toby R version 2.14.0 (2011-10-31) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] library(glmulti) Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: stop(No CurrentVersion entry in ', key, '! Try re-installing Java and make sure R and Java have matching architectures.) error: object 'key' not found Error: package ‘rJava’ could not be loaded install.packages(glmulti) --- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/2.14/glmulti_1.0.2.zip' Content type 'application/zip' length 104179 bytes (101 Kb) opened URL downloaded 101 Kb package ‘glmulti’ successfully unpacked and MD5 sums checked The downloaded packages are in C:\Users\TobyM\AppData\Local\Temp\RtmpUD3kYK\downloaded_packages library(glmulti) Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: stop(No CurrentVersion entry in ', key, '! Try re-installing Java and make sure R and Java have matching architectures.) error: object 'key' not found Error: package ‘rJava’ could not be loaded install.packages(rJava) trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/2.14/rJava_0.9-2.zip' Content type 'application/zip' length 676445 bytes (660 Kb) opened URL downloaded 660 Kb package ‘rJava’ successfully unpacked and MD5 sums checked The downloaded packages are in C:\Users\TobyM\AppData\Local\Temp\RtmpUD3kYK\downloaded_packages library(glmulti) Loading required package: rJava Error : .onLoad failed in loadNamespace() for 'rJava', details: call: stop(No CurrentVersion entry in ', key, '! Try re-installing Java and make sure R and Java have matching architectures.) error: object 'key' not found Error: package ‘rJava’ could not be loaded __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] On-demand importing of a package
On 23.11.2011 16:38, Gábor Csárdi wrote: Just for the records, the solution was to make the matrix 'dgCmatrix instead of 'dsCmatrix', 'dgCmatrix' works and 'dsCmatrix' does not. I suspect that this has to do something with the S4 class hierarchy in Matrix, but I am not sure. This is a quite ugly workaround, since it depends on some internal Matrix features, so I might end up just importing Matrix, as many of you suggested in the first place However, I agree with Gabor Grotherdieck that the issue is still there, in general. Another example would be (optionally) using the 'snow' (or now 'parallel') package. I would like to add optional parallel processing to some of my functions in a package, without actually requiring the installation of snow/parallel. Errr, parallel as a base package is *always* installed for R = 2.14.0. If snow is there and the user wants to use it, then it is used, otherwise not. Actually, 'snow' works similarly. It (optionally) calls function from the Rmpi package, but Rmpi is only suggested, there is no hard dependency. This seems to work well for snow, but in my case I the S4 features in Matrix interfere. Well the is an important difference here: Rmpi does not produce name clashes and its functionality is found when it is simply attached to the search path in the case of snow. The problem with Matrix is that you import from base and hence base names are found before Matrix names. Hence require()ing Matrix as a suggest and calling directly Matrix::rowSums explicitly and so on should work. And exactly this is what Namespaces are made for: deal appropriately with name clashes by importing into the own namespace. Best, Uwe Ligges Gabor On Tue, Nov 22, 2011 at 8:09 PM, Gábor Csárdicsa...@rmki.kfki.hu wrote: Dear Martin, thanks a lot, this all makes sense and looks great. I suspected some S4 trickery and totally forgot that the base package is imported automatically. Unfortunately I still get Error in callGeneric() : 'callGeneric' must be called from a generic function or method for my real function, but it works fine for the toy f() function, so I think I can sort this out from here. Best Regards, Gabor On Tue, Nov 22, 2011 at 6:57 PM, Martin Morganmtmor...@fhcrc.org wrote: On 11/22/2011 03:06 PM, Gábor Csárdi wrote: On Tue, Nov 22, 2011 at 4:27 PM, Martin Morganmtmor...@fhcrc.orgwrote: [...] No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Not just loading, installing a package has a cost, too. Dependencies are bad, they might make my package fail, and I have no control over them. It's not just 'Matrix', I have this issue with other packages as well. Anyway, 'Imports: Matrix' is just a workaround I think. Or is the example in my initial mail expected to fail? Why is that? Why can I call some functions from 'Matrix' that way and why can't I call others? I'm more into black-and-white -- it either needs Matrix or not; apparently it does. It's a matter of opinion, I guess. I find it very annoying when I need to install a bunch of packages from which I don't use any code, just because some tiny bit of a package I need uses them. I would like to spare my users from this. [...] In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Another poster suggested this, that's why I tried. It is clear that I should not call it directly. All I want to do is having a function like this: f- function() { if (require(Matrix)) { res- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) } else { res- diag(1:5) } y- rowSums(res) res / y } Setting the subjective bit, about depending or not, aside, is there really no solution for this? The code in the manual page examples work fine without importing the package and just loading it if needed and available. Why doesn't the code within the package? If I create a package that does not Import: Matrix (btw, Matrix is distributed with all R), with only a function f, and with exports(f) in NAMESPACE, I get library(pkgA) f() Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det Error in rowSums(res) : 'x' must be an array of at least two dimensions This is because (a) Matrix is attached to the user search path but (b) because f is defined in the NAMESPACE of pkgA, rowSums is looked for first in the pkgA NAMESPACE,
Re: [R] Installing rJava from source on Mac
This is not an appropriate topic for R-help (see the posting guide), and it is what R-sig-mac is there for. 'on Mac' is not specific enough: they will need to know your exact OS. But it looks like a path problem. Those tools are part of Xcode, and tools in its path is not being found *when the package installation is being run*. And as the comment inline below shows, you didn't tell us how you did this. BTW, your R is very old, and the posting guide asked you to update before posting. I don't think that would solve the immediate problem here, but it might avoid subsequent ones. On 24/11/2011 09:34, christiaan pauw wrote: Hi Everybody I am trying to install the latest version of JavaGD from source but get the following error. You omitted what you did here. trying URL 'http://cran.za.r-project.org/src/contrib/JavaGD_0.5-4.tar.gz' Content type 'application/x-gzip' length 102242 bytes (99 Kb) opened URL == downloaded 99 Kb * installing *source* package ‘JavaGD’ ... /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 143: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 144: make: command not found /Library/Frameworks/R.framework/Resources/bin/config: line 220: make: command not found checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: no acceptable C compiler found in $PATH See `config.log' for more details. ERROR: configuration failed for package ‘JavaGD’ line 143, 144 and 220 reads as follows: 143: LIBR=`eval $query VAR=LIBR` 144: STATIC_LIBR=`eval $query VAR=STATIC_LIBR` 220: eval ${query} VAR=${var} I do have gcc installed: (from terminal) $ which gcc /Developer/usr/bin/gcc Can anyone guide me on how to resolve this. sessionInfo below thanks in advance Christiaan sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.1 Warning messages: [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] looking for beta parameters
Dear Community, I am trying to write (update) a code for the following problem. Lets assume we have a beta distribution. I know one quantile, lets say, 10% of the mass lies above .8, that is between .8 and 1. In addition, I know that the average of this truncated tail is a given number, lets say .86. I have found the beta.select function in the LearnBayes package, which is as follows: function (quantile1, quantile2) { betaprior1 = function(K, x, p) { m.lo = 0 m.hi = 1 flag = 0 while (flag == 0) { m0 = (m.lo + m.hi)/2 p0 = pbeta(x, K * m0, K * (1 - m0)) if (p0 p) m.hi = m0 else m.lo = m0 if (abs(p0 - p) 1e-04) flag = 1 } return(m0) } p1 = quantile1$p x1 = quantile1$x p2 = quantile2$p x2 = quantile2$x logK = seq(-3, 8, length = 100) K = exp(logK) m = sapply(K, betaprior1, x1, p1) prob2 = pbeta(x2, K * m, K * (1 - m)) ind = ((prob2 0) (prob2 1)) app = approx(prob2[ind], logK[ind], p2) K0 = exp(app$y) m0 = betaprior1(K0, x1, p1) return(round(K0 * c(m0, (1 - m0)), 2)) } I assume one could change this code to get the results I need, but some parts of the function are not clear for me, any help would be greatly appreciated. Thanks a lot: Daniel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] (no subject)
http://dina.newhypothesis.com/wp-content/plugins/extended-comment-options/wfkjnf.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.
[R] dataframe indexing by number of cases per group
Hello, assume we have following dataframe: group -c(rep(A,5),rep(B,6),rep(C,4)) x - c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) df - data.frame(group,x) Now I want to select all cases (rows) for those groups which have more or equal 5 cases (so I want to select all cases of group A and B). How can I use the indexing for such questions? df[??]... I think it is probably quite easy but I really don't know how to do that at the moment. maybe someone can help me... /johannes -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] First read (was: Re: Looping and paste)
On Thu, Nov 24, 2011 at 9:27 AM, Patrick Burns pbu...@pburns.seanet.com wrote: It's very seldom that I disagree with Bert, but here is one time. I don't think An Introduction to R is a suitable first read for people with little computational experience. I must agree with Patrick here. The 'Intro to R' may be appropriate for someone already versed in statistics and/or programming, but it is hardly useful as a first read for the neophytes. Better (I modestly suggest) would be: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html To chip in, the first two chapters of Fox and Weisberg (2011) make for an excellent introduction to R programming. It's gentle, but also covers many of the difficulties and misunderstandings that one would encounter in R. Regards Liviu which includes some other references. 'Hints' is imperfect and incomplete but it suffers slightly less from the curse of knowledge than a lot of other R documentation. Pat On 24/11/2011 00:15, Bert Gunter wrote: ... and you can of course do the assignment: Bndy- paste (BndY,to,50+seq_len(BndY), mN, sep = ) An Introduction to R tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunterbgun...@gene.com wrote: Don't do this! paste() is vectorized. paste (BndY,to,50+seq_len(BndY), mN, sep = ) Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77Sbps0...@auburn.edu wrote: out- vector(list) Ylab- for(i in 1:length(BndY)) { out[i]- paste(BndY[i], to ,BndY[i],mN) } Ylab- do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to add waiting for page change to my script
I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? Jabez [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to add waiting for page change to my script
I thing it is par(ask = TRUE) Sent from my iPad On Nov 24, 2011, at 7:28, Jabez Wilson jabez...@yahoo.co.uk wrote: I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? Jabez [[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] CovSde F. sources?
D'oh. Thanks you very much, Michael -- View this message in context: http://r.789695.n4.nabble.com/CovSde-F-sources-tp4100374p4103647.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] understanding all.equal() output: Mean relative difference
Dear all How should one parse all.equal() output? I'm specifically referring to the 'mean relative difference' messages. For example, all.equal(pi, 355/113) [1] Mean relative difference: 8.491368e-08 But I'm not sure how to understand these messages. When they're close to 0 (or 1xe-16), then it's intuitive. But when they're big, all.equal(1, 4) [1] Mean relative difference: 3 all.equal(2, 4) [1] Mean relative difference: 1 all.equal(3, 4) [1] Mean relative difference: 0.333 the messages start making much less sense. I tried Wikipedia [1], but the description is cryptic, as is the help page. Also, Fox and Weisberg (2011) don't explain this particular message. Regards Liviu [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] readGDAL or raster for reading bit map files
Dear all, I have asked yesterday of how I can read a simple bitmap file in R cran. I was suggest to use either readGDAL or raster for loading my bitmap a. I have done it with readGDAL like store-readGDAL(fname='lena256.bmp') and it works,... but it converts my matrix-like notion of a bitmap to a large vector b. Raster also returns a class that I can not understand. So 1, I want to load it and keep the image as a matrix (so every cell in the matrix will correspond to a pixel) 2. I want to be able to plot the image based on that matrix that I have loaded too. Could you please explain me how I can do those? B.R Alex [[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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?
Hi, First I should note I am relatively new to R so I would appreciate answers that take this into account. I am trying to perform an MDS ordination using the function “metaMDS” of the “vegan” package. I want to ordinate species according to a set of functional traits. “Species” here refers to “sites” in traditional vegetation analyses while “traits” here correspond to “species” in such analyses. My data looks like this: Trait1 Trait2 Trait3 Trait4 Trait5 Trait… Species1 228.44 16.56 1.66 13.22 1 short Species2 150.55 28.07 0.41 0.60 1 mid Species3 NA 25.89 NA 0.55 0 large Species4 147.70 17.65 0.42 1.12 NA large Species… 132.68 NA 1.28 2.75 0 short Because the traits have different variable types, different measurement scales, and also missing values for some species, I have calculated the matrix of species distances using the Gower coefficient of similarity available in Package “FD” (which allows missing values). My problem comes when I create a bi-plot of species and traits. As I have used a distance matrix in function “metaMDS” there are no species scores available. This is given as a warning in R: NMDSgowdis- metaMDS(SpeciesGowdis) plot(NMDSgowdis, type = t) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available” I have read from internet resources that in principle I could obtain the trait (species) scores to plot them in the ordination but my attempts have been unsuccessful. I have tried using the function “wascores” in package vegan and “add.spec.scores” in package BiodiversityR. For this purpuse I have created a new species x traits table where factor traits were coded into dummy variables and all integer variables (including binary) were coerced to numeric variables. Here are the codes used and the error messages I have got: “ NMDSgowdis- metaMDS(SpeciesGowdis) NMDSpoints-postMDS(NMDSgowdis$points,SpeciesGowdis) NMDSwasc-wascores(NMDSpoints,TraitsNMDSdummies) Error in if (any(w 0) || sum(w) == 0) stop(weights must be non-negative and not all zero) : missing value where TRUE/FALSE needed” I imagine the problem is with the NA’s in the data. Alternatively, I have used the “add.spec.scores” function, method=”cor.scores”, found in package BiodiversityR. This seemed to work, as I got no error message, but the species scores were not returned. Here the R code and results: “ A-add.spec.scores(ordi=NMDSgowdis,comm=TraitsNMDSdummies,method=cor.scores,multi=1, Rscale=F,scaling=1) plot(A) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available“ Can anyone guide me to get the trait (“species”) scores to plot together with my species (“site”) scores? Thanks in advance, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Need some vectorizing help
So I have a problem that I'm trying to get through, and I just can't seem to get it to run very fast in R. What I'm trying to do is to find in a vector a local peak, then the next time that value is crossed later. I don't care about peaks that may be lower than this first one - they can be ignored. I've tried some sapply methods along the way, but they all are slower. The best solution I have is a loop, and I just know there are smart R folks that could help me eliminate it. Peak2Return - function(v) { Q - (1:m)[diff(v)0]; find all the peaks L - Q[c(TRUE,v[Q[-1]] v[Q[-length(Q)]])] ; eliminate lower peaks R - sapply(L,function (x,v) { ((x+1):length(v))[v[x] v[(x+1):m]][1]; }, v) ; find the next crossing out - data.frame(peak=L,Return=R) out } Thanks in advance! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error in expand.covs: 'data' must be an 'msdata' object
Hi, I have transformed a Lexis object to a msdata object and tried to apply expand.covs() on this object, but I got an error message: Error in expand.covs... 'data' must be an 'msdata' object. I need to change the class of data to msdata, but don't know how to do it. Thanks in advance, Kadriye -- View this message in context: http://r.789695.n4.nabble.com/Error-in-expand-covs-data-must-be-an-msdata-object-tp4103316p4103316.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] Vegan: how to plot sites labes in diversity plot
Dear List, I can'f figure how to add point labels in the next plot (example from ?taxondive help page, from vegan package): library(vegan) data(dune) data(dune.taxon) taxdis - taxa2dist(dune.taxon, varstep=TRUE) mod - taxondive(dune, taxdis) plot(mod) The points in this plot are diversity values of single sites, and I'd like to add a label to each one. The plot command don't accept a label argument. Any tip? Thanks in advance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 add waiting for page change to my script
see ?devAskNewPage plot(1:10, col = green, pch = 19) devAskNewPage(ask = TRUE) plot(1:10, col = blue, pch = 19) Am 24.11.2011 13:28, schrieb Jabez Wilson: I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? � Jabez [[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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] readGDAL or raster for reading bit map files
Just do m - as.matrix(store) or m - as.image.SpatialGridDataFrame(store)$z image(m) They give the same result with different orientations. Note that both assume a single-band raster, e.g. you only have a greyscale bitmap (for example). The details behind all this is given in the documentation for the sp package. See ?image for the basic image plot for a matrix. Cheers, Mike. On Thu, Nov 24, 2011 at 11:50 PM, Alaios ala...@yahoo.com wrote: Dear all, I have asked yesterday of how I can read a simple bitmap file in R cran. I was suggest to use either readGDAL or raster for loading my bitmap a. I have done it with readGDAL like store-readGDAL(fname='lena256.bmp') and it works,... but it converts my matrix-like notion of a bitmap to a large vector b. Raster also returns a class that I can not understand. So 1, I want to load it and keep the image as a matrix (so every cell in the matrix will correspond to a pixel) 2. I want to be able to plot the image based on that matrix that I have loaded too. Could you please explain me how I can do those? B.R Alex [[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. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.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] understanding all.equal() output: Mean relative difference
On 11-11-24 7:44 AM, Liviu Andronic wrote: Dear all How should one parse all.equal() output? I'm specifically referring to the 'mean relative difference' messages. For example, all.equal(pi, 355/113) [1] Mean relative difference: 8.491368e-08 But I'm not sure how to understand these messages. When they're close to 0 (or 1xe-16), then it's intuitive. But when they're big, all.equal(1, 4) [1] Mean relative difference: 3 all.equal(2, 4) [1] Mean relative difference: 1 all.equal(3, 4) [1] Mean relative difference: 0.333 In the first case, the difference is 3, and 3/1 = 3. In the second case, the difference is 2, and 2/2 = 1. In the third case, the difference is 1, and 1/3 = 0.333. It's the difference relative to the first number. It says mean because the two arguments could both be vectors, in which case it would calculate a vector of differences first. You'll have to look at all.equal.numeric to see the exact way those are combined, but its something like mean(abs(x-y))/mean(abs(x)) Duncan Murdoch the messages start making much less sense. I tried Wikipedia [1], but the description is cryptic, as is the help page. Also, Fox and Weisberg (2011) don't explain this particular message. Regards Liviu [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe indexing by number of cases per group
A very similar question was asked a couple of days ago - see the thread titled Removing rows in dataframe w'o duplicated values - in particular, the responses by Dimitris Rizopoulos and David Winsemius. The adaptation to this problem is df[ave(as.numeric(df$group), as.numeric(df$group), FUN = length) 4, ] groupx 1 A 3.903747 2 A 3.599547 3 A 2.449991 4 A 2.740639 5 A 4.268988 6 B 8.649600 7 B 5.493841 8 B 1.892154 9 B 6.781754 10 B 1.459250 11 B 6.749522 HTH, Dennis On Thu, Nov 24, 2011 at 4:02 AM, Johannes Radinger jradin...@gmx.at wrote: Hello, assume we have following dataframe: group -c(rep(A,5),rep(B,6),rep(C,4)) x - c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) df - data.frame(group,x) Now I want to select all cases (rows) for those groups which have more or equal 5 cases (so I want to select all cases of group A and B). How can I use the indexing for such questions? df[??]... I think it is probably quite easy but I really don't know how to do that at the moment. maybe someone can help me... /johannes -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to add waiting for page change to my script
Thanks, Enrico, that will do nicely.  Jab --- On Thu, 24/11/11, Enrico Schumann enricoschum...@yahoo.de wrote: From: Enrico Schumann enricoschum...@yahoo.de Subject: Re: [R] how to add waiting for page change to my script To: Jabez Wilson jabez...@yahoo.co.uk Cc: R-Help r-h...@stat.math.ethz.ch Date: Thursday, 24 November, 2011, 13:20 see ?devAskNewPage plot(1:10, col = green, pch = 19) devAskNewPage(ask = TRUE) plot(1:10, col = blue, pch = 19) Am 24.11.2011 13:28, schrieb Jabez Wilson: I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? � Jabez    [[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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dataframe indexing by number of cases per group
On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger jradin...@gmx.at wrote: Hello, assume we have following dataframe: group -c(rep(A,5),rep(B,6),rep(C,4)) x - c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) df - data.frame(group,x) Now I want to select all cases (rows) for those groups which have more or equal 5 cases (so I want to select all cases of group A and B). How can I use the indexing for such questions? df[??]... I think it is probably quite easy but I really don't know how to do that at the moment. maybe someone can help me... Here are three approaches: subset(merge(df, xtabs(~ group, df)), Freq = 5) : subset(transform(df, len = ave(x, group, FUN = length)), len = 5) library(sqldf) sqldf('select a.* from df a join (select group, count(*) count from df group by group) using (group) where count = 5') -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] errors with lme4
Alessio Unisi franceschi6 at unisi.it writes: Dear R-users, i need help for this topic! I'm trying to determine if the reproductive success (0=fail, 1=success) of a species of bird is related to a list of covariates. These are the covariates: §elev: elevation of nest (meters) §seadist: distance from the sea (meters) §meanterranova: records of temperature §minpengS1: records of temperature §wchillpengS1: records of temperature §minpengS2: records of temperature §wchillpengS2: records of temperature §nnd: nearest neighbour distance §npd: nearest penguin distance §eggs: numbers of eggs §lay: laying date (julian calendar) §hatch: hatching date (julian calendar) I have some NAs in the data. I want to test the model with all the variable then i want to remove some, but the ideal model: GLM.1 -lmer(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 +(1|territory), family=binomial(logit), data=fledge) doesn't work because of these errors: 'Warning message: In mer_finalize(ans) : gr cannot be computed at initial par (65)'. matrix is not symmetric [1,2] If i delete one or more of the T records (i.e. minpengS2 +wchillpengS2) the model works...below and example: GLM.16 -lmer(fledgesucc ~ lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +(1|territory), family=binomial(logit), data=fledge) summary(GLM.16) Generalized linear mixed model fit by the Laplace approximation Formula: fledgesucc ~ lay + hatch + elev + seadist + nnd + npd + meanterranova + minpengS1 + (1 | territory) Data: fledge AIC BIC logLik deviance 174 204.2-77 154 Random effects: GroupsNameVariance Std.Dev. territory (Intercept) 0.54308 0.73694 Number of obs: 152, groups: territory, 96 I can't prove it, but I strongly suspect that some of your coefficients are perfectly multicollinear. Try running your model as a regular GLM: g1 - glm(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 and see if some of the coefficients are NA. coef(g1) lm() and glm() can handle this sort of rank-deficient or multicollinear input, (g)lmer can't, as of now. I suspect that you may be overfitting your model anyway: you should aim for not more than 10 observations per parameter (in your case, since all your predictors appear to be continuous, How many observations are left after na.omit(fledge)? What is the difference between your 'S1' and 'S2' temperature records? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] First read (was: Re: Looping and paste)
Pat: 1. Thank you for this. Having not read your tutorial, but based on what I know of your other efforts, I am sure that you are correct. Is there a link to this on CRAN somewhere so I can refer to it in future (too lazy to search myself)? 2. Thank you also for your continuing contributions to R documentation. I know this takes a lot of work and you do it well. Would that more R learners would read them -- there would be a lot less RTFM type queries on r-help. Best, Bert On Thu, Nov 24, 2011 at 12:27 AM, Patrick Burns pbu...@pburns.seanet.com wrote: It's very seldom that I disagree with Bert, but here is one time. I don't think An Introduction to R is a suitable first read for people with little computational experience. Better (I modestly suggest) would be: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html which includes some other references. 'Hints' is imperfect and incomplete but it suffers slightly less from the curse of knowledge than a lot of other R documentation. Pat On 24/11/2011 00:15, Bert Gunter wrote: ... and you can of course do the assignment: Bndy- paste (BndY,to,50+seq_len(BndY), mN, sep = ) An Introduction to R tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunterbgun...@gene.com wrote: Don't do this! paste() is vectorized. paste (BndY,to,50+seq_len(BndY), mN, sep = ) Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77Sbps0...@auburn.edu wrote: out- vector(list) Ylab- for(i in 1:length(BndY)) { out[i]- paste(BndY[i], to ,BndY[i],mN) } Ylab- do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.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] errors with lme4
Ben et. al: Shouldn't this thread be taken to R-sig-mixed-models ? Cheers, Bert On Thu, Nov 24, 2011 at 6:14 AM, Ben Bolker bbol...@gmail.com wrote: Alessio Unisi franceschi6 at unisi.it writes: Dear R-users, i need help for this topic! I'm trying to determine if the reproductive success (0=fail, 1=success) of a species of bird is related to a list of covariates. These are the covariates: § elev: elevation of nest (meters) § seadist: distance from the sea (meters) § meanterranova: records of temperature § minpengS1: records of temperature § wchillpengS1: records of temperature § minpengS2: records of temperature § wchillpengS2: records of temperature § nnd: nearest neighbour distance § npd: nearest penguin distance § eggs: numbers of eggs § lay: laying date (julian calendar) § hatch: hatching date (julian calendar) I have some NAs in the data. I want to test the model with all the variable then i want to remove some, but the ideal model: GLM.1 -lmer(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 +(1|territory), family=binomial(logit), data=fledge) doesn't work because of these errors: 'Warning message: In mer_finalize(ans) : gr cannot be computed at initial par (65)'. matrix is not symmetric [1,2] If i delete one or more of the T records (i.e. minpengS2 +wchillpengS2) the model works...below and example: GLM.16 -lmer(fledgesucc ~ lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +(1|territory), family=binomial(logit), data=fledge) summary(GLM.16) Generalized linear mixed model fit by the Laplace approximation Formula: fledgesucc ~ lay + hatch + elev + seadist + nnd + npd + meanterranova + minpengS1 + (1 | territory) Data: fledge AIC BIC logLik deviance 174 204.2 -77 154 Random effects: Groups Name Variance Std.Dev. territory (Intercept) 0.54308 0.73694 Number of obs: 152, groups: territory, 96 I can't prove it, but I strongly suspect that some of your coefficients are perfectly multicollinear. Try running your model as a regular GLM: g1 - glm(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 and see if some of the coefficients are NA. coef(g1) lm() and glm() can handle this sort of rank-deficient or multicollinear input, (g)lmer can't, as of now. I suspect that you may be overfitting your model anyway: you should aim for not more than 10 observations per parameter (in your case, since all your predictors appear to be continuous, How many observations are left after na.omit(fledge)? What is the difference between your 'S1' and 'S2' temperature records? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.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] how to add waiting for page change to my script
Yes But checking the Help I just learned that from R2.14.0 (I presume): asklogical. If TRUE (and the R session is interactive) the user is asked for input, before a new figure is drawn. As this applies to the device, it also affects output by packages grid and lattice. It can be set even on non-screen devices but may have no effect there. ***This not really a graphics parameter, and its use is deprecated in favour of devAskNewPage. *** -- Bert On Thu, Nov 24, 2011 at 4:39 AM, Jim Holtman jholt...@gmail.com wrote: I thing it is par(ask = TRUE) Sent from my iPad On Nov 24, 2011, at 7:28, Jabez Wilson jabez...@yahoo.co.uk wrote: I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? Jabez [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.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] how to add waiting for page change to my script
That works wonderfully - thank you --- On Thu, 24/11/11, Jim Holtman jholt...@gmail.com wrote: From: Jim Holtman jholt...@gmail.com Subject: Re: [R] how to add waiting for page change to my script To: Jabez Wilson jabez...@yahoo.co.uk Cc: R-Help r-h...@stat.math.ethz.ch Date: Thursday, 24 November, 2011, 12:39 I thing it is par(ask = TRUE) Sent from my iPad On Nov 24, 2011, at 7:28, Jabez Wilson jabez...@yahoo.co.uk wrote: I'd like to step through 24 histograms by using the return or click button option, as shown in the demo(graphics) demonstration. I've searched for interactive graphics, and waiting for page change in R documentation but with no result. I'm sure that this is a relatively straightforward procedure. Can anyone point me to the correct solution? Jabez [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Thank you
... and while I am at it, as this is the U.S. Thanksgiving... My sincere thanks to the many R developers and documenters who contribute large amounts of their personal time and effort to developing, improving, and enhancing the accessibility of R for data analysis and science. I believe it is fair to say that R has had as much or more impact than Gosset's Student's T, and I fear that academics who do much of this work do not receive the professional recognition they deserve. I continue to be amazed and humbled by their high quality and consummate professionalismism -- I could not live without R. Kind regards and best wishes to all, -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.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] character substitution within a variable name
Great! I got it. You're right, I misinterpreted Duncan's suggestion. Thanks a lot to both of you... Matteo On 24 November 2011 02:47, Rolf Turner-3 [via R] ml-node+s789695n4102338...@n4.nabble.com wrote: On 24/11/11 09:23, matric wrote: Thanks Duncan, I knew it. But if I use the complete variable name, I'll have far too many arguments for my function Did you understand Duncan's post?  He told you that    df[,var] would work, whereas df$var doesn't.  So he gave you a solution to the problem whereby you ***don't*** have to use the ``complete variable name''. The ``var'' in the foregoing is the object (character string) that you constructed using paste().  I think you are misinterpreting Duncan to be suggesting that you use df[,x_narrow], df[,x_wide] etc. explicitly.    cheers,      Rolf Turner P. S.  But anyway, as Duncan said in a follow-up post, a new design is probably called for.      R. T. On 23 November 2011 20:59, Duncan Murdoch-2 [via R] [hidden email]  wrote: On 23/11/2011 2:29 PM, matric wrote: Hi, I'd like to create a function that accepts as arguments a string that is to be substituted within a variable name. For instance, suppose I have a data frame df: df-data.frame(x_narrow=c(rnorm(100,0,1)),x_wide=c(rnorm(100,0,10))) What I have in mind is something like: f- function(string){ var = paste(x_,string,sep = ) df$var } which does not work. Any suggestion for modifications? Thanks in advance, For indexing a dataframe, use the name as the column index: df[, var] will work. Duncan Murdoch __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/character-substitution-within-a-variable-name-tp4101154p4102338.html To unsubscribe from character substitution within a variable name, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/character-substitution-within-a-variable-name-tp4101154p4103700.html Sent from the R help mailing list archive at Nabble.com. [[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] Legend
Hi everyone. I have a linear regression where I retrieve the R2 like this: r2 = sprintf('%4.2f %s',(summary(reg1)$r.squared)) In my figure I have a legend where I would like to add that R2 value to the legend text. Something like: My text R^2 = r2 legend('topright', inset = .05, title='light ratios', pch = c(21), c(paste('Green/Red', R^2, '=', r2)), horiz=F,pt.bg =c('gray', 'black'), cex = 0.75, bg = 'white') But its not working. Any help would be appreciated. Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Legend-tp4103799p4103799.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] object 'gs' not found
Hello, What is wrong in the below code? What do Ihave to do to make it work? Gs file is my working directory but for some reason it cannot be found.. da - read.table(file.choose(),header=T,sep=\t) head(da) source(garchoxfit_R.txt) m1=garchOxFit(formula.mean=~arma(0,0),formula.var=~igarch(1,1),series=gs,include.var=F) Error in garchOxFit(formula.mean = ~arma(0, 0), formula.var = ~igarch(1, : object 'gs' not found -- View this message in context: http://r.789695.n4.nabble.com/object-gs-not-found-tp4103915p4103915.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] Horizontal Y axis title above the y axis
Dear R-help team I have tried hard to turn my Y axis 90 degrees, so that it is written horizontally, and placing it above the Y axis, but I did not succeed. I have tried to adapt the following functions: - plot() - title() - mtext() And some more that did not prove to be useful (e.g. text() etc). The closest I got to my aim was with mtext(): mtext(Yield [kg/ha], side=3, adj=0). However, font.lab=2 does not seem to work in mtext, meaning I could not make the text bold. Some forums suggest that you can specify the rotation in title(), and I tried crt() and srt() but this did not work either... Can you help me? Thanks in advance Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.orgmailto:christian.and...@fibl.org [[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] pairs(), expression in label and color in text.panel
Hello, I'd like to add custom labels to my pair() plot. These labels include math expression but they aren't correctly displayed... Further, I want that the boxes for the text.panel (diagonal) have an other background color (grey80). Is that generally possible? If yes how do I have to set it? What I've so far is: panel.cor - function(x, y, digits=2, prefix=, cex.cor) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r - abs(cor(x, y)) txt - format(c(r, 0.123456789), digits=digits)[1] txt - paste(prefix, txt, sep=) if(missing(cex.cor)) cex - 0.5/strwidth(txt) test - cor.test(x,y) # borrowed from printCoefmat Signif - symnum(test$p.value, corr = FALSE, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c(***, **, *, ., )) text(0.5, 0.5, paste(txt,Signif), cex = 2) } #correlation pair plot pairs(df, labels=c(expression(alpha),text,expression(beta)), lower.panel=panel.smooth, upper.panel=panel.cor) Maybe someone knows how to do that and can give some hints... /Johannes -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] dataframe indexing by number of cases per group
Hi, thank you for your suggestions. I think I'll stay with Dennis' approach as this is a real indexing approach: df[ave(as.numeric(df$group), as.numeric(df$group), FUN = length) 4, ] I'll try that out now best regards /Johannes Original-Nachricht Datum: Thu, 24 Nov 2011 09:12:57 -0500 Von: Gabor Grothendieck ggrothendi...@gmail.com An: Johannes Radinger jradin...@gmx.at CC: r-help@r-project.org Betreff: Re: [R] dataframe indexing by number of cases per group On Thu, Nov 24, 2011 at 7:02 AM, Johannes Radinger jradin...@gmx.at wrote: Hello, assume we have following dataframe: group -c(rep(A,5),rep(B,6),rep(C,4)) x - c(runif(5,1,5),runif(6,1,10),runif(4,2,15)) df - data.frame(group,x) Now I want to select all cases (rows) for those groups which have more or equal 5 cases (so I want to select all cases of group A and B). How can I use the indexing for such questions? df[??]... I think it is probably quite easy but I really don't know how to do that at the moment. maybe someone can help me... Here are three approaches: subset(merge(df, xtabs(~ group, df)), Freq = 5) : subset(transform(df, len = ave(x, group, FUN = length)), len = 5) library(sqldf) sqldf('select a.* from df a join (select group, count(*) count from df group by group) using (group) where count = 5') -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Horizontal Y axis title above the y axis
On 24/11/2011 9:25 AM, Andres Christian wrote: Dear R-help team I have tried hard to turn my Y axis 90 degrees, so that it is written horizontally, and placing it above the Y axis, but I did not succeed. I have tried to adapt the following functions: - plot() - title() - mtext() And some more that did not prove to be useful (e.g. text() etc). The closest I got to my aim was with mtext(): mtext(Yield [kg/ha], side=3, adj=0). However, font.lab=2 does not seem to work in mtext, meaning I could not make the text bold. The parameter to mtext is just called font, not font.lab. It is called font.lab in other functions because the have multiple types of text, and that's the one that is used for labels. So this works: mtext(Yield [kg/ha], side=3, adj=0, font=2) Duncan Murdoch Some forums suggest that you can specify the rotation in title(), and I tried crt() and srt() but this did not work either... Can you help me? Thanks in advance Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.orgmailto:christian.and...@fibl.org [[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. pl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] post the message
On 24.11.2011 04:34, M Subbiah wrote: When I fit a logistic regression with 5 predictors (all of them are coded) i get the standard error almost zero for the estimated coeffts. I request the members to offer comments / suggestions / diagnostics? [[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. Please really do the latter and repost appropriately afterwards. Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Thank you
Well said. +1 Dennis On Thu, Nov 24, 2011 at 6:43 AM, Bert Gunter gunter.ber...@gene.com wrote: ... and while I am at it, as this is the U.S. Thanksgiving... My sincere thanks to the many R developers and documenters who contribute large amounts of their personal time and effort to developing, improving, and enhancing the accessibility of R for data analysis and science. I believe it is fair to say that R has had as much or more impact than Gosset's Student's T, and I fear that academics who do much of this work do not receive the professional recognition they deserve. I continue to be amazed and humbled by their high quality and consummate professionalismism -- I could not live without R. Kind regards and best wishes to all, -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SPSS F-test on change in R square between hierarchical models
Christopher, I am wondering if anyone knows how to perform an F-test on the change in R square between hierarchical models in R? SPSS provides this information and a researcher that I am working with is interested in getting this information. Alternatively, if someone knows how I can calculate the test statistic (SPSS calls it F-change?) and dfs that would be helpful as well. What you describe is just the standard F test for comparing two models, or testing deviance reduction between tow *nested* models (I suspect this is what you mean by hierarchical). The anova() function will do that. The R2STATS GUI will also give you these tests, along with the R-squared, in the same table. A common misconception about an F-test is that it is the test on a variable effect, when strictly speaking it is a test on the deviance reduction between two models that include or not that particular variable (and there may be several ways to do that, each leading to possibly different F-values). Yvonnick Noel University of Brittany Department of Psychology Rennes, France __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Horizontal Y axis title above the y axis
On 24/11/2011 10:08 AM, Andres Christian wrote: Dear Duncan Thanks for your help. However, your suggestion still does not solve my problem because mtext() only allows me to put the text at the beginning of the Y axis (adj=0), but not centered above it, because values below 0 are not permitted for the parameter adj. Use the at parameter. Duncan Murdoch Best regards Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.org -Ursprüngliche Nachricht- Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Gesendet: Donnerstag, 24. November 2011 16:02 An: Andres Christian Cc: R-help@r-project.org Betreff: Re: [R] Horizontal Y axis title above the y axis On 24/11/2011 9:25 AM, Andres Christian wrote: Dear R-help team I have tried hard to turn my Y axis 90 degrees, so that it is written horizontally, and placing it above the Y axis, but I did not succeed. I have tried to adapt the following functions: - plot() - title() - mtext() And some more that did not prove to be useful (e.g. text() etc). The closest I got to my aim was with mtext(): mtext(Yield [kg/ha], side=3, adj=0). However, font.lab=2 does not seem to work in mtext, meaning I could not make the text bold. The parameter to mtext is just called font, not font.lab. It is called font.lab in other functions because the have multiple types of text, and that's the one that is used for labels. So this works: mtext(Yield [kg/ha], side=3, adj=0, font=2) Duncan Murdoch Some forums suggest that you can specify the rotation in title(), and I tried crt() and srt() but this did not work either... Can you help me? Thanks in advance Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.orgmailto:christian.and...@fibl.org [[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. pl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] object 'gs' not found
On 24.11.2011 14:34, Arto wrote: Hello, What is wrong in the below code? What do Ihave to do to make it work? Gs file is my working directory but for some reason it cannot be found.. da- read.table(file.choose(),header=T,sep=\t) head(da) source(garchoxfit_R.txt) m1=garchOxFit(formula.mean=~arma(0,0),formula.var=~igarch(1,1),series=gs,include.var=F) What is garchoxfit_R.txt? WHat is garchOxFit()? What is F? What is gs? You mean a character vector containg the path of your working directory as you got from getwd()? I cannot believe that. Uwe Ligges Error in garchOxFit(formula.mean = ~arma(0, 0), formula.var = ~igarch(1, : object 'gs' not found -- View this message in context: http://r.789695.n4.nabble.com/object-gs-not-found-tp4103915p4103915.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] Legend
On 24.11.2011 14:18, Filoche wrote: Hi everyone. I have a linear regression where I retrieve the R2 like this: r2 = sprintf('%4.2f %s',(summary(reg1)$r.squared)) In my figure I have a legend where I would like to add that R2 value to the legend text. Something like: My text R^2 = r2 legend('topright', inset = .05, title='light ratios', pch = c(21), c(paste('Green/Red', R^2, '=', r2)), horiz=F,pt.bg =c('gray', 'black'), cex = 0.75, bg = 'white') legend('topright', inset = .05, title = 'light ratios', pch = 21, legend = substitute('Green/Red' ~~ R^2 == r2, list(r2=r2)), horiz = FALSE, pt.bg = c('gray', 'black'), cex = 0.75, bg = 'white') Uwe Ligges But its not working. Any help would be appreciated. Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Legend-tp4103799p4103799.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] readGDAL or raster for reading bit map files
Thanks a lot! That worked. I have two R related questions when I use the store-readGDAL(fname='lena256.bmp') this returns the struct below str(store) Formal class 'SpatialGridDataFrame' [package sp] with 6 slots ..@ data :'data.frame': 65536 obs. of 1 variable: .. ..$ band1: int [1:65536] 255 255 255 255 255 255 255 255 255 255 ... ..@ grid :Formal class 'GridTopology' [package sp] with 3 slots .. .. ..@ cellcentre.offset: Named num [1:2] 0 -722925 .. .. .. ..- attr(*, names)= chr [1:2] x y .. .. ..@ cellsize : num [1:2] 2835 2835 .. .. ..@ cells.dim : int [1:2] 256 256 ..@ grid.index : int(0) ..@ coords : num [1:2, 1:2] 0 722925 -722925 0 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] -1418 -724342 724342 1418 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA How the R when I run image(store) plots the lena correct. Where it store how the file was originally? Also when I do str(as.matrix(store)) this takes only the data and transforms them to the original matri str(as.matrix(store)) int [1:256, 1:256] How it does that? Looks as magic to me B.R Alex From: Michael Sumner mdsum...@gmail.com Cc: R-help@r-project.org R-help@r-project.org Sent: Thursday, November 24, 2011 2:25 PM Subject: Re: [R] readGDAL or raster for reading bit map files Just do m - as.matrix(store) or m - as.image.SpatialGridDataFrame(store)$z image(m) They give the same result with different orientations. Note that both assume a single-band raster, e.g. you only have a greyscale bitmap (for example). The details behind all this is given in the documentation for the sp package. See ?image for the basic image plot for a matrix. Cheers, Mike. Dear all, I have asked yesterday of how I can read a simple bitmap file in R cran. I was suggest to use either readGDAL or raster for loading my bitmap a. I have done it with readGDAL like store-readGDAL(fname='lena256.bmp') and it works,... but it converts my matrix-like notion of a bitmap to a large vector b. Raster also returns a class that I can not understand. So 1, I want to load it and keep the image as a matrix (so every cell in the matrix will correspond to a pixel) 2. I want to be able to plot the image based on that matrix that I have loaded too. Could you please explain me how I can do those? B.R Alex [[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. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.com [[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] Horizontal Y axis title above the y axis
Dear Duncan Thanks for your help. However, your suggestion still does not solve my problem because mtext() only allows me to put the text at the beginning of the Y axis (adj=0), but not centered above it, because values below 0 are not permitted for the parameter adj. Best regards Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.org -Ursprüngliche Nachricht- Von: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Gesendet: Donnerstag, 24. November 2011 16:02 An: Andres Christian Cc: R-help@r-project.org Betreff: Re: [R] Horizontal Y axis title above the y axis On 24/11/2011 9:25 AM, Andres Christian wrote: Dear R-help team I have tried hard to turn my Y axis 90 degrees, so that it is written horizontally, and placing it above the Y axis, but I did not succeed. I have tried to adapt the following functions: - plot() - title() - mtext() And some more that did not prove to be useful (e.g. text() etc). The closest I got to my aim was with mtext(): mtext(Yield [kg/ha], side=3, adj=0). However, font.lab=2 does not seem to work in mtext, meaning I could not make the text bold. The parameter to mtext is just called font, not font.lab. It is called font.lab in other functions because the have multiple types of text, and that's the one that is used for labels. So this works: mtext(Yield [kg/ha], side=3, adj=0, font=2) Duncan Murdoch Some forums suggest that you can specify the rotation in title(), and I tried crt() and srt() but this did not work either... Can you help me? Thanks in advance Christian ___ Mr Christian Andres MSc ETH Agr Research Institute of Organic Agriculture (FiBL) International Division CH-5070 Frick, Switzerland Phone: +41 (0)62 865 7216 E-mail: christian.and...@fibl.orgmailto:christian.and...@fibl.org [[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. pl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?
-- View this message in context: http://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4104295.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] understanding all.equal() output: Mean relative difference
The help page says that large differences are returned as relative difference. A look at the code shows that all.equal.numeric, the version used for a numeric first argument, uses the 'target', that is, the first parametter, as the scaling factor. Thus c(1,4) has a difference of 3, scaled by 1, giving 3 c(2,4) has a difference of 2, scaled by 2, giving 1 ... and so on. The other potentially useful part of the help page is the bit right at the beginning than says Don't use 'all.equal' directly in 'if' expressions-either use 'isTRUE(all.equal())' or 'identical' if appropriate. which usually avoids the need to parse the result at all. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Liviu Andronic Sent: 24 November 2011 12:45 To: r-help@r-project.org Help Subject: [R] understanding all.equal() output: Mean relative difference Dear all How should one parse all.equal() output? I'm specifically referring to the 'mean relative difference' messages. For example, all.equal(pi, 355/113) [1] Mean relative difference: 8.491368e-08 But I'm not sure how to understand these messages. When they're close to 0 (or 1xe-16), then it's intuitive. But when they're big, all.equal(1, 4) [1] Mean relative difference: 3 all.equal(2, 4) [1] Mean relative difference: 1 all.equal(3, 4) [1] Mean relative difference: 0.333 the messages start making much less sense. I tried Wikipedia [1], but the description is cryptic, as is the help page. Also, Fox and Weisberg (2011) don't explain this particular message. Regards Liviu [1] http://en.wikipedia.org/wiki/Mean_difference#Relative_mean_difference -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Need some vectorizing help
On Nov 24, 2011, at 4:52 AM, Scott Tetrick wrote: So I have a problem that I'm trying to get through, and I just can't seem to get it to run very fast in R. What I'm trying to do is to find in a vector a local peak, then the next time that value is crossed later. I don't care about peaks that may be lower than this first one - they can be ignored. I've tried some sapply methods along the way, but they all are slower. The best solution I have is a loop, and I just know there are smart R folks that could help me eliminate it. It looks as though you are reinventing hte function: ?cummax Peak2Return - function(v) { Q - (1:m)[diff(v)0]; find all the peaks L - Q[c(TRUE,v[Q[-1]] v[Q[-length(Q)]])] ; eliminate lower peaks R - sapply(L,function (x,v) { ((x+1):length(v))[v[x] v[(x+1):m]] [1]; }, v) ; find the next crossing out - data.frame(peak=L,Return=R) out } Thanks in advance! David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R package for nested random-effects ANOVA models
Hello, can anyone recommend an R package which can deal with nested random-effects ANOVA models? Cheers Syrvn -- View this message in context: http://r.789695.n4.nabble.com/R-package-for-nested-random-effects-ANOVA-models-tp4104374p4104374.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] Vegan: how to plot sites labes in diversity plot
On Nov 24, 2011, at 8:12 AM, Alejo C.S. wrote: Dear List, I can'f figure how to add point labels in the next plot (example from ?taxondive help page, from vegan package): library(vegan) data(dune) data(dune.taxon) taxdis - taxa2dist(dune.taxon, varstep=TRUE) mod - taxondive(dune, taxdis) plot(mod) The points in this plot are diversity values of single sites, and I'd like to add a label to each one. The plot command don't accept a label argument. Right. Generally you cannot just make up argument names and expect plotting routines to honor them. There is no labels argument in `plot.default` either. class(mod) # to figure out what vegan thinks it object is named [1] taxondive methods(plot) # to make sure there is a specific plot method vegan:::plot.taxondive # triple dots because it is hidden function (x, ...) { plot(x$Species, x$Dplus, xlab = Number of Species, ylab = expression(Delta^+), ...) i - order(x$Species) abline(h = x$EDplus, ...) lines(x$Species[i], x$EDplus - 2 * x$sd.Dplus[i], ...) lines(x$Species[i], x$EDplus + 2 * x$sd.Dplus[i], ...) } environment: namespace:vegan So from that above you see that the plotting routine is doing nothing special. Just plotting x,y values and a bit of annotation So to plot labels offset a bit to the left and down you look at the scale of the plot dimension and take a guess at what will collide th least. There are also tricky routines in packages plotrix and Hmisc that will do the placement for you, but you clearly need to start learning basic R first. with( mod, text(Species-.3, Dplus-1, as.character(1:length(Dplus))) ) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?
Try the daisy() function from the package cluster, it seems to be able to handle NAs and non-dummy coded character variables metaMDS(daisy(df, metric=gower)) Edwin Lebrija Trejos wrote Hi, First I should note I am relatively new to R so I would appreciate answers that take this into account. I am trying to perform an MDS ordination using the function “metaMDS” of the “vegan” package. I want to ordinate species according to a set of functional traits. “Species” here refers to “sites” in traditional vegetation analyses while “traits” here correspond to “species” in such analyses. My data looks like this: Trait1 Trait2 Trait3 Trait4 Trait5 Trait… Species1 228.44 16.56 1.66 13.22 1 short Species2 150.55 28.07 0.41 0.60 1 mid Species3 NA 25.89 NA 0.55 0 large Species4 147.70 17.65 0.42 1.12 NA large Species… 132.68 NA 1.28 2.75 0 short Because the traits have different variable types, different measurement scales, and also missing values for some species, I have calculated the matrix of species distances using the Gower coefficient of similarity available in Package “FD” (which allows missing values). My problem comes when I create a bi-plot of species and traits. As I have used a distance matrix in function “metaMDS” there are no species scores available. This is given as a warning in R: NMDSgowdis- metaMDS(SpeciesGowdis) plot(NMDSgowdis, type = t) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available” I have read from internet resources that in principle I could obtain the trait (species) scores to plot them in the ordination but my attempts have been unsuccessful. I have tried using the function “wascores” in package vegan and “add.spec.scores” in package BiodiversityR. For this purpuse I have created a new species x traits table where factor traits were coded into dummy variables and all integer variables (including binary) were coerced to numeric variables. Here are the codes used and the error messages I have got: “ NMDSgowdis- metaMDS(SpeciesGowdis) NMDSpoints-postMDS(NMDSgowdis$points,SpeciesGowdis) NMDSwasc-wascores(NMDSpoints,TraitsNMDSdummies) Error in if (any(w 0) || sum(w) == 0) stop(weights must be non-negative and not all zero) : missing value where TRUE/FALSE needed” I imagine the problem is with the NA’s in the data. Alternatively, I have used the “add.spec.scores” function, method=”cor.scores”, found in package BiodiversityR. This seemed to work, as I got no error message, but the species scores were not returned. Here the R code and results: “ A-add.spec.scores(ordi=NMDSgowdis,comm=TraitsNMDSdummies,method=cor.scores,multi=1, Rscale=F,scaling=1) plot(A) Warning message:In ordiplot(x, choices = choices, type = type, display = display, :Species scores not available“ Can anyone guide me to get the trait (“species”) scores to plot together with my species (“site”) scores? Thanks in advance, Edwin __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/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://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4104406.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] Thank you
Bert you said it better than I ever could. What R creators, developers, and documenters do for us every day by how they effect our work as statisticians is something I would not know how to measure. THANK YOU! Frank Bert Gunter wrote ... and while I am at it, as this is the U.S. Thanksgiving... My sincere thanks to the many R developers and documenters who contribute large amounts of their personal time and effort to developing, improving, and enhancing the accessibility of R for data analysis and science. I believe it is fair to say that R has had as much or more impact than Gosset's Student's T, and I fear that academics who do much of this work do not receive the professional recognition they deserve. I continue to be amazed and humbled by their high quality and consummate professionalismism -- I could not live without R. Kind regards and best wishes to all, -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Thank-you-tp4104117p4104420.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] R package for nested random-effects ANOVA models
syrvn mentor_ at gmx.net writes: Hello, can anyone recommend an R package which can deal with nested random-effects ANOVA models? Cheers Syrvn lme in the nlme package; lmer in the lme4 package; and/or visit the r-sig-mixed-models list. Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] sem package (version 2.1-1)
Dear R users, Version 2.1-1 of the sem package, for structural equation modeling, is now on CRAN. Unlike version 2.0-0, which was a major overhaul of the package, version 2.1-1 just sprinkles some syntactic sugar on it, introducing the specifyEquations() and cfa() functions; specifyEquations() supports model specification in equation (rather than path) format, and cfa() facilitates compact specification of simple confirmatory factor analysis models. For example, from ?sem, the Duncan, Haller, and Portes peer-influences model can now be specified as model.dhp.1 - specifyEquations(covs=RGenAsp, FGenAsp) RGenAsp = gam11*RParAsp + gam12*RIQ + gam13*RSES + gam14*FSES + beta12*FGenAsp FGenAsp = gam23*RSES + gam24*FSES + gam25*FIQ + gam26*FParAsp + beta21*RGenAsp ROccAsp = 1*RGenAsp REdAsp = lam21(1)*RGenAsp # to illustrate setting start values, not necessary here FOccAsp = 1*FGenAsp FEdAsp = lam42(1)*FGenAsp and the Wheaton alientation model as model.wh - specifyEquations() Anomia67 = 1*Alienation67 Powerless67 = lamby*Alienation67 Anomia71 = 1*Alienation71 Powerless71 = lamby*Alienation71 Education = 1*SES SEI = lambx*SES Alienation67 = gam1*SES Alienation71 = gam2*SES + beta*Alienation67 V(Anomia67) = the1 V(Anomia71) = the1 V(Powerless67) = the2 V(Powerless71) = the2 V(SES) = phi C(Anomia67, Anomia71) = the5 C(Powerless67, Powerless71) = the5 Similarly, the following are equivalent specifications of a CFA model for the Thurstore mental-tests data: (1) in CFA format: mod.cfa.thur.c - cfa() FA: Sentences, Vocabulary, Sent.Completion FB: First.Letters, 4.Letter.Words, Suffixes FC: Letter.Series, Pedigrees, Letter.Group cfa.thur.c - sem(mod.cfa.thur.c, R.thur, 213) summary(cfa.thur.c) (2) in equation format: mod.cfa.thur.e - specifyEquations(covs=F1, F2, F3) Sentences = lam11*F1 Vocabulary = lam21*F1 Sent.Completion = lam31*F1 First.Letters = lam42*F2 4.Letter.Words = lam52*F2 Suffixes = lam62*F2 Letter.Series = lam73*F3 Pedigrees = lam83*F3 Letter.Group = lam93*F3 V(F1) = 1 V(F2) = 1 V(F3) = 1 cfa.thur.e - sem(mod.cfa.thur.e, R.thur, 213) summary(cfa.thur.e) (3) in path format: mod.cfa.thur.p - specifyModel(covs=F1, F2, F3) F1 - Sentences, lam11 F1 - Vocabulary, lam21 F1 - Sent.Completion,lam31 F2 - First.Letters, lam41 F2 - 4.Letter.Words, lam52 F2 - Suffixes, lam62 F3 - Letter.Series, lam73 F3 - Pedigrees, lam83 F3 - Letter.Group, lam93 F1 - F1,NA, 1 F2 - F2,NA, 1 F3 - F3,NA, 1 As usual, I'd be grateful for comments, suggestions, and bug reports. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there way to add a new row to a data frame in a specific location
Is there easy way (without copying the existing rows to a temporary location and copying back) to add a new row to a specific index location in an existing data frame? Example df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) newrow = c('X', 100, 200) I want to add the newrow as the second row to the data frame df Please suggest a solution that is efficient for a data frame that can have millions of rows, and I want to add a new row in any given index location of the data frame. Thanks, Sammy [[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] Is there way to add a new row to a data frame in a specific location
Hi. May be this: df = data.frame( A=c('a','b','c'), B=c(1,2,3), C=c(10,20,30), stringsAsFactors=FALSE) newrow = c('X', 100, 200) rbind(df,newrow)[c(1,4,2,3),] Andrija On Thu, Nov 24, 2011 at. 6:05 PM, Sammy Zee szee2...@gmail.com wrote: Is there easy way (without copying the existing rows to a temporary location and copying back) to add a new row to a specific index location in an existing data frame? Example df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) newrow = c('X', 100, 200) I want to add the newrow as the second row to the data frame df Please suggest a solution that is efficient for a data frame that can have millions of rows, and I want to add a new row in any given index location of the data frame. Thanks, Sammy [[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] Thank you
And from the side of a ordinary user who opened the page that read: Chapter 1: What is R? two years ago to all of you on this list: Since reading that first page things have changed so that I would get through a normal working day without the software you create and the advice you give. Thank you to all of you Christiaan On 24 November 2011 18:00, Frank Harrell f.harr...@vanderbilt.edu wrote: Bert you said it better than I ever could. What R creators, developers, and documenters do for us every day by how they effect our work as statisticians is something I would not know how to measure. THANK YOU! Frank Bert Gunter wrote ... and while I am at it, as this is the U.S. Thanksgiving... My sincere thanks to the many R developers and documenters who contribute large amounts of their personal time and effort to developing, improving, and enhancing the accessibility of R for data analysis and science. I believe it is fair to say that R has had as much or more impact than Gosset's Student's T, and I fear that academics who do much of this work do not receive the professional recognition they deserve. I continue to be amazed and humbled by their high quality and consummate professionalismism -- I could not live without R. Kind regards and best wishes to all, -- Bert -- Bert Gunter Genentech Nonclinical Biostatistics [[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] content of global environment with dump.frames()
Dear R users, I am using dump.frames() to investigate the content of the different environments in cases of errors or during certain steps of a non interactive calculation. I am, however, wondering about how to see the content of the global environment at the moment that dump.fames() was invoked. Her is some test piece (careful about the rm(list=ls(), remove the # if you know what you are doing to easier see the effect): # rm(list=ls()) a=2 test = function() { b=3 dump.frames(dumpto='test', to.file = TRUE ) } test() # rm(list=ls()) load('test.rda') debugger(test) I can now investigate the value of 'b' but could not figure out a way to get the value of 'a'. Am I missing something or is dump.frames only intended to be uses with options(error=dump.frames) ? Most probably some modification of save() would be more apropriate to use in my case but I could not (yet) figure out how to mimic the convenient behaviour of dump.frames() to save the whole call stack. Thanks for any advice Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] content of global environment with dump.frames()
Are perhaps you looking for options(error = recover)? Michael On Thu, Nov 24, 2011 at 12:52 PM, Jannis bt_jan...@yahoo.de wrote: Dear R users, I am using dump.frames() to investigate the content of the different environments in cases of errors or during certain steps of a non interactive calculation. I am, however, wondering about how to see the content of the global environment at the moment that dump.fames() was invoked. Her is some test piece (careful about the rm(list=ls(), remove the # if you know what you are doing to easier see the effect): # rm(list=ls()) a=2 test = function() { b=3 dump.frames(dumpto='test', to.file = TRUE ) } test() # rm(list=ls()) load('test.rda') debugger(test) I can now investigate the value of 'b' but could not figure out a way to get the value of 'a'. Am I missing something or is dump.frames only intended to be uses with options(error=dump.frames) ? Most probably some modification of save() would be more apropriate to use in my case but I could not (yet) figure out how to mimic the convenient behaviour of dump.frames() to save the whole call stack. Thanks for any advice Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is there way to add a new row to a data frame in a specific location
AFAIK all solutions to the grow object size problem in R involve creation of a new object to change an old one. There is considerable sophistication under the hood that allows a minimum of intermediate objects to be created if you are careful, but actually changing the size of an object in place is not supported. That doesn't mean that you have to copy... to a temporary and then copy back, since you can reference chunks of an existing object without actually moving them in memory by using indexing. But (AFAIK) you cannot escape creating at least one new copy of the data that becomes the object if you use rbind to grow your object. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Sammy Zee szee2...@gmail.com wrote: Is there easy way (without copying the existing rows to a temporary location and copying back) to add a new row to a specific index location in an existing data frame? Example df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) newrow = c('X', 100, 200) I want to add the newrow as the second row to the data frame df Please suggest a solution that is efficient for a data frame that can have millions of rows, and I want to add a new row in any given index location of the data frame. Thanks, Sammy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question on density values obtained from kde2d() from package MASS
On Thu, 24 Nov 2011, Andreas Klein wrote: Hello, I am a little bit confused regarding the density values obtained from the function kde2d() from the package MASS because the are not in the intervall [0,1] as I would expect them to be. Here is an Your expectation is wrong. example: x - c(0.0036,0.0088,0.0042,0.0022,-0.0013,0.0007,0.0028,-0.0028,0.0019,0.0026,-0.0029,-0.0081,-0.0024,0.0090,0.0088,0.0038,0.0022,0.0068,0.0089,-0.0015,-0.0062,0.0066) y - c(0.00614,0.00194,0.00264,0.00064,0.00344,0.00314,-0.6,-0.00066,0.00174,0.00274,-0.00076,0.00024,-0.00236,0.00234,0.00504,0.00114,0.00054,-0.00116,-0.00016,-0.00566,0.00044,0.00404) tmp - kde2d(x=x, y=y, n=100) range(tmp$z) #3.621288 11989.060924 Do I have to transform them further? Or what scale are they? They are density values, as you quote from the help page. Try dnorm(0, 0, 1e-6) in R. That's a density, way above 1. Perhaps you need to revise Probability 101. Or did I get something wrong regarding the output because in the help file it reads: zAn n[1] by n[2] matrix of the estimated density: rows ^ correspond to the value of x, columns to the value of y. Regards, Andy. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] Is there way to add a new row to a data frame in a specific location
On Thu, 24 Nov 2011, Jeff Newmiller wrote: AFAIK all solutions to the grow object size problem in R involve creation of a new object to change an old one. There is considerable sophistication under the hood that allows a minimum of intermediate objects to be created if you are careful, but actually changing the size of an object in place is not supported. Just for the record, it actually is (R vectors have a LENGTH and TRUELENGTH property at C level), but this is AFAIK only used internally. The better question is why you care about the order of the rows of a data frame? A good way to think of a d.f. is like a table in a DBMS: for efficiency the cases are unordered, but you can retrieve them in any order you want (or no order). Indeed, for efficient operations on millions of rows an R-DBMS interface is highly recomemded -- see the R-data manual. That doesn't mean that you have to copy... to a temporary and then copy back, since you can reference chunks of an existing object without actually moving them in memory by using indexing. But (AFAIK) you cannot escape creating at least one new copy of the data that becomes the object if you use rbind to grow your object. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Sammy Zee szee2...@gmail.com wrote: Is there easy way (without copying the existing rows to a temporary location and copying back) to add a new row to a specific index location in an existing data frame? Example df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) newrow = c('X', 100, 200) I want to add the newrow as the second row to the data frame df Please suggest a solution that is efficient for a data frame that can have millions of rows, and I want to add a new row in any given index location of the data frame. Thanks, Sammy -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] Comments disappearing from local functions (R 2.14.0)
On Mon, 21-Nov-2011 at 09:46PM +1300, Rolf Turner wrote: [] | It *doesn't* happen to me. Ergo it would appear to be peculiar | to your particular set-up. | | What does options()$keep.source say? (Mine says TRUE.) | Same here in both cases. | | P. S.: | | sessionInfo() | R version 2.14.0 (2011-10-31) | Platform: i686-pc-linux-gnu (32-bit) | | locale: | [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C | [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 | [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 | [7] LC_PAPER=C LC_NAME=C | [9] LC_ADDRESS=C LC_TELEPHONE=C | [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C Both the same except the Kubuntu one is Platform: x86_64-unknown-linux-gnu (64-bit) | | attached base packages: | [1] stats graphics grDevices utils datasets methods base | | other attached packages: | [1] misc_0.0-15 attached base packages: [1] splines grDevices utils stats graphics methods base other attached packages: [1] multicore_0.1-7 gbm_1.6-3.1 survival_2.36-10 lattice_0.20-0 loaded via a namespace (and not attached): [1] grid_2.14.0 tools_2.14.0 With the one using multicore, I get a strange error that didn't occur with R-2.13.1. A function which runs on 7 cores produces a swag of PDF files and then returns a list of information. New to the 2.14.0 is an error like this: Error in dev.off() : internal error in PDF_endpage\n From what I can work out, that is a C message and tricky to trace. However, if I use a postscript device instead of PDF, it works fine. It's a simple matter to convert a postscript file to pdf, so that's easy to deal with. It's impossible to make a toy example of the problem which doesn't appear when run on a single core. Maybe if I knew exactly where the problem arises I could make a toy example but it's rather a lot of code I'm dealing with. The fact that the two problems I'm encountering did not occur with earlier versions makes me less suspicious of my own code. My main question is: Can I redo the updating of the packages with checkBuilt to downgrade them back to the previous version? Something is not right with either of my installations and I'd like to revert. The problem with the disappearing comments occurs when I wish to attach to another directory. I commonly reuse functions from previous years and modify them for the current year. If my pwd is, say ~/thisYear, I'll do something like attach(~/lastYear/.RData) If I then edit the function of interest, when it's saved I have the appropriate version in ~/thisYear/.RData which I find a convenient way to work. If the comments aren't there, it's far less usable. If I can go back to R-2.13.1 I can still work that way. TIA -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] proper work-flow with 'formula' objects and lm()
Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed results or summary(). However, if I pass through a formula object (form - formula(y1~x1)) y1 ~ x1 lm(form, anscombe) Call: lm(formula = form, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 then I only get the object name in the call, 'form', instead of the formula. When passing a 'formula' object to lm, is it possible to retain in the resulting 'lm' object the actual formula used for the regression: y1 ~ x1? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] jzoj4 43vwibnt
5ja7o, h5ih0aufrt. http://yjgv6d1r.blog.com/nrd/ s2gqnd gkajocjaked 6fzlef, qufk5mowaax0 zcy51g1f. avgvvqnqiq79 g11hp. [[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] proper work-flow with 'formula' objects and lm()
On 24/11/2011 2:48 PM, Liviu Andronic wrote: Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed results or summary(). However, if I pass through a formula object (form- formula(y1~x1)) y1 ~ x1 lm(form, anscombe) Call: lm(formula = form, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 then I only get the object name in the call, 'form', instead of the formula. When passing a 'formula' object to lm, is it possible to retain in the resulting 'lm' object the actual formula used for the regression: y1 ~ x1? It is retained. terms(fit) will give it to you, if fit is an lm object. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] First read
Bert, Your laziness is well founded -- it is not on CRAN, you have to go all the way over to another website. And thanks for the kind words (even though we Europeans are free to be ingrates today). Pat On 24/11/2011 14:23, Bert Gunter wrote: Pat: 1. Thank you for this. Having not read your tutorial, but based on what I know of your other efforts, I am sure that you are correct. Is there a link to this on CRAN somewhere so I can refer to it in future (too lazy to search myself)? 2. Thank you also for your continuing contributions to R documentation. I know this takes a lot of work and you do it well. Would that more R learners would read them -- there would be a lot less RTFM type queries on r-help. Best, Bert On Thu, Nov 24, 2011 at 12:27 AM, Patrick Burns pbu...@pburns.seanet.com wrote: It's very seldom that I disagree with Bert, but here is one time. I don't think An Introduction to R is a suitable first read for people with little computational experience. Better (I modestly suggest) would be: http://www.burns-stat.com/pages/Tutor/hints_R_begin.html which includes some other references. 'Hints' is imperfect and incomplete but it suffers slightly less from the curse of knowledge than a lot of other R documentation. Pat On 24/11/2011 00:15, Bert Gunter wrote: ... and you can of course do the assignment: Bndy- paste (BndY,to,50+seq_len(BndY), mN, sep = ) An Introduction to R tells you about such fundamentals and should be a first read for anyone learning R. --- Bert On Wed, Nov 23, 2011 at 4:10 PM, Bert Gunterbgun...@gene.comwrote: Don't do this! paste() is vectorized. paste (BndY,to,50+seq_len(BndY), mN, sep = ) Cheers, Bert On Wed, Nov 23, 2011 at 3:31 PM, B77Sbps0...@auburn.eduwrote: out- vector(list) Ylab- for(i in 1:length(BndY)) { out[i]- paste(BndY[i], to ,BndY[i],mN) } Ylab- do.call(c, out) markm0705 wrote Dear R helpers I'm trying to make up some labels for plot from this vector BndY-seq(from = 18900,to= 19700, by = 50) using Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))} but the vector created is NULL However if i use for(i in BndY) {print(c(paste(i, to ,i+50,mN)))} I can see the for loop is making the labels I'm looking for but not sure on my error in assigning them to a vector Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Thank you
On 24/11/11 14:43, Bert Gunter wrote: ... and while I am at it, as this is the U.S. Thanksgiving... My sincere thanks to the many R developers and documenters who contribute large amounts of their personal time and effort to developing, improving, and enhancing the accessibility of R for data analysis and science. I believe it is fair to say that R has had as much or more impact than Gosset's Student's T, and I fear that academics who do much of this work do not receive the professional recognition they deserve. I continue to be amazed and humbled by their high quality and consummate professionalismism -- I could not live without R. Kind regards and best wishes to all, -- Bert and even though I'm (and many others) are the 'wrong' side of the pond, I'd like to add my +1 to these thanks. Thanks ! Paul. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comments disappearing from local functions (R 2.14.0)
On Fri, 25 Nov 2011, Patrick Connolly wrote: On Mon, 21-Nov-2011 at 09:46PM +1300, Rolf Turner wrote: [] Please don't excise content, nor mix up topics. I am going to reply here just to the subject line, and reply to your use of pdf() under multicore separately. | It *doesn't* happen to me. Ergo it would appear to be peculiar | to your particular set-up. | | What does options()$keep.source say? (Mine says TRUE.) | Same here in both cases. [...] My main question is: Can I redo the updating of the packages with checkBuilt to downgrade them back to the previous version? Something is not right with either of my installations and I'd like to revert. The problem with the disappearing comments occurs when I wish to attach to another directory. I commonly reuse functions from previous years and modify them for the current year. If my pwd is, say ~/thisYear, I'll do something like attach(~/lastYear/.RData) If I then edit the function of interest, when it's saved I have the appropriate version in ~/thisYear/.RData which I find a convenient way to work. If the comments aren't there, it's far less usable. If I can go back to R-2.13.1 I can still work that way. So you missed the NEWS item: • The source attribute on functions created with keep.source=TRUE has been replaced with a srcref attribute. The srcref attribute references an in-memory copy of the source file using the srcfilecopy class or the new srcfilealias class. This means that if you save a function under R 2.13.1 and load/attach it under R 2.14.0, its kept source (with the comments) is no longer available. However your original posting did not mention save/attach, nor that you saved under one version and attached under another. That is hte only circumstance under which I can make it do what you claim. And now you know not to do that. Dump your functions in 2.13.1, and source/save in 2.14.0. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 9:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: It is retained. terms(fit) will give it to you, if fit is an lm object. Thank you. The following works nicely. (form - formula(y1~x1)) y1 ~ x1 x - lm(form, anscombe) formula(terms(x)) y1 ~ x1 However, I was hoping that there was a way to input the 'form' object so that summary(x) would print the underlying formula used, not the formula object name. I was thinking of something in the style of x - lm(deparse(form), anscombe) summary(x) Can this be done? Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] pdf() under multicore (was Comments disappearing from local functions (R 2.14.0))
On Fri, 25 Nov 2011, Patrick Connolly wrote: [... about a completely different topic] With the one using multicore, I get a strange error that didn't occur with R-2.13.1. A function which runs on 7 cores produces a swag of PDF files and then returns a list of information. New to the 2.14.0 is an error like this: Error in dev.off() : internal error in PDF_endpage\n From what I can work out, that is a C message and tricky to trace. Easy to trace; you look for it in the code! It indicates that you used PDF compression (new to 2.14.0) and that the page-stream file got corrupted. So simply use compress=FALSE to get the previous behaviour. However, mixing graphics devices with multicore is probably asking for trouble. If your fork with an open graphics device you certainly are since the parent and child will share file handles. But even if each child opens a separate pdf() device and closes it before it returns, there still are many pitfalls as the parent and child share a session temporary directory and all assume they have exclusive access to it. My guess is that two pdf() devices in different processes are using the same temporary file, or the same FILE stream associated with a temporary file. And only onefile=FALSE or compress=TRUE use such temporary files. However, if I use a postscript device instead of PDF, it works fine. It's a simple matter to convert a postscript file to pdf, so that's easy to deal with. It's impossible to make a toy example of the problem which doesn't appear when run on a single core. Maybe if I knew exactly where the problem arises I could make a toy example but it's rather a lot of code I'm dealing with. The fact that the two problems I'm encountering did not occur with earlier versions makes me less suspicious of my own code. You could at least have outlined what you are doing. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] proper work-flow with 'formula' objects and lm()
On Thu, 24 Nov 2011, Liviu Andronic wrote: On Thu, Nov 24, 2011 at 9:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: It is retained. terms(fit) will give it to you, if fit is an lm object. Thank you. The following works nicely. (form - formula(y1~x1)) y1 ~ x1 x - lm(form, anscombe) formula(terms(x)) y1 ~ x1 However, I was hoping that there was a way to input the 'form' object so that summary(x) would print the underlying formula used, not the formula object name. I was thinking of something in the style of x - lm(deparse(form), anscombe) summary(x) Can this be done? Regards Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) ... Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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, rip...@stats.ox.ac.uk 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I wanted. Thanks! However, I do want to simplify the syntax and define a new function: x.lm - function(formula, data, ...) { eval(substitute(lm(f, data, ...), list(f = formula))) } For the simple case it works just fine (form - formula(y1~x1)) y1 ~ x1 x - x.lm(form, anscombe) But it fails when I try to input more lm() arguments: (x - x.lm(form, anscombe, subset=-5)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in Am I doing something obviously wrong? Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 2:48 PM, Liviu Andronic landronim...@gmail.com wrote: Dear all I have a work-flow issue with lm(). When I use lm(y1~x1, anscombe) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 I get as expected the formula, y1 ~ x1, in the print()ed results or summary(). However, if I pass through a formula object (form - formula(y1~x1)) y1 ~ x1 lm(form, anscombe) Call: lm(formula = form, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 then I only get the object name in the call, 'form', instead of the formula. When passing a 'formula' object to lm, is it possible to retain in the resulting 'lm' object the actual formula used for the regression: y1 ~ x1? Try this: form - formula(y1~x1) do.call(lm, list(form, quote(anscombe))) Call: lm(formula = y1 ~ x1, data = anscombe) Coefficients: (Intercept) x1 3.0001 0.5001 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] readGDAL or raster for reading bit map files
It is by magic, otherwise known as R classes and methods. See sp:::as.matrix.SpatialGridDataFrame There's a lot of background here so I suggest you start with the general R documentation, and the sp package documentation, including vignette(sp) and these citation(sp) Cheers, Mike. On Fri, Nov 25, 2011 at 1:49 AM, Alaios ala...@yahoo.com wrote: Thanks a lot! That worked. I have two R related questions when I use the store-readGDAL(fname='lena256.bmp') this returns the struct below str(store) Formal class 'SpatialGridDataFrame' [package sp] with 6 slots ..@ data :'data.frame': 65536 obs. of 1 variable: .. ..$ band1: int [1:65536] 255 255 255 255 255 255 255 255 255 255 ... ..@ grid :Formal class 'GridTopology' [package sp] with 3 slots .. .. ..@ cellcentre.offset: Named num [1:2] 0 -722925 .. .. .. ..- attr(*, names)= chr [1:2] x y .. .. ..@ cellsize : num [1:2] 2835 2835 .. .. ..@ cells.dim : int [1:2] 256 256 ..@ grid.index : int(0) ..@ coords : num [1:2, 1:2] 0 722925 -722925 0 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] -1418 -724342 724342 1418 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA How the R when I run image(store) plots the lena correct. Where it store how the file was originally? Also when I do str(as.matrix(store)) this takes only the data and transforms them to the original matri str(as.matrix(store)) int [1:256, 1:256] How it does that? Looks as magic to me B.R Alex From: Michael Sumner mdsum...@gmail.com To: Alaios ala...@yahoo.com Cc: R-help@r-project.org R-help@r-project.org Sent: Thursday, November 24, 2011 2:25 PM Subject: Re: [R] readGDAL or raster for reading bit map files Just do m - as.matrix(store) or m - as.image.SpatialGridDataFrame(store)$z image(m) They give the same result with different orientations. Note that both assume a single-band raster, e.g. you only have a greyscale bitmap (for example). The details behind all this is given in the documentation for the sp package. See ?image for the basic image plot for a matrix. Cheers, Mike. On Thu, Nov 24, 2011 at 11:50 PM, Alaios ala...@yahoo.com wrote: Dear all, I have asked yesterday of how I can read a simple bitmap file in R cran. I was suggest to use either readGDAL or raster for loading my bitmap a. I have done it with readGDAL like store-readGDAL(fname='lena256.bmp') and it works,... but it converts my matrix-like notion of a bitmap to a large vector b. Raster also returns a class that I can not understand. So 1, I want to load it and keep the image as a matrix (so every cell in the matrix will correspond to a pixel) 2. I want to be able to plot the image based on that matrix that I have loaded too. Could you please explain me how I can do those? B.R Alex [[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. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.com -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.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] proper work-flow with 'formula' objects and lm()
You would get exactly the same problem with ...,, anway. Here's a commonly used approach in R sources: x.lm - function(formula, data, ...) { Call - match.call(expand.dots = TRUE) Call[[1]] - as.name(lm) Call$formula - as.formula(terms(formula)) eval(Call) } On Thu, 24 Nov 2011, Liviu Andronic wrote: On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I wanted. Thanks! However, I do want to simplify the syntax and define a new function: x.lm - function(formula, data, ...) { eval(substitute(lm(f, data, ...), list(f = formula))) } For the simple case it works just fine (form - formula(y1~x1)) y1 ~ x1 x - x.lm(form, anscombe) But it fails when I try to input more lm() arguments: (x - x.lm(form, anscombe, subset=-5)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in Am I doing something obviously wrong? Regards Liviu -- Brian D. Ripley, rip...@stats.ox.ac.uk 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] proper work-flow with 'formula' objects and lm()
On Thu, Nov 24, 2011 at 11:55 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: You would get exactly the same problem with ...,, anway. Here's a commonly used approach in R sources: x.lm - function(formula, data, ...) { Call - match.call(expand.dots = TRUE) Call[[1]] - as.name(lm) Call$formula - as.formula(terms(formula)) eval(Call) } From limited testing this seems to do exactly what I wanted! I thank all those who came up with suggestions. Regards Liviu On Thu, 24 Nov 2011, Liviu Andronic wrote: On Thu, Nov 24, 2011 at 10:25 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Yes. That's a job for substitute (the second time today). form - formula(y1~x1) x - eval(substitute(lm(f, anscombe), list(f = form))) summary(x) Call: lm(formula = y1 ~ x1, data = anscombe) That's what I wanted. Thanks! However, I do want to simplify the syntax and define a new function: x.lm - function(formula, data, ...) { eval(substitute(lm(f, data, ...), list(f = formula))) } For the simple case it works just fine (form - formula(y1~x1)) y1 ~ x1 x - x.lm(form, anscombe) But it fails when I try to input more lm() arguments: (x - x.lm(form, anscombe, subset=-5)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in Am I doing something obviously wrong? Regards Liviu -- Brian D. Ripley, rip...@stats.ox.ac.uk 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, UK Fax: +44 1865 272595 -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] content of global environment with dump.frames()
On 11/24/2011 07:02 PM, R. Michael Weylandt wrote: Are perhaps you looking for options(error = recover)? Michael No, not really. First I use this for non-interactive sessions (otherwise I would mtrace() from package debug) and second I also want to save and retrieve the environment contents in case there is no error which causes R to stop. Thanks, however, for your reply! Jannis On Thu, Nov 24, 2011 at 12:52 PM, Jannisbt_jan...@yahoo.de wrote: Dear R users, I am using dump.frames() to investigate the content of the different environments in cases of errors or during certain steps of a non interactive calculation. I am, however, wondering about how to see the content of the global environment at the moment that dump.fames() was invoked. Her is some test piece (careful about the rm(list=ls(), remove the # if you know what you are doing to easier see the effect): # rm(list=ls()) a=2 test = function() { b=3 dump.frames(dumpto='test', to.file = TRUE ) } test() # rm(list=ls()) load('test.rda') debugger(test) I can now investigate the value of 'b' but could not figure out a way to get the value of 'a'. Am I missing something or is dump.frames only intended to be uses with options(error=dump.frames) ? Most probably some modification of save() would be more apropriate to use in my case but I could not (yet) figure out how to mimic the convenient behaviour of dump.frames() to save the whole call stack. Thanks for any advice Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Objects disappearing in my R work space
I am running MCMC chains with a self written MCMC algorithm. When I have multiple R terminals open while running the Chain, when it finishes it is not there. when I press ls() it does not show up and when I type the Name it says the Object is not found. I assume It is unrecoverable... but how do I stop it from happening in the future? Thanks Mike -- View this message in context: http://r.789695.n4.nabble.com/Objects-disappearing-in-my-R-work-space-tp4104389p4104389.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] Legend
Thank you for your precious help. It works fine. However, what about if I have two entries in the legend? I tryed: legend('topright', inset = .05, title = 'light ratios', pch = c(21,22), legend = c(substitute('Green/Red' ~~ R^2 == r2, list(r2=r2)),substitute('Green/Red' ~~ R^2 == r2, list(r2=r2))), horiz = FALSE, pt.bg = c('gray', 'black'), cex = 0.75, bg = 'white') But it does not work. Regards, Phil -- View this message in context: http://r.789695.n4.nabble.com/Legend-tp4103799p4104386.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] How to increase precision to handle very low P-values
Interesting observation, Duncan! I investigate its effects in my case. Thanks again for your time. all the best, Alonso -- View this message in context: http://r.789695.n4.nabble.com/How-to-increase-precision-to-handle-very-low-P-values-tp4100250p4104503.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] The contrast and Design libraries
Dear all, I have been using the contrast library in my teaching for the last couple of years and am right in the middle of this year's round. In the last week R has been updated to version 2.14.0 on our computers. This has had the unfortunate effect of meaning the contrasts library no longer works, as the Design library is no longer available. I wonder if anyone has a fix for this...or alternatively can tell me another package that is as simple to use (the students won't cope with anything more complicated - we're all biologists not statisticians). I hope someone can help. Here is a typical bit of code I'm currently running so you can see what I'm trying to do: exptime is a covariate and both infstat and status are factors mod-glm(propalive~exptime+infstat+status+ infstat:status, data=dat) library(contrast) contrast(mod3, a = list(status = levels(dat$status), infstat=control, exptime=8230), b = list(status = levels(dat$status), infstat=infected,exptime=8230)) any help gratefully received, Jo Dr Joanne Lello Cardiff University School of Biosciences Organism and Environment Group Biomedical Sciences Building Museum Avenue Cardiff CF10 3AX Tel: 02920 875885 E-mail: lel...@cardiff.ac.uk [[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] object 'gs' not found
Hello, I got the code working now. Thanks for the help anyways=)! Arto -- View this message in context: http://r.789695.n4.nabble.com/object-gs-not-found-tp4103915p4104792.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] Question on density values obtained from kde2d() from package MASS
Hello, I am a little bit confused regarding the density values obtained from the function kde2d() from the package MASS because the are not in the intervall [0,1] as I would expect them to be. Here is an example: x - c(0.0036,0.0088,0.0042,0.0022,-0.0013,0.0007,0.0028,-0.0028,0.0019,0.0026,-0.0029,-0.0081,-0.0024,0.0090,0.0088,0.0038,0.0022,0.0068,0.0089,-0.0015,-0.0062,0.0066) y - c(0.00614,0.00194,0.00264,0.00064,0.00344,0.00314,-0.6,-0.00066,0.00174,0.00274,-0.00076,0.00024,-0.00236,0.00234,0.00504,0.00114,0.00054,-0.00116,-0.00016,-0.00566,0.00044,0.00404) tmp - kde2d(x=x, y=y, n=100) range(tmp$z) #3.621288 11989.060924 Do I have to transform them further? Or what scale are they? Or did I get something wrong regarding the output because in the help file it reads: zAn n[1] by n[2] matrix of the estimated density: rows correspond to the value of x, columns to the value of y. Regards, Andy. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] CAPM-GARCH - Regression analysis with heteroskedasticity
Hey Guys, i want to do a CAPM-GARCH model. I didn´t find anything posted online. (If there is something - shame on me - i didn´t find it.) My Problem: What is the difference if I let the residuals “e” follow a garch process ? How do I do my regression analysis now? I began reading about regression analyis withheteroscedasticity, but didn´t get it. So i started programming. First loading data with quantmod and applying a function to get continously compounded returns and squared returns. Looks good - stylised facts seems to be covered. Starting with GARCH: I use a GARCH(1,1) but will use it as an infinite ARCH(1,1): Let h be the variance. ß_1 and a0 the coefficents and r2 the squared returns: Infinitive ARCH Model: h-ao*sum(ß_1^i)+a1*sum(ß_1^(i-1)*r2_{t-i}) How I used it in R: sumofbeta- ß_1^rep(1:length(r2)) # Beta-Seq sum(ß_1^i) for the sum of the product h-a0*(1/1-ß_1)+a1*(t(sumofbeta)%*%r2) Now i have my variance: DOING THE CAPM: Applying a simple regression analysis ri - alpha+beta*rm+e e ~ N(0,h) h is following the GARCH process decribed above I don´t really get how my regression analysis changed when I change the distribution of my residual “e”. May be a dump question and somehow ashaming because it´s the concept of CAPM-GARCH =) but I have to admit I don’t get it. Thanks for your time and help Regards Tonio -- View this message in context: http://r.789695.n4.nabble.com/CAPM-GARCH-Regression-analysis-with-heteroskedasticity-tp4105346p4105346.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] R-2.14.0: read.csv2 with fileEncoding=UTF-8
Dear R-List, I'm trying to read an UTF-8-encoded text file which works fine under # ### CONFIG 1 sessionInfo() R version 2.12.1 (2010-12-16) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5] LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base running under Windows Server 2008. ### RESULT: read.csv2(example.utf, fileEncoding=UTF-8) VARIABLELABEL ORDER_IN_PROFILE 1A Umlauts:äüö 45 2B Umlauts:äüöß 35 # The exact same command executed under R-2.14.0 (running under Windows 7) gives a different output: # ### CONFIG 2 sessionInfo() R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5] LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.14.0 ### RESULT: read.csv2(example.utf, fileEncoding=UTF-8) #same command [1] X. 0 rows (or 0-length row.names) Warning messages: 1: In read.table(file = file, header = header, sep = sep, quote = quote, : invalid input found on input connection 'example.utf' 2: In read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'example.utf' ## same results with read.csv2(example.utf, fileEncoding=UCS-2LE) read.csv2(example.utf, fileEncoding=UTF-16LE) If I specify encoding instead of fileEncoding, non-ascii-chars are displayed fine, but apparently the UTF-8-bytes are not stripped: ### RESULT: read.csv2(example.utf, encoding=UTF-8) X.U.FEFF.VARIABLELABEL ORDER_IN_PROFILE 1 A Umlauts:äüö 45 2 B Umlauts:äüöß 35 ## Any hints what I could do to reach the results from config 1 under config 2? Many thanks in advance, Christian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] loop through columns in S4 objects
Dear experts, I am trying to perform an association using snpStats. I have a snp matrix called 'plink' which contains my genotype data (as a list of $genotypes, $map, $fam), and a phenotype data frame which contains the outcomes (outcome1, outcome2,...) I would like to associate with the genotype. My question is, how do I loop through the outcomes? This type of data seems different from all the others and I am having trouble manipulating it, so I would also be grateful if you have suggestions of some tutorials that can help me understand how to do this and other manipulations such as subsetting the snp.matrix data for example. This is what I have tried for the loop: rhs - function(x) { x- snp.rhs.tests(x, family=gaussian, data=phenotype, snp.data=snp.matrix$genotype) } res_ - apply(phenotype,2,rhs) Error in x$terms : $ operator is invalid for atomic vectors Then I tried this: for (cov in names(phenotype)) { association-snp.rhs.tests(cov, family=gaussian,data=phenotype, snp.data=snp.matrix$genotype) } Error in eval(expr, envir, enclos) : object 'outcome1' not found Thank you as usual for your help! -f -- View this message in context: http://r.789695.n4.nabble.com/loop-through-columns-in-S4-objects-tp4104836p4104836.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] Copula Fitting Using R
Hi, Is anybody using Copula package for fitting copulas to own data? I have two marginals Log Normal with (parameters 1.17 and 0.76) and Gamma ( 2.7 and 1.05) Which package I should use to fit Gumbel and Clayton Copulas? Thanks, fayyad [[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] CAPM-GARCH - Regression analysis with heteroskedasticity
Okay, it seems to work with Mahalanobis: b = (X′S^−1X)−1X′S^−1Y minimizes the Mahalanobis-distance of Xb to Y . And S is the covariance-matrix. cov = a0+a1x_{n-1}*y_{n-1}+ß*cov{n-1} But shouldn´t it be the covariance of the residuals? Anyone experiences with that? -- View this message in context: http://r.789695.n4.nabble.com/CAPM-GARCH-Regression-analysis-with-heteroskedasticity-tp4105346p4106088.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] The contrast and Design libraries
On another list it was reported that a new version of contrast was uploaded to CRAN earlier today that makes use of Design's replacement rms. Wait a day or two and then download this updated version and rms. http://www.mail-archive.com/r-sig-mac@r-project.org/msg00924.html Michael On Thu, Nov 24, 2011 at 12:23 PM, Joanne Lello lel...@cardiff.ac.uk wrote: Dear all, I have been using the contrast library in my teaching for the last couple of years and am right in the middle of this year's round. In the last week R has been updated to version 2.14.0 on our computers. This has had the unfortunate effect of meaning the contrasts library no longer works, as the Design library is no longer available. I wonder if anyone has a fix for this...or alternatively can tell me another package that is as simple to use (the students won't cope with anything more complicated - we're all biologists not statisticians). I hope someone can help. Here is a typical bit of code I'm currently running so you can see what I'm trying to do: exptime is a covariate and both infstat and status are factors mod-glm(propalive~exptime+infstat+status+ infstat:status, data=dat) library(contrast) contrast(mod3, a = list(status = levels(dat$status), infstat=control, exptime=8230), b = list(status = levels(dat$status), infstat=infected,exptime=8230)) any help gratefully received, Jo Dr Joanne Lello Cardiff University School of Biosciences Organism and Environment Group Biomedical Sciences Building Museum Avenue Cardiff CF10 3AX Tel: 02920 875885 E-mail: lel...@cardiff.ac.uk [[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] Objects disappearing in my R work space
Can you say more about how your algorithm is implemented? If it's wrapped in a function, the result might disappear with the end of the function's environment. I don't think having multiple R sessions would be a problem...it's never been for me. Michael On Thu, Nov 24, 2011 at 10:50 AM, Aldo michael.v.claw...@gmail.com wrote: I am running MCMC chains with a self written MCMC algorithm. When I have multiple R terminals open while running the Chain, when it finishes it is not there. when I press ls() it does not show up and when I type the Name it says the Object is not found. I assume It is unrecoverable... but how do I stop it from happening in the future? Thanks Mike -- View this message in context: http://r.789695.n4.nabble.com/Objects-disappearing-in-my-R-work-space-tp4104389p4104389.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.
[R] options(errorfn=traceback)
Dear R experts---I may have asked this in the past, but I don't think I figured out how to do this. I would like to execute traceback() automatically if my R program dies---every R programI ever invoke. I guessed that I could have wrapped my entire R code into tryCatch( ... oodles of R code , error = function(e) traceback(), finally = cat(done) } but the traceback docs tell me that this does not generate a traceback(). in a perfect world, I would stick this into my .Rprofile and forget about it. in an super-perfect world, it would be an option() that I just don't know yet... possible? /iaw __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] options(errorfn=traceback)
Hi Ivo, Does this do what you want? options(error = function(x) base::traceback()) Cheers, Josh On Thu, Nov 24, 2011 at 8:22 PM, ivo welch ivo.we...@gmail.com wrote: Dear R experts---I may have asked this in the past, but I don't think I figured out how to do this. I would like to execute traceback() automatically if my R program dies---every R programI ever invoke. I guessed that I could have wrapped my entire R code into tryCatch( ... oodles of R code , error = function(e) traceback(), finally = cat(done) } but the traceback docs tell me that this does not generate a traceback(). in a perfect world, I would stick this into my .Rprofile and forget about it. in an super-perfect world, it would be an option() that I just don't know yet... possible? /iaw __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Objects disappearing in my R work space
It works when I do not have multiple windows open, but is not there when I do have multiple windows open, so I dont think it has to do with the function The function is pretty complicated but I can share more if you think it will help -- View this message in context: http://r.789695.n4.nabble.com/Objects-disappearing-in-my-R-work-space-tp4104389p4106379.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] Unable to reproduce Stata Heckman sample selection estimates
Hello, I am working on reproducing someone's analysis which was done in Stata. The analysis is estimation of a standard Heckman sample selection model (Tobit-2), for which I am using the sampleSelection package and the selection() function. I have a few problems with the estimation: 1) The reported standard error for all estimates is Inf ... vcov(selectionObject) yields Inf in every cell. 2) While the selection equation coefficient estimates are almost exactly the same as the Stata results, the outcome equation coefficient estimates are quite different (different sign in one case, order of magnitude difference in some other cases). 3) I can't seem to figure out how to specify the initial values for the MLE ... whatever argument I pass to start (even of the form coef(selectionObject)), I get the following error: Error in gr[, fixed] - NA : (subscript) logical subscript too long I have to admit I am pretty confused by #1, I feel like I must be doing something wrong, missing something obvious, but I have no idea what. I figure #2 might be because the algorithms (selection and Stata) are just finding different local maxima, but because of #3 I can't test that guess by using different initial values in selection. Let me know if I should provide any more information. Thanks in advance for any pointers in the right direction. - Clara __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Objects disappearing in my R work space
Is there a maximum memory allocation for all R windows open? because it is like 1-3 million runs so... it may be reaching some sort of memory limit -- View this message in context: http://r.789695.n4.nabble.com/Objects-disappearing-in-my-R-work-space-tp4104389p4106390.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.