Re: [R] regular expression
Gabor Grothendieck a écrit : On 4/7/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : I assume is to replace single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes that's rignt while leaving double quoted strings not containing single quotes as they are (i.e. leave them as double quoted). No, at the end, I have to replace all the double quotes () by simple quote (') In that case it simplifies to the following (same as before except for definition of f): library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I have the following error message : gsubfn('[][^]*[]', f, s) # ['...' '...\...'] Erreur dans parse(file, n, text, prompt) : erreur de syntaxe dans c([\,replacement(...\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression
I can't reproduce that error. For me it works fine. What version of R and gsubfn are you using? I switched to a French locale just to be sure. I tried pasting it into an R session and also sourcing it but both worked fine for me. Sys.getlocale() [1] LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Sys.putenv(LANGUAGE=FR);Sys.setlocale(LC_ALL,FR) [1] LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252 library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] [1] ['...' '...\...'] R.version.string # XP [1] R version 2.4.1 Patched (2006-12-30 r40331) packageDescription(gsubfn)$Version [1] 0.3-3 On 4/8/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : On 4/7/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : I assume is to replace single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes that's rignt while leaving double quoted strings not containing single quotes as they are (i.e. leave them as double quoted). No, at the end, I have to replace all the double quotes () by simple quote (') In that case it simplifies to the following (same as before except for definition of f): library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I have the following error message : gsubfn('[][^]*[]', f, s) # ['...' '...\...'] Erreur dans parse(file, n, text, prompt) : erreur de syntaxe dans c([\,replacement(...\ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Simulation of the Frailty of the Cox PH model
Dear R-list users, I am trying to do simulation of survival data to enable it to run under frailty option. Below is the function a that I am using. My questions are: 1. How do I modify it to get bigger (hopefully significant) value of Variance of random effect? 2. What changes do I have to make in the function to run it under correlated frailty model? (may be in kinship package) 3. Is there any program to run frailty by Inverse gaussian or stable family in R? Thank you for your time. Thanks in advance. Mohammad Ehsanul Karim wildscop at yahoo dot com Institute of Statistical Research and Training University of Dhaka # *** sim.data- function(g,m){ set.seed(123) group - rep(1:m,rep(g,m)) Frailty - rep(rgamma(m,100,1),rep(g,m)) covariate - rbinom(g*m,1,.05) stimes - rweibull(g*m,1.1,1/(5*Frailty*exp((covariate)/.5))) cens - 5 + 5*runif(25) times - pmin(stimes, cens) censored - as.numeric(cens times) data.mat - cbind(group,covariate,times,censored,Frailty) data.mat - data.mat[rev(order(times)),1:length(data.mat[1,])] data.fr - data.frame(data.mat) return(data.fr) } # *** # Example of 50 group each with 100 members sim.fr-sim.data(50,100) library(survival) fit.c - coxph(Surv(times,censored) ~ covariate,data= sim.fr) # fit.c gives the Usual cox proportional hazards model fit.gm.em - coxph(Surv(times,censored) ~ covariate + frailty(group, dist='gamma', method='em'), data= sim.fr) # fit.gm.em gives the gamma frailty model by EM algorithm fit.c # result of Cox PH model fit.gm.em # result of gamma frailty model __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression
Gabor Grothendieck a écrit : I can't reproduce that error. For me it works fine. What version of R and gsubfn are you using? I switched to a French locale just to be sure. I tried pasting it into an R session and also sourcing it but both worked fine for me. Sys.getlocale() [1] LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Sys.putenv(LANGUAGE=FR);Sys.setlocale(LC_ALL,FR) [1] LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252 library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] [1] ['...' '...\...'] R.version.string # XP [1] R version 2.4.1 Patched (2006-12-30 r40331) packageDescription(gsubfn)$Version [1] 0.3-3 On 4/8/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : On 4/7/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : I assume is to replace single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes that's rignt while leaving double quoted strings not containing single quotes as they are (i.e. leave them as double quoted). No, at the end, I have to replace all the double quotes () by simple quote (') In that case it simplifies to the following (same as before except for definition of f): library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I have the following error message : gsubfn('[][^]*[]', f, s) # ['...' '...\...'] Erreur dans parse(file, n, text, prompt) : erreur de syntaxe dans c([\,replacement(...\ I am sorry Gabor, I had the R 2.3.1 version. I downloaded the good versions (R and gsubfn). All works fine now. Thank you very much for your nice solution ! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression
Gabor Grothendieck a écrit : On 4/7/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : I assume is to replace single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes that's rignt while leaving double quoted strings not containing single quotes as they are (i.e. leave them as double quoted). No, at the end, I have to replace all the double quotes () by simple quote (') In that case it simplifies to the following (same as before except for definition of f): library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I discovered that it doesn't work when the pattern is not on one line. Here's an example of file read with readLines : Lines - c(line one example, line two example, example \comment on one line it works \ end of the line, example \ comment on two lines, the end of the comment \ without ' inside, example \ comment on one line with ' inside it works \ end of the line, example \ comment on two lines with ', inside it doesn't works \) s - Lines f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) [1] line one example [2] line two example [3] example 'comment on one line it works ' end of the line [4] example \ comment on two lines [5] the end of the comment \ without ' inside [6] example ' comment on one line with \ inside it works ' end of the line [7] example \ comment on two lines with ' [8] inside it doesn't works \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Labelling boxplot with fivenumber summary
Just wanted to say thanks very much. I used Chuck's 2nd idea as I found it the easiest to understand as I'm still finding me feet with R. Just for reference for anyone else, fn[1] and fn[5] actually pasted and gave the values at the whiskers (~1.5 IQR) so replaced them with a max and min function which returned the true max and min values and pasted at the correct heights. Thanks once again for all the help. Regards, Daniel Siddle __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] regular expression
Your example is a vector of strings not a string with mulitple lines. To turn it into a string with mulitple lines use paste: gsubfn('[][^]*[]', f, paste(Lines, collapse = \n)) If you want to break up the output to create a vector of strings rather than a single multi-line string see ?strsplit On 4/8/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : On 4/7/07, Laurent Rhelp [EMAIL PROTECTED] wrote: Gabor Grothendieck a écrit : I assume is to replace single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes that's rignt while leaving double quoted strings not containing single quotes as they are (i.e. leave them as double quoted). No, at the end, I have to replace all the double quotes () by simple quote (') In that case it simplifies to the following (same as before except for definition of f): library(gsubfn) squote - ' # single quote. This is a double quote, single quote, double quote dquote - '' # double quote This is a single quote, double quote, single quote s - [\...\ \...'...\] f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) # ['...' '...\...'] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I discovered that it doesn't work when the pattern is not on one line. Here's an example of file read with readLines : Lines - c(line one example, line two example, example \comment on one line it works \ end of the line, example \ comment on two lines, the end of the comment \ without ' inside, example \ comment on one line with ' inside it works \ end of the line, example \ comment on two lines with ', inside it doesn't works \) s - Lines f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) gsubfn('[][^]*[]', f, s) [1] line one example [2] line two example [3] example 'comment on one line it works ' end of the line [4] example \ comment on two lines [5] the end of the comment \ without ' inside [6] example ' comment on one line with \ inside it works ' end of the line [7] example \ comment on two lines with ' [8] inside it doesn't works \ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] data encapsulation with classes
Hi All, I'm new to R from a C and Octave/Matlab background. I am trying to construct some classes in R to which I want to attach pieces of data. First, is attr(obj, 'member name') - data the accepted way of doing this? Second, having attached member data with attr is there anything wrong with accessing it by the asperand (@), i.e. t = attr(t, 'test') - 4 [EMAIL PROTECTED] [1] 4 I can't find any documentation on using the asperand to access attributes like this. I saw it in a piece of code as I was googling around trying to find some information on attaching data to a class in R. Is this deprecated? Is this poor form? If anyone has some suggestions please let me know. Thank you __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data encapsulation with classes
On Sun, 8 Apr 2007, Peter Williams wrote: Hi All, I'm new to R from a C and Octave/Matlab background. I am trying to construct some classes in R to which I want to attach pieces of data. First, is attr(obj, 'member name') - data the accepted way of doing this? No, it isn't. You seem to be trying to deduce new-style classes from a representation used before R 2.4, but in any case it would not be sensible. Please consult John M. Chambers. Programming with Data. Springer, New York, 1998, and/or William N. Venables and Brian D. Ripley. S Programming. Springer, New York, 2000, or for a shorter online resource: http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/Methods.pdf Second, having attached member data with attr is there anything wrong with accessing it by the asperand (@), i.e. t = attr(t, 'test') - 4 [EMAIL PROTECTED] [1] 4 I can't find any documentation on using the asperand to access attributes like this. I saw it in a piece of code as I was googling around trying to find some information on attaching data to a class in R. Is this deprecated? Is this poor form? If anyone has some suggestions please let me know. Thank you __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data encapsulation with classes
On 4/8/07, Roger Bivand [EMAIL PROTECTED] wrote: On Sun, 8 Apr 2007, Peter Williams wrote: Hi All, I'm new to R from a C and Octave/Matlab background. I am trying to construct some classes in R to which I want to attach pieces of data. First, is attr(obj, 'member name') - data the accepted way of doing this? No, it isn't. You seem to be trying to deduce new-style classes from a representation used before R 2.4, but in any case it would not be sensible. Please consult John M. Chambers. Programming with Data. Springer, New York, 1998, and/or William N. Venables and Brian D. Ripley. S Programming. Springer, New York, 2000, or for a shorter online resource: http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/Methods.pdf Unfortunately, all of those references are at least 4 years out of date when it comes to S4 methods. Is there any comprehensive reference of the current implementation of the S4 OO system apart from the source code? Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Labelling boxplot with fivenumber summary
You may wish to provide brief commented source code: that would be most helpful for people referring to it in the archives. Many thanks and best wishes, Ranjan On Sun, 8 Apr 2007 11:43:47 + Daniel Siddle [EMAIL PROTECTED] wrote: Just wanted to say thanks very much. I used Chuck's 2nd idea as I found it the easiest to understand as I'm still finding me feet with R. Just for reference for anyone else, fn[1] and fn[5] actually pasted and gave the values at the whiskers (~1.5 IQR) so replaced them with a max and min function which returned the true max and min values and pasted at the correct heights. Thanks once again for all the help. Regards, Daniel Siddle __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] compile errors with rgl-0.70.570 on FreeBSD
On Wed, 2007-04-04 at 21:12 +0200, Rainer Hurling wrote: Thank you for your work on rgl. Reading in another thread about your new (inofficial) version of rgl (see below) I tried it with R version 2.5.0 alpha (2007-03-31 r40986) under FreeBSD 7.0-CURRENT. Unfortunately I got the following error: --- #R CMD INSTALL rgl_0.70.570.tar.gz * Installing to library '/usr/local/lib/R/library' * Installing *source* package 'rgl' ... checking for libpng-config... yes configure: using libpng-config configure: using libpng dynamic linkage checking for X... libraries /usr/X11R6/lib, headers /usr/X11R6/include checking GL/gl.h usability... no checking GL/gl.h presence... no checking for GL/gl.h... no checking GL/glu.h usability... no checking GL/glu.h presence... no checking for GL/glu.h... no configure: error: missing required header GL/gl.h ERROR: configuration failed for package 'rgl' ** Removing '/usr/local/lib/R/library/rgl' ** Restoring previous '/usr/local/lib/R/library/rgl' --- Rainer, I have same problem in my Ubuntu. I solve instaling OpenGl in system, in my case I install this debian poackages: freeglut3, freeglut3-dev, libgl1-mesa-dev, libglu1-mesa-dev, libice-dev, libsm-dev, libx11-dev, libxau-dev, libxdmcp-dev, libxext-dev, libxt-dev, mesa-common-dev, x11proto-core-dev, x11proto-input-dev, x11proto-kb-dev, x11proto-xext-dev, xlibmesa-gl-dev and xtrans-dev If you install similar packages in your system I think your problem will be solve. -- Bernardo Rangel Tura, M.D, PhD National Institute of Cardiolgy Rio de Janeiro - Brasil __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] compile errors with rgl-0.70.570 on FreeBSD
Bernardo, thank you for your tips. But before version 0.70.570 rgl was running fine on my system. All necessary GL files are installed. Duncan Murdoch is working on a configure script to get rgl also work on Mac OSX. Some of his changes breaks things for FreeBSD. We tested it without posting on [EMAIL PROTECTED] Duncan now tries to find a solution for all platforms. Rainer Hurling Bernardo Rangel Tura schrieb: On Wed, 2007-04-04 at 21:12 +0200, Rainer Hurling wrote: Thank you for your work on rgl. Reading in another thread about your new (inofficial) version of rgl (see below) I tried it with R version 2.5.0 alpha (2007-03-31 r40986) under FreeBSD 7.0-CURRENT. Unfortunately I got the following error: --- #R CMD INSTALL rgl_0.70.570.tar.gz * Installing to library '/usr/local/lib/R/library' * Installing *source* package 'rgl' ... checking for libpng-config... yes configure: using libpng-config configure: using libpng dynamic linkage checking for X... libraries /usr/X11R6/lib, headers /usr/X11R6/include checking GL/gl.h usability... no checking GL/gl.h presence... no checking for GL/gl.h... no checking GL/glu.h usability... no checking GL/glu.h presence... no checking for GL/glu.h... no configure: error: missing required header GL/gl.h ERROR: configuration failed for package 'rgl' ** Removing '/usr/local/lib/R/library/rgl' ** Restoring previous '/usr/local/lib/R/library/rgl' --- Rainer, I have same problem in my Ubuntu. I solve instaling OpenGl in system, in my case I install this debian poackages: freeglut3, freeglut3-dev, libgl1-mesa-dev, libglu1-mesa-dev, libice-dev, libsm-dev, libx11-dev, libxau-dev, libxdmcp-dev, libxext-dev, libxt-dev, mesa-common-dev, x11proto-core-dev, x11proto-input-dev, x11proto-kb-dev, x11proto-xext-dev, xlibmesa-gl-dev and xtrans-dev If you install similar packages in your system I think your problem will be solve. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Confidence-Intervals.... help...
Hi... I have to use R to find out the 90% confidence-interval for the sensitivity and specificity of the following diagnostic test: A particular diagnostic test for multiple sclerosis was conducted on 20 MS patients and 20 healthy subjects, 6 MS patients were classified as healthy and 8 healthy subjects were classified as suffering from the MS. Furthermore, I need to find the number of MS patients required for a sensitivity of 1%... Is there a simple R-command which can do that for me? I am completely new to R... Help please! Jochen -- View this message in context: http://www.nabble.com/Confidence-Intervals-help...-tf3544217.html#a9894014 Sent from the R help mailing list archive at Nabble.com. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Confidence-Intervals.... help...
Hm... sounds like a homework problem to me... Maybe start by figuring out how to do it without R - what's the approach, and how would you calculate it? Then search R help for the possible key words you came up with. Sarah On 4/8/07, Jochen.F [EMAIL PROTECTED] wrote: Hi... I have to use R to find out the 90% confidence-interval for the sensitivity and specificity of the following diagnostic test: A particular diagnostic test for multiple sclerosis was conducted on 20 MS patients and 20 healthy subjects, 6 MS patients were classified as healthy and 8 healthy subjects were classified as suffering from the MS. Furthermore, I need to find the number of MS patients required for a sensitivity of 1%... Is there a simple R-command which can do that for me? I am completely new to R... Help please! Jochen -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Failure of mcsamp() but not mcmcsamp()
Daer r-helpers, Can anyone help with the following: I get: mcmcsamp(txt.lmer3f) Markov Chain Monte Carlo (MCMC) output: Start = 1 End = 1 Thinning interval = 1 But: mcsamp(txt.lmer3f) Error in as.bugs.array(sims, program = lmer, n.iter = n.iter, n.burnin = n.burnin, : error in parameter sigma.s in parameters.to.save I had attached the arm package: library(arm) Loading required package: R2WinBUGS arm (Version 1.0-15, built: 2007-3-17) Working directory is /Users/mk/Documents/projects/Mike/prediss/Exp-Text Loading required package: foreign sessionInfo() R version 2.4.1 (2006-12-18) i386-apple-darwin8.8.1 locale: C attached base packages: [1] tools grid datasets stats graphics grDevices utils methods [9] base other attached packages: foreign armR2WinBUGS coda Hmisc gmodels effects lme4 0.8-18 1.0-15 2.0-4 0.10-7 3.2-1 2.13.2 1.0-9 0.9975-13 Matrix car weavercodetools digest xtable latticeExtra lattice 0.9975-11 1.2-1 1.0.1 0.0-3 0.2.3 1.4-3 0.1-40.14-17 gridBase MASS JGR iplots JavaGDrJava 0.4-3 7.2-33 1.4-15 1.0-5 0.3-6 0.4-14 Thanks, MK _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reasons to Use R
On 4/6/07, Wilfred Zegwaard [EMAIL PROTECTED] wrote: I'm not a programmer, but I have the experience that R is good for processing large datasets, especially in combination with specialised statistics. This I find a little surprising, but maybe it's just a sign that I'm not experienced enough with R yet. I can't use R for big datasets. At all. Big datasets take forever to load with read.table, R frequently runs out of memory, and nlm or gnlm never seem to actually converge to answers. By comparison, I can point SAS and NLIN at this data without problem. (Of course, SAS is running on a pretty powerful dedicated machine with a big ram disk, so that may be part of the problem.) R's pass-by-value semantics also make it harder than it should be to deal with where it's crucial that you not make a copy of the data frame, for fear of running out of memory. Pass-by-reference would make implementing data transformations so much easier that I don't really understand how pass-by-value became the standard. (If there's a trick to doing in-place transformations, I've not found it.) Right now, I'm considering starting on a project involving some big Monte Carlo integrations over the complicated posterior parameter distributions of a nonlinear regression model, and I have the strong feeling that R will just choke. R's great for small projects, but as soon as you even a few hundred megs of data, it seems to break down. If I'm doing things wrong, please tell me. :-) SAS is a beast to work with. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reasons to Use R
On 4/8/07, Johann Hibschman [EMAIL PROTECTED] wrote: R's pass-by-value semantics also make it harder than it should be to deal with where it's crucial that you not make a copy of the data frame, for fear of running out of memory. Pass-by-reference would make implementing data transformations so much easier that I don't really understand how pass-by-value became the standard. (If there's a trick to doing in-place transformations, I've not found it.) Because R processes objects in memory I also would not rate it as as strong as some other packages on very large data sets but you can use databases which may make it less important in some cases and you can get a certain amount of mileage out of R environments and as 64 bit computers become commonplace and memory sizes grow larger and larger data sets will become easy to handle. Regarding environments, also available are proto objects from the proto package which are environments with slightly different semantics. Even if you don't intend to use the proto package its got quite a bit of documentation and supporting information that might be helpful: - home page: http://code.google.com/p/r-proto/ - overview (click on Wiki tab at home page) which includes article links that discuss OO and environments - tutorial, reference card, reference manual, vignette (see Links box) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [Fwd: Re: regular expression]
---BeginMessage--- Uwe Ligges a écrit : I guess your problem has been solved by last night's discussion with Gabor G.? Uwe Ligges Laurent Rhelp wrote: Uwe Ligges a écrit : Laurent Rhelp wrote: Uwe Ligges a écrit : Laurent Rhelp wrote: Dear R-List, I have a great many files in a directory and I would like to replace in every file the character by the character ' and in the same time, I have to change ' by '' (i.e. the character ' twice and not the unique character ) when the character ' is embodied in . So, . becomes '.' and .'.. becomes '.''..' Certainly, regular expression could help me but I am not able to use it. How can I do that with R ? In fact, you do not need to know anything about regular expressions in this case, since you are simply going to replace certain characters by others without any fuzzy restrictions: x - \.'..\ cat(x, \n) xn - gsub('', ', gsub(', '', x)) cat(xn, \n) Uwe Ligges Thank you very much __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Yes, You are right. So I wrote the code below (that I find a little awkward but it works). ##- dirdata - getwd() fichnames - list.files(path=paste(dirdata,\\initial\\,sep=)) see ?file.path to improve the above. for( i in 1:length(fichnames)){ see ?seq to improve the above: seq(along = fichnames) Or even better, just work on the names (see below). filein - paste(dirdata,\\initial\\,fichnames[i],sep=) again, file.path() is your friend conin - file(filein) open(conin) nbrows - length( readLines(conin,n=-1) ) close(conin) You can simply use readLines() with the filename which open the connection to a file itself. And I do not see why you want to read the file here. Since your code becomes really complicated now, let me suggest the following procedure (untested!): dirdata - getwd() fichnames - list.files(file.path(dirdata, initial)) for(i in fichnames){ temp - readLines(file.path(dirdata, initial, i)) temp - gsub('', ', gsub(', '', temp)) writeLines(temp, con = file.path(dirdata, result, i)) } Uwe Ligges fileout - paste(dirdata,\\result\\,fichnames[i],sep=) conout - file(fileout,w) conin - file(filein) open(conin) for( l in 1:nbrows ) { text - gsub('',',gsub(','',readLines(conin,n=1))) writeLines(con=conout,text=text) } close(conin) close(conout) } ##-- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Dear Uwe, The code doesn't do what I want because I want to replace ' by '' only when the character ' is embodied in .. So : 1. becomes ' 2. .'.. becomes '..''..' 3. but '...' has to stay '...' and not ''..'' Did I miss something ? Yes, Gabor gave me the end of the solution. Thank you Uwe and Gabor. For the people who are interested in the solution I will recapitulate below the differents steps. The objective was to replace in a lot of files single quotes in double quoted strings with single quoted strings containing double quotes in place of the single quotes. We have to allow for the fact that the pattern can be written on several lines in the files. Let us list the steps to realize that : 1. read the lines of every file in a vector of strings (readLines) 2. transform this vector in a string with multiple lines (paste(,collapse=\n) 3. use a regular expression on this string to do the replacement 4. go back to a vector of strings (strsplit) to have again the initial file altered 5. write the new file ##-- library(gsubfn) squote - ' # single quote. # This is a double quote, single quote, double quote dquote - '' # double quote #This is a single quote, double quote, single quote f - function(x) chartr(paste(squote, dquote), paste(dquote, squote), x) dirdata - getwd() # not necessary fichnames - list.files(file.path(dirdata, \\initial),pattern=.PRC$) # to select only the files with .PRC extension for example for(i in fichnames){ Lines - readLines(file.path(dirdata, \\initial, i)) temp - gsubfn('[][^]*[]', f, paste(Lines, collapse = \n)) Lines - unlist(strsplit(temp,\n)) # strsplit returns a list not a character vector writeLines(Lines, con = file.path(dirdata, \\result, i)) } Thank you very much again. ---End Message---
[R] How do I back transforme ordinary log-krigged prdiction values?
I have a question to everybody. After log10 transfprmation, I have done ordinary kriging in gstat in R? I need to back trnasform the prediction values to orgiginal scale. How do I do this in gstat in R? Thanks Zia -- Zia Uddin Ahmed 915 Brad Field Hall Department of Crop and Soil Cornell University Ithaca NY 14850 USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot symbols dimensions
I am writing some code to obtain publication-like plots (like the ones can be obtained with SigmaPlot). I am not able to find the dimensions of a point. Parameters like cex make you able to make it bigger or smaller but I need to know the exact dimension (in relative coordinates : if my plot is 640x480 a dot plotted with cex=1.5 will be...) Massimo Cressoni __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reasons to Use R
Dear Johann and Gabor, It's what amounts to large datasets. There are hundreds of datasets R can't handle, probably thousands or more. I noticed on my computer (which is nothing more that an average PC) that R breaks down after 250 MB of memory. I also note that SPSS breaks down, Matlab, etc. I'm not a SAS user, but I have worked in the past with SAS. It's very good as a remember, but it's ten years ago. And it's a dollar machine I've been told: you add dollars to SAS as you add dollars to a Porsche. I haven't got it and for most statistical applications it isn't necessary I've been told. R is sufficient for that. The datasets I use are often not that big (the way I like it). About three years ago I spoke to somebody who has worked with it and said it's database system is excellent and statistical profound. Someone with a PhD, so probably he is right. Monte-Carlo simulations are computationally time-consuming, but probably these can be done in R. I haven't seen any libaries for it (they might be there). It has been done with S (the commercial counterpart of R), so probably with R too. If you tie Monte Carlo simulaton with large datasets you probably run into problems with a conventional R system. What I've been told in those instances is buy a new computer / add memory and buy a new processor... and don't smoke hashiesh. That wasn't a good advice because the guy who told me smoked hashiesh like hell and drank Pastis (blue liqor) like water. I kicked him out. But that's another story. Cheers, Wilfred (I drink wine and tailor made beer, and only on occasions. That's why. His simulations were good I've been told.) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Could not fit correct values in discriminant analysis by bruto.
Dear R-users, I would like to use bruto function in mda package for flexible discriminant analysis. Then, I tried, for example, following approach. x band1 band2band3 1 -1.206780 -1.448007 -1.084431 2 -0.294938 -0.113222 -0.95 3 -0.267303 -0.241567 -1.040979 4 -1.206780 -1.448007 -1.040979 5 -1.151518 -0.806286 -0.671630 6 -1.179146 -1.396670 -1.453775 7 -0.294938 -0.241567 -1.453775 8 -0.350200 -0.267239 -1.084431 9 -1.151518 -0.857623 -0.649901 10 1.362954 -1.396670 -2.235926 11 -0.239675 1.118883 1.457551 12 -0.294938 -1.268325 -0.497817 13 -0.294938 -0.729278 -0.106745 14 -1.123883 -0.703612 -0.150196 15 0.616905 1.144548 -0.150196 16 -0.267303 1.657930 1.044750 17 1.611637 1.041874 0.610225 18 -1.123883 -0.677941 0.262605 19 -0.239675 -0.626604-0.128473 20 2.274797 1.118883 1.805171 y [1] 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 fit - bruto(x,y) But, obtained fit$fitted.values are enormously high (or low) . Execution of bruto(x[,2:3], y) is done well (values are nearly 1 or 0). Values of column 1 are wrong or appropriate option is needed? I contacted the package maintainer, but the problem could not be solved. Thanks Shuji Kawaguchi R.version platform i386-apple-darwin8.8.1 arch i386 os darwin8.8.1 system i386, darwin8.8.1 version.string R version 2.4.0 (2006-10-03) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Repeated Measures design using lme
Hi, I have what I believe is a repeated-measures dataset that I'm trying to analyze using lme(). This is *not* homework, but an exercise in my trying to self-teach myself repeated-measure ANOVA for other *real* datasets that I have and that are extremely similar to the following design. I'm fairly sure the dataset described below would work with lme() -- but it'd be great if anybody can confirm that after I describe the dataset below) The study involves measuring the effect of a drug on blood pressure. There were 16 patients in all and 6 replicate measures per patient of their blood pressure on one week (one measure per day). Two weeks later, a drug was introduced to 8 randomly selected patients in such a way that I had equal representation of the 4 age groups among the two treatment groups. Then, another two weeks later, 6 replicate measures per patient (per day) of blood pressure was retaken. So each patient had 12 total measures whether they were in the treatment group or in the control group (6 reads (R1-R6) in the baseline-week and another 6 reads (R1-R6) in the post-treatment week). So, Background: 16 patients Response measure: Blood pressure Fixed Factor: 4 Age groups Fixed Factor: Drug vs. NoDrug Random factor: Day of the read (i.e. 6 replicate reads (R1-R6) at the baseline time, and 6 replicate reads (R1-R6) after the drug has had time to take effect) Random Factor: Subjects 1-16 PatientAgeGroupBP(Blood Pressure)Read (replicate reads) Pre/PostTreatmentWeekGroup 120-2983 R1 preTreat 220-2981 R1 preControl 320-2974 R1 preTreat 420-2985 R1 preControl 530-3982 R1 preTreat ……………… 320-2974 R2 preTreat ……………… 120-2983 R1 post Treat 220-2982 R1 post Control 320-2986 R1 post Treat 420-2984 R1 post Control ……………… I'm trying to do an analysis of variance to decide whether there is a measurable change in blood pressure between the Treat and Control groups. Another issue is that some of the 16 patients didn't get all 6 replicate reads in their pre/post treatment weeks, so I need to include the na.omit function. What I think I'm having the most trouble with is the repeated reads (R1 through R6) in the pre/post treatment weeks. I'm fairly sure this is a random variable -- their order or identify (R1 in pre-treatment week has no relation to R1 in the post-treatment week, etc). By placing Read as a random variable, am I covering myself there? If I execute: summary(lme(BP ~ Group, random = ~ 1 | Patient, data = bloodpress, na.action=na.omit)) I get a result, but I'm not sure it's correct -- do I need to tell the model about the Read factor (R1-R6 in pre/post weeks)? I'm really trying to set the right form of the lme() function call to decide 1) if there is a statistical difference between the Treat/Control groups and, 2) if one takes into account AgeGroup, is there a statistical difference between Treat/Control Groups, and finally 3) if I don't see a statistical difference, can someone recommend an R function that might solve the supplemental question, given the noise in day-to-day blood pressure reads, and given that I wanted to have enough statistical power to observe a say, a 5% benefit in blood pressure, how many additional reads or patients I would need. Basically, is lme() the proper function, and can someone offer any pointers on what my call to this function should look like to make the above to determinations? Thanks! -Scott __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE
[R] R:Maximum likelihood estimation using BHHH and BFGS
Dear R users, I am new to R. I would like to find *maximum likelihood estimators for psi and alpha* based on the following *log likelihood function*, c is consumption data comprising 148 entries: fn-function(c,psi,alpha) { s1-sum(for(i in 1:n){(c[i]-(psi^(-1/alpha)*(lag(c[i],-1^2* (lag(c[i],-1)^((-2)*(alpha+1)) )}); s2- sum(for(m in 1:n){log(lag(c[m],-1)^(((2)*alpha)+2))}); constant-(74*s1)-(1/2)*s2} In particular I want to use the BHHH and the BFGS algorithms. I have found the following packages that can be used for the task: *mle{stats4}, optim{stats}, maxBHHH{micEcon}, maxBFGS{micEcon}*. I have documented some of my attempts below ((a) package name (b) usage (c) my attempt and corresponding error). In all humility I apologise for any bad coding, and ask if anyone can *direct me in finding these estimators*. Yours sincerely. *(1a) mle{stats4} (b) Usage: mle(minuslogl, start = formals(minuslogl), method = BFGS, fixed = list(), ...) (For this I use the negative of the log-likelihood function,bn)* *(c) mle(start=list(psi=1,alpha=0),fn, method=BFGS,fixed=list(c=c))* Error in optim(start, f, method = method, hessian = TRUE, ...) : non-finite finite-difference value [1] *(2a) optim{stats} (b) optim(par, fn, gr = NULL, method = c(Nelder-Mead, BFGS, CG, L-BFGS-B, SANN),* * lower = -Inf, upper = Inf, control = list(), hessian = FALSE, ...) (c) optim(c(c,1,0),fn, method=BFGS, control=list(c=c))* Error: argument psi is missing, with no default *(3a) maxBHHH{micEcon} (b) Usage: maxBHHH(fn, grad = NULL, hess=NULL, theta, print.level = 0, iterlim = 100, ...)* * * *(c) maxBHHH(fn(c,psi,alpha),theta=list(psi=1,alpha=0))* Error in psi^(-1/alpha) * (lag(c[i], -1)) : time-series/vector length mismatch (4a) maxBFGS{micEcon} (b) Usage: maxBFGS(fn, grad = NULL, theta, print.level = 0, iterlim = 200, tol = 1e-06, ... ) *(ci) maxBFGS(fn(c,psi,alpha),theta=list(psi=1,alpha=0))* Error in psi^(-1/alpha) * (lag(c[i], -1)) : time-series/vector length mismatch *(cii) maxBFGS(fn,theta=list(psi=1,alpha=0))* Error: argument psi is missing, with no default [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dealing with large nominal predictor in sem package
Hi, I am using tsls function from sem package to estimate a model which includes large number of data. Among its predictors, it has a nominal data which has about 10 possible values. So I expand this parameter into 9-binary-value predictors with the coefficient of base value equals 0. I also have another continuous predictor. The problem is that, whenever I run the tsls, I will get 'System is computationally singular' error all the time. I'm wondering if there is anyway that I can overcome this problem? Please kindly suggest. Thank you so much in advance. - adschai [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.