[R] Extracting overdispersion estimates from lmer amd glm objects
Dear list, I am needing to extract the estimate of overdispersion (deviance / residual degrees of freedom or c-hat) from multiple model objects - so they can then be used to compare the extent of overdispersion among alternative models as well as calculate qausi-AIC values. I have been unable to do this, despite consulting a number of manuals and searching the R-help. I am imaging that in theory it should be possible with some call to attr(), but i have so far had no success. An example model output would be: modeltest-lmer(Coleodactylus_amazonicus_N~USD + (1|site),data=SFArray,family=poisson,method=Laplace,control=list(usePQL=FALSE, msVerbose=TRUE)) summary(modeltest) Generalized linear mixed model fit using Laplace Formula: Coleodactylus_amazonicus_N ~ USD + (1 | site) Data: SFArray Family: poisson(log link) AIC BIClogLik deviance 75.94996 81.68603 -34.97498 69.94996 Random effects: Groups NameVariance Std.Dev. site (Intercept) 2.6076 1.6148 number of obs: 50, groups: site, 5 Estimated scale (compare to 1) 1.080798 What I need is to extract this value (1.080798) from multiple lmer objects. Has anyone any recommendations? I also need to do this for glm objects although I suspect if someone was able to kindly point me in the right direction then the solution is likely to be similar. Very many thanks, Toby Gardner sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] datasets graphics grDevices methods stats utils base other attached packages: JGR iplots JavaGD lme4 Matrixlattice MASS rJava 1.4-71.0-30.3-4 0.995-2 0.995-15 0.13-8 7.2-27.1 0.4-6 School of Environmental Sciences University of East Anglia Norwich, NR4 7TJ United Kingdom Email: [EMAIL PROTECTED] Website: www.uea.ac.uk/~e387495 [[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] Command equivalent of rgui File, Save to File?
On 9/11/2006 3:57 PM, Michael Prager wrote: R 2.3.1 on Windows XP Professional. I am writing some scripts to generate examples. The Rgui menu item File, Save to File is helpful. Is there perhaps an equivalent R function that can be incorporated into a script? I think sink() is the closest you can get: set R to write to a file before generating whatever output you want to save. The menu item writes out the GUI text buffer; the R core doesn't know what's in that buffer. Other front ends don't have a buffer at all. Of course, we could write an Rgui-specific C function that put that text into an R character vector so you could do what you liked with it, but since sink() exists and is portable, there isn't a lot of motivation to do that. This will happen automatically if we ever get around to defining an abstract GUI interface all controllable and configurable from R, but I don't know anyone working on that right now. Duncan Murdoch Mike Prager Southeast Fisheries Science Center, NOAA Beaufort, North Carolina USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Test internet presence
On 11-Sep-06 Gregor Gorjanc wrote: Thank you. Your solution is usable but unfortunatelly not portable to Windows. I would like to use this test in package check, which can include also windows OS. Now that I think about it (should have done that earlier), you can use the value of .Platform$OS.type (either unix or windows) to determine the OS type, and also the value of the system command to see what is sent back from the ping command. Then the R command to ping a remote host once would be system(ping -c 1 remote host) for unix system(ping -n 1 remote host) for windows (at any rate for the DOS-based ping in Windows 98). However, the returned value of system (which consists of the output of the ping commmand) is a multi-line value, and is different between Unix and Windows So to distinguish between success and failure, you would have to do some slightly complex parsing of the output returned by system, and evaluate it differently according to operating system. And the latter may vary between different versions of the OS ... Maybe it wasn't such a good suggestion after all. However, since separate versions of your package would be compiled for Unix-like systems and for Windows, perhaps a way round such differences is to write a different script for each one (shell script as before for Unix, batch file for Windows), crafted so as to return identical results in the two cases for success, and for failure. Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 12-Sep-06 Time: 01:28:15 -- XFMail -- __ 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] Installation difficulty with rimage
On Mon, 11 Sep 2006, John Kornak wrote: Thanks to Professor Ripley and Sarah Goslee for their helpful responses which have progressed my installation of rimage a little further. Installing fftw2 instead of fftw3 of course solves the problem and I apologize for initially missing that requirement in the rimage documentation. My install has now unfortunately stalled at the next stage and once again I would appreciate any advice as to how to solve the problem: checking jpeglib.h usability... no checking jpeglib.h presence... no checking for jpeglib.h... no configure: error: Sorry, can't find jpeglib header ERROR: configuration failed for package 'rimage' I believe that I have successfully installed libjpeg from the web site http://www.ijg.org as specified in the documentation. I have also checked for the existence of the jpeglib.h file which is sitting in /usr/local/bin/jpeg-6b Ah, but it needs to be in /usr/include or /usr/local/include for the package to find it. I noticed an old posting on this issue, but the solution was to make sure that the jpeglib.h existed, which it does. I am now running FFTW version 2.1.5, fedora core 3 and R version 2.3.1 My FC3 system has RPMs libjpeg-6b-33 and libjpeg-devel-6b-33. If you install those all your paths should be as you need them. -- 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] Test internet presence
Prof Brian Ripley ripley at stats.ox.ac.uk writes: ... Check out tests/internet.R. nsl() checks if you can resolve host names, which has worked well enough there. Thank you prof. Ripley for this pointer. I am posting here the relevant part if someone does not look at SVN. I would just like to ask why is .Platform$OS.type == unix added to the test? Is nsl() available only on unix like platforms or ... I did not found any specifics in its help page. if(!capabilities()[http/ftp]) { warning(no internet capabilities) q() } if(.Platform$OS.type == unix is.null(nsl(cran.r-project.org))) q() Does it make any sense to write a function that would use these two tests. isNetAvailable - function() { ifelse(!capabilities()[http/ftp] ## .Platform$OS.type == unix ## ??? is.null(nsl(cran.r-project.org)), FALSE, TRUE) } Regards, Gregor __ 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] plotting curves
Aldo Crossa aldo.crossa at wright.edu writes: Hi, I've been trying to recreate plots of that follow a cubic form. [snip] I've noticed that in R all curves are pixelated, regardless of howmany points I use. Is there anything I can do to smoothen these graphs so that they are no longer pixelated? I've tried saving it as a metafile, postcript, etc., and although the I've been able to increase the resolution, I haven't been able to fix the pixelation. Weird. I think you need to give us a reproducible example so we can help. The best thing, if possible, would be to give us an example of the code you used and simultaneously to post examples of the output to a web page somewhere, if that's possible. I would just say, e.g., curve(x^3-2*x^2+x-1,from=-10,to=10) there is an n= argument that specifies how many points to use, but it doesn't seem necessary. Ben Bolker __ 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] syntax of nlme
in line Douglas Bates wrote: On 9/11/06, Thomas Wutzler [EMAIL PROTECTED] wrote: Hello, How do I specify the formula and random effects without a startup object ? I thought it would be a mixture of nls and lme. after trying very hard, I ask for help on using nlme. Can someone hint me to some examples? There are quite a few examples in the book Pinheiro and Bates (2000), Mixed-effects Models in S and S-PLUS Permit me to offer a personal testimonial: If you do more statistics than just this one data set, I believe you will be amply rewarded for investing money and time in that book. The value of this investment will be further enhanced by working line by line (as you read the text) through the files ch01.R, ch02.R, ..., ch06.R and ch08.R in ~library\nlme\scripts in your R installation directory. Spencer Graves __ 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] dotchart() help
On Tue, 12 Sep 2006, Alexander Nervedi wrote: Hi I am having trouble with dotcharts, and I keep getting the error message: Error in Summary.data.frame(..., na.rm = na.rm) : only defined on a data frame with all numeric or complex variables I am sure there is a really simple fix, but I am missing it and I wondered if you may have some advice. Test code from R help works prefectly, but I cant seem to recreate it # example dotchart(VADeaths) VADeaths Rural Male Rural Female Urban Male Urban Female 50-54 11.7 8.7 15.4 8.4 55-59 18.1 11.7 24.3 13.6 60-64 26.9 20.3 37.0 19.3 65-69 41.0 30.9 54.6 35.1 70-74 66.0 54.3 71.1 50.0 # it works with mssing data test -VADeaths test[2,]- NA test Rural Male Rural Female Urban Male Urban Female 50-54 11.7 8.7 15.4 8.4 55-59 NA NA NA NA 60-64 26.9 20.3 37.0 19.3 65-69 41.0 30.9 54.6 35.1 70-74 66.0 54.3 71.1 50.0 dotchart(test) # So i created my own test data test- expand.grid( Educ = c(B, I, A), Prof = c(L, M,C), Blacks = NA, Asian = NA, Hispanic = NA, Native = NA, Female = NA) rownames(test) - with(test, paste(Educ,Prof, sep = -)) test[2:9,3:7] - 2 temp - test[,3:7] temp[1, 2:3] -5 # I want to plot temp which looks like temp Blacks Asian Hispanic Native Female B-L NA 55 NA NA I-L2 22 2 2 A-L 2 22 2 2 B-M 2 22 2 2 I-M 2 22 2 2 A-M 2 22 2 2 B-C 2 22 2 2 I-C 2 22 2 2 A-C 2 22 2 2 dotchart(temp) Error in Summary.data.frame(..., na.rm = na.rm) : only defined on a data frame with all numeric or complex variables Everything in temp is numeric and hence I dont understand the error message. From the help page of dotchart: x: either a vector or matrix of numeric values ('NA's are allowed). If 'x' is a matrix the overall plot consists of juxtaposed dotplots for each row. class(temp) [1] data.frame which is neither. Try as.matrix(temp). -- 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] Description of x-axis
Thanks, that works but what are the coordinates of at in the y-direction? On which y-position mtext plots? Christian Jeff Bricker schrieb: ?mtext, also ?barplot since barplot returns midpoints of the bars. also ?rep for setting up a vector of repeating values. something like this: xLabels-c(rep(2003,4),rep(2005,11),rep(2006,5)) midPoints-barplot(your original statements here) mtext(xLabels,side=1,at=apply(midPoints,2,mean)) On 9/11/06, Christian Oswald [EMAIL PROTECTED] wrote: Hello, I have made a barplot with some data and need a description below the x-axis. For example there are 20 values and I need a description 2003 for the first four values, then 2005 for the next eleven and 2006 for the last five values. I want the description below the x-axis-labels and above the x-axis title. Thanks, Christian __ 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. -- Diplom-Ingenieur Christian Oswald Universitaet des Saarlandes Lehrstuhl fuer Pulvertechnologie von Glas und Keramik Gebaude D2 2 D-66123 Saarbruecken Tel.: (+49) 0681/302-5249 Fax.: (+49) 0681/302-5227 __ 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] Description of x-axis
Christian Oswald wrote: Thanks, that works but what are the coordinates of at in the y-direction? On which y-position mtext plots? Please read ?mtext which tells you to use argument line. Uwe Ligges Christian Jeff Bricker schrieb: ?mtext, also ?barplot since barplot returns midpoints of the bars. also ?rep for setting up a vector of repeating values. something like this: xLabels-c(rep(2003,4),rep(2005,11),rep(2006,5)) midPoints-barplot(your original statements here) mtext(xLabels,side=1,at=apply(midPoints,2,mean)) On 9/11/06, Christian Oswald [EMAIL PROTECTED] wrote: Hello, I have made a barplot with some data and need a description below the x-axis. For example there are 20 values and I need a description 2003 for the first four values, then 2005 for the next eleven and 2006 for the last five values. I want the description below the x-axis-labels and above the x-axis title. Thanks, Christian __ 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] rename cols
Christos Hatzis christos at nuverabio.com writes: Try this: old.colnames - colnames(my.439.vars.df) old.colnames[old.colnames==fksm] - new.name.a old.colnames[old.colnames==klmk] - new.name.b For a newcomer, it will be useful to have a function like this in the base R: that can take a list of old.names and new.names, and do the assignment. It is far more efficient to have functions that are shared via the R distribution, than having to write own functions for carrying out basic data management tasks, and simple routinely used statistical procedures. Most users would rather spend time on thinking about the substantive work, instead of figuring out how to program---this may be specially true for new users. This way the functions used will also be more efficient and better designed than the typical new user. __ 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] Can't run nlme with nested structure
Hello! So, my problem is following. I have bird offspring growth data and I'd like to model individual growth curves (aim is to study asymptotes and inflection points) with nlme according to Pinheiro Bates 2000: first using nlsList to generate individual curves and then nlme to study the parameters and fixed effects. The data is structured to two levels. I have broods and individuals within the broods. Problems arise if I specify the groupedData object to have two levels. Running of the nlme gives me an error message can't run the model with multiple levels, or something alike.. Is there a way around this or should I start looking fo another way of analysing the data? Thank you for your time. Pekka Kontiainen Ph.D. Candidate Bird Ecology Unit Department of Environmental and Biosciences P.O. Box 65 (00014) University of Helsinki FINLAND Phone +35844-5496858 - Edelleenlähetetty viesti päättyy - Pekka Kontiainen Ph.D. Candidate Bird Ecology Unit Department of Environmental and Biosciences P.O. Box 65 (00014) University of Helsinki FINLAND Phone +35844-5496858 __ 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] Successive Graphs
... or use lattice and splom() instead. If the successive graphs bear some relationship to each other, this might produce a more useful display, too. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Prager Sent: Monday, September 11, 2006 2:38 PM To: r-help@stat.math.ethz.ch Subject: Re: [R] Successive Graphs [EMAIL PROTECTED] wrote: Hello! I have written an R script on a Windows platform where I calculate eight result matrices I plot using matplot. I would like to display the resulting plots successively, rather than simultaneously, and I was wondering if anyone could point me in the right direction as to how to do this. The graphs pop up in this manner by default when I run my script in S-PLUS, with tabs separating them so I can view each graph at my leisure. However when I run my script in R, each graph pops up only for a moment before it is replaced by the next until I am left with only the plot of the eighth matrix at the end of the script. Thanks in advance for your help! Others have pointed out the R plot history mechanism, which is very nice. A few additions. If you are re-running the script often and want to get rid of old windows, you can put near the top of your script graphics.off() You can open a graphics window -- with history enabled -- with windows(record=TRUE) Plot history is saved. If desired, you can clear the old history before making new plots with .SavedPlots - NULL Mike Prager Southeast Fisheries Science Center, NOAA Beaufort, North Carolina USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Reading fixed column format
Jason Barnhart jasoncbarnhart at msn.com writes: These posts may be helpful. http://tolstoy.newcastle.edu.au/R/help/05/06/5776.html https://stat.ethz.ch/pipermail/r-help/2002-May/021145.html Using scan directly may also work for you rather than read.fwf. Also, there are posts regarding using other tools such a 'perl' or 'cut' to prepocess the data before reading with R. Searching the archives with those keywords should help. I new user should not have to learn perl,cut, awk, etc simply to be able to use R. Does not make sense to me. __ 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] Extracting overdispersion estimates from lmer amd glm objects
summary(modeltest)@sigma Toby Gardner wrote: Dear list, I am needing to extract the estimate of overdispersion (deviance / residual degrees of freedom or c-hat) from multiple model objects - so they can then be used to compare the extent of overdispersion among alternative models as well as calculate qausi-AIC values. I have been unable to do this, despite consulting a number of manuals and searching the R-help. I am imaging that in theory it should be possible with some call to attr(), but i have so far had no success. An example model output would be: modeltest-lmer(Coleodactylus_amazonicus_N~USD + (1|site),data=SFArray,family=poisson,method=Laplace,control=list(usePQL=FALSE, msVerbose=TRUE)) summary(modeltest) Generalized linear mixed model fit using Laplace Formula: Coleodactylus_amazonicus_N ~ USD + (1 | site) Data: SFArray Family: poisson(log link) AIC BIClogLik deviance 75.94996 81.68603 -34.97498 69.94996 Random effects: Groups NameVariance Std.Dev. site (Intercept) 2.6076 1.6148 number of obs: 50, groups: site, 5 Estimated scale (compare to 1) 1.080798 What I need is to extract this value (1.080798) from multiple lmer objects. Has anyone any recommendations? I also need to do this for glm objects although I suspect if someone was able to kindly point me in the right direction then the solution is likely to be similar. Very many thanks, Toby Gardner sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] datasets graphics grDevices methods stats utils base other attached packages: JGR iplots JavaGD lme4 Matrixlattice MASS rJava 1.4-71.0-30.3-4 0.995-2 0.995-15 0.13-8 7.2-27.1 0.4-6 School of Environmental Sciences University of East Anglia Norwich, NR4 7TJ United Kingdom Email: [EMAIL PROTECTED] Website: www.uea.ac.uk/~e387495 [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat. Centre for Resource and Environmental Studies The Australian National University Canberra ACT 0200 Australia T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au F: +61 2 6125 0757 CRICOS Provider # 00120C The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. - John Tukey. __ R-help@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] stepAIC
Hi I hope this isn't off topics, but I have always found when I stepAIC() some glm I get an improvement in accuracy and kappa, but I have just done a case where I got a marginal deterioration. Is this possible, or should I be going through my figures carefully to see if I have messed up? Stephen Choularton 02 2226 0413 545 182 Checked by AVG Free Edition. __ 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] Extracting overdispersion estimates from lmer amd glm objects
You can extract it from a summary.lmer object, which has a slot names sigma that contains this scale parameter. For example, sum.modeltest - summary(modeltest) [EMAIL PROTECTED] On 11/09/06, Toby Gardner [EMAIL PROTECTED] wrote: Dear list, I am needing to extract the estimate of overdispersion (deviance / residual degrees of freedom or c-hat) from multiple model objects - so they can then be used to compare the extent of overdispersion among alternative models as well as calculate qausi-AIC values. I have been unable to do this, despite consulting a number of manuals and searching the R-help. I am imaging that in theory it should be possible with some call to attr(), but i have so far had no success. An example model output would be: modeltest-lmer(Coleodactylus_amazonicus_N~USD + (1|site),data=SFArray,family=poisson,method=Laplace,control=list(usePQL=FALSE, msVerbose=TRUE)) summary(modeltest) Generalized linear mixed model fit using Laplace Formula: Coleodactylus_amazonicus_N ~ USD + (1 | site) Data: SFArray Family: poisson(log link) AIC BIClogLik deviance 75.94996 81.68603 -34.97498 69.94996 Random effects: Groups NameVariance Std.Dev. site (Intercept) 2.6076 1.6148 number of obs: 50, groups: site, 5 Estimated scale (compare to 1) 1.080798 What I need is to extract this value (1.080798) from multiple lmer objects. Has anyone any recommendations? I also need to do this for glm objects although I suspect if someone was able to kindly point me in the right direction then the solution is likely to be similar. Very many thanks, Toby Gardner sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] datasets graphics grDevices methods stats utils base other attached packages: JGR iplots JavaGD lme4 Matrixlattice MASS rJava 1.4-71.0-30.3-4 0.995-2 0.995-15 0.13-8 7.2-27.1 0.4-6 School of Environmental Sciences University of East Anglia Norwich, NR4 7TJ United Kingdom Email: [EMAIL PROTECTED] Website: www.uea.ac.uk/~e387495 [[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. -- = 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.
Re: [R] stepAIC
On Tue, 12 Sep 2006, stephenc wrote: Hi I hope this isn't off topics, but I have always found when I stepAIC() some glm I get an improvement in accuracy and kappa, but I have just done a case where I got a marginal deterioration. Is this possible, or should I be going through my figures carefully to see if I have messed up? It is certainly possible. Optimizing AIC is only aimed at getting an improvement in one prediction measure, on average. -- 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] Installation difficulty with rimage
Thanks to Professor Ripley and Sarah Goslee for their helpful responses which have progressed my installation of rimage a little further. Installing fftw2 instead of fftw3 of course solves the problem and I apologize for initially missing that requirement in the rimage documentation. My install has now unfortunately stalled at the next stage and once again I would appreciate any advice as to how to solve the problem: checking jpeglib.h usability... no checking jpeglib.h presence... no checking for jpeglib.h... no configure: error: Sorry, can't find jpeglib header ERROR: configuration failed for package 'rimage' I believe that I have successfully installed libjpeg from the web site http://www.ijg.org as specified in the documentation. I have also checked for the existence of the jpeglib.h file which is sitting in /usr/local/bin/jpeg-6b I noticed an old posting on this issue, but the solution was to make sure that the jpeglib.h existed, which it does. I am now running FFTW version 2.1.5, fedora core 3 and R version 2.3.1 Thanks again John Prof Brian Ripley wrote: On Mon, 11 Sep 2006, John Kornak wrote: Dear R people, I am trying to install rimage using install.packages(rimage) but am receiving the following errors despite having FFTW installed. I would appreciate any help to get this fixed. checking fftw.h usability... no checking fftw.h presence... no checking for fftw.h... no configure: error: Sorry, can't find fftw header ERROR: configuration failed for package 'rimage' I am using FFTW version 3.1, fedora core 3 and R version 2.3.1 I noticed an old posting on the subject but the solution was to install FFTW which I already did but the error still persists. You need fftw2, not fftw3 (as the DESCRIPTION file says). That posting was spot on. -- John Kornak,PhD Assistant Professor Departments of Radiology, and Epidemiology Biostatistics University of California, San Francisco Box 0946 San Francisco, CA 94143 Tel: (415) 353-4740 fax: (415) 353-9423 Email: [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] Problem with geweke.diag
Dear R-users, I have some problems with the geweke.diag-Function of the coda-package. I try to obtain the Geweke-diagnostic by using the following, simple code: library(coda) input.geweke = as.mcmc(input.matrix)#input.matrix is a 25.000 x 35 matrix with the 25.000 saved draws of the 35 parameters of interest output = geweke.diag(input.geweke) However, I get the following error message: output = geweke.diag(input.matrix) Fehler in glm.fit(x = X, y = Y, weights = weights, start = start, etastart = etastart, : inner loop 1; cannot correct step size Zusätzlich: Warning message: step size truncated due to divergence Does anybody have any hints or ideas about what causes this error message? The MCMC-graphs clearly look like the chain has converged. Thank you very much in advance, Ralph _ Diese E-Mail (ggf. nebst Anhang) enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind, oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet. This e-mail (and any attachment/s) contains confidential and...{{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] Can't run nlme with nested structure
Hello Pekka, there may be a way around it. However, you should provide commented, minimal, self-contained, reproducible code so we can see what you are trying to do. We need to see exactly what you are telling R, and what nlme is telling you. Cheers Andrew On Tue, Sep 12, 2006 at 09:49:28AM +0300, Pekka Kontiainen wrote: Hello! So, my problem is following. I have bird offspring growth data and I'd like to model individual growth curves (aim is to study asymptotes and inflection points) with nlme according to Pinheiro Bates 2000: first using nlsList to generate individual curves and then nlme to study the parameters and fixed effects. The data is structured to two levels. I have broods and individuals within the broods. Problems arise if I specify the groupedData object to have two levels. Running of the nlme gives me an error message can't run the model with multiple levels, or something alike.. Is there a way around this or should I start looking fo another way of analysing the data? Thank you for your time. Pekka Kontiainen Ph.D. Candidate Bird Ecology Unit Department of Environmental and Biosciences P.O. Box 65 (00014) University of Helsinki FINLAND Phone +35844-5496858 - Edelleenl?hetetty viesti p??ttyy - Pekka Kontiainen Ph.D. Candidate Bird Ecology Unit Department of Environmental and Biosciences P.O. Box 65 (00014) University of Helsinki FINLAND Phone +35844-5496858 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: [EMAIL PROTECTED] http://www.ms.unimelb.edu.au __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extracting overdispersion estimates from lmer amd glm objects
PS, the equivalent for a glm is: sum.modeltest - summary(modeltest) sum.modeltest$dispersion Hope this helps. On 11/09/06, Toby Gardner [EMAIL PROTECTED] wrote: Dear list, I am needing to extract the estimate of overdispersion (deviance / residual degrees of freedom or c-hat) from multiple model objects - so they can then be used to compare the extent of overdispersion among alternative models as well as calculate qausi-AIC values. I have been unable to do this, despite consulting a number of manuals and searching the R-help. I am imaging that in theory it should be possible with some call to attr(), but i have so far had no success. An example model output would be: modeltest-lmer(Coleodactylus_amazonicus_N~USD + (1|site),data=SFArray,family=poisson,method=Laplace,control=list(usePQL=FALSE, msVerbose=TRUE)) summary(modeltest) Generalized linear mixed model fit using Laplace Formula: Coleodactylus_amazonicus_N ~ USD + (1 | site) Data: SFArray Family: poisson(log link) AIC BIClogLik deviance 75.94996 81.68603 -34.97498 69.94996 Random effects: Groups NameVariance Std.Dev. site (Intercept) 2.6076 1.6148 number of obs: 50, groups: site, 5 Estimated scale (compare to 1) 1.080798 What I need is to extract this value (1.080798) from multiple lmer objects. Has anyone any recommendations? I also need to do this for glm objects although I suspect if someone was able to kindly point me in the right direction then the solution is likely to be similar. Very many thanks, Toby Gardner sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1] datasets graphics grDevices methods stats utils base other attached packages: JGR iplots JavaGD lme4 Matrixlattice MASS rJava 1.4-71.0-30.3-4 0.995-2 0.995-15 0.13-8 7.2-27.1 0.4-6 School of Environmental Sciences University of East Anglia Norwich, NR4 7TJ United Kingdom Email: [EMAIL PROTECTED] Website: www.uea.ac.uk/~e387495 [[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. -- = 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.
Re: [R] Reading fixed column format
On Sep 12, 2006, at 2:47 AM, Anupam Tyagi wrote: Jason Barnhart jasoncbarnhart at msn.com writes: These posts may be helpful. http://tolstoy.newcastle.edu.au/R/help/05/06/5776.html https://stat.ethz.ch/pipermail/r-help/2002-May/021145.html Using scan directly may also work for you rather than read.fwf. Also, there are posts regarding using other tools such a 'perl' or 'cut' to prepocess the data before reading with R. Searching the archives with those keywords should help. I new user should not have to learn perl,cut, awk, etc simply to be able to use R. Does not make sense to me. Hi Anupam, You'll get much better help here if you're not ill-tempered. This is a group of extraordinarily helpful volunteers who owe you less than you paid for the product. Please consider saving your data in a way that will make it easier to read into R. No program can read every dataset. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading fixed column format
Michael Kubovy wrote: Please consider saving your data in a way that will make it easier to read into R. No program can read every dataset. going back to the original post, there seems to be a couple of hanging questions: None of these seem to read non-coniguous variables from columns; or may be I am missing something. read.fwf is not meant for large files according to a post in the archives. Thanks for the pointers. I have read the R data input and output. Anupam. First up, how 'large' is your 'large ASCII file'? How many rows and columns? Secondly, what are 'non-contiguous' variables? Perhaps if you posted the first few lines and columns of the file then we might get an idea of how to read it in. 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.
[R] Gnuplot epslatex format also in R?
Dear All Is there some way of exporting R plots to epslatex, i.e., to a file with the eps file and another one with the LaTeX commands (representing the text in the plots), likewise Gnuplot does? If so, could you please indicate it to me? Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Gnuplot epslatex format also in R?
I did an eps/ps file with e.g.: postscript(c:/Temp/test.eps, width = 8.0, height = 6.0, horizontal = FALSE, onefile = FALSE, paper = special) curve(x^2) dev.off() but I am not sure what you mean with the second file with the latex commands. Paul Smith schrieb: Dear All Is there some way of exporting R plots to epslatex, i.e., to a file with the eps file and another one with the LaTeX commands (representing the text in the plots), likewise Gnuplot does? If so, could you please indicate it to me? Thanks in advance, Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] Gnuplot epslatex format also in R?
On Tue, 12 Sep 2006, Paul Smith wrote: Is there some way of exporting R plots to epslatex, i.e., to a file with the eps file and another one with the LaTeX commands (representing the text in the plots), likewise Gnuplot does? If so, could you please indicate it to me? R has an xfig driver, and AFAIK you can do this from xfig. -- 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.
[R] Help understanding how nls parses the formula argument to estimate the model
I could use some help understanding how nls parses the formula argument to a model.frame and estimates the model. I am trying to utilize the functionality of the nls formula argument to modify garchFit() to handle other variables in the mean equation besides just an arma(u,v) specification. My nonlinear model is y-nls(t~a*sin(w*2*pi/365*id+p)+b*id+int,data=t1, start=list(w=.5,a=.1,p=.5,b=init.y$coef[2],int=init.y$coef[1] ), control=list(maxiter=100,minFactor=1e-18)) where t is change in daily temperatures, id is just a time trend and the a*sin is a one year fourier series. I have tried to debug the nls code using the following code t1-data.frame(t=as.vector(x),id=index(x)) data=t1; formula - as.formula(t ~ a *sin(w *2* pi/365 * id + p) + b * id + int); varNames - all.vars(formula) algorithm-'default'; mf - match.call(definition=nls,expand.dots=FALSE, call('nls',formula, data=parent.frame(),start,control = nls.control(), algorithm = default, trace = FALSE, subset, weights, na.action, model = FALSE, lower = -Inf, upper = Inf)); mWeights-F;#missing(weights); start=list(w=.5,a=.1,p=.5,b=init.y$coef[2],int=init.y$coef[1] ); pnames - names(start); varNames - varNames[is.na(match(varNames, pnames, nomatch = NA))] varIndex - sapply(varNames, function(varName, data, respLength) { length(eval(as.name(varName), data))%%respLength == 0}, data, length(eval(formula[[2]], data)) ); mf$formula - as.formula(paste(~, paste(varNames[varIndex], collapse = +)), env = environment(formula)); mf$start - NULL;mf$control - NULL;mf$algorithm - NULL; mf$trace - NULL;mf$model - NULL; mf$lower - NULL;mf$upper - NULL; mf[[1]] - as.name(model.frame); mf-evalq(mf,data); n-nrow(mf) mf-as.list(mf); wts - if (!mWeights) model.weights(mf) else rep(1, n) if (any(wts 0 | is.na(wts))) stop(missing or negative weights not allowed) m - switch(algorithm, plinear = nlsModel.plinear(formula, mf, start, wts), port = nlsModel(formula, mf, start, wts, upper), nlsModel(formula, mf, start, wts)); I am struggling with the environment issues associated with performing these operations. thank you __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] nls
Hello everyone ! I am trying to write a short program to estimate semivariogram parameters. But I keep running into a problem when using the nls function. Could you please shed some light. I have put a sample of one of the codes and ran a short example so you see what I mean. - fit.gaus-function(coordinates,values,guess.c0,guess.c1,guess.a) { long-rep(coordinates[,1],each=length(coordinates[,1])) lag.long-t(matrix(long,nrow=length(coordinates[,1]),byrow=TRUE)) dif.long -(lag.long-t(lag.long))^2 lat -rep(coordinates[,2],each=length(coordinates[,2])) lag.lat-t(matrix(lat,nrow=length(coordinates[,2]),byrow=TRUE)) dif.lat -(lag.lat-t(lag.lat))^2 h -sqrt(dif.long+dif.lat) print (h) #distance matrix between data points if( length(values[1,])1) { y.m -apply(values,1,sum,na.rm=TRUE) y.m -as.matrix(y.m) y.mod -(1/length(values[1,]))*(y.m) } else { y.mod -as.matrix(values) } semi -rep(y.mod,each=length(y.mod)) mat1-t(matrix(semi,nrow=length(y.mod),byrow=TRUE)) mat2-t(mat1) semivariance -(1/2)*(mat1-mat2)^2 model -semivariance ~c0+c1*(1-exp(-(h^2)/a^2)) parameters -nls(model,start = list(c0=guess.c0,c1=guess.c1,a=guess.a),trace=TRUE) results -summary(parameters) print(results) } don -matrix(c(2,3,9,6,5,2,7,9,5,3),5,2) don [,1] [,2] [1,]22 [2,]37 [3,]99 [4,]65 [5,]53 data -matrix(c(3,4,2,4,6)) data [,1] [1,]3 [2,]4 [3,]2 [4,]4 [5,]6 fit.gaus(don,data,2,3,5) [,1] [,2] [,3] [,4] [,5] [1,] 0.00 5.099020 9.899495 5.00 3.162278 [2,] 5.099020 0.00 6.324555 3.605551 4.472136 [3,] 9.899495 6.324555 0.00 5.00 7.211103 [4,] 5.00 3.605551 5.00 0.00 2.236068 [5,] 3.162278 4.472136 7.211103 2.236068 0.00 178.9113 : 2 3 5 Error in qr.qty(QR, resid) : 'qr' and 'y' must have the same number of rows __ 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] Reading fixed column format
Hi Well. I use R quite extensively for a quite a long time without knowing perl, cut, awk etc. Do you think I shall learn it? I agree with Barry Rowlingson that best way how to get a correct answer is to present all relevant information. Seems to me that read.table, read.fwf are obvious choce, but there are other read options as you can find out from help index, e.g. readLines, readBin. Maybe you could try to fine tune readLines. HTH Petr On 12 Sep 2006 at 6:47, Anupam Tyagi wrote: To: r-help@stat.math.ethz.ch From: Anupam Tyagi [EMAIL PROTECTED] Date sent: Tue, 12 Sep 2006 06:47:56 + (UTC) Subject:Re: [R] Reading fixed column format Jason Barnhart jasoncbarnhart at msn.com writes: These posts may be helpful. http://tolstoy.newcastle.edu.au/R/help/05/06/5776.html https://stat.ethz.ch/pipermail/r-help/2002-May/021145.html Using scan directly may also work for you rather than read.fwf. Also, there are posts regarding using other tools such a 'perl' or 'cut' to prepocess the data before reading with R. Searching the archives with those keywords should help. I new user should not have to learn perl,cut, awk, etc simply to be able to use R. Does not make sense to me. __ 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. Petr Pikal [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] nls
Hello everyone ! I am trying to write a short program to estimate semivariogram parameters. But I keep running into a problem when using the nls function. Could you please shed some light. I have put a sample of one of the codes and ran a short example so you see what I mean. - fit.gaus-function(coordinates,values,guess.c0,guess.c1,guess.a) { long-rep(coordinates[,1],each=length(coordinates[,1])) lag.long-t(matrix(long,nrow=length(coordinates[,1]),byrow=TRUE)) dif.long -(lag.long-t(lag.long))^2 lat -rep(coordinates[,2],each=length(coordinates[,2])) lag.lat-t(matrix(lat,nrow=length(coordinates[,2]),byrow=TRUE)) dif.lat -(lag.lat-t(lag.lat))^2 h -sqrt(dif.long+dif.lat) if( length(values[1,])1) { y.m -apply(values,1,sum,na.rm=TRUE) y.m -as.matrix(y.m) y.mod -(1/length(values[1,]))*(y.m) } else { y.mod -as.matrix(values) } semi -rep(y.mod,each=length(y.mod)) mat1-t(matrix(semi,nrow=length(y.mod),byrow=TRUE)) mat2-t(mat1) semivariance -(1/2)*(mat1-mat2)^2 model -semivariance ~c0+c1*(1-exp(-(h^2)/a^2)) parameters -nls(model,start = list(c0=guess.c0,c1=guess.c1,a=guess.a),trace=TRUE) results -summary(parameters) print(results) } -- don -matrix(c(2,3,9,6,5,2,7,9,5,3),5,2) don [,1] [,2] [1,]22 [2,]37 [3,]99 [4,]65 [5,]53 data -matrix(c(3,4,2,4,6)) data [,1] [1,]3 [2,]4 [3,]2 [4,]4 [5,]6 fit.gaus(don,data,2,3,5) [,1] [,2] [,3] [,4] [,5] [1,] 0.00 5.099020 9.899495 5.00 3.162278 [2,] 5.099020 0.00 6.324555 3.605551 4.472136 [3,] 9.899495 6.324555 0.00 5.00 7.211103 [4,] 5.00 3.605551 5.00 0.00 2.236068 [5,] 3.162278 4.472136 7.211103 2.236068 0.00 178.9113 : 2 3 5 Error in qr.qty(QR, resid) : 'qr' and 'y' must have the same number of rows __ 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] rename cols
Hi On 12 Sep 2006 at 6:44, Anupam Tyagi wrote: To: r-help@stat.math.ethz.ch From: Anupam Tyagi [EMAIL PROTECTED] Date sent: Tue, 12 Sep 2006 06:44:03 + (UTC) Subject:Re: [R] rename cols Christos Hatzis christos at nuverabio.com writes: Try this: old.colnames - colnames(my.439.vars.df) old.colnames[old.colnames==fksm] - new.name.a old.colnames[old.colnames==klmk] - new.name.b For a newcomer, it will be useful to have a function like this in the base R: that can take a list of old.names and new.names, and do the assignment. It is far more efficient to have functions that are shared via the R distribution, than having to write own functions for carrying out basic data management tasks, and simple routinely used statistical procedures. Most users would rather spend time on thinking about the substantive work, instead of figuring out how to program---this may be specially true for new users. This way the R is programming environment and language so more or less even newcomers are expected to do some programming. And it is also volunteer project. I expect that renaming columns is task which is not done very often, so there did not come up anybody who was interested in programming such function. Also the pool of available functions seems to be quite extensive in base R and even bigger in all available packages. Sometimes is hard enough to remember correct function name. There is also excellent help and manual pages with nice copy/paste feature examples. I wonder if you ever tried to get some help from e.g. Excel help. Quite often you are completely lost. functions used will also be more efficient and better designed than the typical new user. If a new user does not wont to use command line syntax he/she can use some of available GUIS (see R GUI in home page) e.g. JGR. Petr __ 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. Petr Pikal [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] rename cols
I don't know, this seems pretty simple and intuitive (to me) # Create a sample data set with 439 variables tmp - data.frame(matrix(c(rnorm(4390)), ncol=439)) colnames(tmp)-paste(col, 1:439, sep = ) # rename a certain variable in that dataset names(tmp)[(which(names(tmp)=='col1'))]-'NewName' Here you are using indexing and a simple evaluation to find a variable by name in a large data set and rename it. R is so flexible that this cat can be skinned in many (and maybe even easier) ways, though. Harold -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Anupam Tyagi Sent: Tuesday, September 12, 2006 12:34 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] rename cols For a newcomer who wants to rename variable fksm and klmk in a dataframe of with 439 variables there is not easy and intuitive solution. That person has to spend a lot of time listing columns and counting columns or doing string searches or using brackets within brackets within brackets to get a simple thing done. Is there a simple function or solution to this in R without using an add-on package? __ 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] rename cols
For a newcomer who wants to rename variable fksm and klmk in a dataframe of with 439 variables there is not easy and intuitive solution. That person has to spend a lot of time listing columns and counting columns or doing string searches or using brackets within brackets within brackets to get a simple thing done. Is there a simple function or solution to this in R without using an add-on package? I use: rename - function(x, replace) { replacement - replace[names(x)] names(x)[!is.na(replacement)] - replacement[!is.na(replacement)] x } (which is available in the reshape package) You use it like: df - data.frame(a=1:2, b=3:4) df - rename(df, c(a=variable 1)) Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lattice cloud and conditional axis limits
I'm using the 'cloud' function in the 'lattice' package to produce multi-panel 3D scatter plots. The range of the values used vary much between each panel (especially on the z axis), so I wish the axis limits to be calculated based on the (conditional) data. Here's a minimal example: library(lattice) z=1:200 x=runif(200) y=runif(200) s=factor(rep(c(1,2),each=100)) cloud(z~x*y|s,scales=list(arrows=FALSE)) On the first panel, the z values are in the range [1,100], and on the second panel, they are in the range [101,200]. I wish the z axis to reflect this, i.e., to only span these values. (In my actual data sets, this does make more sense than in this example.) If 'cloud' worked the same way the 'xypanel' function does, one of the following would work: cloud(z~x*y|s,scales=list(arrows=FALSE,z=list(relation=free))) cloud(z~x*y|s,scales=list(arrows=FALSE,relation=free)) However, it does not. Any ideas how I can make it work? -- Karl Ove Hufthammer E-mail and Jabber: [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] rename cols
Hi There is even an Excel like possibility for renaming columns. try newDF-edit(oldDF) you can go through columns and after clicking on header you can change column name. Petr On 12 Sep 2006 at 8:31, hadley wickham wrote: Date sent: Tue, 12 Sep 2006 08:31:43 -0400 From: hadley wickham [EMAIL PROTECTED] To: Anupam Tyagi [EMAIL PROTECTED] Copies to: r-help@stat.math.ethz.ch Subject:Re: [R] rename cols For a newcomer who wants to rename variable fksm and klmk in a dataframe of with 439 variables there is not easy and intuitive solution. That person has to spend a lot of time listing columns and counting columns or doing string searches or using brackets within brackets within brackets to get a simple thing done. Is there a simple function or solution to this in R without using an add-on package? I use: rename - function(x, replace) { replacement - replace[names(x)] names(x)[!is.na(replacement)] - replacement[!is.na(replacement)] x } (which is available in the reshape package) You use it like: df - data.frame(a=1:2, b=3:4) df - rename(df, c(a=variable 1)) Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Petr Pikal [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] (no subject)
Hi, I have a problem with aggregate. x - aggregate(t1,list(t2,t3,t4), mean) z-x[,3] I want z to be a vector but it is a factor. I've tried to use as.vector(z,mode=numeric) but then the numbers get scrambeled. Any help is appriciated /anders __ 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] Gnuplot epslatex format also in R?
On 9/12/06, Prof Brian Ripley [EMAIL PROTECTED] wrote: Is there some way of exporting R plots to epslatex, i.e., to a file with the eps file and another one with the LaTeX commands (representing the text in the plots), likewise Gnuplot does? If so, could you please indicate it to me? R has an xfig driver, and AFAIK you can do this from xfig. Yes, your suggestion works! Thanks. Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Kendall's tau-c
Hello, I can't find a package which calculates Kendall's tau-c. There is the package Kendall, but it only calcuates Kendall's tau-b. Here is the example from ttp://www2.chass.ncsu.edu/garson/pa765/assocordinal.htm. cityriots - data.frame(citysize=c(1,1,2,2,3,3), riotsize=c(1,2,1,2,1,2), weight=c(4,2,2,3,0,4)) cityriots - data.frame(lapply(cityriots,function(x) rep(x,cityriots$weight))) xtabs(~ riotsize+citysize,cityriots) tau-c should be .57. Do you have a hint? Best regards Knut Wenzig -- Dipl.-Sozialw. Knut Wenzig Lehrstuhl fuer Soziologie und empirische Sozialforschung Universitaet Augsburg | Universitaetsstrasse 6 | 86159 Augsburg Tel ++49 821 598-4101 | FAX -4222 | ICQ: 210200999 | Germany http://www.philso.uni-augsburg.de/lehrstuehle/soziologie/sozio2/ __ 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] factor to numeric (no subject)
Hi all culumns which are used for discrimination (in your case 3) are factor. If you want to change them to numeric you has to use as.numeric(as.character(x[,3])) I believe it is in FAQ. HTH Petr Please use sensible subject. On 12 Sep 2006 at 14:49, Anders Eklund wrote: Date sent: Tue, 12 Sep 2006 14:49:18 +0200 (CEST) From: Anders Eklund [EMAIL PROTECTED] To: [EMAIL PROTECTED] r-help@stat.math.ethz.ch Subject:[R] (no subject) Hi, I have a problem with aggregate. x - aggregate(t1,list(t2,t3,t4), mean) z-x[,3] I want z to be a vector but it is a factor. I've tried to use as.vector(z,mode=numeric) but then the numbers get scrambeled. Any help is appriciated /anders __ 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. Petr Pikal [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] Fwd: (no subject)
From the FAQ: 7.10 How do I convert factors to numeric? It may happen that when reading numeric data into R (usually, when reading in a file), they come in as factors. If f is such a factor object, you can use as.numeric(as.character(f)) to get the numbers back. More efficient, but harder to remember, is as.numeric(levels(f))[as.integer(f)] In any case, do not call as.numeric() or their likes directly for the task at hand (as as.numeric() or unclass() give the internal codes). On 12/09/06, Anders Eklund [EMAIL PROTECTED] wrote: Hi, I have a problem with aggregate. x - aggregate(t1,list(t2,t3,t4), mean) z-x[,3] I want z to be a vector but it is a factor. I've tried to use as.vector(z,mode=numeric) but then the numbers get scrambeled. Any help is appriciated /anders __ 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 -- = 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.
Re: [R] Test internet presence
Gabor Grothendieck wrote: Here is a variation for Windows. The second line returns TRUE or FALSE and may need to be varied if the output of ping is not the same on your system as on mine: ping - system(ping www.google.com, intern = TRUE) as.numeric(strsplit(grep(Received, ping, value = TRUE), [ ,])[[1]][8]) 0 ... Thank you Gabor and Ted! These are all fine ways, but as both of you have stated not really general as you never know what ping will produce on different versions etc. I am really keen on test from tests/internet.R. If that test is OK for base R, I do not see why it should not be OK for R package. I just hope to get some more feedback on my question[1] to prof. Ripley. [1]https://stat.ethz.ch/pipermail/r-help/2006-September/112766.html Thank you! -- Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3 mail: gregor.gorjanc at bfro.uni-lj.si SI-1230 Domzale tel: +386 (0)1 72 17 861 Slovenia, Europefax: +386 (0)1 72 17 888 -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ 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] Kendall's tau-c
On Tue, 2006-09-12 at 15:02 +0200, Knut Wenzig wrote: Hello, I can't find a package which calculates Kendall's tau-c. There is the package Kendall, but it only calcuates Kendall's tau-b. Here is the example from ttp://www2.chass.ncsu.edu/garson/pa765/assocordinal.htm. cityriots - data.frame(citysize=c(1,1,2,2,3,3), riotsize=c(1,2,1,2,1,2), weight=c(4,2,2,3,0,4)) cityriots - data.frame(lapply(cityriots,function(x) rep(x,cityriots$weight))) xtabs(~ riotsize+citysize,cityriots) tau-c should be .57. Do you have a hint? Best regards Knut Wenzig Here is some code: # Calculate CONcordant Pairs in a table # cycle through x[r, c] and multiply by # sum(x elements below and to the right of x[r, c]) # x = table concordant - function(x) { x - matrix(as.numeric(x), dim(x)) # get sum(matrix values r AND c) # for each matrix[r, c] mat.lr - function(r, c) { lr - x[(r.x r) (c.x c)] sum(lr) } # get row and column index for each # matrix element r.x - row(x) c.x - col(x) # return the sum of each matrix[r, c] * sums # using mapply to sequence thru each matrix[r, c] sum(x * mapply(mat.lr, r = r.x, c = c.x)) } # Calculate DIScordant Pairs in a table # cycle through x[r, c] and multiply by # sum(x elements below and to the left of x[r, c]) # x = table discordant - function(x) { x - matrix(as.numeric(x), dim(x)) # get sum(matrix values r AND c) # for each matrix[r, c] mat.ll - function(r, c) { ll - x[(r.x r) (c.x c)] sum(ll) } # get row and column index for each # matrix element r.x - row(x) c.x - col(x) # return the sum of each matrix[r, c] * sums # using mapply to sequence thru each matrix[r, c] sum(x * mapply(mat.ll, r = r.x, c = c.x)) } # Calculate Kendall-Stuart Tau-c # x = table calc.KSTc - function(x) { x - matrix(as.numeric(x), dim(x)) c - concordant(x) d - discordant(x) m - min(dim(x)) n - sum(x) KSTc - (m * 2 * (c - d)) / ((n ^ 2) * (m - 1)) KSTc } calc.KSTc(with(cityriots, table(riotsize, citysize))) [1] 0.569 The above code, along with other such measures, will eventually find its way into the CrossTable() function in the gmodels CRAN package when time permits (which seems to be in short supply of late...) HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using XY location data to calculate ecological parameters
Dear R gurus, I have XY data giving the locations of tree seedlings that were surveyed during a 210 meter belt transect. This belt transect was taken by stretching a line across the field, then measuring all seedlings within 1 meter on either side of the line. The end result was XY coordinates and height for ~1,300 seedlings. I would like to use that data to calculate density of seedlings per 10 meters per species and relative species abundance in order to compare between this transect and other transects as well as to compare between segments of the same transect. Are there any R packages out there that will allow me make those calculations? To give an idea of my data, here's a fictional example: Species X (m) Y(m) Acer negundo90.10 -.19 Acer negundo90.14 -.90 Acer saccharinum90.25 .54 Acer rubrum 90.89 .21 Acer negundo91.25 .36 Acer negundo91.46 -.65 etc. Thanks. Jim Milks __ 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] Command equivalent of rgui File, Save to File?
On 9/12/2006 9:27 AM, Michael Prager wrote: Duncan Murdoch wrote: On 9/11/2006 3:57 PM, Michael Prager wrote: R 2.3.1 on Windows XP Professional. I am writing some scripts to generate examples. The Rgui menu item File, Save to File is helpful. Is there perhaps an equivalent R function that can be incorporated into a script? I think sink() is the closest you can get: set R to write to a file before generating whatever output you want to save. The menu item writes out the GUI text buffer; the R core doesn't know what's in that buffer. Other front ends don't have a buffer at all. [...] Thanks, Duncan, for the helpful response. Unless I have overlooked something (quite possible), sink() saves only the output, not the input as well. I'll continue using the menu system -- which I am delighted to have. Another possibility is to put your script into a file (e.g. script.R), and run Rcmd BATCH script.R This puts the whole transcript of the session into script.Rout. It's not identical to running in the gui, because functions can tell whether they're running interactively or not, but it's close. Duncan Murdoch __ 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] Using XY location data to calculate ecological parameters
Assuming you only use the X direction to split the data into 10 m cells. table(list(Species, round(X, digits = -1))) This will generate a table with the number of seedlings per species in each 10 m cell. Divide this by the area of each cell and you get the densities. 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 -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens James R. Milks Verzonden: dinsdag 12 september 2006 15:36 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Using XY location data to calculate ecological parameters Dear R gurus, I have XY data giving the locations of tree seedlings that were surveyed during a 210 meter belt transect. This belt transect was taken by stretching a line across the field, then measuring all seedlings within 1 meter on either side of the line. The end result was XY coordinates and height for ~1,300 seedlings. I would like to use that data to calculate density of seedlings per 10 meters per species and relative species abundance in order to compare between this transect and other transects as well as to compare between segments of the same transect. Are there any R packages out there that will allow me make those calculations? To give an idea of my data, here's a fictional example: Species X (m) Y(m) Acer negundo90.10 -.19 Acer negundo90.14 -.90 Acer saccharinum90.25 .54 Acer rubrum 90.89 .21 Acer negundo91.25 .36 Acer negundo91.46 -.65 etc. Thanks. Jim Milks __ 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] Conservative ANOVA tables in lmer
On 9/11/06, Manuel Morales [EMAIL PROTECTED] wrote: On Mon, 2006-09-11 at 11:43 -0500, Douglas Bates wrote: On 9/10/06, Andrew Robinson [EMAIL PROTECTED] wrote: On Thu, Sep 07, 2006 at 07:59:58AM -0500, Douglas Bates wrote: I would be happy to re-institute p-values for fixed effects in the summary and anova methods for lmer objects using a denominator degrees of freedom based on the trace of the hat matrix or the rank of Z:X if others will volunteer to respond to the these answers are obviously wrong because they don't agree with whatever and the idiot who wrote this software should be thrashed to within an inch of his life messages. I don't have the patience. This seems to be more than fair to me. I'll volunteer to help explain why the anova.lmer() output doesn't match SAS, etc. Is it worth putting a caveat in the output and the help files? Is it even worth writing a FAQ about this? Having made that offer I think I will now withdraw it. Peter's example has convinced me that this is the wrong thing to do. I am encouraged by the fact that the results from mcmcsamp correspond closely to the correct theoretical results in the case that Peter described. I appreciate that some users will find it difficult to work with a MCMC sample (or to convince editors to accept results based on such a sample) but I think that these results indicate that it is better to go after the marginal distribution of the fixed effects estimates (which is what is being approximated by the MCMC sample - up to Bayesian/frequentist philosophical differences) than to use the conditional distribution and somehow try to adjust the reference distribution. Am I right that the MCMC sample can not be used, however, to evaluate the significance of parameter groups. For example, to assess the significance of a three-level factor? Are there better alternatives than simply adjusting the CI for the number of factor levels (1-alpha/levels). Hmm - I'm not sure what confidence interval and what number of levels you mean there so I can't comment on that method. Suppose we go back to Spencer's example and consider if there is a signficant effect for the Nozzle factor. That is equivalent to the hypothesis H_0: beta_2 = beta_3 = 0 versus the general alternative. A p-value could be formulated from an MCMC sample if we assume that the marginal distribution of the parameter estimates for beta_2 and beta_3 has roughly elliptical contours and you can evaluate that by, say, examining a hexbin plot of the values in the MCMC sample. One could take the ellipses as defined by the standard errors and estimated correlation or, probably better, by the observed standard deviations and correlations in the MCMC sample. Then determine the proportion of (beta_2, beta_3) pairs in the sample that fall outside the ellipse centered at the estimates and with that eccentricity and scaling factors that passes through (0,0). That would be an empirical p-value for the test. I would recommend calculating this for a couple of samples to check on the reproducibility. __ 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] Installation difficulty with rimage
Thanks again to both Sarah Goslee and Professor Ripley. Installing the libjpeg-devel package was the key. John Sarah Goslee wrote: Well, there are two possible problems. One, you don't have the file. Two, it isn't where it's supposed to be. Did you install it from the rpm? If so, did you install both libjpeg and libjpeg-devel The header files (*.h) are usually in the devel packages, and are needed if you want to compile R code against them (which you do). The easiest way to do it is to install both packages from the rpms, using yum or however you prefer to do it, rather than to install the library as source a package from the developers. It sounds like you did the latter? You may be able to convince rimage that everything is okay by putting a symbolic link from the actual header location to where it is supposed to be: ln -s /usr/local/bin/jpeg-6b/jpeglib.h /usr/include/jpeglib.h You will be best off, though (probably) by just installing the libjpeg-devel package. Sarah P.S. Prof. Ripley's answer is both correct and sufficient, of course, but possibly a bit terse - I thought you might appreciate a longer explanation. -- John Kornak,PhD Assistant Professor Departments of Radiology, and Epidemiology Biostatistics University of California, San Francisco Box 0946 San Francisco, CA 94143 Tel: (415) 353-4740 fax: (415) 353-9423 Email: [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] levels of factor when subsetting the factor
All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levels of factor when subsetting the factor
Just add the following to your code new.fact = fact[1:6, drop=T] new.fact [1] A A A B B B Levels: A B -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Afshartous, David Sent: Tuesday, September 12, 2006 11:23 AM To: r-help@stat.math.ethz.ch Subject: [R] levels of factor when subsetting the factor All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] levels of factor when subsetting the factor
Try new.fact = fact[1:6, drop=TRUE] On 12/09/06, Afshartous, David [EMAIL PROTECTED] wrote: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = 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.
Re: [R] levels of factor when subsetting the factor
You have at least two choices: R factor(fact[1:6]) [1] A A A B B B Levels: A B R fact[1:6, drop=TRUE] [1] A A A B B B Levels: A B HTH, Andy From: Afshartous, David All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachments,...{{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] levels of factor when subsetting the factor
On 9/12/06, Afshartous, David [EMAIL PROTECTED] wrote: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? Use the optional argument drop = TRUE cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B fact[1:6, drop = TRUE] [1] A A A B B B Levels: A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levels of factor when subsetting the factor
I think you want 'fact[1:6, drop = TRUE]' -roger Afshartous, David wrote: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/ __ 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] levels of factor when subsetting the factor
factor(new.fact) will do the trick. But that will recode the levels and that might be something you don't want. fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C factor(new.fact) [1] A A A B B B Levels: A B 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 -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Afshartous, David Verzonden: dinsdag 12 september 2006 17:23 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] levels of factor when subsetting the factor All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ 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] levels of factor when subsetting the factor
Also, it is probably easier to use gl() than coerce your data into a factor fact - gl(3, 3, label = c(A, B, C)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Liaw, Andy Sent: Tuesday, September 12, 2006 11:32 AM To: Afshartous, David; r-help@stat.math.ethz.ch Subject: Re: [R] levels of factor when subsetting the factor You have at least two choices: R factor(fact[1:6]) [1] A A A B B B Levels: A B R fact[1:6, drop=TRUE] [1] A A A B B B Levels: A B HTH, Andy From: Afshartous, David All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Notice: This e-mail message, together with any attachments,...{{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. __ 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] Command equivalent of rgui File, Save to File?
Duncan Murdoch wrote: On 9/11/2006 3:57 PM, Michael Prager wrote: R 2.3.1 on Windows XP Professional. I am writing some scripts to generate examples. The Rgui menu item File, Save to File is helpful. Is there perhaps an equivalent R function that can be incorporated into a script? I think sink() is the closest you can get: set R to write to a file before generating whatever output you want to save. The menu item writes out the GUI text buffer; the R core doesn't know what's in that buffer. Other front ends don't have a buffer at all. [...] Thanks, Duncan, for the helpful response. Unless I have overlooked something (quite possible), sink() saves only the output, not the input as well. I'll continue using the menu system -- which I am delighted to have. Mike Mike Prager Southeast Fisheries Science Center, NOAA Beaufort, North Carolina USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] levels of factor when subsetting the factor
check ?[.factor, you need: fact[1:6, drop = TRUE] Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Afshartous, David [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, September 12, 2006 5:22 PM Subject: [R] levels of factor when subsetting the factor All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Test internet presence
On Mon, 11 Sep 2006, Gregor Gorjanc wrote: Prof Brian Ripley ripley at stats.ox.ac.uk writes: ... Check out tests/internet.R. nsl() checks if you can resolve host names, which has worked well enough there. Thank you prof. Ripley for this pointer. I am posting here the relevant part if someone does not look at SVN. I would just like to ask why is .Platform$OS.type == unix added to the test? Is nsl() available only on unix like platforms or ... I did not found any specifics in its help page. Did you look at the help page on Windows? Looking at the help page on Unix only tells you about Unix. Hint: the help page is src/library/utils/man/unix/nsl.Rd (In my country, PhD students are supposed to be able to find things like that out for themselves.) if(!capabilities()[http/ftp]) { warning(no internet capabilities) q() } if(.Platform$OS.type == unix is.null(nsl(cran.r-project.org))) q() Does it make any sense to write a function that would use these two tests. isNetAvailable - function() { ifelse(!capabilities()[http/ftp] ## .Platform$OS.type == unix ## ??? is.null(nsl(cran.r-project.org)), FALSE, TRUE) } Regards, Gregor __ 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] levels of factor when subsetting the factor
thanks to all for the quick replies! if the factor is part of a dataframe, I can apply the subsetting to the entire dataframe, and then use drop=True to the factor separately and then put it back into the new dataframe (code below). is there a way to do this in a single step? dat -data.frame(fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))),Y = rnorm(9)) dat.new = dat[1:6, ] dat.new$fact = dat$fact[1:6, drop = T] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard Sent: Tuesday, September 12, 2006 11:45 AM To: Afshartous, David Cc: r-help@stat.math.ethz.ch Subject: Re: [R] levels of factor when subsetting the factor Afshartous, David [EMAIL PROTECTED] writes: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B Just use factor(new.fact) [1] A A A B B B Levels: A B or fact[1:6, drop=T] [1] A A A B B B Levels: A B And, no, it is not a bug. The fact that a subsample happens to consist only of males does not turn gender into a one-level factor... (Apart from the philosophy, it makes a real difference in tabulation.) -- 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] levels of factor when subsetting the factor
Afshartous, David [EMAIL PROTECTED] writes: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B Just use factor(new.fact) [1] A A A B B B Levels: A B or fact[1:6, drop=T] [1] A A A B B B Levels: A B And, no, it is not a bug. The fact that a subsample happens to consist only of males does not turn gender into a one-level factor... (Apart from the philosophy, it makes a real difference in tabulation.) -- 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] coerce matrix to number
Dear List, how can I coerce a matrix like this [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 to be filled with numbers? this is the result of replacing some character (v, d) with 0 and 1, using the code I found with RSiteSearch() z[] - lapply(z, factor, levels = c(d, v), labels = c(0, 1)); thank you, Simone |-| dott. Simone Gabbriellini PhD Student Dipartimento di Scienze Sociali Università di Pisa via Colombo 35 - 56100 Pisa mail: [EMAIL PROTECTED] mobile: +39 3475710037 |-| Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html [[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] Plotting in R within NX client
Hello, has anyone tried doing this? Local System: NX client (windows version) Remote System: Linux Fedora Core 5, running on 64 bit Intel R 2.3.1 The plots display weird in the sense that the y-labels don't show, i.e. they appear as solid black rectangles rather than numbers. I know the problem has something to do with NX because when I was about to screenshot the problem to send to this list, I noticed that the screenshot got the image right. Searching for the problem didn't yield anything, however there seems to have been related problems with gnuplot + nx. Oddly, gnuplot seems to work fine, although perhaps it's because by default the y-labels are not rotated there. Lastly, tried installing the extra fonts for NX, but still no dice. Does anyone have any suggestions? TIA 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] Use of xvfb : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray
Hi, I use R in remote access on a Debian server. I need X11() to create graphical things so I use xvfb-run (Virtual X server environnement) R to allowing X11() capabilities to R. An other technique is to connect in shh -X to execute my R script. With the connection ssh -X, my R script is well executed. BUT when I use Xvfb, some graphics are created but an error occured and stop the script. here the error : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray There is obviously a problem witth xvfb but I can't not resolve it please help me! Thank you Gael Even __ 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] References about dot a files
Hello: I'm trying to find some reading material about .a files. I'm attempting to build a package which accesses many C routines via .Call, and its been suggested that I need a lib_C_code.a file inside the C directory. What does such a file do? Where can I read somthing about it? I've tried to search for it, but keywords R package .a doesn't work because the .a is too generic. Thanks in advance! [[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] levels of factor when subsetting the factor
Yes. I do this periodically: dat.new - dat[1:6, ] dat.new[] - lapply(dat.new, function(x) if(is.factor(x)) factor(x) else x) HTH, --sundar Afshartous, David said the following on 9/12/2006 11:00 AM: thanks to all for the quick replies! if the factor is part of a dataframe, I can apply the subsetting to the entire dataframe, and then use drop=True to the factor separately and then put it back into the new dataframe (code below). is there a way to do this in a single step? dat -data.frame(fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))),Y = rnorm(9)) dat.new = dat[1:6, ] dat.new$fact = dat$fact[1:6, drop = T] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard Sent: Tuesday, September 12, 2006 11:45 AM To: Afshartous, David Cc: r-help@stat.math.ethz.ch Subject: Re: [R] levels of factor when subsetting the factor Afshartous, David [EMAIL PROTECTED] writes: All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B Just use factor(new.fact) [1] A A A B B B Levels: A B or fact[1:6, drop=T] [1] A A A B B B Levels: A B And, no, it is not a bug. The fact that a subsample happens to consist only of males does not turn gender into a one-level factor... (Apart from the philosophy, it makes a real difference in tabulation.) __ 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] coerce matrix to number
On Tue, 2006-09-12 at 18:42 +0200, Simone Gabbriellini wrote: Dear List, how can I coerce a matrix like this [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 to be filled with numbers? this is the result of replacing some character (v, d) with 0 and 1, using the code I found with RSiteSearch() z[] - lapply(z, factor, levels = c(d, v), labels = c(0, 1)); thank you, Simone I reverse engineered your (presumably) original data frame: z 1 2 3 4 5 6 1 d v v d d d 2 v d v d d d 3 v v d d d d 4 d d d d v d 5 d d d v d d 6 d d d d d d str(z) `data.frame': 6 obs. of 6 variables: $ 1: Factor w/ 2 levels d,v: 1 2 2 1 1 1 $ 2: Factor w/ 2 levels d,v: 2 1 2 1 1 1 $ 3: Factor w/ 2 levels d,v: 2 2 1 1 1 1 $ 4: Factor w/ 2 levels d,v: 1 1 1 1 2 1 $ 5: Factor w/ 2 levels d,v: 1 1 1 2 1 1 $ 6: Factor w/ 2 levels d,v: 1 1 1 1 1 1 If that is correct, then the following should yield what you want in one step: z.num - sapply(z, function(x) as.numeric(x) - 1) z.num 1 2 3 4 5 6 [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 str(z.num) num [1:6, 1:6] 0 1 1 0 0 0 1 0 1 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:6] 1 2 3 4 ... Alternatively, if you were starting out with the character matrix: z.char [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 You could do: storage.mode(z.char) - numeric z.char [,1] [,2] [,3] [,4] [,5] [,6] [1,]011000 [2,]101000 [3,]110000 [4,]000010 [5,]000100 [6,]000000 str(z.char) num [1:6, 1:6] 0 1 1 0 0 0 1 0 1 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : NULL Yet another alternative: matrix(as.numeric(z.char), dim(z.char)) [,1] [,2] [,3] [,4] [,5] [,6] [1,]011000 [2,]101000 [3,]110000 [4,]000010 [5,]000100 [6,]000000 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] coerce matrix to number
if only 2 letters: (z==v)*1 else: lapply(z, function(x) as.numeric(as.character(factor(x,levels= c(d,v,w),labels=c(0,1,2) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Simone Gabbriellini a écrit : Dear List, how can I coerce a matrix like this [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 to be filled with numbers? this is the result of replacing some character (v, d) with 0 and 1, using the code I found with RSiteSearch() z[] - lapply(z, factor, levels = c(d, v), labels = c(0, 1)); thank you, Simone |-| dott. Simone Gabbriellini PhD Student Dipartimento di Scienze Sociali Università di Pisa via Colombo 35 - 56100 Pisa mail: [EMAIL PROTECTED] mobile: +39 3475710037 |-| Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to install R-2.3.1 on Mac OS X 10.3.9?
Hi, is there anyone knows how to install R-2.3.1 on Mac OS X 10.3.9(panther)? Thanks a lot! Lei __ 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] coerce matrix to number
Marc, wpw, great, what a lot of solutions!!! thank you very much, simone Il giorno 12/set/06, alle ore 19:21, Marc Schwartz (via MN) ha scritto: On Tue, 2006-09-12 at 18:42 +0200, Simone Gabbriellini wrote: Dear List, how can I coerce a matrix like this [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 to be filled with numbers? this is the result of replacing some character (v, d) with 0 and 1, using the code I found with RSiteSearch() z[] - lapply(z, factor, levels = c(d, v), labels = c(0, 1)); thank you, Simone I reverse engineered your (presumably) original data frame: z 1 2 3 4 5 6 1 d v v d d d 2 v d v d d d 3 v v d d d d 4 d d d d v d 5 d d d v d d 6 d d d d d d str(z) `data.frame': 6 obs. of 6 variables: $ 1: Factor w/ 2 levels d,v: 1 2 2 1 1 1 $ 2: Factor w/ 2 levels d,v: 2 1 2 1 1 1 $ 3: Factor w/ 2 levels d,v: 2 2 1 1 1 1 $ 4: Factor w/ 2 levels d,v: 1 1 1 1 2 1 $ 5: Factor w/ 2 levels d,v: 1 1 1 2 1 1 $ 6: Factor w/ 2 levels d,v: 1 1 1 1 1 1 If that is correct, then the following should yield what you want in one step: z.num - sapply(z, function(x) as.numeric(x) - 1) z.num 1 2 3 4 5 6 [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 str(z.num) num [1:6, 1:6] 0 1 1 0 0 0 1 0 1 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:6] 1 2 3 4 ... Alternatively, if you were starting out with the character matrix: z.char [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 1 1 0 0 0 [2,] 1 0 1 0 0 0 [3,] 1 1 0 0 0 0 [4,] 0 0 0 0 1 0 [5,] 0 0 0 1 0 0 [6,] 0 0 0 0 0 0 You could do: storage.mode(z.char) - numeric z.char [,1] [,2] [,3] [,4] [,5] [,6] [1,]011000 [2,]101000 [3,]110000 [4,]000010 [5,]000100 [6,]000000 str(z.char) num [1:6, 1:6] 0 1 1 0 0 0 1 0 1 0 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : NULL Yet another alternative: matrix(as.numeric(z.char), dim(z.char)) [,1] [,2] [,3] [,4] [,5] [,6] [1,]011000 [2,]101000 [3,]110000 [4,]000010 [5,]000100 [6,]000000 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. |-| dott. Simone Gabbriellini PhD Student Dipartimento di Scienze Sociali Università di Pisa via Colombo 35 - 56100 Pisa mail: [EMAIL PROTECTED] mobile: +39 3475710037 |-| Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html [[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] rename cols
Thank you so much!! ej On 9/11/06, Tony Plate [EMAIL PROTECTED] wrote: The following works for data frames and matrices (you didn't say which you were working with). x - data.frame(V1=1:3,V2=4:6) x V1 V2 1 1 4 2 2 5 3 3 6 colnames(x) - c(Apple, Orange) x Apple Orange 1 1 4 2 2 5 3 3 6 For a data frame, 'names(x) - c(Apple, Orange)' also works, because a dataframe is stored internally as a list of columns. -- Tony Plate Ethan Johnsons wrote: A quick question please! How do you rename column names? i.e. V1 -- Apple; V2 -- Orange, etc. thx much ej [[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.
[R] extract a value from vector
A quick question, please! How do you extract a certain value of vector? i.e. x = c(2,5,3,6,21,3,6,24, ) How do you get the 1st one (which is 2); the 5th one (which is 21); etc? thx much, ej [[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] Use of xvfb : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray
It's a known problem. Run the X11 device with the arguments stated, as it says On Tue, 12 Sep 2006, Gael Even wrote: Hi, I use R in remote access on a Debian server. I need X11() to create graphical things so I use xvfb-run (Virtual X server environnement) R to allowing X11() capabilities to R. An other technique is to connect in shh -X to execute my R script. With the connection ssh -X, my R script is well executed. BUT when I use Xvfb, some graphics are created but an error occured and stop the script. here the error : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray There is obviously a problem witth xvfb but I can't not resolve it please help me! Thank you Gael Even __ 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] extract a value from vector
I'm not quite sure what you mean. To get the first item in a vector you use x[1] [1] 2 x[5] [1] 21 Is that what you want? On 12/09/06, Ethan Johnsons [EMAIL PROTECTED] wrote: A quick question, please! How do you extract a certain value of vector? i.e. x = c(2,5,3,6,21,3,6,24, ) How do you get the 1st one (which is 2); the 5th one (which is 21); etc? thx much, ej [[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. -- = 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.
Re: [R] extract a value from vector
On 9/12/06, Ethan Johnsons [EMAIL PROTECTED] wrote: A quick question, please! How do you extract a certain value of vector? i.e. x = c(2,5,3,6,21,3,6,24, ) How do you get the 1st one (which is 2); the 5th one (which is 21); etc? Simple, Ethan: x[1], x[5], ... Paul __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Use of xvfb : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray
Prof Brian Ripley [EMAIL PROTECTED] writes: It's a known problem. Run the X11 device with the arguments stated, as it says Alternatively, try playing with the pixel depth of xvfb. I think this mainly happens with 8-bit displays. On Tue, 12 Sep 2006, Gael Even wrote: Hi, I use R in remote access on a Debian server. I need X11() to create graphical things so I use xvfb-run (Virtual X server environnement) R to allowing X11() capabilities to R. An other technique is to connect in shh -X to execute my R script. With the connection ssh -X, my R script is well executed. BUT when I use Xvfb, some graphics are created but an error occured and stop the script. here the error : X11 cannot allocate additional graphics colors. Consider using colortype=pseudo.cube or gray There is obviously a problem witth xvfb but I can't not resolve it please help me! Thank you Gael Even -- 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] About truncated distribution
Hi All, I tried RSiteSearch('truncated distribution') , and found a lot of threads on 'fitting truncated normal distribution'. No doubt they are all helpful in fitting the distribution based on the data of known original mean and sd. But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? Could anybody give me some advice? Thanks in advance! Jen [[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] Test internet presence
Prof Brian Ripley wrote: On Mon, 11 Sep 2006, Gregor Gorjanc wrote: Prof Brian Ripley ripley at stats.ox.ac.uk writes: ... Check out tests/internet.R. nsl() checks if you can resolve host names, which has worked well enough there. Thank you prof. Ripley for this pointer. I am posting here the relevant part if someone does not look at SVN. I would just like to ask why is .Platform$OS.type == unix added to the test? Is nsl() available only on unix like platforms or ... I did not found any specifics in its help page. Did you look at the help page on Windows? Looking at the help page on Unix only tells you about Unix. Hint: the help page is src/library/utils/man/unix/nsl.Rd (In my country, PhD students are supposed to be able to find things like that out for themselves.) ... Thank you for additional pointer. I did not look windows help page as I do not have windows at disposal all the time, but You are right - I should have looked into the sources. I found out that there is no such function i.e. nsl() under windows. If I summarize the thread there is (currently) no way to test for internet presence with a general approach. -- Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana PhD student Biotechnical Faculty Zootechnical Department URI: http://www.bfro.uni-lj.si/MR/ggorjan Groblje 3 mail: gregor.gorjanc at bfro.uni-lj.si SI-1230 Domzale tel: +386 (0)1 72 17 861 Slovenia, Europefax: +386 (0)1 72 17 888 -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. __ 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] rgl: exporting to pdf or png does not work
[This is a follow-up to the recent discussion on R-help] Hi all, I can reproduce both problems on gentoo (2006.0 profile), but not on OpenSuSE-10.1. bash cat rgl.postscript.r library(rgl) example(spheres3d) rgl.postscript(spheres.eps, fmt=eps) R source(rgl.postscript.r) X Error of failed request: GLXBadContextState Major opcode of failed request: 142 (GLX) Minor opcode of failed request: 5 (X_GLXMakeCurrent) Serial number of failed request: 102 Current serial number in output stream: 102 bash cat rgl.snapshot.r library(rgl) example(spheres3d) rgl.postscript(spheres.png, fmt=png) R source(rgl.snapshot.r) [1] failed Installed libraries: * Gentoo: R-2.2.1, rgl-0.67.2, OpenSuSE: R-2.3.1, rgl-0.67.2 * Gentoo: libpng-1.2.12, OpenSuSE: libpng-1.2.8 * Gentoo: Xorg-6.8.2 (mga), OpenSuSE: 6.9.0 (nvidia) * Gentoo: freeglut-2.4.0, OpenSuSE: freeglut-051110 * OpenSuse: mesa-6.4.2 Please let me know if there is anything I can do to help to solve this issue. Regards Daniel P.S. Please CC me in your replies, I am not subscribed to the list. __ 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] whole object approach for nested loops
I have the following code that I am trying to execute using the whole object approach and get rid of the for loop. I have looked at the manual and seached the database for examples or similar questions with no luck. The following example works without any problems. for (j in 1:186) { entropy.cogp[1:3, j]-alpha3[1:3]*c[j,2] } But when I try to remove the for loop and use entropy.cogp[1:3, 1:186]-alpha3[1:3]*c[1:186,2] R tries to multiply the first member of alpha3 with the first member of c[,2] and once c is exhausted, it multiplies the 187th member of alpha3 with the first member of c[,2] and so on, resulting in an error where it requires the size of alpha3 to be an exact multiple of the size of c. This is clearly not what is intended by the for loop given above. Is there a way to do this using a whole object approach to make things run faster? Or is the for loop the only way of doing this? Thanks... __ 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] summary(glm) for categorical variables
You want: anova(my.glm) On 12-Sep-06, at 4:00 AM, [EMAIL PROTECTED] wrote: Suppose we have a data.frame where variables are categorical and the response is categorical eg: my.df=NULL for(i in LETTERS[1:3]){my.df[[i]]=sample(letters, size=10)} my.df=data.frame(my.df) my.df$class=factor(rep(c(pos, neg), times=5)) my.glm=glm(class ~ ., data=my.df, family=binomial) summary(my.glm) Estimate Std. Error z value Pr(|z|) (Intercept) 2.457e+01 1.310e+05 1.88e-041 Ad -8.559e-11 1.853e+05 -4.62e-161 Aj -9.897e-10 1.853e+05 -5.34e-151 An -4.913e+01 1.853e+05 -2.65e-041 ... My question is is it possible to get the terms to appear as A,B, C instead of every combination of Aa, Ab, Ac etc separately? Many Thanks in advance __ 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] variables in object names
Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through 5 gathering there values. The %i% in my third line indicates which object to draw from. The question is is there any way to pass a variable such as i as part of a name? Ken Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire [[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] Bitmap file size problems
I am experiencing some problems with the windows graphics device and bitmaps. (Everything is done in R 2.3.1 on Windows XP) As an example, I will use windows(3,2) plot(1:10) It is not a pretty or meaningful graph, but it demonstrates the problem. savePlot(file=test,type=bmp) creates a bitmap file of size 303x207 which is somewhat strange because it seems to use slightly different values for pixels per inch horizontally and vertically. (By the way, in my version of R 2.4.0alpha, the bitmap has size 303x206) The documentation warns that the graphics devices use pixel per inch values reported by Windows, and that might be unreliable. In my case, windows(3,2,xpinch=96) plot(1:10) savePlot(file=test,type=bmp) produces the same image (of the same size) as before, so Windows seems to report 96 for the pixels per inch value. The next result surprised me: windows(3,2,xpinch=96,ypinch=96) plot(1:10) savePlot(file=test,type=bmp) produces a square graphics window and a bitmap file of size 303x303. (In R 2.4.0 alpha the size is 303x302). In fact, when ypinch is given, height seems to be ignored and the graphics windows height:width ratio is the ypinch:xpinch ratio from the call to windows. windows(10,1,xpinch=96,ypinch=192) will produce a window which is higher than wide, which is not what I expected after reading the docs. (This also is true in R 2.4.0 alpha) The alternative solution is to use dev2bitmap. windows(3,2) plot(1:10) dev2bitmap(file=test.bmp,type=bmp256,width=3,height=2,res=100) produces a bitmap of size 300x200 which is exactly what is to be expected. In this bitmap, however, the leftmost part of the image displayed in R's graphics window is cut off. What is the best way of creating bitmaps of a given size containing the full contents of an R graphics window? -- Erich Neuwirth, Didactic Center for Computer Science University of Vienna Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-9394 __ 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] variables in object names
Hi Ken, Not quite the way you're thinking about it, but yes, there is, and it is very useful. See ?get for more information, but here's the basics: for(i in 2:5) { thismodel - get(paste(model, i, sep=)) rsq - c(rsq, summary(thismodel)$r.squared) } Also see ?assign for the opposite effect. On 9/12/06, Pierce, Ken [EMAIL PROTECTED] wrote: Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } -- Sarah Goslee USDA-ARS PSWMRU University Park, PA 16802 [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] variables in object names
Ken, I have a similar example in my blog: http://statcompute.spaces.live.com/blog/cns!39C8032DBD1321B7!229.entry On 9/12/06, Pierce, Ken [EMAIL PROTECTED] wrote: Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through 5 gathering there values. The %i% in my third line indicates which object to draw from. The question is is there any way to pass a variable such as i as part of a name? Ken Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire [[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. -- WenSui Liu (http://spaces.msn.com/statcompute/blog) Senior Decision Support Analyst Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center __ 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] variables in object names
you need something like the following, fit.lis - list(model1, model2, model3, model4, model5) # or if you have many models fit.lis - lapply(paste(model, 1:5, sep = ), get) sapply(fit.lis, function(x) summary(x)$r.squared) 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 Quoting Pierce, Ken [EMAIL PROTECTED]: Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through 5 gathering there values. The %i% in my third line indicates which object to draw from. The question is is there any way to pass a variable such as i as part of a name? Ken Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] variables in object names
Thanks to all who showed me to the get() function. That works like a charm. Ken From: David Barron [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 12, 2006 1:24 PM To: Pierce, Ken; r-help Subject: Re: [R] variables in object names The trick is to use the function get(): vns - paste(model,1:4,sep=) x - rnorm(10) model1 - lm(rnorm(10) ~ x) model2 - lm(rnorm(10) ~ x) model3 - lm(rnorm(10) ~ x) model4 - lm(rnorm(10) ~ x) r.sq - summary(model1)$r.square for (i in 2:4) r.sq - c(r.sq,summary(get(vns[i]))$r.square) On 12/09/06, Pierce, Ken [EMAIL PROTECTED] wrote: Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through 5 gathering there values. The %i% in my third line indicates which object to draw from. The question is is there any way to pass a variable such as i as part of a name? Ken Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire [[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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[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] variables in object names
The trick is to use the function get(): vns - paste(model,1:4,sep=) x - rnorm(10) model1 - lm(rnorm(10) ~ x) model2 - lm(rnorm(10) ~ x) model3 - lm(rnorm(10) ~ x) model4 - lm(rnorm(10) ~ x) r.sq - summary(model1)$r.square for (i in 2:4) r.sq - c(r.sq,summary(get(vns[i]))$r.square) On 12/09/06, Pierce, Ken [EMAIL PROTECTED] wrote: Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq - summary(model1)$r.squared for(i in 2:5){ rsq - c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through 5 gathering there values. The %i% in my third line indicates which object to draw from. The question is is there any way to pass a variable such as i as part of a name? Ken Kenneth B. Pierce Jr. Research Ecologist Landscape Ecology, Modeling, Mapping and Analysis Team PNW Research Station - USDA-FS 3200 SW Jefferson Way, Corvallis, OR 97331 [EMAIL PROTECTED] 541 750-7393 http://www.fsl.orst.edu/lemma/gnnfire [[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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[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] error in make check
Hi! I got error when I did make check: running code in 'reg-tests-1.R' .../bin/sh: line 1: 9538 Segmentation fault LC_ALL=C SRCDIR=. R_DEFAULT_PACKAGES= ../bin/R --vanilla reg-tests-1.R reg-tests-1.Rout 21 make[3]: *** [reg-tests-1.Rout] Error 1 make[3]: Leaving directory `/home/xwu/R-2.3.1/tests' make[2]: *** [test-Reg] Error 2 make[2]: Leaving directory `/home/xwu/R-2.3.1/tests' make[1]: *** [test-all-basics] Error 1 make[1]: Leaving directory `/home/xwu/R-2.3.1/tests' make: *** [check] Error 2 At the end of the reg-tests-1.Rout.fail file: *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Fortran(rg, n, n, x, values = dbl.n, ivalues = dbl.n, !only.values, vectors = x, integer(n), dbl.n, ierr = integer(1), PACKAGE = base) 2: eigen(Gm, EISPACK = TRUE) aborting ... Thanks. Note: I tried 3.2.0 and got the same error, except the number of the segmentation fault. Best, Clear [[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] Basic help needed: group bunch of lines in a list (matrix)
Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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] Basic help needed: group bunch of lines in a list (matrix)
Emmanuel Levy said the following on 9/12/2006 3:50 PM: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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. Try aggregate: aggregate(x[1], x[2:3], mean) where `x' is your data.frame. --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] whole object approach for nested loops
you are looking for the outer product ?outer a - 1:6 cc - matrix(1:6, 3, 2) e - matrix(0, 6,3) for (j in 1:3) e[,j] - a*cc[j,2] e [,1] [,2] [,3] [1,]456 [2,]8 10 12 [3,] 12 15 18 [4,] 16 20 24 [5,] 20 25 30 [6,] 24 30 36 a %o% cc[,2] [,1] [,2] [,3] [1,]456 [2,]8 10 12 [3,] 12 15 18 [4,] 16 20 24 [5,] 20 25 30 [6,] 24 30 36 __ 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] About truncated distribution
Dear listers, I tried RSiteSearch('truncated distribution') , and found a lot of threads on 'fitting truncated normal distribution'. No doubt they are all helpful in fitting the distribution based on the data of known original mean and sd. But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? Could anybody give me some advice? Thanks in advance! Jen [[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] Conservative ANOVA tables in lmer
On Tue, September 12, 2006 7:34 am, Manuel Morales wrote: On Mon, 2006-09-11 at 11:43 -0500, Douglas Bates wrote: Having made that offer I think I will now withdraw it. Peter's example has convinced me that this is the wrong thing to do. I am encouraged by the fact that the results from mcmcsamp correspond closely to the correct theoretical results in the case that Peter described. I appreciate that some users will find it difficult to work with a MCMC sample (or to convince editors to accept results based on such a sample) but I think that these results indicate that it is better to go after the marginal distribution of the fixed effects estimates (which is what is being approximated by the MCMC sample - up to Bayesian/frequentist philosophical differences) than to use the conditional distribution and somehow try to adjust the reference distribution. Am I right that the MCMC sample can not be used, however, to evaluate the significance of parameter groups. For example, to assess the significance of a three-level factor? Are there better alternatives than simply adjusting the CI for the number of factor levels (1-alpha/levels). I wonder whether the likelihood ratio test would be suitable here? That seems to be supported. It just takes a little longer. require(lme4) data(sleepstudy) fm1 - lmer(Reaction ~ Days + (Days|Subject), sleepstudy) fm2 - lmer(Reaction ~ Days + I(Days^2) + (Days|Subject), sleepstudy) anova(fm1, fm2) So, a brief overview of the popular inferential needs and solutions would then be: 1) Test the statistical significance of one or more fixed or random effects - fit a model with and a model without the terms, and use the LRT. 2) Obtain confidence intervals for one or more fixed or random effects - use mcmcsamp Did I miss anything important? - What else would people like to do? Cheers Andrew Andrew Robinson Senior Lecturer in Statistics Tel: +61-3-8344-9763 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: [EMAIL PROTECTED]Website: http://www.ms.unimelb.edu.au __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] About truncated distribution
But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? You can't, as they are plainly not sufficient (you need to know the amount of truncation also). If you have only the mean and sd and neither the actual data nor the truncation point you're through. -- Bert Gunter Genentech Could anybody give me some advice? Thanks in advance! Jen [[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] About truncated distribution
However, if you know the point(s) of truncation then you should be able to work your way back. Look for the mean and variance of a truncated normal, it will involve mu, sigma and c (point of truncation). You will need to solve for mu and sigma from two equation. For example look at the wikipedia page on normal distribution, it has the mean of a truncated normal distribution. Many standard statistics books should have the rest of the information. On 9/12/06, Berton Gunter [EMAIL PROTECTED] wrote: But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? You can't, as they are plainly not sufficient (you need to know the amount of truncation also). If you have only the mean and sd and neither the actual data nor the truncation point you're through. -- Bert Gunter Genentech Could anybody give me some advice? Thanks in advance! Jen [[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. -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[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] lattice cloud and conditional axis limits
On 9/12/06, Karl Ove Hufthammer [EMAIL PROTECTED] wrote: I'm using the 'cloud' function in the 'lattice' package to produce multi-panel 3D scatter plots. The range of the values used vary much between each panel (especially on the z axis), so I wish the axis limits to be calculated based on the (conditional) data. Here's a minimal example: library(lattice) z=1:200 x=runif(200) y=runif(200) s=factor(rep(c(1,2),each=100)) cloud(z~x*y|s,scales=list(arrows=FALSE)) On the first panel, the z values are in the range [1,100], and on the second panel, they are in the range [101,200]. I wish the z axis to reflect this, i.e., to only span these values. (In my actual data sets, this does make more sense than in this example.) If 'cloud' worked the same way the 'xypanel' function does, one of the following would work: cloud(z~x*y|s,scales=list(arrows=FALSE,z=list(relation=free))) cloud(z~x*y|s,scales=list(arrows=FALSE,relation=free)) However, it does not. Any ideas how I can make it work? There's no direct support, but you can write a small panel function with more or less the desired effect: cloud(z ~ x * y | s, scales = list(arrows=FALSE), panel = function(x, y, subscripts, z, ..., zlim) { zlim - range(z[subscripts], na.rm = TRUE) panel.cloud(x, y, subscripts, z, ..., zlim = zlim) }) This is for z only, x and y should work similarly. A general solution is possible, but I don't think the benefits justify the amount of work required (patches are welcome, of course). Deepayan -- Karl Ove Hufthammer E-mail and Jabber: [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] wireplot margins and additional z-axis
On 9/12/06, Klaus Nordhausen [EMAIL PROTECTED] wrote: Dear Deepayan, thanks for your reply, the change of the aspect does however not solve my problem with the space below the graph on the .eps I attached the .eps (still with the old aspect) so that it is maybe clearer what my problem is. No, it's not clearer; this is basically the same EPS that I got, so it gives me no new information. What do you get with the new aspect? If it's not what you want, you'll have to explain what you want more clearly. Also, don't make the panel borders transparent, as it makes it difficult to understand what's going on. Deepayan Any other suggestions? Klaus Dear R experts, it would be very kind if you could help me with two wireplot problems. First, when I make a wireplot and transform it into an .eps using the postscript function the eps-file leaves always a lot of space below the plot, as if it would leave space for a legend or something like that. How can i get the plot into the bottom corner without the space below? The space is not there when I just display the plot in R on my screen (I use R.2.3.1 on Windows XP). Or in general, how can I get the margins on all sides as small as possible since I wnat to include the eps into a report and do not need the space around. The following code has the space on the eps: library(lattice) plot.vol - wireframe(volcano, aspect = 1, scales=list(arrows=F) ,zlab=list(Z-axis,rot=90)) Perhaps you want something like aspect = c(1, 1.5) instead. postscript(example_plot.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=0,lwd=1)) print(plot.vol) dev.off() Secondly, is it possible to add to the wireplot a further z-axis. I found only how to choose at which veritcal line I want the tickmarks and label, but is it also possible to have it at two vertical lines? No (but it shouldn't be too hard to add that feature; I'll have to check). Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bootstrapping for Firth bias reduction logistic regression
Dear list, I want to validate the coefficients computed from Firth bias reduction ligistic regression using bootstrap resampling method. However, I got an error message which I coule not decipher. Help is needed Error in if (mx 1) delta - delta/mx : missing value where TRUE/FALSE needed fixed-function(data,indices){ + resampling-data[indices,] # select obs. in bootstrap sample + mod-logistf(abf.flag~TBF,data=resampling) + coefficients(mod) + } library(boot) set.seed(1231) fixed.boot-boot(group3,fixed,R=1000) Error in if (mx 1) delta - delta/mx : missing value where TRUE/FALSE needed Best regards, stella __ 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] Updating lmer - object is not subsettable?
I'm attempting to write a general function to implement Faraway's bootstrapping algorithm for mixed models with lmer, but have run into a curious problem. I'm comparing two models model.1-lmer(Response ~ Treatment + (1|Trial), data=exp.data, method=ML) model.2-lmer(Response ~ 1 + (1|Trial), data=exp.data, method=ML) When I attempt to update model.2 with simulated data, however, I get the following error: sim.data-unlist(simulate(model.1)) sim.model.2-update(model.2, sim.data~.) Error in x[[3]] : object is not subsettable Now, the following sim.model.1-update(model.1, sim.data~.) appears to work just fine. Does anyone know why update won't work, and is there something I can do about this? -Jarrett __ 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.