Re: [R] A question about R environment
Francois (sorry can't type the right letter) , thanks a million for the detailed response, you have really cool functions there ! Philippe : I will definitely follow your advice later, but I got some time pressure from the current project, so have to go with the easy sol. now , thanks a lot. Happy new year every one! cheers tong - Original Message - From: Philippe Grosjean [EMAIL PROTECTED] Date: Monday, January 8, 2007 10:09 pm Subject: Re: [R] A question about R environment To: François Pinard [EMAIL PROTECTED], Tong Wang [EMAIL PROTECTED], R help r-help@stat.math.ethz.ch Please, don't reinvent the wheel: putting functions in a dedicated environment is one of the things done by R packages (together with a good documentation of the function, and making them easily installable on any R implementation). So, this is probably the time for you to read the Writing R extensions manual, and to start implementing your own R package! Best, Philippe Grosjean François Pinard wrote: [Tong Wang] I created environment mytoolbox by : mytoolbox - new.env(parent=baseenv()). Is there anyway I put it in the search path? In a project, I often write some small functions, and load them into my workspace directly, so when I list the objects with ls(), it looks pretty messy. So I am wondering if it is possible to creat an environment, and put these tools into this environment. For example, I have functions fun1(), fun2() ... and creat an environment mytoolbox which contains all these functions. And it should be somewhere in the search path: .GlobalEnv mytoolbox package:methods. Here is a trick, shown as a fairly simplified copy of my ~/.Rprofile. It allows for a few simple functions always available, yet without having to create a package, and leaving ls() and any later .RData file unencumbered. The idea is to use local() to prevent any unwanted clutter to leak out (my real ~/.Rprofile holds more than shown below and use temporary variables), to initialise a list meant to hold a bunch of functions or other R things, and to save that list on the search path. This example also demonstrate a few useful functions for when I read the R mailing list. I often need to transfer part of emails containing code excerpts within the window where R executes, while removing quotation marks, white lines and other noise. I merely highlight- select part of the message with the mouse, and then, within R, do things like: xs() source the highlighted region xd() read in a data.frame xm() read in a matrix xe() evaluate and print an expression xv() read a list of values as a vector The list above in decreasing order of usefulness (for me). Except for xs(), which has no automatic printout, you may either let the others print what they got, or assign their value to some variable. Arguments are also possible, for example like this: xd(T) read in a data.frame when the first line holds column names if (interactive()) { local({ fp.etc - list() fp.etc$xsel.vector - function (...) { connexion - textConnection(xselection()) on.exit(close(connexion)) scan(connexion, ...) } fp.etc$xsel.dataframe - function (...) { connexion - textConnection(xselection()) on.exit(close(connexion)) read.table(connexion, ...) } fp.etc$xsel.matrix - function (...) { connexion - textConnection(xselection()) on.exit(close(connexion)) data.matrix(read.table(connexion, ...)) } fp.etc$xsel.eval - function (...) { connexion - textConnection(xselection()) on.exit(close(connexion)) eval(parse(connexion, ...)) } fp.etc$xsel.source - function (...) { connexion - textConnection(xselection()) on.exit(close(connexion)) source(connexion, ...) } fp.etc$xselection - function () { lignes - suppressWarnings(readLines('clipboard')) lignes - lignes[lignes != ''] stopifnot(length(lignes) != 0) marge - substr(lignes, 1, 1) while (all(marge %in% c('', '+', ':', '|')) || all(marge == ' ')) { lignes - substring(lignes, 2) marge - substr(lignes, 1, 1) } lignes } fp.etc$xv - fp.etc$xsel.vector fp.etc$xd - fp.etc$xsel.dataframe fp.etc$xm - fp.etc$xsel.matrix fp.etc$xe - fp.etc$xsel.eval fp.etc$xs - fp.etc$xsel.source attach(fp.etc, warn=FALSE) }) } # vim: ft=r
Re: [R] A question about R environment
Hi, Thanks a lot for your response, but it is strange that when I do attach() , I got the follow error: Error in attach(e) : attach only works for lists and data frames Any suggestions on this? tong - Original Message - From: Henrik Bengtsson [EMAIL PROTECTED] Date: Monday, January 8, 2007 10:40 pm Subject: Re: [R] A question about R environment To: Gabor Grothendieck [EMAIL PROTECTED] Cc: Tong Wang [EMAIL PROTECTED], R help r-help@stat.math.ethz.ch sourceTo() in R.utils will allow you to source() a file into an environment. /Henrik On 1/9/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: e - new.env() e$f - function(x)x attach(e) search() [1] .GlobalEnve package:stats [4] package:graphics package:grDevices package:utils [7] package:datasets package:methods Autoloads [10] package:base f function(x)x On 1/8/07, Tong Wang [EMAIL PROTECTED] wrote: Hi all, I created environment mytoolbox by : mytoolbox - new.env(parent=baseenv()) Is there anyway I put it in the search path ? If you need some background : In a project, I often write some small functions, and load them into my workspace directly, so when I list the objects with ls(), it looks pretty messy. So I am wondering if it is possible to creat an environment, and put these tools into this environment. For example, I have functionsfun1(), fun2() ..and creat an environment mytoolbox which contains all these functions. And it should be somewhere in the search path: .GlobalEnvmytoolbox package:methods __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R- project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Multivariate OLS
Dear all R users, Suppose I have a VECTOR of time series y[t] consists of 2000 data point. For example suppose I have data frame which has two columns. First column represents a time series of exchange rate for 2000 days. And the second column represents the price of a commodity for the same period. Now I want to fit a OLS regression like that, y[t] = a + b*delta[y[t-1]] + c*delta[y[t-2]] + epsilon[t] as y[t] is not a vector rather a data frame containing two columns I could not use lm() function. Can anyone give me any idea how to do that in R? Thanks and regards, jon Send instant messages to your online friends http://uk.messenger.yahoo.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] Cross-compilation of R and ld bug ?
Not sure to really understand 1) . The makefile (available at http://cran.r-project.org/doc/contrib/Makefile-rcb) use wget --passive-ftp http://www.stats.ox.ac.uk/pub/Rtools/mingw-cross5.tar.bz2; This version seems to be the current, I am correct ? Note that : [EMAIL PROTECTED]:~/Rdev/CrossCompileBuild$ cross-tools/bin/i586-mingw32-ld -v GNU ld version 2.16.91 20050827 [EMAIL PROTECTED]:~/Rdev/CrossCompileBuild$ cross-tools/i586-mingw32/bin/ld -v GNU ld version 2.16.91 20050827 However, I have use R-2.4.1 and everything seems ok. Thanks. Prof Brian Ripley wrote: There are two problems here: 1) your binutils is not current. 2) your R is not current. Updating either will solve this, but please update both. Almost up-to-date cross-compilers are (as ever) available from http://www.stats.ox.ac.uk/pub/Rtools/ (If you want to compile R-devel you will need to update the mingw, which can be done from the i386 distribution. I will rebuild the cross-compilers in due course.) On Mon, 8 Jan 2007, Stéphane Dray wrote: Hello list, I would like to cross-compile R packages using R 2.4.0. I am working on Linux Debian and cross-compiled (windows binaries) without problems with older R version. I have used the doc of Yan and Rossini in the contributed section of the R documentation (same version of MinGW...). When I try to cross-compile R (make R), the procedure stopped and returns : i586-mingw32-windres --include-dir ../include -i dllversion.rc -o dllversion.o i586-mingw32-gcc -shared -s -mwindows -o R.dll R.def console.o dataentry.o dynl oad.o edit.o editor.o embeddedR.o extra.o opt.o pager.o preferences.o psignal.o rhome.o rui.o run.o shext.o sys-win32.o system.o e_pow.o malloc.o ../main/libmai n.a ../appl/libappl.a ../nmath/libnmath.a graphapp/ga.a getline/gl.a ../extra/xd r/libxdr.a ../extra/zlib/libz.a ../extra/pcre/libpcre.a ../extra/bzip2/libbz2.a ../extra/intl/libintl.a ../extra/trio/libtrio.a dllversion.o -L. -lg2c -lRblas - lcomctl32 -lversion ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1703): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1740): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1848): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x187f): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1966): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1f2a): more un defined references to `__pcre_ucp_findprop' follow collect2: ld returned 1 exit status make[4]: *** [R.dll] Erreur 1 make[3]: *** [../../bin/R.dll] Erreur 2 make[2]: *** [rbuild] Erreur 2 make[1]: *** [all] Erreur 2 make[1]: quittant le répertoire « /home/stephane/Rdev/CrossCompileBuild/WinR/R-2 .4.0/src/gnuwin32 » I have read (http://www.murdoch-sutherland.com/Rtools/) that a bug exists for ld version 2.16.91 20050827 and that Prof Ripley produced a patched version. It seems that my problem is also related to ld (and I have the same version). So I wonder if the same bug could be responsible of the error in the cross-compiler. Two questions: - Are they other people which have the same problem when cross-compiling R on Linux - Is it possible that the problem is related to ld. If yes, is it possible to obtain a patched version ? Thanks in advance. Sincerely, -- Stéphane DRAY ([EMAIL PROTECTED] ) Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I 43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France Tel: 33 4 72 43 27 57 Fax: 33 4 72 43 13 88 http://biomserv.univ-lyon1.fr/~dray/ __ 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] Cross-compilation of R and ld bug ?
On Tue, 9 Jan 2007, Stéphane Dray wrote: Not sure to really understand 1) . The makefile (available at http://cran.r-project.org/doc/contrib/Makefile-rcb) use wget --passive-ftp http://www.stats.ox.ac.uk/pub/Rtools/mingw-cross5.tar.bz2; This version seems to be the current, I am correct ? Note that : Well, those tools built 2.4.0 for me, but earlier versions of mingw-cross5.tar.bz2 did not because bintools was too old. So assuming you didn't get a cached older file, I don't understand. [EMAIL PROTECTED]:~/Rdev/CrossCompileBuild$ cross-tools/bin/i586-mingw32-ld -v GNU ld version 2.16.91 20050827 [EMAIL PROTECTED]:~/Rdev/CrossCompileBuild$ cross-tools/i586-mingw32/bin/ld -v GNU ld version 2.16.91 20050827 However, I have use R-2.4.1 and everything seems ok. Thanks. Prof Brian Ripley wrote: There are two problems here: 1) your binutils is not current. 2) your R is not current. Updating either will solve this, but please update both. Almost up-to-date cross-compilers are (as ever) available from http://www.stats.ox.ac.uk/pub/Rtools/ (If you want to compile R-devel you will need to update the mingw, which can be done from the i386 distribution. I will rebuild the cross-compilers in due course.) On Mon, 8 Jan 2007, Stéphane Dray wrote: Hello list, I would like to cross-compile R packages using R 2.4.0. I am working on Linux Debian and cross-compiled (windows binaries) without problems with older R version. I have used the doc of Yan and Rossini in the contributed section of the R documentation (same version of MinGW...). When I try to cross-compile R (make R), the procedure stopped and returns : i586-mingw32-windres --include-dir ../include -i dllversion.rc -o dllversion.o i586-mingw32-gcc -shared -s -mwindows -o R.dll R.def console.o dataentry.o dynl oad.o edit.o editor.o embeddedR.o extra.o opt.o pager.o preferences.o psignal.o rhome.o rui.o run.o shext.o sys-win32.o system.o e_pow.o malloc.o ../main/libmai n.a ../appl/libappl.a ../nmath/libnmath.a graphapp/ga.a getline/gl.a ../extra/xd r/libxdr.a ../extra/zlib/libz.a ../extra/pcre/libpcre.a ../extra/bzip2/libbz2.a ../extra/intl/libintl.a ../extra/trio/libtrio.a dllversion.o -L. -lg2c -lRblas - lcomctl32 -lversion ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1703): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1740): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1848): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x187f): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1966): undefin ed reference to `__pcre_ucp_findprop' ../extra/pcre/libpcre.a(pcre_dfa_exec.o):pcre_dfa_exec.c:(.text+0x1f2a): more un defined references to `__pcre_ucp_findprop' follow collect2: ld returned 1 exit status make[4]: *** [R.dll] Erreur 1 make[3]: *** [../../bin/R.dll] Erreur 2 make[2]: *** [rbuild] Erreur 2 make[1]: *** [all] Erreur 2 make[1]: quittant le répertoire « /home/stephane/Rdev/CrossCompileBuild/WinR/R-2 .4.0/src/gnuwin32 » I have read (http://www.murdoch-sutherland.com/Rtools/) that a bug exists for ld version 2.16.91 20050827 and that Prof Ripley produced a patched version. It seems that my problem is also related to ld (and I have the same version). So I wonder if the same bug could be responsible of the error in the cross-compiler. Two questions: - Are they other people which have the same problem when cross-compiling R on Linux - Is it possible that the problem is related to ld. If yes, is it possible to obtain a patched version ? Thanks in advance. Sincerely, -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A question about R environment
On Tue, 9 Jan 2007, Tong Wang wrote: Hi, Thanks a lot for your response, but it is strange that when I do attach() , I got the follow error: Error in attach(e) : attach only works for lists and data frames Any suggestions on this? Update your R, as the posting guide asked you to in this circumstance. This was new in R 2.4.0. You don't need the baggage of the R.utils package here: the base function sys.source loads into an environment. So the definitive way to do this is env - attach(NULL, name = myenv) sys.source(some file, env) and that has worked since well before 2.0.0. tong - Original Message - From: Henrik Bengtsson [EMAIL PROTECTED] Date: Monday, January 8, 2007 10:40 pm Subject: Re: [R] A question about R environment To: Gabor Grothendieck [EMAIL PROTECTED] Cc: Tong Wang [EMAIL PROTECTED], R help r-help@stat.math.ethz.ch sourceTo() in R.utils will allow you to source() a file into an environment. /Henrik On 1/9/07, Gabor Grothendieck [EMAIL PROTECTED] wrote: Try this: e - new.env() e$f - function(x)x attach(e) search() [1] .GlobalEnve package:stats [4] package:graphics package:grDevices package:utils [7] package:datasets package:methods Autoloads [10] package:base f function(x)x On 1/8/07, Tong Wang [EMAIL PROTECTED] wrote: Hi all, I created environment mytoolbox by : mytoolbox - new.env(parent=baseenv()) Is there anyway I put it in the search path ? If you need some background : In a project, I often write some small functions, and load them into my workspace directly, so when I list the objects with ls(), it looks pretty messy. So I am wondering if it is possible to creat an environment, and put these tools into this environment. For example, I have functionsfun1(), fun2() ..and creat an environment mytoolbox which contains all these functions. And it should be somewhere in the search path: .GlobalEnvmytoolbox package:methods __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R- project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R scripts to plot Taylor Diagram
Happy New Year, dear useRs...and Linda. I have a small toy-script that plots Taylor Diagrams for vectors, it is not wonderful but may help... perhaps you can change some details for your own needs. It is far from optimization,... perhaps someone can do this and put it into a package ? Hope this helps. Regards. Olivier # fonction TAYLOR # construction d'un diagramme de Taylor # Taylor K.E. Summarizing multiple aspects of model performance in a single diagram # J. Geophys. Res., 106, 7183-7192, 2001 # version 1.0 # progr. Olivier.Eterradossi, 12/2007 Taylor-function(ref,batch,add=F,couleur=red){ # ref, batch : vecteurs x- ref y- batch grad.corr.full-c(0,0.2,0.4,0.6,0.8,0.9,0.95,0.99,1) grad.corr.lines-c(0.2,0.4,0.6,0.8,0.9) R-cor(x,y,use=pairwise) sd.r-sd(x) sd.f-sd(y) if (add==F) { # pourtour du diagramme maxray-1.5*max(sd.f,sd.r) plot(c(-maxray,maxray),c(0,maxray),type=n,asp=1,bty=n,xaxt=n,yaxt=n,xlab=,ylab=,main=Taylor Diagram) discrete-seq(180,0,by=-1) listepoints-NULL for (i in discrete){ listepoints-cbind(listepoints,maxray*cos(i*pi/180),maxray*sin(i*pi/180)) } listepoints-matrix(listepoints,2,length(listepoints)/2) listepoints-t(listepoints) lines(listepoints[,1],listepoints[,2]) # axes x,y lines(c(-maxray,maxray),c(0,0)) lines(c(0,0),c(0,maxray)) # lignes radiales jusqu'à R = +/- 0.8 for (i in grad.corr.lines){ lines(c(0,maxray*i),c(0,maxray*sqrt(1-i^2)),lty=3) lines(c(0,-maxray*i),c(0,maxray*sqrt(1-i^2)),lty=3) } # texte radial for (i in grad.corr.full){ text(1.05*maxray*i,1.05*maxray*sqrt(1-i^2),i,cex=0.6) text(-1.05*maxray*i,1.05*maxray*sqrt(1-i^2),-i,cex=0.6) } # sd concentriques autour de la reference seq.sd-seq.int(0,2*maxray,by=(maxray/10)) for (i in seq.sd){ xcircle-sd.r+(cos(discrete*pi/180)*i) ycircle-sin(discrete*pi/180)*i for (j in 1:length(xcircle)){ if ((xcircle[j]^2+ycircle[j]^2)(maxray^2)){points(xcircle[j],ycircle[j], col=darkgreen,pch=.) if (j==10){text(xcircle[j],ycircle[j],signif(i,2),cex=0.5,col=darkgreen)}} } } # sd concentriques autour de l'origine seq.sd-seq.int(0,maxray,length.out=5) for (i in seq.sd){ xcircle-(cos(discrete*pi/180)*i) ycircle-sin(discrete*pi/180)*i lines(xcircle,ycircle,lty=3,col=blue) text(min(xcircle),-0.03*maxray,signif(i,2),cex=0.5,col=blue) text(max(xcircle),-0.03*maxray,signif(i,2),cex=0.5,col=blue) } text(0,-0.08*maxray,Standard Deviation,cex=0.7,col=blue) text(0,-0.12*maxray,Centered RMS Difference,cex=0.7,col=darkgreen) points(sd.r,0,pch=22,bg=darkgreen,cex=1.1) text(0,1.1*maxray,Correlation Coefficient,cex=0.7) } # placer les points points(sd.f*cos(acos(R)),sd.f*sin(acos(R)),pch=21,bg=couleur,cex=0.8) } -- Olivier ETERRADOSSI Maître-Assistant CMGD / Equipe Propriétés Psycho-Sensorielles des Matériaux Ecole des Mines d'Alès Hélioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 tel std: +33 (0)5.59.30.54.25 nouveau tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 http://www.ema.fr __ 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] Random effects and level 1 censoring
I have a question about constructing the likelihood function where there is censoring at level 1 in a two-level random effects sum. In a conventional solution, the likelihood function is constructed using the density for failures and the survivor function for (in this case, right) censored results. Within (for example) an R environment, this is easy to do and gives the same solution as survreg even if it is a little heavy. But where there is an hierarchical situation, we need to consider the contributions at level 2. y_ij=X_ij.beta'+err2_i+err1_ij If all the units at level 1 for a given level 2 are censored, then the information we have for the level 2 is itself censored and we should presumably use the survivor function. Conversely if none of the units at level 1 are censored, then the information at level 2 is complete and the density should be used. But what do we do if only some of the level 1 units for a given level 2 are censored? My instinct is to weight the density and survivor functions for that given level 2 case according to the proportion of level 1 failures. Am I right? For a number of reasons I don't want to code for specific distributions and I am quite happy to use a sledge hammer to crack a walnut with optim().:) Best wishes John John Logsdon Try to make things as simple Quantex Research Ltd, Manchester UK as possible but not simpler [EMAIL PROTECTED] [EMAIL PROTECTED] +44(0)161 445 4951/G:+44(0)7717758675 www.quantex-research.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] contingency table analysis; generalized linear model
Dear List, I would appreciate help on the following matter: I am aware that higher dimensional contingency tables can be analysed using either log-linear models or as a poisson regression using a generalized linear model: log-linear: loglm(~Age+Site, data=xtabs(~Age+Site, data=SSites.Rev, drop.unused.levels=T)) GLM: glm.table - as.data.frame(xtabs(~Age+Site, data=SSites.Rev, drop.unused.levels=T)) glm(Freq ~ Age + Site, data=glm.table, family='poisson') where Site is a factor and Age is cast as a factor by xtabs() and treated as such. **Question**: Is it acceptable to step away from contingency table analysis by recasting Age as a numerical variable, and redoing the analysis as: glm(Freq ~ as.numeric(Age) + Site, data=glm.table, family='poisson') My reasons for wanting to do this are to be able to include non-linear terms in the model, using say restricted or natural cubic splines. Thank you in advance for your help. Regards, Mark Difford. --- Mark Difford Ph.D. candidate, Botany Department, Nelson Mandela Metropolitan University, Port Elizabeth, SA. __ 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] Multivariate OLS
Dear David, Thank you very much for this reply. But unfortunately it is not that I want. In my equation 'a' is a vector with length 2, 'b' and 'c' are matrix with row and columns 2. It is like Vector Autoregressive model, but there is some difference between that model and my model. Is there any suggestion? Thanks and regards, - Original Message From: David Barron [EMAIL PROTECTED] To: r400 r400 [EMAIL PROTECTED] Sent: Tuesday, January 9, 2007 3:15:27 PM Subject: Re: [R] Multivariate OLS I don't understand the problem; why can't you use lm with a data frame? Is something like this what you are after? dat - data.frame(y=rnorm(100),x=rnorm(100,5)) dif1 - diff(dat[,1]) dif2 - diff(dat[,1],lag=2) lm(y ~ dif1[-1] + dif2, data=dat[-(1:2),]) On 08/01/07, r400 r400 [EMAIL PROTECTED] wrote: Dear all R users, Suppose I have a VECTOR of time series y[t] consists of 2000 data point. For example suppose I have data frame which has two columns. First column represents a time series of exchange rate for 2000 days. And the second column represents the price of a commodity for the same period. Now I want to fit a OLS regression like that, y[t] = a + b*delta[y[t-1]] + c*delta[y[t-2]] + epsilon[t] as y[t] is not a vector rather a data frame containing two columns I could not use lm() function. Can anyone give me any idea how to do that in R? Thanks and regards, jon Send instant messages to your online friends http://uk.messenger.yahoo.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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ 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] logistic regression in R - changing defaults
Hello, I was hoping for some advice in changing 2 defaults in a logistic regression. 1. It looks like the first category is the reference category? In the following syntax 'where' has 4 levels, how can I make the reference category the third category? model- glm(cbind(sucesses, failures) ~ where + who + firstep + dxnarrow + age + sex + medyear, family = binomial, data=life.use) model 2. Is it possible to round results to 4 decimal points? If so, what syntax is required? Any assistance is appreciated, Bob Green __ 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] logistic regression in R - changing defaults
an option is to use ?relevel(), e.g., life.use$where. - relevel(life.use$where, 3) model- glm(cbind(sucesses, failures) ~ where. + who + firstep + dxnarrow + age + sex + medyear, family = binomial, data = life.use) print(model, digits = 1) print(model, digits = 2) print(model, digits = 3) print(model, digits = 4) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Bob Green [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, January 09, 2007 1:16 PM Subject: [R] logistic regression in R - changing defaults Hello, I was hoping for some advice in changing 2 defaults in a logistic regression. 1. It looks like the first category is the reference category? In the following syntax 'where' has 4 levels, how can I make the reference category the third category? model- glm(cbind(sucesses, failures) ~ where + who + firstep + dxnarrow + age + sex + medyear, family = binomial, data=life.use) model 2. Is it possible to round results to 4 decimal points? If so, what syntax is required? Any assistance is appreciated, Bob Green __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] a question of substitute
Hi all, I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers: fun.1 - function(formula) { summary(aov(formula)) } fun.2 - function(formula) { oneway.test(formula) } values - c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16, 24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group - rep(1:3, each=7) # While the first wrapper works just fine: fun.1(values ~ group) # the second throws an error: fun.2(values ~ group) Error in substitute(formula)[[2]] : object is not subsettable ### I also tried binding the two vectors in a data.frame, with no avail. I did find a hack, creating two new vectors inside the function and creating a fresh formula, so I presume this has something to do with environments. Could anybody give me a hint on this? Thank you, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a question of substitute
oneway.test is using substitute on its arguments so its literally getting formula rather than the value of formula. Try these: fun.3 - function(formula) { mc - match.call() mc[[1]] - as.name(oneway.test) eval.parent(mc) } fun.3(values ~ group) fun.4 - function(formula) { do.call(oneway.test, list(formula)) } fun.4(values ~ group) On 1/9/07, Adrian Dusa [EMAIL PROTECTED] wrote: Hi all, I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers: fun.1 - function(formula) { summary(aov(formula)) } fun.2 - function(formula) { oneway.test(formula) } values - c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16, 24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group - rep(1:3, each=7) # While the first wrapper works just fine: fun.1(values ~ group) # the second throws an error: fun.2(values ~ group) Error in substitute(formula)[[2]] : object is not subsettable ### I also tried binding the two vectors in a data.frame, with no avail. I did find a hack, creating two new vectors inside the function and creating a fresh formula, so I presume this has something to do with environments. Could anybody give me a hint on this? Thank you, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] memory problem --- use sparse matrices
Unfortunatelly, i have to fill all the cells, with numbers..., so I need a better machine, or i have to split the data for smaller parts, but that way is much slower, but i see i dont have other alternative way. But thanx for your help, because i work with big networks too (1 vertex), and with this package i sholuld speed up my work.. I have to simulate little world networks - Does anybody knows any package what colud make a network like that type? 2007/1/8, Martin Maechler [EMAIL PROTECTED]: UweL == Uwe Ligges [EMAIL PROTECTED] on Sun, 07 Jan 2007 09:42:08 +0100 writes: UweL Zoltan Kmetty wrote: Hi! I had some memory problem with R - hope somebody could tell me a solution. I work with very large datasets, but R cannot allocate enough memoty to handle these datasets. I want work a matrix with row= 100 000 000 and column=10 A know this is 1 milliard cases, but i thought R could handle it (other commercial software like spss could do), but R wrote out everytime: not enough memory.. any good idea? UweL Buy a machine that has at least 8Gb (better 16Gb) of UweL RAM and proceed ... Well, I doubt that Zoltan wants to *fill* his matrix with all non-zeros. If he does, Uwe and Roger are right. Otherwise, working with a *sparse* matrix, using the 'Matrix' (my recommendation, but I am biased) or 'SparseM' package, might well be feasible: install.packages(Matrix) # if needed; only once for your R library(Matrix) # each time you need it TsparseMatrix - function(nrow, ncol, i,j,x) { ## Purpose: User friendly construction of sparse Matrix from triple ## -- ## Arguments: (i,j,x): 2 integer and 1 numeric vector of the same length: ## ## The matrix M will have ## M[i[k], j[k]] == x[k] , for k = 1,2,..., length(i) ##and M[ i', j' ] == 0 for `` all other pairs (i',j') ## -- ## Author: Martin Maechler, Date: 8 Jan 2007, 18:46 nnz - length(i) stopifnot(length(j) == nnz, length(x) == nnz, is.numeric(x), is.numeric(i), is.numeric(j)) dim - c(as.integer(nrow), as.integer(ncol)) ## The conformability of (i,j) with 'dim' will be checked automatically ## by an internal validObject() that is part of new(.): new(dgTMatrix, x = x, Dim = dim, ## our Tsparse Matrices use 0-based indices : i = as.integer(i - 1:1), j = as.integer(j - 1:1)) } For example : TsparseMatrix(10,20, c(1,3:8), c(2,9,6:10), 7 * (1:7)) 10 x 20 sparse Matrix of class dgTMatrix [1,] . 7 . . . . . . . . . . . . . . . . . . [2,] . . . . . . . . . . . . . . . . . . . . [3,] . . . . . . . . 14 . . . . . . . . . . . [4,] . . . . . 21 . . . . . . . . . . . . . . [5,] . . . . . . 28 . . . . . . . . . . . . . [6,] . . . . . . . 35 . . . . . . . . . . . . [7,] . . . . . . . . 42 . . . . . . . . . . . [8,] . . . . . . . . . 49 . . . . . . . . . . [9,] . . . . . . . . . . . . . . . . . . . . [10,] . . . . . . . . . . . . . . . . . . . . But nr - 1e8 nc - 10 set.seed(1) i - sample(nr, 1) j - sample(nc, 1) x - round(rnorm(1), 2) M - TsparseMatrix(nr, nc, i=i, j=j, x=x) works, e.g. you can x - 1:10 system.time(y - M %*% x) # needs around 4 sec on one of our better machines y - as.vector(y) ## but you can become even more efficient, translating from the ## so-called triplet to the (recommended) Csparse ## representation: M. - as(M, CsparseMatrix) object.size(M) / object.size(M.) ## 1.328921; i.e. we saved 33% ## and system.time(y. - M. %*% x) # much faster (1 sec) identical(as.vector(y.), y) --- --- --- I hope this is useful to you. Martin Maechler, ETH Zurich [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a question of substitute
On Tuesday 09 January 2007 15:14, Gabor Grothendieck wrote: oneway.test is using substitute on its arguments so its literally getting formula rather than the value of formula. Ah-haa... I understand now. Thanks for the tips, they both work as expected. Best, Adrian Try these: fun.3 - function(formula) { mc - match.call() mc[[1]] - as.name(oneway.test) eval.parent(mc) } fun.3(values ~ group) fun.4 - function(formula) { do.call(oneway.test, list(formula)) } fun.4(values ~ group) On 1/9/07, Adrian Dusa [EMAIL PROTECTED] wrote: Hi all, I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers: fun.1 - function(formula) { summary(aov(formula)) } fun.2 - function(formula) { oneway.test(formula) } values - c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16, 24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group - rep(1:3, each=7) # While the first wrapper works just fine: fun.1(values ~ group) # the second throws an error: fun.2(values ~ group) Error in substitute(formula)[[2]] : object is not subsettable ### I also tried binding the two vectors in a data.frame, with no avail. I did find a hack, creating two new vectors inside the function and creating a fresh formula, so I presume this has something to do with environments. Could anybody give me a hint on this? Thank you, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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. -- Adrian Dusa Arhiva Romana de Date Sociale Bd. Schitu Magureanu nr.1 050025 Bucuresti sectorul 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a question of substitute
oneway.test expects a literal formula, not a variable containing a formula. The help page says formula: a formula of the form 'lhs ~ rhs' where 'lhs' gives the sample values and 'rhs' the corresponding groups. Furthermore, if you had foo.2 - function() oneway.test(value ~ group) it would still not work, as data: an optional matrix or data frame (or similar: see 'model.frame') containing the variables in the formula 'formula'. By default the variables are taken from 'environment(formula)'. I could show you several complicated workarounds, but why do you want to do this? On Tue, 9 Jan 2007, Adrian Dusa wrote: Hi all, I want to write a wrapper for an analysis of variance and I face a curious problem. Here are two different wrappers: fun.1 - function(formula) { summary(aov(formula)) } fun.2 - function(formula) { oneway.test(formula) } values - c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16, 24, 20, 19, 9, 17, 11, 8, 15, 6, 14) group - rep(1:3, each=7) # While the first wrapper works just fine: fun.1(values ~ group) # the second throws an error: fun.2(values ~ group) Error in substitute(formula)[[2]] : object is not subsettable ### I also tried binding the two vectors in a data.frame, with no avail. I did find a hack, creating two new vectors inside the function and creating a fresh formula, so I presume this has something to do with environments. Could anybody give me a hint on this? Thank you, Adrian -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Access, Process and Read Information from Web Sites
Not sure about R, but for a Perl example check http://yosucker.sourceforge.net/ . -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tudor Bodea Sent: Monday, January 08, 2007 11:53 AM To: r-help@stat.math.ethz.ch Cc: Tudor Bodea Subject: [R] Access, Process and Read Information from Web Sites Dear R useRs, Does any of you know if it is possible to access a web site (e.g., www.marriott.com), fill in the requested information (e.g., city, check-in date, etc), and save the results (e.g., room availability and room rates) in text files through R? I started with url and url.show but it seems that this does not do what I would like to do. Any lead would be greatly appreciated. Thanks. Tudor -- Tudor Dan Bodea Ph.D. Candidate Georgia Institute of Technology School of Civil and Environmental Engineering __ 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] a question of substitute
On Tuesday 09 January 2007 15:41, Prof Brian Ripley wrote: oneway.test expects a literal formula, not a variable containing a formula. The help page says formula: a formula of the form 'lhs ~ rhs' where 'lhs' gives the sample values and 'rhs' the corresponding groups. Furthermore, if you had foo.2 - function() oneway.test(value ~ group) it would still not work, as data: an optional matrix or data frame (or similar: see 'model.frame') containing the variables in the formula 'formula'. By default the variables are taken from 'environment(formula)'. I could show you several complicated workarounds, but why do you want to do this? Thank you for your reply. The data argument was exactly the next problem I faced. My workaround involves checking if(missing(data)) then uses different calls to oneway.test(). I am certainly interested in other solutions, this one is indeed limited. I do this for the students in the anova class, checking first the homogeneity of variances with fligner.test(), printing the p.value and based on that changing the var.equal argument in the oneway.test() It's just for convenience, but they do like having it all-in-one. Best regards, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd 050025 Bucharest sector 5 Romania Tel./Fax: +40 21 3126618 \ +40 21 3120210 / int.101 __ 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] min() return factor class values
Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e-mail. In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] limitation in the number of covariates in nlme
Thanks Brian The new version fixed the problem. Prof Brian Ripley [EMAIL PROTECTED] wrote: Please check you have the latest version of nlme (3.1-79), as some restrictions of this sort were lifted a few weeks ago. If you have, please note the advice about a minimal reproducible example in the footer of every help message as we will need one to be able to help you. On Mon, 8 Jan 2007, mohammad frarouei wrote: Dear All I am fitting a nlme model in which I have 7 covariates. Adding one more variable to the model, R gives me an error message: Error in parse(file, n, text, prompt) : syntax error in list( .. This does not depend on which variables are in the model and seems to depend strictly on the number of covariates. Any suggestion would be appreciated. M.Fararooei PhD candidate __ [[alternative HTML version deleted]] -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 __ [[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] dimensions of a all objects
Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) -- Farrel Buchinsky [[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] RSQLite NA on input
Hello I haev some .csv data files with missing values - eg below 1,'F','C04','X100',20.93,'C','B',7,8,7.5,2421,2230,2230,2,1,85,43,85,46,48,60 If I have a missing value - so file looks like ,85,46,,48, etc then RSQLite reads it as zero. ,85,46,0,48, etc I need it read it as NA. Tried various combinations with no success, adn found nothing on help site. Must be somehting very simple but . . . . Help much appreciated. Richard. __ 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] dimensions of a all objects
You need something like this: sapply(objects() , function(x)(dim(eval(parse(text = x) a - rnorm(1) b - matrix(rnorm(4), ncol = 2, nrow = 2) sapply(objects() , function(x)(dim(eval(parse(text = x) $a NULL $b [1] 2 2 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Farrel Buchinsky Verzonden: dinsdag 9 januari 2007 15:30 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] dimensions of a all objects Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) -- Farrel Buchinsky [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] min() return factor class values
Milton Cezar Ribeiro wrote: Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e-mail. min() is not doing anything out of the ordinary, but cbind'ing it with the character vector sp coerces it to character and rbind'ing to a data frame turns character vectors into factors... The whole thing looks like it could be a straightforward application of aggregate(). In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dimensions of a all objects
Farrel Buchinsky wrote: Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) 'objects()' returns character strings - the names of objects - then the dim of the character strings are all NULL. I'll assume that's what you are getting at - you've not posted an example or the output you are getting or why it 'does not work'. Maybe you want this: sapply(objects(),function(x){dim(get(x))}) $f NULL $m [1] 2 5 $x NULL $y [1] 5 2 - where m and y are matrices, f is a function, x is a scalar. Barry __ 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] min() return factor class values
Hi Milton! I don't know why, but this thing happend with me too, quite a lot times. It's a useful way that convert the value type like that: *as.numeric(as.character(min(...)))* Zoltan 2007/1/9, Milton Cezar Ribeiro [EMAIL PROTECTED]: Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e-mail. In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min (sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base __ [[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. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dimensions of a all objects
BaRow == Barry Rowlingson [EMAIL PROTECTED] on Tue, 09 Jan 2007 14:53:05 + writes: BaRow Farrel Buchinsky wrote: Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) BaRow 'objects()' returns character strings - the names of objects - then BaRow the dim of the character strings are all NULL. BaRow I'll assume that's what you are getting at - you've not posted an BaRow example or the output you are getting or why it 'does not work'. BaRow Maybe you want this: sapply(objects(),function(x){dim(get(x))}) BaRow $f BaRow NULL BaRow $m BaRow [1] 2 5 BaRow $x BaRow NULL BaRow $y BaRow [1] 5 2 BaRow - where m and y are matrices, f is a function, x is a scalar. Yes. Since he's just interested in printing, maybe ls.str() # would be even more revealing (or maybe too # confusing for a newbie) Martin __ 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] posthoc tests with ANCOVA
dear all, I want to perform a posthoc test for my ANCOVA: a1-aov(seeds~treatment*length) With summary(glht(a1, linfct = mcp(treatment = Tukey))) R tells me: covariate interactions found -- please choose appropriate contrast How do I build these contrasts? Ideally, I would like to have the posthoc test for the ANCOVA including a block-effect a2-aov(seeds~treatment*length+Error(site)) How do I make a posthoc test here? Thanks for any comments Walter -- * Dr. Walter Durka Department Biozönoseforschung Department of community ecology Helmholtz-Zentrum für Umweltforschung GmbH - UFZ Helmholtz Centre for Environmental Research - UFZ Theodor-Lieser-Str. 4 / 06120 Halle / Germany [EMAIL PROTECTED] / http://www.ufz.de/index.php?en=798 phone +49 345 558 5314 / Fax +49 345 558 5329 + Das UFZ hat einen neuen Namen: Helmholtz-Zentrum für Umweltforschung GmbH - UFZ The UFZ has a new name: Helmholtz Centre for Environmental Research - UFZ + __ 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] dimensions of a all objects
You have assumed everything as I meant it. I understand what is happening now. ls() simply creates a vector with character elements and dim() sees each element as not having dimensions. The critical part of what you have shown is the get(command) that turns what is just a string into the dataframe or vector whose name is the string. The other issue which you showed, and one that I have come across before is that sapply and tapply and lapply cannot handle a function on a function. I would have thought that I should get the same result from lapply(ls(),dim(get())) or something such as that. But instead one has to create a function command within the lapply to handle a dimension command upon a get command. On 1/9/07, Barry Rowlingson [EMAIL PROTECTED] wrote: Farrel Buchinsky wrote: Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) 'objects()' returns character strings - the names of objects - then the dim of the character strings are all NULL. I'll assume that's what you are getting at - you've not posted an example or the output you are getting or why it 'does not work'. Maybe you want this: sapply(objects(),function(x){dim(get(x))}) $f NULL $m [1] 2 5 $x NULL $y [1] 5 2 - where m and y are matrices, f is a function, x is a scalar. Barry -- Farrel Buchinsky Mobile: (412) 779-1073 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scripts with littler
Guys, thanks very much for your help. Rscript looks great and I'll look forward to it. The /usr/bin/env thing seems to be a general difficulty with the mechanism. One's first thought has to be to modify env to parse and then pass the arguments in the expected way (maybe #!/usr/bin/env2?), and of course one's second is that this must already have been done... An S of TFW produces 'Citizens for a better env', but this isn't as hopeful as it sounds. I'm actually tempted to use #!/usr/bin/env r rm(list=ls()) as the first two lines of every script, rather than messing about trying to pass options. Cheers, John. -- Contractor in Cambridge UK -- http://www.aspden.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.
[R] manipulating elements of lists
I want to manipulate lists as described below: Imagine these two lists: list1 $WR7 [1] 1 2 3 4 $YH5YH6 [1] 3 4 5 6 7 $YH4 [1] 4 5 $UC4UC8 [1] 4 5 6 7 8 9 list2 V1V2 1WR7Averrhoa 2 ? Sarcotheca 3 YH5YH6 caesia 4YH4arbuscula 5 UC4UC8rosea 6 ?acetosella How can I exchange the names(list1) by the entries in the second column of list2, if (a) length(list1) ≠ length(list2) and (b) the elements of both lists are not in the same order? Is there a easy way to do this? Thank you! Christoph Heibl PhD student 'Phylogenetics and phylogeography of endemic Atacama Desert flora' Systematic Botany Ludwig-Maximilians-Universität München Menzinger Str. 67 D-80638 München GERMANY phone: +49-(0)89-17861-251 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] RSQLite NA on input
Hi Richard, It would help if you provided a bit more on how you are going about the import (along with your version of R and RSQLite). R Gott [EMAIL PROTECTED] writes: I haev some .csv data files with missing values - eg below 1,'F','C04','X100',20.93,'C','B',7,8,7.5,2421,2230,2230,2,1,85,43,85,46,48,60 If I have a missing value - so file looks like ,85,46,,48, etc then RSQLite reads it as zero. ,85,46,0,48, etc I need it read it as NA. Tried various combinations with no success, adn found nothing on help site. Must be somehting very simple but . . . . Help much appreciated. The most flexible approach would be to use read.table to read in your csv file. Then use dbWriteTable to put the resulting data.frame object into the DB. + seth __ 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] listing all functions in R
Earl F. Glynn [EMAIL PROTECTED] writes: Prof Brian Ripley [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Here is a reasonable shot: findfuns - function(x) { if(require(x, character.only=TRUE)) { env - paste(package, x, sep=:) nm - ls(env, all=TRUE) nm[unlist(lapply(nm, function(n) exists(n, where=env, mode=function, inherits=FALSE)))] } else character(0) } pkgs - dir(.Library) z - lapply(pkgs, findfuns) names(z) - pkgs Any recommendations on how to trap problems with require when using findfuns? One bad package and the lapply above doesn't return anything. Are you sure you need to? I just tried your code above with: pkgs - c(Biobase, GOstats, flrblr, bazbaz) And while I see warning messages about the flrblr and bazbaz packages, the function completed and I get the expected results in z. Oh, perhaps you have some broken installs? Broken in the sense that you have a package installed but not its dependencies? How about this: safeRequire - function(x) { tryCatch(require(x, character.only=TRUE), error=function(e) FALSE) } And then replace the call to require in findfuns(). + seth __ 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] dimensions of a all objects
See below. On 1/9/07, Farrel Buchinsky [EMAIL PROTECTED] wrote: You have assumed everything as I meant it. I understand what is happening now. ls() simply creates a vector with character elements and dim() sees each element as not having dimensions. The critical part of what you have shown is the get(command) that turns what is just a string into the dataframe or vector whose name is the string. The other issue which you showed, and one that I have come across before is that sapply and tapply and lapply cannot handle a function on a function. I would have thought that I should get the same result from lapply(ls(),dim(get())) or something such as that. The gsubfn package can do nearly that. Just preface the function of interest (in this case sapply) with fn$ and then you can write the function as a formula: library(gsubfn) fn$sapply(c(iris, CO2), ~ dim(get(x)), simplify = FALSE) $iris [1] 150 5 $CO2 [1] 84 5 But instead one has to create a function command within the lapply to handle a dimension command upon a get command. On 1/9/07, Barry Rowlingson [EMAIL PROTECTED] wrote: Farrel Buchinsky wrote: Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) 'objects()' returns character strings - the names of objects - then the dim of the character strings are all NULL. I'll assume that's what you are getting at - you've not posted an example or the output you are getting or why it 'does not work'. Maybe you want this: sapply(objects(),function(x){dim(get(x))}) $f NULL $m [1] 2 5 $x NULL $y [1] 5 2 - where m and y are matrices, f is a function, x is a scalar. Barry -- Farrel Buchinsky Mobile: (412) 779-1073 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odfWeave and figures in MS Word Format
Laurent, Since you question was not about odfWeave (despite the message title), it would have been better to send this question to an OpenOffice mailing list. That said, I think that the issues was your workflow (odt - html - doc). HTML is plain text, so when you saved the file in that format the image files are saved separately. Links are creating in the html file to the image files. When you converted the html to Word format, the images are still linked (not embedded into the Word document). When you move the word file to a different location, the links are broken and you won't be able to see the images. Rtf worked because the images are embedded into the rtf file. odt - doc works just fine with images, so that would be a better idea. Max -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Laurent Rhelp Sent: Monday, January 08, 2007 1:42 PM To: R-help@stat.math.ethz.ch Subject: [R] odfWeave and figures in MS Word Format I answer to myself. I understood my error : first of all, we have to save the file in the .rtf format ! Then, from the rtf file, we can generate the file in the .doc format. I am sorry for my question. Thanks Laurent __ 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. -- LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}} __ 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] min() return factor class values
Dear Peter, I tryed something like head(especies.aicc) especie aicc 1 Attila.rufus 17.15934 2 Attila.rufus 11.41371 3 Attila.rufus 11.41371 4 Attila.rufus 19.55998 5 Attila.rufus 17.23780 6 Attila.rufus 19.22545 especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),max) But it works fine only for mean FUN and not for min and max. Also also, when I use mean I got the following warnings: especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),mean) Warning messages: 1: argument is not numeric or logical: returning NA in: mean.default(X[[1]], ...) 2: argument is not numeric or logical: returning NA in: mean.default(X[[2]], ...) In fact I need only min() and max(). Miltinho - Peter Dalgaard [EMAIL PROTECTED] escreveu: Milton Cezar Ribeiro wrote: Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e-mail. min() is not doing anything out of the ordinary, but cbind'ing it with the character vector sp coerces it to character and rbind'ing to a data frame turns character vectors into factors... The whole thing looks like it could be a straightforward application of aggregate(). In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] min() return factor class values
Milton Cezar Ribeiro wrote: Dear Peter, I tryed something like head(especies.aicc) especie aicc 1 Attila.rufus 17.15934 2 Attila.rufus 11.41371 3 Attila.rufus 11.41371 4 Attila.rufus 19.55998 5 Attila.rufus 17.23780 6 Attila.rufus 19.22545 especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),max) Make sure to aggregate only the part of your data frame that is numeric: x - read.table(stdin()) 0: especie aicc 1: 1 Attila.rufus 17.15934 2: 2 Attila.rufus 11.41371 3: 3 Attila.rufus 11.41371 4: 4 Attila.rufus 19.55998 5: 5 Attila.rufus 17.23780 6: 6 Attila.rufus 19.22545 7: aggregate(x[2], list(x$especie), min) Group.1 aicc 1 Attila.rufus 11.41371 aggregate(x[2], list(x$especie), max) Group.1 aicc 1 Attila.rufus 19.55998 aggregate(x, list(x$especie), max) # this breaks Error in Summary.factor(..., na.rm = na.rm) : max not meaningful for factors But it works fine only for mean FUN and not for min and max. Also also, when I use mean I got the following warnings: especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),mean) Warning messages: 1: argument is not numeric or logical: returning NA in: mean.default(X[[1]], ...) 2: argument is not numeric or logical: returning NA in: mean.default(X[[2]], ...) In fact I need only min() and max(). Miltinho - Peter Dalgaard [EMAIL PROTECTED] escreveu: Milton Cezar Ribeiro wrote: Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e-mail. min() is not doing anything out of the ordinary, but cbind'ing it with the character vector sp coerces it to character and rbind'ing to a data frame turns character vectors into factors... The whole thing looks like it could be a straightforward application of aggregate(). In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min(sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica.1252;LC_MONETARY=English_Jamaica.1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Logical operations or selecting data from data.frames
Hi all, why doesn't something like this does not work? speedy - (sdata$VaR sdata$DdtdAbs) sdata$DdtdDuration = qpois(pct,lambda) sdata$Ddtd MinDD or sdata$Ddtd[sdata$Ddtd 0 sdata$VaR sdata$DdtdAbs] sdata looks like this: dataId date value Ddtd VaR DdtdAbs DdtdDuration 18948 79637 2004-07-27 10085.10 NA NA0.000 18949 79638 2004-07-28 10117.10 NA NA0.000 18950 79639 2004-07-29 10129.20 NA NA0.000 18951 79640 2004-07-30 10139.70 NA NA0.000 18952 79641 2004-08-02 10179.20 NA NA0.000 18953 79642 2004-08-03 10120.20 0.579613329 336.060090 59.001 18954 79643 2004-08-04 10126.50 NA NA0.000 18955 79644 2004-08-05 9963.03 1.614279366 334.306978 163.471 18956 79645 2004-08-06 9815.33 3.072828717 386.173057 311.172 18957 79646 2004-08-09 9814.66 3.079445020 420.167049 311.843 18958 79647 2004-08-10 9944.67 NA NA0.000 18959 79648 2004-08-11 9938.32 0.063853300 328.3159926.351 18960 79649 2004-08-12 9814.59 1.308037371 379.182568 130.082 I am trying to select rows from the data.frame which have Ddtd x, VaR DdtdAbs and DdtdDuration z. Thank you, Benjamin __ 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] Logical operations or selecting data from data.frames
I suppose this doesn't work for the same reason as sdata$VaR sdata$DdtdAbs sdata$DdtdDuration = 1 does only return FALSE and not a vector of TRUE and FALSE as sdata$VaR sdata$DdtdAbs would return. Is there a ways around this? Benjamin On 1/9/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi all, why doesn't something like this does not work? speedy - (sdata$VaR sdata$DdtdAbs) sdata$DdtdDuration = qpois(pct,lambda) sdata$Ddtd MinDD or sdata$Ddtd[sdata$Ddtd 0 sdata$VaR sdata$DdtdAbs] sdata looks like this: dataId date value Ddtd VaR DdtdAbs DdtdDuration 18948 79637 2004-07-27 10085.10 NA NA0.000 18949 79638 2004-07-28 10117.10 NA NA0.000 18950 79639 2004-07-29 10129.20 NA NA0.000 18951 79640 2004-07-30 10139.70 NA NA0.000 18952 79641 2004-08-02 10179.20 NA NA0.000 18953 79642 2004-08-03 10120.20 0.579613329 336.060090 59.001 18954 79643 2004-08-04 10126.50 NA NA0.000 18955 79644 2004-08-05 9963.03 1.614279366 334.306978 163.471 18956 79645 2004-08-06 9815.33 3.072828717 386.173057 311.172 18957 79646 2004-08-09 9814.66 3.079445020 420.167049 311.843 18958 79647 2004-08-10 9944.67 NA NA0.000 18959 79648 2004-08-11 9938.32 0.063853300 328.3159926.351 18960 79649 2004-08-12 9814.59 1.308037371 379.182568 130.082 I am trying to select rows from the data.frame which have Ddtd x, VaR DdtdAbs and DdtdDuration z. Thank you, Benjamin __ 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] min() return factor class values
Milton, have you looked at the structure of your data.frame? str(especies.aicc) Are you sure especies.aicc is defined as numeric? b On Jan 9, 2007, at 10:51 AM, Milton Cezar Ribeiro wrote: Dear Peter, I tryed something like head(especies.aicc) especie aicc 1 Attila.rufus 17.15934 2 Attila.rufus 11.41371 3 Attila.rufus 11.41371 4 Attila.rufus 19.55998 5 Attila.rufus 17.23780 6 Attila.rufus 19.22545 especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),max) But it works fine only for mean FUN and not for min and max. Also also, when I use mean I got the following warnings: especies.min-aggregate.data.frame(especies.aicc,list (Especie=especies.aicc$especie),mean) Warning messages: 1: argument is not numeric or logical: returning NA in: mean.default (X[[1]], ...) 2: argument is not numeric or logical: returning NA in: mean.default (X[[2]], ...) In fact I need only min() and max(). Miltinho - Peter Dalgaard [EMAIL PROTECTED] escreveu: Milton Cezar Ribeiro wrote: Hi R-friends I don´t know why the min() function below return the min value as factor. When i force the aicc.min using a as.numeric() function, it return a factor index (1,2,..) and not min value as I want. By the way, I included a sessionInfo() at the end of this e- mail. min() is not doing anything out of the ordinary, but cbind'ing it with the character vector sp coerces it to character and rbind'ing to a data frame turns character vectors into factors... The whole thing looks like it could be a straightforward application of aggregate(). In fact I had the same problem (values as factor) on other part of my script and I noticed that it occour when I use cbind(). It is real? Any idea? Kind regards, Miltinho especies.aicc.min-data.frame() for (sp in levels(especies.aicc$especie)) + { + sele-subset(especies.aicc,especie==sp) + especies.aicc.min-rbind(especies.aicc.min,cbind(sp,aicc.min=min (sele$aicc))) + } especies.aicc.min sp aicc.min 1 Attila.rufus 6.7387056413613 2 Automolus.leucophthalmus 125.791300522824 class(especies.aicc.min$aicc.min) [1] factor --- sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_Jamaica.1252;LC_CTYPE=English_Jamaica. 1252;LC_MONETARY=English_Jamaica. 1252;LC_NUMERIC=C;LC_TIME=English_Jamaica.1252 attached base packages: [1] methods stats graphics grDevices utils datasets base -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple spectral analysis
Georg Hoermann [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Peter Dalgaard wrote: Earl F. Glynn wrote: Thanks a lot for the help. I will post the script when its ready (an introduction for our biology students to time series, just 8 hours) I've been working with one of our labs here to find cyclic genes from microarray data. The supplement for the paper we published is here (I haven't bothered making the code general enough for a package yet): http://research.stowers-institute.org/efg/2005/LombScargle/index.htm Normally we only have about 20 to 50 points in our time series for each gene. With missing data a problem, I used a Lomb-Scargle approach to find the periodicity. With Fourier analysis, one must impute any missing data points, but with Lomb-Scargle you just process the data you have without any imputation. Perhaps you or your students would be interested in the Numerical Experiments on this page http://research.stowers-institute.org/efg/2005/LombScargle/supplement/NumericalExperiments/index.htm I was curious how well the Lomb-Scargle technique would work with your data -- see the R code below. Normally the Lomb-Scargle periodogram shows a single peak when there is a single dominant frequency. The Peak Significance curve for all your data is a difficult to interpret, and I'm not sure the statistical tests are valid (without some tweaks) for your size dataset. I took a random sample of 50 of your ~3000 data points and analyzed those -- see the second code block below. [For 50 data points I know all the assumptions are good enough for the statistics being computed.] The periodogram here shows a single peak for period 365.6 days, which has good statistical significance. Other subset samples can show harmonic frequencies, sometimes. # efg, 9 Jan 2007 air = read.csv(http://www.hydrology.uni-kiel.de/~schorsch/air_temp.csv;) #air - read.csv(air_temp.csv) TempAirC - air$T_air Time - as.Date(air$Date, %d.%m.%Y) N - length(Time) # Lomb-Scargle code source(http://research.stowers-institute.org/efg/2005/LombScargle/R/LombScargle.R;) MAXSPD - 1500 unit - day M - N# Usually use factor of 2 or 4, but with large N use 1 instead # Look at test frequencies corresponding to periods of 200 days to 500 days: f = 1/T TestFrequencies - (1/500) + (1/200 - 1/500) * (1:M / M) # Use Horne Baliunas' estimate of independent frequencies Nindependent - NHorneBaliunas(length(Time)) # valid for this size? # Fairly slow with this large dataset ComputeAndPlotLombScargle(as.numeric(Time), TempAirC, TestFrequencies, Nindependent, Air Temperature [C]) # Could get good results with fewer points too, say 50 chosen at random MAXSPD - 25 TempAirC - air$T_air Time - as.Date(air$Date, %d.%m.%Y) set.seed(19) # For reproducible results RandomSet - sample(1:length(Time), 50) TempAirC - TempAirC[RandomSet] Time -Time[RandomSet] N - length(Time) M - 4 * N# Usually use factor of 2 or 4 # Look at test frequencies corresponding to periods of 200 days to 500 days: f = 1/T TestFrequencies - (1/500) + (1/200 - 1/500) * (1:M / M) # Use Horne Baliunas' estimate of independent frequencies Nindependent - NHorneBaliunas(length(Time)) # Very fast to compute for only 50 points ComputeAndPlotLombScargle(as.numeric(Time), TempAirC, TestFrequencies, Nindependent, Air Temperature [C]) efg Earl F. Glynn Scientific Programmer Stowers Institute __ 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] Logical operations or selecting data from data.frames
Is the solution this simple? sdata$VaR sdata$DdtdAbs sdata$DdtdDuration = 1 Regards, Johan 2007/1/9, Benjamin Dickgiesser [EMAIL PROTECTED]: I suppose this doesn't work for the same reason as sdata$VaR sdata$DdtdAbs sdata$DdtdDuration = 1 does only return FALSE and not a vector of TRUE and FALSE as sdata$VaR sdata$DdtdAbs would return. Is there a ways around this? Benjamin On 1/9/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi all, why doesn't something like this does not work? speedy - (sdata$VaR sdata$DdtdAbs) sdata$DdtdDuration = qpois(pct,lambda) sdata$Ddtd MinDD or sdata$Ddtd[sdata$Ddtd 0 sdata$VaR sdata$DdtdAbs] sdata looks like this: dataId date value Ddtd VaR DdtdAbs DdtdDuration 18948 79637 2004-07-27 10085.10 NA NA0.00 0 18949 79638 2004-07-28 10117.10 NA NA0.00 0 18950 79639 2004-07-29 10129.20 NA NA0.00 0 18951 79640 2004-07-30 10139.70 NA NA0.00 0 18952 79641 2004-08-02 10179.20 NA NA0.00 0 18953 79642 2004-08-03 10120.20 0.579613329 336.060090 59.00 1 18954 79643 2004-08-04 10126.50 NA NA0.00 0 18955 79644 2004-08-05 9963.03 1.614279366 334.306978 163.47 1 18956 79645 2004-08-06 9815.33 3.072828717 386.173057 311.17 2 18957 79646 2004-08-09 9814.66 3.079445020 420.167049 311.84 3 18958 79647 2004-08-10 9944.67 NA NA0.00 0 18959 79648 2004-08-11 9938.32 0.063853300 328.3159926.35 1 18960 79649 2004-08-12 9814.59 1.308037371 379.182568 130.08 2 I am trying to select rows from the data.frame which have Ddtd x, VaR DdtdAbs and DdtdDuration z. Thank you, Benjamin __ 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. -- Johan Sandblom N8, MRC, Karolinska sjh t +46851776108 17176 Stockholm m +46735521477 Sweden What is wanted is not the will to believe, but the will to find out, which is the exact opposite - Bertrand Russell __ 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] Logical operations or selecting data from data.frames
On Tue, 9 Jan 2007, Benjamin Dickgiesser wrote: I suppose this doesn't work for the same reason as sdata$VaR sdata$DdtdAbs sdata$DdtdDuration = 1 does only return FALSE and not a vector of TRUE and FALSE as See ?: '' and '' indicate logical AND and '|' and '||' indicate logical OR. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector... a - rep(c(1,2), 5) b - rep(1,10) a 1 b = 1 a 1 b = 1 sdata$VaR sdata$DdtdAbs would return. Is there a ways around this? Benjamin On 1/9/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi all, why doesn't something like this does not work? speedy - (sdata$VaR sdata$DdtdAbs) sdata$DdtdDuration = qpois(pct,lambda) sdata$Ddtd MinDD or sdata$Ddtd[sdata$Ddtd 0 sdata$VaR sdata$DdtdAbs] sdata looks like this: dataId date value Ddtd VaR DdtdAbs DdtdDuration 18948 79637 2004-07-27 10085.10 NA NA0.00 0 18949 79638 2004-07-28 10117.10 NA NA0.00 0 18950 79639 2004-07-29 10129.20 NA NA0.00 0 18951 79640 2004-07-30 10139.70 NA NA0.00 0 18952 79641 2004-08-02 10179.20 NA NA0.00 0 18953 79642 2004-08-03 10120.20 0.579613329 336.060090 59.00 1 18954 79643 2004-08-04 10126.50 NA NA0.00 0 18955 79644 2004-08-05 9963.03 1.614279366 334.306978 163.47 1 18956 79645 2004-08-06 9815.33 3.072828717 386.173057 311.17 2 18957 79646 2004-08-09 9814.66 3.079445020 420.167049 311.84 3 18958 79647 2004-08-10 9944.67 NA NA0.00 0 18959 79648 2004-08-11 9938.32 0.063853300 328.3159926.35 1 18960 79649 2004-08-12 9814.59 1.308037371 379.182568 130.08 2 I am trying to select rows from the data.frame which have Ddtd x, VaR DdtdAbs and DdtdDuration z. Thank you, Benjamin __ 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] scripts with littler
John Lawrence Aspden wrote: I'm actually tempted to use #!/usr/bin/env r rm(list=ls()) Ahem, it turns out to be better to use: #!/usr/bin/env r rm(list=ls()[ls()!=argv]) -- Contractor in Cambridge UK -- http://www.aspden.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] Logical operations or selecting data from data.frames
Thx for the help, sorry I am just used to use from php and simply assumed it would work identically. On 1/9/07, Patrick Burns [EMAIL PROTECTED] wrote: S Poetry (and other documentation) will tell you the difference between '' and ''. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Benjamin Dickgiesser wrote: I suppose this doesn't work for the same reason as sdata$VaR sdata$DdtdAbs sdata$DdtdDuration = 1 does only return FALSE and not a vector of TRUE and FALSE as sdata$VaR sdata$DdtdAbs would return. Is there a ways around this? Benjamin On 1/9/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote: Hi all, why doesn't something like this does not work? speedy - (sdata$VaR sdata$DdtdAbs) sdata$DdtdDuration = qpois(pct,lambda) sdata$Ddtd MinDD or sdata$Ddtd[sdata$Ddtd 0 sdata$VaR sdata$DdtdAbs] sdata looks like this: dataId date value Ddtd VaR DdtdAbs DdtdDuration 18948 79637 2004-07-27 10085.10 NA NA0.00 0 18949 79638 2004-07-28 10117.10 NA NA0.00 0 18950 79639 2004-07-29 10129.20 NA NA0.00 0 18951 79640 2004-07-30 10139.70 NA NA0.00 0 18952 79641 2004-08-02 10179.20 NA NA0.00 0 18953 79642 2004-08-03 10120.20 0.579613329 336.060090 59.00 1 18954 79643 2004-08-04 10126.50 NA NA0.00 0 18955 79644 2004-08-05 9963.03 1.614279366 334.306978 163.47 1 18956 79645 2004-08-06 9815.33 3.072828717 386.173057 311.17 2 18957 79646 2004-08-09 9814.66 3.079445020 420.167049 311.84 3 18958 79647 2004-08-10 9944.67 NA NA0.00 0 18959 79648 2004-08-11 9938.32 0.063853300 328.3159926.35 1 18960 79649 2004-08-12 9814.59 1.308037371 379.182568 130.08 2 I am trying to select rows from the data.frame which have Ddtd x, VaR DdtdAbs and DdtdDuration z. Thank you, Benjamin __ 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] odfWeave and figures in MS Word Format
Kuhn, Max a écrit : Laurent, Since you question was not about odfWeave (despite the message title), it would have been better to send this question to an OpenOffice mailing list. That said, I think that the issues was your workflow (odt - html - doc). HTML is plain text, so when you saved the file in that format the image files are saved separately. Links are creating in the html file to the image files. When you converted the html to Word format, the images are still linked (not embedded into the Word document). When you move the word file to a different location, the links are broken and you won't be able to see the images. Rtf worked because the images are embedded into the rtf file. odt - doc works just fine with images, so that would be a better idea. Max -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Laurent Rhelp Sent: Monday, January 08, 2007 1:42 PM To: R-help@stat.math.ethz.ch Subject: [R] odfWeave and figures in MS Word Format I answer to myself. I understood my error : first of all, we have to save the file in the .rtf format ! Then, from the rtf file, we can generate the file in the .doc format. I am sorry for my question. Thanks Laurent __ 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. -- LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. Thank you very much for your detailed explanations. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use Rattle for Data mining through R?
Received Tue 09 Jan 2007 12:36pm +1100 from Bhanu Kalyan.K: Dear Mr. Bengtsson, Now i am able to work with R-Matlab interface comfortably. Thanks to you. Recently, I came to know that R can be used for data mining as well. I went through the following site for this : http://rattle.togaware.com/ As they have suggested, I have also installed the two packages: install.packages(RGtk2) install.packages(rattle) Now, can you explain how to work on this? Can this be used to implement the clustering algorithms? If yes, Kindly elaborate. A patchy (but regularly updated) user guide is under development and freely available as HTML from: http://datamining.togaware.com/ (follow the links provided from rattle.togaware.com) In particular the starting point it: http://datamining.togaware.com/survivor/Data_Mining.html There is a cluster tab under the Unsupervised paradigm, but not documented yet. I noticed some formatting problems with the HTML. Currently being fixed. Regards, Graham __ 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] scripts with littler
John Lawrence Aspden wrote: John Lawrence Aspden wrote: I'm actually tempted to use #!/usr/bin/env r rm(list=ls()) Ahem, it turns out to be better to use: #!/usr/bin/env r rm(list=ls()[ls()!=argv]) Eww!! I'm not sure you want to do that. I would recommend sticking with: #!/usr/bin/r -v as that gives you a truer scripting environment. I understand that won't load the libraries in your home area automatically, but consider the way scripts in other languages are written and distributed: they usually load the libraries at the beginning of the script. Silently loading them before the script is run hides behavior from the script user. If you have libraries installed outside of the library search path, consider expanding it with .libPaths() before calling library() or require(). Cheers, Jeff -- http://biostat.mc.vanderbilt.edu/JeffreyHorner __ 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] differential item function for item response theory
Hi my friends, I'm very new to R and need your help. I used R and ltm package for item response theory (IRT) modeling. I also need to compute differential item function (DIF) for IRT models. I searched the archive but basically found nothing. Could you help me find some sources about handling DIF of IRT? Many thanks in advance! Feng __ 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] A vectorization question
Hi, A function calculates the absolute difference between the two largest values of each row of a matrix, as shown in the following example code: cx - matrix(runif(15),5) cy - t( apply(cx, 1, order, decreasing=TRUE) ) cz - rep(0, nrow(cx)) for( i in 1:nrow(cx) ) cz[i] - abs(diff(cx[i, cy[i,1:2]])) Anybody has any ideas on how the last loop can be vectorized? Thanks. Christos Hatzis, Ph.D. Nuvera Biosciences, Inc. 400 West Cummings Park Suite 5350 Woburn, MA 01801 Tel: 781-938-3830 www.nuverabio.com http://www.nuverabio.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] differential item function for item response theory
I don't know of any functions specifically designed to handle DIF (e.g., mantel-hantzel). But, ltm does give you the point estimates and standard errors so you can do a t-test between the focal and reference groups. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SHEN,FENG Sent: Tuesday, January 09, 2007 4:09 PM To: r-help@stat.math.ethz.ch Subject: [R] differential item function for item response theory Hi my friends, I'm very new to R and need your help. I used R and ltm package for item response theory (IRT) modeling. I also need to compute differential item function (DIF) for IRT models. I searched the archive but basically found nothing. Could you help me find some sources about handling DIF of IRT? Many thanks in advance! Feng __ 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] randomForest and missing data
There is an improved version of the original random forest algorithm available in the party package (you can find some additional information on the details here: http://www.stat.uni-muenchen.de/sfb386/papers/dsp/paper490.pdf ). I do not know whether it yields a solution to your problem about missing data, but maybe it's a check worth... Best regards: Bálint On 1/4/07, Darin A. England [EMAIL PROTECTED] wrote: Does anyone know a reason why, in principle, a call to randomForest cannot accept a data frame with missing predictor values? If each individual tree is built using CART, then it seems like this should be possible. (I understand that one may impute missing values using rfImpute or some other method, but I would like to avoid doing that.) If this functionality were available, then when the trees are being constructed and when subsequent data are put through the forest, one would also specify an argument for the use of surrogate rules, just like in rpart. I realize this question is very specific to randomForest, as opposed to R in general, but any comments are appreciated. I suppose I am looking for someone to say It's not appropriate, and here's why ... or Good idea. Please implement and post your code. Thanks, Darin England, Senior Scientist Ingenix __ 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] A vectorization question
On Tue, 2007-01-09 at 16:10 -0500, Christos Hatzis wrote: Hi, A function calculates the absolute difference between the two largest values of each row of a matrix, as shown in the following example code: cx - matrix(runif(15),5) cy - t( apply(cx, 1, order, decreasing=TRUE) ) cz - rep(0, nrow(cx)) for( i in 1:nrow(cx) ) cz[i] - abs(diff(cx[i, cy[i,1:2]])) Anybody has any ideas on how the last loop can be vectorized? Thanks. How about this: mat - matrix(sample(1:50, 12), ncol = 4) mat [,1] [,2] [,3] [,4] [1,] 391 22 11 [2,] 34 28 13 48 [3,] 25 40 383 apply(mat, 1, function(x) abs(diff(sort(x, decreasing = TRUE)[1:2]))) [1] 17 14 2 Or apply(mat, 1, function(x) diff(sort(x)[3:4])) [1] 17 14 2 HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A vectorization question
Thanks, Marc. This is what I was trying to do but could not get it to work. -Christos -Original Message- From: Marc Schwartz [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 09, 2007 4:32 PM To: [EMAIL PROTECTED] Cc: 'R-help' Subject: Re: [R] A vectorization question On Tue, 2007-01-09 at 16:10 -0500, Christos Hatzis wrote: Hi, A function calculates the absolute difference between the two largest values of each row of a matrix, as shown in the following example code: cx - matrix(runif(15),5) cy - t( apply(cx, 1, order, decreasing=TRUE) ) cz - rep(0, nrow(cx)) for( i in 1:nrow(cx) ) cz[i] - abs(diff(cx[i, cy[i,1:2]])) Anybody has any ideas on how the last loop can be vectorized? Thanks. How about this: mat - matrix(sample(1:50, 12), ncol = 4) mat [,1] [,2] [,3] [,4] [1,] 391 22 11 [2,] 34 28 13 48 [3,] 25 40 383 apply(mat, 1, function(x) abs(diff(sort(x, decreasing = TRUE)[1:2]))) [1] 17 14 2 Or apply(mat, 1, function(x) diff(sort(x)[3:4])) [1] 17 14 2 HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scripts with littler
Jeffrey Horner wrote: John Lawrence Aspden wrote: I'm actually tempted to use #!/usr/bin/env r rm(list=ls()[ls()!=argv]) Eww!! I'm not sure you want to do that. I would recommend sticking with: #!/usr/bin/r -v as that gives you a truer scripting environment. I understand that won't load the libraries in your home area automatically, but consider the way scripts in other languages are written and distributed: they usually load the libraries at the beginning of the script. Silently loading them before the script is run hides behavior from the script user. If you have libraries installed outside of the library search path, consider expanding it with .libPaths() before calling library() or require(). Cheers, Jeff Hi, thanks, it's not that it doesn't load the libraries automatically (which I'd hate), it's that it no longer knows how to load them. I've got a library (brainwaver), installed locally in ~/R/library, and this information is recorded in the ~/.Renviron file. This is because there's no debian package for it, and I don't want to mess up the system by trying to install it manually as root (after all, it should be fairly obvious that I don't know what I'm doing!...) In my script I load the library, but if I call it using #!/usr/bin/r --vanilla, this stops working. (I can still load the system-wide libraries, it's the ones installed in my home directory that break) Since I can't use subroutines without using the library mechanism, and I want to use brainwaver, and I want people to be able to use this stuff without needing root privileges, or needing to hack hard-coded file locations into every script, I'd prefer ~/.Renviron read. Also, of course, using #!/usr/bin/r depends on it being installed there, and I can't use the env mechanism and still pass it the vanilla option. My main problem with R's/littler's default behaviour is that it introduces lots of spurious variables pulled in from .Rdata that are different depending where it's invoked. I'm aware that the rm(list... is a nasty hack, but it seems like the least bad option. Most of the other things seem to produce scripts that won't work if you tar them up and send them to people. Thanks for the hint about .libPaths(), but without ~/.Renviron how am I to know which directories to add to it? Of course I'm not saying that there might not be other subtle difficulties with the default. But so far I prefer the default + explicitly remove all variables to --vanilla, and I can't pass --vanilla without being sure where R's installed anyway! Is anyone still reading by this point?? Thanks for your perseverance if so! Cheers, John. -- Contractor in Cambridge UK -- http://www.aspden.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] A vectorization question
Welcome Christos. Note that my first example can actually be simplified to: apply(mat, 1, function(x) -diff(sort(x, decreasing = TRUE)[1:2])) Since we really just need to negate the difference, rather than take the abs(). The advantage of this approach is that the two max values will always be the first and second values, so will be independent of the length of 'x' (number of columns in the matrix). Using the second example more generally, you would have to use something like: apply(mat, 1, function(x) diff(sort(x)[-c(1:(length(x) - 2))])) in the subsetting of the sort() results or precalcuate the indices (ie. ncol(mat) and ncol(mat) - 1). Might add a bit more overhead, but testing would give you more empiric timing data. That might have to be balanced by whether the rows tend to be random in order or closer to being sorted in increasing/decreasing order, which would affect the sort time. Worst case scenario is generally having to reverse the sort order. Of course, if the matrices are relatively small, sorting time would likely be a non-issue. HTH, Marc On Tue, 2007-01-09 at 16:39 -0500, Christos Hatzis wrote: Thanks, Marc. This is what I was trying to do but could not get it to work. -Christos snip __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A vectorization question
That's true. Just need to negate the difference. Actually, straight diff can be used after reversing the vector: apply(mat, 1, function(x) diff(sort(x, decreasing = TRUE)[2:1])) I only have 3 columns in my matrix so sorting should not add much overhead, but I will time both versions. Thanks again. -Christos -Original Message- From: Marc Schwartz [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 09, 2007 5:07 PM To: [EMAIL PROTECTED] Cc: 'R-help' Subject: RE: [R] A vectorization question Welcome Christos. Note that my first example can actually be simplified to: apply(mat, 1, function(x) -diff(sort(x, decreasing = TRUE)[1:2])) Since we really just need to negate the difference, rather than take the abs(). The advantage of this approach is that the two max values will always be the first and second values, so will be independent of the length of 'x' (number of columns in the matrix). Using the second example more generally, you would have to use something like: apply(mat, 1, function(x) diff(sort(x)[-c(1:(length(x) - 2))])) in the subsetting of the sort() results or precalcuate the indices (ie. ncol(mat) and ncol(mat) - 1). Might add a bit more overhead, but testing would give you more empiric timing data. That might have to be balanced by whether the rows tend to be random in order or closer to being sorted in increasing/decreasing order, which would affect the sort time. Worst case scenario is generally having to reverse the sort order. Of course, if the matrices are relatively small, sorting time would likely be a non-issue. HTH, Marc On Tue, 2007-01-09 at 16:39 -0500, Christos Hatzis wrote: Thanks, Marc. This is what I was trying to do but could not get it to work. -Christos snip __ 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] listing all functions in R
Seth Falcon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Are you sure you need to? I just tried your code above with: pkgs - c(Biobase, GOstats, flrblr, bazbaz) And while I see warning messages about the flrblr and bazbaz packages, the function completed and I get the expected results in z. Oh, perhaps you have some broken installs? Broken in the sense that you have a package installed but not its dependencies? I installed all known CRAN packages after installing R 2.4.1 last week on a PC. Perhaps some new consistency checks checks could be be made to catch such dependency problems? How about this: safeRequire - function(x) { tryCatch(require(x, character.only=TRUE), error=function(e) FALSE) } Thanks. That's a much better function. But if your process a lot of packages, even with just safeRequire (or findfuns), the search() path grows quite long, and things break, so it's not really possible to get a list of all functions in R if you have all packages installed. Consider: pkgs - dir(.Library) length(pkgs)#957 length( search() ) # 9 # First 100 Packages set1 - lapply(pkgs[1:100], safeRequire) pkgs[which(!unlist(set1))] #[1] bcp cairoDevice caMassClass length( search() ) # 135 safeRequire(bcp) Loading required package: bcp Loading required package: DNAcopy Warning in library(pkg, character.only = TRUE, logical = TRUE, lib.loc = lib.loc) : there is no package called 'DNAcopy' [1] FALSE In the 2nd 100 many packages seem to be affected by the Maximal number of DLLs reached... I didn't bother trying to process packages 201 through 957. efg Earl F. Glynn Scientific Programmer Bioinformatics Stowers Institute for Medical Research __ 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] manipulating elements of lists
Maybe I misunderstand what you want to do, one solution is: l1 $a [1] 1 2 $b [1] 1 2 3 $c [1] 1 2 3 4 l2 V1 V2 1 d nd 2 c nc 3 b nb 4 a na names(l1)-sapply(names(l1),function(n)l2[l2$V1==n,2]) l1 $na [1] 1 2 $nb [1] 1 2 3 $nc [1] 1 2 3 4 On 1/10/07, Christoph Heibl [EMAIL PROTECTED] wrote: I want to manipulate lists as described below: Imagine these two lists: list1 $WR7 [1] 1 2 3 4 $YH5YH6 [1] 3 4 5 6 7 $YH4 [1] 4 5 $UC4UC8 [1] 4 5 6 7 8 9 list2 V1 V2 1WR7 Averrhoa 2 ? Sarcotheca 3 YH5YH6 caesia 4YH4 arbuscula 5 UC4UC8 rosea 6 ? acetosella How can I exchange the names(list1) by the entries in the second column of list2, if (a) length(list1) ≠ length(list2) and (b) the elements of both lists are not in the same order? Is there a easy way to do this? Thank you! Christoph Heibl PhD student 'Phylogenetics and phylogeography of endemic Atacama Desert flora' Systematic Botany Ludwig-Maximilians-Universität München Menzinger Str. 67 D-80638 München GERMANY phone: +49-(0)89-17861-251 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.
[R] roc and lattice
Hello, I am afraid I do not fully understand all intricacies of programming in lattice plots. In the code below I try to plot an ROC curve, following R-news 4(1). When I condition on the variable 'group' I get the error message below, when I plot the curve for all data (i.e., y ~ pred.prob), I get the plot I want. Can someone point out why conditioning gives that message? Thanks, Ruud plot.a - xyplot(y ~ pred.prob|group, data=x.df, + xlim=c(0,1),xlab=1-specificiteit, + ylab=sensitiviteit, + panel=function(x,y,subscripts,...){ + DD - table(-x,y) + sens - cumsum(DD[,2])/sum(DD[,2]) + mspec - cumsum(DD[,1])/sum(DD[,1]) + panel.xyplot(mspec,sens,type=l,...) + panel.abline(0,1) + }) print(plot.a) Error in panel(x = c(0.000265710002003069, 0.000345712857778025, 0.000265710002003069, : subscript out of bounds __ 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.