Re: [R] simulating Gaussian Mixture Method
You should not add the 3 six dimensional variables!!! By adding them you are getting a multivariate normal variable and not a mixture! To get a mixture with probabilities p1 for the first, p2 for the second and p3 for the third one (p1+p2+p3=1), simulate a [0,1] uniform variable X and return the first one if X p1, the second one if p1 = X p1+p2 and the third one if X = p1+p2. --- On Mon, 16/6/08, Peng Jiang [EMAIL PROTECTED] wrote: From: Peng Jiang [EMAIL PROTECTED] Subject: [R] simulating Gaussian Mixture Method To: R-help@r-project.org Received: Monday, 16 June, 2008, 3:48 PM Hi, I have a mixture pdf which has three components, each satisfies the 6 dimension normal distribution. I use mvrnorm() from the MASS library to generate 1000 samples for each component and I add them to get the random samples which satisfies with the mixture distribution. I use Mclust() from the mclust library to get the model of the samples and strange things happened. First it gave a warning samplesMclust - Mclust( samples ) Warning messages: 1: In summary.mclustBIC(Bic, data, G = G, modelNames = modelNames) : best model occurs at the min or max # of components considered 2: In Mclust(samples) : optimal number of clusters occurs at min choice Then I input samplesMclust best model: XXI with 1 components it says the best model is with 1 component ! I am confused ... Is it because the way that I generate samples is wrong??? thanks so much ! -- Peng Jiang 江鹏 Ph.D. Candidate Antai College of Economics Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simulating Gaussian Mixture Method
Adding them together will not give you a sample from a mixture, it gives you a sample from another multivariate normal distribution. Rather than add them together what you have to do is select from each of the two samples with the appropriate probability. e.g. suppose your mixing probability was 0.6 for the first component and hence 0.4 for the second. Also suppose S1 (1000 x 6) and S2 (1000 x 6) are the two samples generated by mvrnorm. Then to get a sample from a mixture of the two you would need to do S12 - array(c(S1, S2), dim = c(1000*6, 2)) ## both in the one matrix, as two columns comp - cbind(1:6000, ifelse(runif(1000) 0.6, 1, 2)) Smix - matrix(S12[comb], nrow = 1000) This should give you a sample from the mixture. Bill Venables -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peng Jiang Sent: Monday, 16 June 2008 3:48 PM To: R-help@r-project.org Subject: [R] simulating Gaussian Mixture Method Hi, I have a mixture pdf which has three components, each satisfies the 6 dimension normal distribution. I use mvrnorm() from the MASS library to generate 1000 samples for each component and I add them to get the random samples which satisfies with the mixture distribution. I use Mclust() from the mclust library to get the model of the samples and strange things happened. First it gave a warning samplesMclust - Mclust( samples ) Warning messages: 1: In summary.mclustBIC(Bic, data, G = G, modelNames = modelNames) : best model occurs at the min or max # of components considered 2: In Mclust(samples) : optimal number of clusters occurs at min choice Then I input samplesMclust best model: XXI with 1 components it says the best model is with 1 component ! I am confused ... Is it because the way that I generate samples is wrong??? thanks so much ! -- Peng Jiang 江鹏 Ph.D. Candidate Antai College of Economics Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Superimposing Line over Histogram in Density Plot
Hi, Currently I have a density plot generated with this snippet. Is there a way I can add a line curve on top of it? I mean in one figure __BEGIN__ myhist - hist(x col=blue, main = Density Plot, xlab = Exp Level, ) __END__ - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package under unix
If you want a new device opened you can call dev.new() In current R. X11() does have xpos and ypos, *but* there is no guarantee that any value you choose will not be the same as the default. Indeed, with windows(5,5,xpos=0) you will put your second window on top of the first one in my setup. I entirely agree with Patrick, and would add 'why do you think a 5 square window is appropriate on both 8 and 30 monitors?'. Please curb your enthusiasm to make decisions for your package users. On Mon, 16 Jun 2008, Christophe Genolini wrote: Generally, I like to use a pdf device which can have any number of pages. I am proposing a graphical way a selecting a clusterization based a quality criterion. In order to avoid local maximum, you can build something like 10 000 clusterization. Exporting all of them has no sence. So I open two graph, on the left you can see all the quality criterion. On the rigth, you can see the clusterization that you are curently selecting on the left graph. The idea is not to export all the clusterization but to chose one. So you can change the selected clusterization by using the arrow. This is possible only on a screen. But an X11 device will also work for single plots and there's no need to specifically set it in the package. Thanks a lot. Is there a way to set the position at which the x11 windows shall open ? I do not want to be very precise, I just want the two windows to not open one on the top of the other... Why not let users set the device they wish to use? The function that is calling windows(5,5,xpos=0) is called choice(). So users that do not like the output that I propose are free to not call choice(), others are free to use it... Requests to the maintainer gets no response. Lol ! I am so proud when someone is using one of my two package that I answer very fast... ;-) May be it will change when I will have ten to maintain ? Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Display a jpeg inside a widget which already has text
Hi I am trying to insert a jpeg into a widget I have created. I have used this link http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/showImage.html to display a jpeg inside a newly created widget but would like some info on how to insert into a pre existing widget. This is my code below for my first widget. tt-tktoplevel() fontHeading2 - tkfont.create(family=arial,size=16, slant=italic) fontHeading3 - tkfont.create(family=arial,size=12) fontTextLabel - tkfont.create(family=arial,size=12) fontlabel - tkfont.create(family=arial,size=10,weight=bold) tkgrid(tklabel(tt,height=2,width=50, text=)) tkgrid(tklabel(tt,text=)) tkgrid(tklabel(tt,text='Enhance Your Decision Making',font=fontHeading2,foreground=black)) tkgrid(tklabel(tt,text= v 4.0, font=fontTextLabel)) tkgrid(tklabel(tt,height=2,width=50,text=)) tkgrid(tklabel(tt,text=)) ##I would like to insert an image into this widget Any help would be greatly appreciated. cheers Daniel -- View this message in context: http://www.nabble.com/Display-a-jpeg-inside-a-widget-which-already-has-text-tp17858340p17858340.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in dat
Hello everyone, I have the following code which keeps giving me an error. The code is: dat-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt,header=T,row.names=1,blank.lines.skip=F,na..strings=NA) dimnames(dat)((1)) -as.character(dat(,1)) dat-dat(,-1) dat-as.data.frame(dat) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt) ann-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt,header=T) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt) cl-as.character(ann[,2]) dat-dat[,cl] gc-cl(1:19) act-cl(20:39) x-as.numeric(dat(2000,gc)) y-as.numeric(dat(2000,act)) x-x(!is..na(x)) y-y(!is.na(y)) xy.list-list(x,y) boxplot(xy.list,col=c(red,blue),main=Gene 2000) The error is: error in eval .with.vis(expr, envir, enclos) : could not find function dat I do not understand what this error is? Also is there a command to get a more verbose explanation of the error Any help would be appreciated Paul [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] randomForest, 'No forest component...' error while calling Predict()
Now I read it in the manual If xtest is given, defaults to FALSE. Thanks for your help! Jim Moshe Olshansky-2 wrote: You must use randomForest with keep.forest=TRUE - otherwise the Forest object is not saved and so no prediction can be made. --- On Mon, 16/6/08, Jim_S [EMAIL PROTECTED] wrote: From: Jim_S [EMAIL PROTECTED] Subject: [R] randomForest, 'No forest component...' error while calling Predict() To: r-help@r-project.org Received: Monday, 16 June, 2008, 8:13 AM Dear R-users, While making a prediction using the randomForest function (package randomForest) I'm getting the following error message: Error in predict.randomForest(model, newdata = CV) : No forest component in the object Here's my complete code. For reproducing this task, please find my 2 data sets attached ( http://www.nabble.com/file/p17855119/data.rar data.rar ). Thanks in advance for any help! - Jim CT - read.table(CT.txt,header=TRUE,sep=\t) CV - read.table(CV.txt,header=TRUE,sep=\t) # Both CT CV have the syntaxis X1, X2,...,X97,Y where all variables are numeric x - CT[,-98] y - CT[,98] xtest - CV[,-98] ytest - CV[,98] library(randomForest) model - randomForest(x ,y , xtest, ytest,ntree=500,mtry=32,nodesize=5,nPerm=2) model #Call: # randomForest(x = x, y = y, xtest = xtest, ytest = ytest, ntree = 500, mtry = 32, nodesize = 5, # nPerm = 2) # Type of random forest: regression #Number of trees: 500 #No. of variables tried at each split: 32 # # Mean of squared residuals: 0.0022117 #% Var explained: -1.01 # Test set MSE: 0 #% Var explained: 2.61 prediction - predict(model, newdata= CT) #Error in predict.randomForest(model, newdata = CV) : # No forest component in the object # -- View this message in context: http://www.nabble.com/randomForest%2C-%27No-forest-component...%27-error-while-calling-Predict%28%29-tp17855119p17855119.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/randomForest%2C-%27No-forest-component...%27-error-while-calling-Predict%28%29-tp17855119p17858931.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Superimposing Line over Histogram in Density Plot
try something like this: x - rnorm(200) hist(x, col = blue, freq = FALSE) lines(density(x), col = red, lwd = 2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Gundala Viswanath [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 16, 2008 8:25 AM Subject: [R] Superimposing Line over Histogram in Density Plot Hi, Currently I have a density plot generated with this snippet. Is there a way I can add a line curve on top of it? I mean in one figure __BEGIN__ myhist - hist(x col=blue, main = Density Plot, xlab = Exp Level, ) __END__ - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package under unix
Hi I entirely agree with Patrick, and would add 'why do you think a 5 square window is appropriate on both 8 and 30 monitors?'. I do not realy care about 5, 8 or 20, I use it when I devellop, I will remove it for the final package. I just want the two windows to not be one on the top of the other. I do not care if one in on right, the other left, or one at the top of the screen, the other at the bottom... X11() does have xpos and ypos, I am using R 2.7 but I do not manage to deal with X11 and xpos : X11(xpos=0) give an error windows.options(xpos=0) ; X11() open a windows but it does not change the place. Am I misunderstanding something ? Christophe curb your enthusiasm to make decisions for your package users. On Mon, 16 Jun 2008, Christophe Genolini wrote: Generally, I like to use a pdf device which can have any number of pages. I am proposing a graphical way a selecting a clusterization based a quality criterion. In order to avoid local maximum, you can build something like 10 000 clusterization. Exporting all of them has no sence. So I open two graph, on the left you can see all the quality criterion. On the rigth, you can see the clusterization that you are curently selecting on the left graph. The idea is not to export all the clusterization but to chose one. So you can change the selected clusterization by using the arrow. This is possible only on a screen. But an X11 device will also work for single plots and there's no need to specifically set it in the package. Thanks a lot. Is there a way to set the position at which the x11 windows shall open ? I do not want to be very precise, I just want the two windows to not open one on the top of the other... Why not let users set the device they wish to use? The function that is calling windows(5,5,xpos=0) is called choice(). So users that do not like the output that I propose are free to not call choice(), others are free to use it... Requests to the maintainer gets no response. Lol ! I am so proud when someone is using one of my two package that I answer very fast... ;-) May be it will change when I will have ten to maintain ? Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package under unix
X11() is the standard Unix device: see your subject line. Testing x11() under Windows isn't relevant to your subject line (which in any case is not helpful -- the posting guide asks you to use informative subject lines). There is no 'R 2.7', and you are explicitly asked in the posting guide not to be inaccurate about this. On Mon, 16 Jun 2008, [EMAIL PROTECTED] wrote: Hi I entirely agree with Patrick, and would add 'why do you think a 5 square window is appropriate on both 8 and 30 monitors?'. I do not realy care about 5, 8 or 20, I use it when I devellop, I will remove it for the final package. I just want the two windows to not be one on the top of the other. I do not care if one in on right, the other left, or one at the top of the screen, the other at the bottom... X11() does have xpos and ypos, I am using R 2.7 but I do not manage to deal with X11 and xpos : X11(xpos=0) give an error windows.options(xpos=0) ; X11() open a windows but it does not change the place. Am I misunderstanding something ? Christophe curb your enthusiasm to make decisions for your package users. On Mon, 16 Jun 2008, Christophe Genolini wrote: Generally, I like to use a pdf device which can have any number of pages. I am proposing a graphical way a selecting a clusterization based a quality criterion. In order to avoid local maximum, you can build something like 10 000 clusterization. Exporting all of them has no sence. So I open two graph, on the left you can see all the quality criterion. On the rigth, you can see the clusterization that you are curently selecting on the left graph. The idea is not to export all the clusterization but to chose one. So you can change the selected clusterization by using the arrow. This is possible only on a screen. But an X11 device will also work for single plots and there's no need to specifically set it in the package. Thanks a lot. Is there a way to set the position at which the x11 windows shall open ? I do not want to be very precise, I just want the two windows to not open one on the top of the other... Why not let users set the device they wish to use? The function that is calling windows(5,5,xpos=0) is called choice(). So users that do not like the output that I propose are free to not call choice(), others are free to use it... Requests to the maintainer gets no response. Lol ! I am so proud when someone is using one of my two package that I answer very fast... ;-) May be it will change when I will have ten to maintain ? Christophe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in dat
Paul Adams wrote: Hello everyone, I have the following code which keeps giving me an error. The code is: dat-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt,header=T,row.names=1,blank.lines.skip=F,na..strings=NA) dimnames(dat)((1)) -as.character(dat(,1)) dat-dat(,-1) dat-as.data.frame(dat) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt) ann-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt,header=T) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt) cl-as.character(ann[,2]) dat-dat[,cl] gc-cl(1:19) act-cl(20:39) x-as.numeric(dat(2000,gc)) y-as.numeric(dat(2000,act)) x-x(!is..na(x)) y-y(!is.na(y)) xy.list-list(x,y) boxplot(xy.list,col=c(red,blue),main=Gene 2000) The error is: error in eval .with.vis(expr, envir, enclos) : could not find function dat you misuse the syntax, check the docs. with 'dat(...)' r tries to apply dat, but dat is a data frame, and is thus not applicable. what you want is dat[...]. you can argue that the error message is misleading; unless you defined one, r cannot find a function named 'dat', but it does find your data frame, and it should complain about its non-applicability. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in dat
On Mon, 16 Jun 2008, Wacek Kusnierczyk wrote: Paul Adams wrote: Hello everyone, I have the following code which keeps giving me an error. The code is: dat-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt,header=T,row.names=1,blank.lines.skip=F,na..strings=NA) dimnames(dat)((1)) -as.character(dat(,1)) dat-dat(,-1) dat-as.data.frame(dat) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisen.txt) ann-read.table(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt,header=T) file.show(file=C:\\Documents and Settings\\Owner\\My Documents\\eisenClasses.txt) cl-as.character(ann[,2]) dat-dat[,cl] gc-cl(1:19) act-cl(20:39) x-as.numeric(dat(2000,gc)) y-as.numeric(dat(2000,act)) x-x(!is..na(x)) y-y(!is.na(y)) xy.list-list(x,y) boxplot(xy.list,col=c(red,blue),main=Gene 2000) The error is: error in eval .with.vis(expr, envir, enclos) : could not find function dat you misuse the syntax, check the docs. with 'dat(...)' r tries to apply dat, but dat is a data frame, and is thus not applicable. what you want is dat[...]. you can argue that the error message is misleading; unless you defined one, r cannot find a function named 'dat', but it does find your data frame, and it should complain about its non-applicability. It is this explanation which is misleading. R (not r) looks for a function named 'dat': it does not find the data frame when looking for a function. To be explicit, when R encounters foo() it looks in the current environment for a function named 'foo' and ignores all other objects named 'foo' even if they are higher on the search path. This was not the behaviour of Blue-Book S, but it has been the behvaviour of S and R for many years. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I stop strwrap removing escape characters? (and solution to the screen wrapping question from 11/6)
After the helpful reply from Greg Snow (below), I've written a function printtoscreen which does the screen wrapping I need (although not in a very elegant way). This works fine for strings without any escape characters in them, e.g. printtoscreen=function(str) { + str2=strwrap(str,width=getOption(width)) + if (length(str2)1) {str2[2:length(str2)]=paste(\b\b,str2[2:length(str2)],sep=)} #to remove the , s toString puts in + str2=paste(str2,\n,sep=) + cat(str2) + } getOption(width) [1] 59 cat(Measured lengths are (,toString(1:20/100),) mm.\n) Measured lengths are ( 0.01, 0.02, 0.03, 0.04, 0.05, 0.06,$ printtoscreen(paste(Measured lengths are (,toString(1:20/100),) mm.\n,sep=)) Measured lengths are (0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2) mm. HOWEVER, if you use any escape characters in your string, it fails because strwrap removes all of them: cat(\n\tHello.\n) Hello. printtoscreen(\n\tHello.\n) Hello. Is there any way to prevent strwrap doing this? I haven't found any options for this. Thanks very much (and thanks to Greg Snow for the tip about strwrap before). Toby Marthews == Le Mer 11 juin 2008 18:00, Greg Snow a écrit : You could try passing your character string to the strwrap function first, then use cat on the result. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Toby Marthews Sent: Wednesday, June 11, 2008 6:52 AM To: r-help@r-project.org Subject: [R] Word wrapping for character objects (WINDOWS R ONLY) Can anybody help me with this problem? ** ONLY WINDOWS R - PROBLEM DOESN'T OCCUR ON LINUX ** I want to print a long character to screen: getOption(width) [1] 60 z=(1:20)/10#z is a vector of length between 20 and 30 (depending on user options) containing lengths in mm (i.e. each element is 1-5 characters long) str1=paste(The depths chosen are (,toString(z),) mm, and more text ...\n) cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.$ The problem is that on R for Windows the string is cropped by the window size (hence the $). On R for Linux, this doesn't happen and the text is word wrapped (the default for the shell, I guess): cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ) mm, and more text ... I can't find any option for word wrapping in the cat command (fill=TRUE has no effect). I also checked the menu Edit - GUI preferences..., but there doesn't seem to be a Word Wrap option there either. How do I get word wrapping like this in Windows? THANKS FOR ANY HELP! Toby Marthews Previous relevant posts: - The post from 2006 about Screen Wrapping (http://tolstoy.newcastle.edu.au/R/help/06/05/26673.html) which Brian Ripley answered was about controlling how long vectors are cropped to the screen. Unfortunately, the width option in options() does not affect character objects, so I can't use that control here. - I sent the same question to [EMAIL PROTECTED] in Oct 2007, but noone there could help me with it. - Try the following command on Windows R with a small window (getOption(width)117) and a large window (getOption(width)117) and you'll see you get extra nonexistent options in the menu: a=c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);menu(a) I guess this is a related problem? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NLME: Prediction intervals for random effects
Dear all, nbsp; Is there a function to calculate thenbsp; prediction intervals for random effects in non-linear mixed models? I found a way to do it for linear mixed models but not for non-linearnbsp;mixed one. nbsp; Many thnaks nbsp; Bernard nbsp; nbsp; _ o.fr [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can I stop strwrap removing escape characters? (and solution to the screen wrapping question from 11/6)
On Mon, 2008-06-16 at 11:33 +0200, Toby Marthews wrote: After the helpful reply from Greg Snow (below), I've written a function printtoscreen which does the screen wrapping I need (although not in a very elegant way). This works fine for strings without any escape characters in them, e.g. printtoscreen=function(str) { + str2=strwrap(str,width=getOption(width)) + if (length(str2)1) {str2[2:length(str2)]=paste(\b\b,str2[2:length(str2)],sep=)} #to remove the , s toString puts in + str2=paste(str2,\n,sep=) + cat(str2) + } getOption(width) [1] 59 Hi Toby, Have you considered writeLines() as a in-built alternative to printtoscreen: writeLines(strwrap(paste(Measured lengths are (, paste(1:20/100, collapse = , ), ) mm., sep = ), width = 60)) Measured lengths are (0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2) mm. The above is how I would have tackled this previously, but I see toString is something I should add my battery of useful R manipulation routines: writeLines(strwrap(paste(Measured lengths are (, toString(1:20 / 100), ) mm., sep = ), width = 60)) Measured lengths are (0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2) mm. Note you don't need the trailing \n from your example if using writeLines (argument sep to writeLines adds this by default). cat(Measured lengths are (,toString(1:20/100),) mm.\n) Measured lengths are ( 0.01, 0.02, 0.03, 0.04, 0.05, 0.06,$ printtoscreen(paste(Measured lengths are (,toString(1:20/100),) mm.\n,sep=)) Measured lengths are (0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2) mm. HOWEVER, if you use any escape characters in your string, it fails because strwrap removes all of them: cat(\n\tHello.\n) Hello. printtoscreen(\n\tHello.\n) Hello. Is there any way to prevent strwrap doing this? I haven't found any options for this. No, not that I can see and this is as documented on ?strwrap, though consider the prefix argument of strwrap to achieve the same end result as your simple example. writeLines(strwrap(\n\tHello.\n, width = 60, prefix = \n\t)) Hello. Your actual use case may be more complicated than this, however, but I don't have a solution to hand if it is. HTH G Thanks very much (and thanks to Greg Snow for the tip about strwrap before). Toby Marthews == Le Mer 11 juin 2008 18:00, Greg Snow a écrit : You could try passing your character string to the strwrap function first, then use cat on the result. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Toby Marthews Sent: Wednesday, June 11, 2008 6:52 AM To: r-help@r-project.org Subject: [R] Word wrapping for character objects (WINDOWS R ONLY) Can anybody help me with this problem? ** ONLY WINDOWS R - PROBLEM DOESN'T OCCUR ON LINUX ** I want to print a long character to screen: getOption(width) [1] 60 z=(1:20)/10#z is a vector of length between 20 and 30 (depending on user options) containing lengths in mm (i.e. each element is 1-5 characters long) str1=paste(The depths chosen are (,toString(z),) mm, and more text ...\n) cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.$ The problem is that on R for Windows the string is cropped by the window size (hence the $). On R for Linux, this doesn't happen and the text is word wrapped (the default for the shell, I guess): cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ) mm, and more text ... I can't find any option for word wrapping in the cat command (fill=TRUE has no effect). I also checked the menu Edit - GUI preferences..., but there doesn't seem to be a Word Wrap option there either. How do I get word wrapping like this in Windows? THANKS FOR ANY HELP! Toby Marthews Previous relevant posts: - The post from 2006 about Screen Wrapping (http://tolstoy.newcastle.edu.au/R/help/06/05/26673.html) which Brian Ripley answered was about controlling how long vectors are cropped to the screen. Unfortunately, the width option in options() does not affect character objects, so I can't use that control here. - I sent the same question to [EMAIL PROTECTED] in Oct 2007, but noone there could help me with it. - Try the following command on Windows R with a small window (getOption(width)117) and a large window (getOption(width)117) and you'll see you get extra nonexistent options in the menu: a=c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);menu(a) I guess this
Re: [R] How can I stop strwrap removing escape characters? (and solution to the screen wrapping question from 11/6)
I think by 'escape characters' you mean 'whitespace characters'. There are no 'escape characters' in your string -- the escape character is \, and \n and \t are converted by the parser to characters when the string is constructed and so are not escapted in the string. ?strwrap explicitly says 'Whitespace in the input is destroyed.', which seems clear enough in your case. (What is meant by 'whitespace' is not completely clear, but space, tab (\t) and LF (\n) are always whitespace and it seems it means just those three and not FF, VT nor CR.) On Mon, 16 Jun 2008, Toby Marthews wrote: After the helpful reply from Greg Snow (below), I've written a function printtoscreen which does the screen wrapping I need (although not in a very elegant way). This works fine for strings without any escape characters in them, e.g. printtoscreen=function(str) { + str2=strwrap(str,width=getOption(width)) + if (length(str2)1) {str2[2:length(str2)]=paste(\b\b,str2[2:length(str2)],sep=)} #to remove the , s toString puts in + str2=paste(str2,\n,sep=) + cat(str2) + } getOption(width) [1] 59 cat(Measured lengths are (,toString(1:20/100),) mm.\n) Measured lengths are ( 0.01, 0.02, 0.03, 0.04, 0.05, 0.06,$ printtoscreen(paste(Measured lengths are (,toString(1:20/100),) mm.\n,sep=)) Measured lengths are (0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2) mm. HOWEVER, if you use any escape characters in your string, it fails because strwrap removes all of them: cat(\n\tHello.\n) Hello. printtoscreen(\n\tHello.\n) Hello. Is there any way to prevent strwrap doing this? I haven't found any options for this. Thanks very much (and thanks to Greg Snow for the tip about strwrap before). Toby Marthews == Le Mer 11 juin 2008 18:00, Greg Snow a écrit : You could try passing your character string to the strwrap function first, then use cat on the result. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Toby Marthews Sent: Wednesday, June 11, 2008 6:52 AM To: r-help@r-project.org Subject: [R] Word wrapping for character objects (WINDOWS R ONLY) Can anybody help me with this problem? ** ONLY WINDOWS R - PROBLEM DOESN'T OCCUR ON LINUX ** I want to print a long character to screen: getOption(width) [1] 60 z=(1:20)/10#z is a vector of length between 20 and 30 (depending on user options) containing lengths in mm (i.e. each element is 1-5 characters long) str1=paste(The depths chosen are (,toString(z),) mm, and more text ...\n) cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.$ The problem is that on R for Windows the string is cropped by the window size (hence the $). On R for Linux, this doesn't happen and the text is word wrapped (the default for the shell, I guess): cat(str1) The depths chosen are ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2 ) mm, and more text ... I can't find any option for word wrapping in the cat command (fill=TRUE has no effect). I also checked the menu Edit - GUI preferences..., but there doesn't seem to be a Word Wrap option there either. How do I get word wrapping like this in Windows? THANKS FOR ANY HELP! Toby Marthews Previous relevant posts: - The post from 2006 about Screen Wrapping (http://tolstoy.newcastle.edu.au/R/help/06/05/26673.html) which Brian Ripley answered was about controlling how long vectors are cropped to the screen. Unfortunately, the width option in options() does not affect character objects, so I can't use that control here. - I sent the same question to [EMAIL PROTECTED] in Oct 2007, but noone there could help me with it. - Try the following command on Windows R with a small window (getOption(width)117) and a large window (getOption(width)117) and you'll see you get extra nonexistent options in the menu: a=c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);menu(a) I guess this is a related problem? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] ggplot2: How to remove legend component for geom_errorbar() ?
Dear list (probably Hadley), I'm trying to do a plot like the following, composed of bars and error bars: df - data.frame(factor1=gl(2,5), factor2=gl(5,1), y=rnorm(10), err=0.1) ggplot(df, aes(x=factor1, y=y, fill=factor2)) + geom_bar(position=dodge, stat=identity) + geom_errorbar(aes(min=y-err, max=y+err), position=dodge, width=0.1) The plot obtained has a legend named factor2, giving as expected the colours used for the five factor levels of factor2. So far so good. However, the legend also contains solid horizontal lines, obviously representing the error bars. While I do not immediately see the sense of a legend symbol for error bars, is there any easy way to turn these off? Thanks, Carsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] unique-fy colume names
I have a column containing duplicate entries and need to append numeric suffixes to make them unique. How ? e.g., paste(id, c(1:10,1,5,10,10), sep=.) [1] id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9[10] id.10 id.1 id.5 id.10 id.10 I hope to get [1] id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9[10] id.10 id.1.1 id.5.1 id.10.1 id.10.2 _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R on an ASUS eee PC, continued - installing packages
Dear all, I just went through the process of installing R on an eeePC 900 running Linux. As a Windows useR utterly ignorant about Linux, I'd never have done it without reading your posts and the R Wiki, so first of all: thank you! Next, taking up your thread from some weeks ago, I thought this could be useful for somebody else too, so here's what I did: 1) I followed wolfgang's step-by-step guide at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/128565.html, plus 2) I installed the build dependencies as shown in R Wiki: ## quoting from http://wiki.r-project.org/rwiki/doku.php?id=getting-started:installation :debian#build_r ## How much supporting software you need to install depends on how much compilation you want to be able to do with R. If you just want to be able to run R, you can get r-base-core and all the recommended packages by doing: sudo apt-get install r-base If you want to be able to build and install R packages (including those from CRAN), you can get all the common header files, as well as r-base-core by doing: sudo apt-get install r-base-dev If you want to be able to build R from its source code, you can get build dependencies for R (e.g., compilers, header files) by doing: sudo apt-get build-dep r-base ## end quote ## This way I got all the necessary compilers, headers etc. automagically installed as well, so that install.packages() works fine now: I installed the whole Econometrics task view without problems. I still haven't tried to install Rmetrics in order to save space on the little machine, because I do not currently need it, but it should go the same way: maybe this can solve John's problem? I am aware that probably removing the original OS and installing Debian as suggested by Dirk Eddelbuettel here http://finzi.psych.upenn.edu/R/Rhelp02a/archive/128605.html would be a better solution, but I am a complete Linux newbie, never ever tried it before, so it's good both for me and for family use to retain the original easy mode GUI while having R running on the same machine. Full desktop mode (=standard KDE) is also easily enabled by adding kicker and ksmserver (see http://wiki.eeeuser.com/howto:getkde, I did it the manual way and it worked; just take heed that kicker and ksmserver were not found in the '900's repository and I had to take them from the '701's). The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... HTH, Giovanni Giovanni Millo Research Dept., Assicurazioni Generali SpA Via Machiavelli 4, 34131 Trieste (Italy) tel. +39 040 671184 fax +39 040 671160 # original message: From: John C Frain frainj Date: Mon, 28 Apr 2008 15:33:31 +0100 Thanks for the step by step guide. It installs a base R and some libraries very well. I tries to load some of the Rmetrics libraries, using install.packages() nu ran into problems. I used apt-get install to install make and gcc from the Xandros repository. gcc also included binutils, gcc-4.1 and libsspo. Is there an easy answer to the question what I need to install to get the install process working. The R Installation and Administration guide says that I just need the compilers and tools. Installing robustbase gives the following messages. (If it is as simple as R not being able to find the header files how do I tell R where to find them?). Best Regards John output in original message suppressed -- John C Frain Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:frainj at tcd.ie mailto:frainj at gmail.com Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package under unix
On Mon, 16-Jun-2008 at 09:43AM +0200, [EMAIL PROTECTED] wrote: I do not realy care about 5, 8 or 20, I use it when I devellop, I will remove it for the final package. I just want the two windows to not be one on the top of the other. I do not care if one in on right, the other left, or one at the top of the screen, the other at the bottom... X11() does have xpos and ypos, I am using R 2.7 but I do not manage to deal with X11 and xpos : X11(xpos=0) give an error windows.options(xpos=0) ; X11() open a windows but it does not change the place. This is a bit of a stab in the dark since I don't use Windows and can't guess what you've been doing, but I'll try. Without knowing what this windows.options is, it's more difficult to answer, but this might do. With x11, you could achieve what I think you're aiming at with x11(xpos = 1) # makes one on the left x11(xpos = -1) # makes one on the right Just how you make a generic way of keeping track of them, you might have ideas.. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_Middle minds discuss events (:_~*~_:)Small minds discuss people (_)-(_) . Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on an ASUS eee PC, continued - installing packages
Millo Giovanni wrote: The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... That'll be something like X11.options(width=4,height=4,pointsize=8) in your ~/.Rprofile -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unique-fy colume names
See ?make.unique On Mon, 16 Jun 2008, Daren Tan wrote: I have a column containing duplicate entries and need to append numeric suffixes to make them unique. How ? e.g., paste(id, c(1:10,1,5,10,10), sep=.) [1] id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9[10] id.10 id.1 id.5 id.10 id.10 I hope to get [1] id.1 id.2 id.3 id.4 id.5 id.6 id.7 id.8 id.9[10] id.10 id.1.1 id.5.1 id.10.1 id.10.2 _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on an ASUS eee PC, continued - installing packages
I am running R in the konsole of the Kate editor on an eeePC 900 (standard Xandros OS). When a plot is generated it is initially too large to fit in the screen, but if I click on the plot it automatically resizes to fit properly. I have no idea if this is a default behavior. Tom Millo Giovanni wrote: Dear all, I just went through the process of installing R on an eeePC 900 running Linux. As a Windows useR utterly ignorant about Linux, I'd never have done it without reading your posts and the R Wiki, so first of all: thank you! Next, taking up your thread from some weeks ago, I thought this could be useful for somebody else too, so here's what I did: 1) I followed wolfgang's step-by-step guide at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/128565.html, plus 2) I installed the build dependencies as shown in R Wiki: ## quoting from http://wiki.r-project.org/rwiki/doku.php?id=getting-started:installation :debian#build_r ## How much supporting software you need to install depends on how much compilation you want to be able to do with R. If you just want to be able to run R, you can get r-base-core and all the recommended packages by doing: sudo apt-get install r-base If you want to be able to build and install R packages (including those from CRAN), you can get all the common header files, as well as r-base-core by doing: sudo apt-get install r-base-dev If you want to be able to build R from its source code, you can get build dependencies for R (e.g., compilers, header files) by doing: sudo apt-get build-dep r-base ## end quote ## This way I got all the necessary compilers, headers etc. automagically installed as well, so that install.packages() works fine now: I installed the whole Econometrics task view without problems. I still haven't tried to install Rmetrics in order to save space on the little machine, because I do not currently need it, but it should go the same way: maybe this can solve John's problem? I am aware that probably removing the original OS and installing Debian as suggested by Dirk Eddelbuettel here http://finzi.psych.upenn.edu/R/Rhelp02a/archive/128605.html would be a better solution, but I am a complete Linux newbie, never ever tried it before, so it's good both for me and for family use to retain the original easy mode GUI while having R running on the same machine. Full desktop mode (=standard KDE) is also easily enabled by adding kicker and ksmserver (see http://wiki.eeeuser.com/howto:getkde, I did it the manual way and it worked; just take heed that kicker and ksmserver were not found in the '900's repository and I had to take them from the '701's). The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... HTH, Giovanni Giovanni Millo Research Dept., Assicurazioni Generali SpA Via Machiavelli 4, 34131 Trieste (Italy) tel. +39 040 671184 fax +39 040 671160 # original message: From: John C Frain frainj Date: Mon, 28 Apr 2008 15:33:31 +0100 Thanks for the step by step guide. It installs a base R and some libraries very well. I tries to load some of the Rmetrics libraries, using install.packages() nu ran into problems. I used apt-get install to install make and gcc from the Xandros repository. gcc also included binutils, gcc-4.1 and libsspo. Is there an easy answer to the question what I need to install to get the install process working. The R Installation and Administration guide says that I just need the compilers and tools. Installing robustbase gives the following messages. (If it is as simple as R not being able to find the header files how do I tell R where to find them?). Best Regards John output in original message suppressed -- John C Frain Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:frainj at tcd.ie mailto:frainj at gmail.com Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/R-on-an-ASUS-eee-PC%2C-continued---installing-packages-tp17862000p17862223.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on an ASUS eee PC, continued - installing packages
On Mon, 16 Jun 2008, Peter Dalgaard wrote: Millo Giovanni wrote: The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... That'll be something like X11.options(width=4,height=4,pointsize=8) in your ~/.Rprofile You need grDevices::X11.options, and it is better to use a load hook like setHook(packageEvent(grDevices, onLoad), function(...) grDevices::X11.options(width=4,height=4,pointsize=8) ) There is another way to set the geometry, to set X11 resources as described in ?X11. I have in my ~/.Xresources R_x11*geometry: 700x700-0+0 (for a 22 90dpi screen, not a 9 one) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] package under unix
x11(xpos = 1) # makes one on the left x11(xpos = -1) # makes one on the right Thanks you very much, I'll try that. Is there any difference between x11 and X11? Christophe Patrick Connolly [EMAIL PROTECTED] a écrit : On Mon, 16-Jun-2008 at 09:43AM +0200, [EMAIL PROTECTED] wrote: I do not realy care about 5, 8 or 20, I use it when I devellop, I will remove it for the final package. I just want the two windows to not be one on the top of the other. I do not care if one in on right, the other left, or one at the top of the screen, the other at the bottom... X11() does have xpos and ypos, I am using R 2.7 but I do not manage to deal with X11 and xpos : X11(xpos=0) give an error windows.options(xpos=0) ; X11() open a windows but it does not change the place. This is a bit of a stab in the dark since I don't use Windows and can't guess what you've been doing, but I'll try. Without knowing what this windows.options is, it's more difficult to answer, but this might do. With x11, you could achieve what I think you're aiming at with x11(xpos = 1) # makes one on the left x11(xpos = -1) # makes one on the right Just how you make a generic way of keeping track of them, you might have ideas.. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Middle minds discuss events (:_~*~_:)Small minds discuss people (_)-(_). Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Very puzzled why swapping the columns doesn't swap the column names
How can I swap the column names at the same time ? m - cbind(x=1:3, y=2:4, z=3:5) m x y z[1,] 1 2 3[2,] 2 3 4[3,] 3 4 5 m[,c(1,2)] - m[,c(2,1)] m x y z[1,] 2 1 3[2,] 3 2 4[3,] 4 3 5 _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Very puzzled why swapping the columns doesn't swap the column names
What you are doing with the assignment m[,c(1,2)] - m[,c(2,1)] is only changing the values in the matrix; it knows nothing about the names. If you want the names of the columns switched, then you have to do it: m - cbind(x=1:3, y=2:4, z=3:5) m x y z [1,] 1 2 3 [2,] 2 3 4 [3,] 3 4 5 m[,c(1,2)] - m[,c(2,1)] m x y z [1,] 2 1 3 [2,] 3 2 4 [3,] 4 3 5 colnames(m)[c(1,2)] - colnames(m)[c(2,1)] m y x z [1,] 2 1 3 [2,] 3 2 4 [3,] 4 3 5 On Mon, Jun 16, 2008 at 8:10 AM, Daren Tan [EMAIL PROTECTED] wrote: How can I swap the column names at the same time ? m - cbind(x=1:3, y=2:4, z=3:5) m x y z[1,] 1 2 3[2,] 2 3 4[3,] 3 4 5 m[,c(1,2)] - m[,c(2,1)] m x y z[1,] 2 1 3[2,] 3 2 4[3,] 4 3 5 _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Very puzzled why swapping the columns doesn't swap the column names
Daren Tan wrote: How can I swap the column names at the same time ? m - cbind(x=1:3, y=2:4, z=3:5) m x y z[1,] 1 2 3[2,] 2 3 4[3,] 3 4 5 m[,c(1,2)] - m[,c(2,1)] m x y z[1,] 2 1 3[2,] 3 2 4[3,] 4 3 5 what you do here is to columns 1 and 2 put what is in columns 2 and 1, respectively. what you want is m is columns 2, 1, and 3 from m: m = m[,c(2,1,3)] instead of swapping column data and headers separately (you could do that as well), swap columns. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R as chart engine in web-service
Can you put some criteria on 'better'/'faster'. What throughput are you expecting? How many requests per second will you have to handle? It's very difficult to tell how many request per second I will have to handle. If you have normal site it will be max. 2-5 tps (on chart website) but if you have real time quotes it will be about 300 tps. In RT quotes I intend use java applet to make RT charts with independent connection. I thing about service like BigChart.com - put some symbol (GOOG, DJIA etc). http://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=djiasid=164 3 and the chart like: http://www.marketwatch.com/tools/quotes/intchart.asp?submitted=trueintflavo r=advancedsymb=DJIAorigurl=%2Ftools%2Fquotes%2Fintchart.asptime=8freq=1 startdate=enddate=hiddenTrue=comp=Enter+Symbol(s)%3Acompidx=a~0comp ind=a~0uf=7168ma=1maval=50lf=1lf2=4lf3=0type=2size=2optstyle=10 13 In this kind of web services its important how faster the chart engine is in general. If there will be to many request per second I can add more machines and use load balancer (haproxy or pound). What size/type machine will you be running on? Probably 1-2 Quad Core Intel Xeon 2x6MB Cache, 2.0GHz per machine with 8GB (or 16GB) RAM. Zope 3 as web server on Gentoo Linux (x86). Memory will be mounted as a local disk (tmpfs) and python and R binaries will by copy into RAM. Python and R are compiled with ICC compiler. Is data being accessed from a database which may influence the timing? R will connect with Tree Data Server (database): http://tree.sourceforge.net/ Data can be keep in memcached: http://www.danga.com/memcached/ So I think there is very small influence on the timing. And I think about quantmod as a R chart package: http://www.quantmod.com/examples/charting/ The main problem with R is that, R uses x11 server to render images and this way is very slow and I thing that faster would be the Cairo (or GDD) R package but I haven't tested this yet. R engine is very universal and this is the strong of R choice in this kind of web service... then begin write new (faster?) c/c++ plugin. What you think? daniel cegielka -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Monday, June 16, 2008 1:55 AM To: Daniel Cegielka Cc: r-help@r-project.org Subject: Re: [R] R as chart engine in web-service Can you put some criteria on 'better'/'faster'. What throughput are you expecting? How many requests per second will you have to handle? What is the timing of your current method? What size/type machine will you be running on? Is data being accessed from a database which may influence the timing? So you need to give some specificity of what your requirements are. You can probably get faster (but maybe not better) with a plug-in, but I would assume that it would also be more effort. On Sun, Jun 15, 2008 at 6:39 PM, Daniel Cegielka [EMAIL PROTECTED] wrote: Hi R-users I think about some web service with stock charts and I plan use python as web framework with R as mathematical and chart engine. I use rpy to connect R with python. It works good. Is it good idea to use R as chart engine? Maybe it's better (faster) to use c/c++ plugin? Daniel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on an ASUS eee PC, continued - installing packages
Prof Brian Ripley wrote: On Mon, 16 Jun 2008, Peter Dalgaard wrote: Millo Giovanni wrote: The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... That'll be something like X11.options(width=4,height=4,pointsize=8) in your ~/.Rprofile You need grDevices::X11.options, and it is better to use a load hook like setHook(packageEvent(grDevices, onLoad), function(...) grDevices::X11.options(width=4,height=4,pointsize=8) ) Thanks, Brian. Obviously, I haven't used this for a while and overlooked the example in the Examples section of ?Startup. I do wonder if there are ways to make this less easily overlooked, though. Pointers in any or all of ?x11, ?X11.options, and ?Devices could help, but maybe we need it in an introductory document like R-intro, along with the discussion of Rprofile files in Customizing the environment. There is another way to set the geometry, to set X11 resources as described in ?X11. I have in my ~/.Xresources R_x11*geometry: 700x700-0+0 (for a 22 90dpi screen, not a 9 one) That doesn't help with the pointsize, does it? (Quite crucial on low-res screens, even at 1024x768, 12.3 I find that the default pointsize=12 is a bit much.) -p -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] sizing non-vector point shapes in ggplot2
Dear all, With normal plotting, one can size a set of points in a plot using a vector argument to cex in the points() function. This works whether you are using one of the standard R symbols (i.e. 19+) or some ascii symbol, such as '/' eg: plot(1:10, 1:10, type='n'); points(1:10, 1:10, cex = 1:10, pch = '/') Trying to make the transition to ggplot2, I find that the aesthetic size mapping does not apply if i do geom_point(..., shape='/') -- the points show up looking like '/' but they are not sized. Is there anything to do about this? eg: ggplot(data = data.frame(x = 1:10, y = 1:10, size = 1:10), aes(x = x, y = y)) + geom_point(mapping = aes(size = size), shape = '/') the plot that I'm making really needs a vertically oriented mark, not a round-ish point/square/triangle that takes up a lot of area. am I totally out of luck? thanks, mike -- View this message in context: http://www.nabble.com/sizing-non-vector-point-shapes-in-ggplot2-tp17863871p17863871.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] contrasts using adonis function
Hi, Somebody knows how to make contrasts if i'm using the function adonis? Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R vs SAS and HLM on multilevel analysis- basic question
We may want to move this discussion to the R-SIG-Mixed-Models list, which I have cc:'d on this reply. On Sun, Jun 15, 2008 at 6:16 PM, eugen pircalabelu [EMAIL PROTECTED] wrote: Hi R users! I am trying to learn some multilevel analysis, but unfortunately i am now very confused. The reason: http://www.ats.ucla.edu/stat/hlm/seminars/hlm_mlm/mlm_hlm_seminar.htm http://www.ats.ucla.edu/stat/sas/seminars/sas_mlm/mlm_sas_seminar.htm and MlmSoftRev. pdf from mlmRev package. From what i see, the first two links seem to declare the level one variable as a random part (i don't know sas synthax, but i think i am right ) while Mr. Bates' pdf says that a grouping variable is the random part of the model, though both models, use roughly the same type of information, some characteristic of the school, along with individual characteristics in explaining individual achivement. I'm not exactly sure what you are asking. If you are saying that the terminology and notation can be confusing, I certainly agree. I think those who developed HLM and MLWin have done a tremendous service to their users in providing them with sophisticated tools for modeling data. However, the way that they structure the model is really only appropriate for models with nested random effects and, to my mind, introduces many unnecessary and restrictive ways of thinking of the data and the model. Am i mistaken somehow? If not, could they both be valid models (i presume) but each showing something else, in terms of connections between this variables? As I said, I don't quite understand what you are asking and, rather than formulate an answer to the wrong question, I'll ask if you can rephrase your question and perhaps be more explicit about an example. In particular, you made reference to a school. Are you referring to a particular example? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] why does these warning mean?
Hi , I don't know whether it is a Mac specific problem. I hope it does not bother you. When I start R each time I got the following warning , I reinstall for many times the problem still exists. R(4053,0xa0619fa0) malloc: *** error for object 0x15630350: double free *** set a breakpoint in malloc_error_break to debug R(4053,0xa0619fa0) malloc: *** error for object 0x15630f10: double free *** set a breakpoint in malloc_error_break to debug R(4053,0xa0619fa0) malloc: *** error for object 0x15630350: double free *** set a breakpoint in malloc_error_break to debug R(4053,0xa0619fa0) malloc: *** error for object 0x15630f60: double free *** set a breakpoint in malloc_error_break to debug My sessionInfo() is sessionInfo() R version 2.7.0 (2008-04-22) i386-apple-darwin8.10.1 locale: zh_CN.UTF-8/zh_CN.UTF-8/C/C/zh_CN.UTF-8/zh_CN.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base -- Peng Jiang 江鹏 Ph.D. Candidate Antai College of Economics Management 安泰经济管理学院 Department of Mathematics 数学系 Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Superimposing Line over Histogram in Density Plot
Look here: http://msenux.redwoods.edu/mathdept/R/CentralLimit.php D. On Jun 15, 2008, at 11:25 PM, Gundala Viswanath wrote: Hi, Currently I have a density plot generated with this snippet. Is there a way I can add a line curve on top of it? I mean in one figure __BEGIN__ myhist - hist(x col=blue, main = Density Plot, xlab = Exp Level, ) __END__ - Gundala Viswanath Jakarta - Indonesia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R vs SAS and HLM on multilevel analysis- basic question
On Jun 16, 2008, at 6:00 AM, [EMAIL PROTECTED] wrote: From: eugen pircalabelu [EMAIL PROTECTED] Date: June 15, 2008 7:16:09 PM EDT To: R-help [EMAIL PROTECTED] Subject: [R] R vs SAS and HLM on multilevel analysis- basic question Hi R users! I am trying to learn some multilevel analysis, but unfortunately i am now very confused. The reason:http://www.ats.ucla.edu/stat/hlm/seminars/hlm_mlm/mlm_hlm_seminar.htm http://www.ats.ucla.edu/stat/sas/seminars/sas_mlm/mlm_sas_seminar.htm and MlmSoftRev. pdf from mlmRev package. From what i see, the first two links seem to declare the level one variable as a random part (i don't know sas synthax, but i think i am right ) while Mr. Bates' pdf says that a grouping variable is the random part of the model, though both models, use roughly the same type of information, some characteristic of the school, along with individual characteristics in explaining individual achivement. Am i mistaken somehow? If not, could they both be valid models (i presume) but each showing something else, in terms of connections between this variables? Yes, I believe you are mistaken, but I have only a rudimentary understanding of mixed effects modeling so I won't comment further except to say that I'm pretty sure both sources you listed above are talking about the same kinds of models. I don't know SAS at all, but I've used both HLM and R to run mixed effects models. Part of the confusion may be due to the different ways that R and HLM expect the input data to be formatted. To run a 2- level model in HLM you need two separate files corresponding to the two levels. When you input the data into HLM you specify the grouping factor that links the two files together. In R you can use a single data file and specify the grouping factor in the model syntax. I posted a similar question several months ago--see http://tolstoy.newcastle.edu.au/R/e4/help/08/02/3600.html I also received an off-list reply pointing me to http://www.ats.ucla.edu/stat/examples/alda.htm which gives both HLM and R syntax for the same models. One of the examples on the website is as follows: HLM Level 1 Model COG = beta_0 + beta_1(TIME) + r Level 2 model: beta_0 = gamma_00 + gamma_01(PROGRAM) + mu_0 beta_1 = gamma_10 + gamma_11(PROGRAM) + mu_1 # Notice that no grouping factor is specified because this is done separately, in the data input stage. The corresponding R syntax is # R syntax: model1- lmer(cog~time*program + (time | id), data=dataframe) # Notice that there is an extra term in the R syntax (id) that is not in the HLM syntax. Again, this is because you have to tell HLM what the grouping variable is when you input the data, while in R you specify the grouping variable in the model. I'm guessing this may be the source of some of your confusion. Thank you and sorry for taking up your time. No problem, HTH. -Ista [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] contrasts using adonis function
On Mon, 2008-06-16 at 14:38 +0200, Luis San José García wrote: Hi, Somebody knows how to make contrasts if i'm using the function adonis? What is wrong with the defaults? From ?adonis: Usage: adonis(formula, data, permutations = 5, method = bray, strata = NULL, contr.unordered = contr.sum, contr.ordered = contr.poly, ...) So look at ?contr.sum and ?contr.poly for what constrasts adonis uses by default. If you want something different, then supply contr.helmert or contr.treatment, contr.sum, or contr.poly to the relevant argument in your adonis call. If you want your own special contrasts, then I presume they make sense in the context of the analysis? But for that you'll need to write your own function to calculate the constrasts you want, along the lines of contr.sum() or one of the other contrast functions. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Generating Reports from R.
Hi, I have a non-interactive R script that currently produces various graphs in png or pdf format. I need to program the script to combine the graphs with various pages of textual information, including some in tabular format, into an output report in pdf or html format. What is the recommended way of doing this? Regards, David Keegan. -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generating Reports from R.
Try using Sweave On Mon, Jun 16, 2008 at 10:37 AM, David Keegan [EMAIL PROTECTED] wrote: Hi, I have a non-interactive R script that currently produces various graphs in png or pdf format. I need to program the script to combine the graphs with various pages of textual information, including some in tabular format, into an output report in pdf or html format. What is the recommended way of doing this? Regards, David Keegan. -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Delete Block of Rows
Thanks for all the replies. My data frame is actually 4000 rows and 10 columns. This line, df - subset( df, !( rownames(df) %in% 1:25 ) ) Did not work for me. Is there a certain library I need to load for this to work (I'm assuming there isn't)? I didn't get an error message, warning, or anything; it just didn't work. These two lines did work, df = df[ -c(1:25), ]Or, df = df[ 26:200, ] I'm not sure why they didn't work the first time I tried them. Once again, thanks for the help! milton ruser wrote: Hi there, I don´t know if you are trying to solve the delete job or to test how functions work. If you really want to delete lines from a data.frame, try something like this. rowcount-1:100 x-runif(100) y-runif(100) df-data.frame(cbind(rowcount,x,y)) df.subset-subset(df, !(rownames(df) %in% 1:25)) #! (a condition) is the negation of the condition # so the output will be those lines that are not on interval 1:25 By the way, it is not a good idea to use data as a input argument on a function because data is a pre-defined function. Kind regards, miltinho On 6/15/08, nmarti [EMAIL PROTECTED] wrote: I am trying to delete a section of rows from a data frame (based on no condition). Lets say my data frame has 200 rows and I want to delete rows 1 through 25. How would I do this? I know x[ -1, ] deletes the first row (or any desired row). I tried using different variations of this, like x[ -c(1:25), ] but that didn't work. I also tried writting a few functions, for example: deleteRows - function( data, s, e, ) { for( i in s:e ) data[ -i, ] } deleteRows( ds, 1, 25 ) But that didn't work either, it only deleted row 25 (i'm new to writing functions). Any thoughts on how to solve my problem would be appreciated. -- View this message in context: http://www.nabble.com/Delete-Block-of-Rows-tp17849775p17849775.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Delete-Block-of-Rows-tp17849775p17865279.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using spec.pgram
Perhaps I'm applying spec.pgram wrong as you said. I will explain what I want, so you can tell me why I'm wrong and perhaps what I have to do to do it well. I have some points in a 1-D space and I want to know if they are spaced at a certain periodic distance. So, I computed all the distances between points in my space. Then, I would like to know if a certain distance (period), or multiples of a certain distance, is preferred to space my data. I made a histogram of the distances and apply the spec.pgram function to know the frequence (so the period) which is the most important to space the original data. But, when I have to sets of data (without necessarily the same number of observation in each set), I want to compare the importance of the period given by spec.pgram between the sets. Could I normalize the amplitude of the peaks given by spec.pgram? So, am I wrong to apply this methodology to exhibit a periodic distance between my data? If, true, what could you recommend me to do this? Thanks in advance for your answers. Best regards, Anthony On Tue, Jun 10, 2008 at 6:13 PM, stephen sefick [EMAIL PROTECTED] wrote: I from a first thought I would say that you are apply this wrong! The fourier transform convolves a function (cos(x)+isin(x) (this may not be the exact formula but I don't have my books near)) to the data and then integrates over -1/2 to 1/2 takes the modulus and plots this- the periodogram. The reason you preform a fourier transform is to look at recurring frequencies in the data, which are in the time domain. The fourier transform converts the time series into the frequency domain and viola you have a peak into the hidden/recurring parts of your signal. From your explaination your are applying this technique wrong- look at schumway, MASS4, et al. books to get a handle on how this technique is used. If you are to apply a time series analysis please use it on a time series. Maybe your logic is not flawed but I don't see how a histogram with its associated binning is a better candidate for time series analysis than the original time series if at all. good luck Stephen On Tue, Jun 10, 2008 at 8:49 AM, Matthieu Stigler [EMAIL PROTECTED] wrote: Hello I don't know exactly what you want to do but: -why do you use in your example h$counts and not h? Furthermore helpl file says it should be a time series, why then rather not your time series? -usually na.action will make the default action, which you can see by getOptions(na.action) -here in this function it is provided in the function values na.action = na.fail so it will just remove the NA in the time series -if you want to study a function, I advise you to copy it entirely, rename it and then just insert print(curiousobject...) in the function, this will allow you to let the function run and grasp the interessting objects, like: study-function (x, spans = NULL, kernel = NULL, taper = 0.1, pad = 0, fast = TRUE, demean = FALSE, detrend = TRUE, plot = TRUE, na.action = na.fail, ...) { series - deparse(substitute(x)) x - na.action(as.ts(x)) print(x) xfreq - frequency(x) ...} study(sunspots) -when you provide an example, instead of giving an external reference for the data, try to search a convenient internal data (accessed by data() ), so one will be able to reproduce your problems. Here you could use sunspots -to obtain the commented code... I don't know it... -good luck Matthieu Hi everyone, first of all, I would like to say that I am a newbie in R, so I apologize in advance if my questions seem to be too easy for you. Well, I'm looking for periodicity in histograms. I have histograms of certain phenomenons and I'm asking whether a periodicity exists in these data. So, I make a periodogram with the function spec.pgram. For instance, if I have a histogram h, I call spec.pgram by spec.pgram (h, log=no, taper=0.5). So, I have some peaks that appear and I would like to interpret them but I do not know how they are computed and so what a peak with a value of 1 represents in comparison with a peak of value 600 with another histogram. I looked at the source code of the function spec.pgram to better understand what is behind. But, when I apply the source code line by line, I've got a problem. For instance, I make: data = scan (file.txt) h = hist (data, breaks=max(data)/5000) #then I apply the first two lines of the spec.pgram function series - deparse(substitute(h$counts)) x - na.action(as.ts(h$counts)) x NULL I do not understand why when I apply the first two lines of the function I have x which is equal to NULL (which make a mistake in the following lines of the code) but if I apply the function directly with h$counts it gives me a result. So, if someone can explain to me what is the problem and/or how spec.pgram exactly computes the periodogram and how to interpret it with my data, I would be so grateful. And subsidiary
[R] Error in maximum likelihood estimation.
Dear UseRs, I wrote the following function to use MLE. - mlog - function(theta, nx = 1, nz = 1, dt){ beta - matrix(theta[1:(nx+1)], ncol = 1) delta - matrix(theta[(nx+2):(nx+nz+1)], ncol = 1) sigma2 - theta[nx+nz+2] gamma - theta[nx+nz+3] y - as.matrix(dt[, 1], ncol = 1) x - as.matrix(data.frame(1, as.matrix(dt[, 2:(nx+1)], ncol = 2))) z - as.matrix(dt[, (nx+2):(nx+nz+1)], ncol = nz) d - z %*% delta / (gamma * sigma2)^.5 mustar - (1-gamma) * z %*% delta - gamma * ( y - x %*% beta) sigmastar - (gamma * (1-gamma) * sigma2)^.5 dstar - mustar / sigmastar loglik - (-0.5 * nrow(x) *(log(2*pi) + log(sigma2)) -0.5 * sum(( y - x %*% beta + z %*% delta)^2/sigma2) -sum(log(pnorm(d))) + sum(log(pnorm(dstar return(-loglik) } --- Loglikelihood function is from page 21of Battese and Coelli (1993). (You can download this article at http://www.une.edu.au/economics/publications/econometrics/emwp69.PDF ) To test the above function with an artificial data set, I created the following data.frame. --- x1 - abs(rnorm(100))*100 x2 - abs(rnorm(100))*10 z1 - abs(rnorm(100))*5 z2 - abs(rnorm(100))*7 y - abs(0.3 + 0.3* log(x1) + 0.7* log(x2)) dat - data.frame(log(y), log(x1), log(x2), z1, z2) The starting value I set up is as follows: --- theta.start - c(0.09, 0.008, 0.008, 0.023, 0.0008, 0.008, 0.008) -- Applying nlm() function to the above function with the starting values gives the following error message. out - nlm(mlog, theta.start, nx = 2 , nz = 2, dt = dat, print.level = 2, hessian\ = T, iterlim = 500) iteration = 0 Step: [1] 0 0 0 0 0 0 0 Parameter: [1] 0.0900 0.0080 0.0080 0.0230 0.0008 0.0080 0.0080 Function Value [1] 6116.2 Gradient: [1] -10704.8 -46465.7 -22536.4 47168.2 54542.9 -776512.5 579.9 Error in nlm(mlog, theta.start, nx = 2, nz = 2, dt = dat, print.level = 2, : (converted from warning) NA/Inf replaced by maximum positive value My questions are 1. Is my loglikelihood function set up appropriately? 2. How to set up starting values efficiently? I read a thread shown at https://stat.ethz.ch/pipermail/r-help/2005-September/079617.html , but I cannot figure out how to set up starting values with expand.grid() of parameters I used (beta, delta, gamma, sigma2). Thank you in advance. Sincerely, Dong-hyun Oh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Linear Regression ?
Hi All, I have a data with 15 columns. the first 10 column are dependent(y’s) variables and the following 5 an columns are the independent variables(x’s) ( MY DATA HAS A HEADER WITH THE NAME OF THE VAIABLES). I need to apply linear regression y=a+bx where I need x to be one of the independent variable and y to be one of the dependent variable, but for each x I have to repeat the model for all 5 independent variable one at a time . Also each x is a categorical variable with 4 categories so I have to introduce three variables for each x New Variable 1 New Variable 2 New Variable 3 Category 1 0 0 0 Category 2 1 0 0 Category 3 0 1 0 Category 4 0 0 1 I want R to print out the summary and the analysis of variance for each model. How can this done in R? I want to use some loop that loops over the independent variables for each x ?Also , I am not sure how to deal with the problem of each x being a categorical variable and I have to create these new variables for each x? I hope that someone can help. I really Appreciate it. -- View this message in context: http://www.nabble.com/Linear-Regression---tp17865662p17865662.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2: How to remove legend component for geom_errorbar() ?
Hi Carsten, In my eagerness to get every component of the legend working automatically, I've completed neglected a way to turn bits off of you don't want them (the philosophy is that every geom that uses an aesthetic should appear in the legend in some way). The best thing I can suggest at the moment is: GeomErrorbar$guide_geom - function(.) point to use points for the errorbar legend, which you won't see because they'll overlap with the points from the points geom. In the next version, you'll be able to do GeomLine$guide_geom - function(.) blank Or I might come up with a better way of controlling the appearance. Regards, Hadley On Mon, Jun 16, 2008 at 2:55 AM, Carsten Jaeger [EMAIL PROTECTED] wrote: Dear list (probably Hadley), I'm trying to do a plot like the following, composed of bars and error bars: df - data.frame(factor1=gl(2,5), factor2=gl(5,1), y=rnorm(10), err=0.1) ggplot(df, aes(x=factor1, y=y, fill=factor2)) + geom_bar(position=dodge, stat=identity) + geom_errorbar(aes(min=y-err, max=y+err), position=dodge, width=0.1) The plot obtained has a legend named factor2, giving as expected the colours used for the five factor levels of factor2. So far so good. However, the legend also contains solid horizontal lines, obviously representing the error bars. While I do not immediately see the sense of a legend symbol for error bars, is there any easy way to turn these off? Thanks, Carsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Delete Block of Rows
Hi there, The subset function is available on your Base R. So you need not to load any package. May be it is not working because I suppose that your rownames is a sequential one (1...4000). Case it is not true, the command will not work. Anyway, I think that those line that are working find is simple than you use %in%... etc. Good luck, miltinho Brazil On 6/16/08, nmarti [EMAIL PROTECTED] wrote: Thanks for all the replies. My data frame is actually 4000 rows and 10 columns. This line, df - subset( df, !( rownames(df) %in% 1:25 ) ) Did not work for me. Is there a certain library I need to load for this to work (I'm assuming there isn't)? I didn't get an error message, warning, or anything; it just didn't work. These two lines did work, df = df[ -c(1:25), ]Or, df = df[ 26:200, ] I'm not sure why they didn't work the first time I tried them. Once again, thanks for the help! milton ruser wrote: Hi there, I don´t know if you are trying to solve the delete job or to test how functions work. If you really want to delete lines from a data.frame, try something like this. rowcount-1:100 x-runif(100) y-runif(100) df-data.frame(cbind(rowcount,x,y)) df.subset-subset(df, !(rownames(df) %in% 1:25)) #! (a condition) is the negation of the condition # so the output will be those lines that are not on interval 1:25 By the way, it is not a good idea to use data as a input argument on a function because data is a pre-defined function. Kind regards, miltinho On 6/15/08, nmarti [EMAIL PROTECTED] wrote: I am trying to delete a section of rows from a data frame (based on no condition). Lets say my data frame has 200 rows and I want to delete rows 1 through 25. How would I do this? I know x[ -1, ] deletes the first row (or any desired row). I tried using different variations of this, like x[ -c(1:25), ] but that didn't work. I also tried writting a few functions, for example: deleteRows - function( data, s, e, ) { for( i in s:e ) data[ -i, ] } deleteRows( ds, 1, 25 ) But that didn't work either, it only deleted row 25 (i'm new to writing functions). Any thoughts on how to solve my problem would be appreciated. -- View this message in context: http://www.nabble.com/Delete-Block-of-Rows-tp17849775p17849775.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Delete-Block-of-Rows-tp17849775p17865279.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sizing non-vector point shapes in ggplot2
On Mon, Jun 16, 2008 at 7:52 AM, mfrumin [EMAIL PROTECTED] wrote: Dear all, With normal plotting, one can size a set of points in a plot using a vector argument to cex in the points() function. This works whether you are using one of the standard R symbols (i.e. 19+) or some ascii symbol, such as '/' eg: plot(1:10, 1:10, type='n'); points(1:10, 1:10, cex = 1:10, pch = '/') Trying to make the transition to ggplot2, I find that the aesthetic size mapping does not apply if i do geom_point(..., shape='/') -- the points show up looking like '/' but they are not sized. Is there anything to do about this? eg: ggplot(data = data.frame(x = 1:10, y = 1:10, size = 1:10), aes(x = x, y = y)) + geom_point(mapping = aes(size = size), shape = '/') the plot that I'm making really needs a vertically oriented mark, not a round-ish point/square/triangle that takes up a lot of area. am I totally out of luck? Hmmm, I'd never noticed this feature of grid before. To size the points, I'm using the size argument of grid.points, which doesn't seem to affect the size of character based plotting symbols (because the are using the fontsize graphical parameter). I've cc'd Paul on this email so he can confirm whether this is a bug or by design. Regardless, you can make ggplot size the symbols correctly by running the following code: GeomPoint$draw - function(., data, scales, coordinates, ...) { with(coordinates$transform(data), ggname(.$my_name(), pointsGrob(x, y, size=unit(size, mm), pch=shape, gp=gpar(col=colour, fill = fill, fontsize = size * .pt))) ) } Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on an ASUS eee PC, continued - installing packages
On Mon, 16 Jun 2008, Peter Dalgaard wrote: Prof Brian Ripley wrote: On Mon, 16 Jun 2008, Peter Dalgaard wrote: Millo Giovanni wrote: The only thing I wish I were able to do now is to have the graphics windows defaults changed to a size fitting the small 9'' screen, as now I have to reduce it and move it to the right by hand every time to reproduce the results of 'windowstile in Windows. If anybody can help... That'll be something like X11.options(width=4,height=4,pointsize=8) in your ~/.Rprofile You need grDevices::X11.options, and it is better to use a load hook like setHook(packageEvent(grDevices, onLoad), function(...) grDevices::X11.options(width=4,height=4,pointsize=8) ) Thanks, Brian. Obviously, I haven't used this for a while and overlooked the example in the Examples section of ?Startup. I do wonder if there are ways to make this less easily overlooked, though. Pointers in any or all of ?x11, ?X11.options, and ?Devices could help, but maybe we need it in an introductory document like R-intro, along with the discussion of Rprofile files in Customizing the environment. I've added examples in ?X11.options, ?quartz.options and ?windows.options for now. (?X11 and ?X11.options are the same help page.) R-intro is slightly odd in that it and not R-admin has startup info, and it is scattered across 3 sections -- but at least one of those references ?Startup. There is another way to set the geometry, to set X11 resources as described in ?X11. I have in my ~/.Xresources R_x11*geometry: 700x700-0+0 (for a 22 90dpi screen, not a 9 one) That doesn't help with the pointsize, does it? (Quite crucial on low-res screens, even at 1024x768, 12.3 I find that the default pointsize=12 is a bit much.) No -- I was really pointing it out for completeness and 'the geometry' was inserted to try to make this clear. One thing that is a bit odd is that we have ways (two each) to set the initial position of the default device on X11 and Windows, but AFAICS none on Mac OS X. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stretching text vertically
You can embed plots using the subplot function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alex Reynolds Sent: Friday, June 13, 2008 4:56 PM To: r-help@r-project.org Subject: [R] stretching text vertically I'd like to stretch a plotted character vertically, to create a sequence logo. Is there a parameter to allow stretching text() output vertically or squeeze horizontally? I know about Oliver Bembom's seqLogo library, but this generates a sequence logo plot using a separate bitmap device. I want to recreate the sequence logo *inside* an existing plot. Alternatively, is there a way to embed one plot inside another? I could use imagemagick outside R to 'montage' separate bitmaps, but then the sequence logo is going to be very difficult to align (base for base) with the plot I'm trying to join it to. Thanks for any tips, Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] aggregate() function, strange behavior for augmented data
All, I'm re-running some analysis that has been augmented with additional data. When I use the exact same code for the augmented data, the behavior of the aggregate function is very strange, viz., one of the resulting variables is now coded as a factor while it was coded as numeric for the original data. Unfortunately, I cannot provide a reproducible code example since it only seems to occur with this data. I've checked and re-checked the of both the original and augmented data but nothing appears inconsistent. Any suggestions much appreciated. See below for specifics. Cheers, David # original data dim(junk1) [1] 96 3 junk1[1,] Hour Drug Aldo 10P9 junk1$Hour [1] 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 [39] 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 [77] 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 ### Not coded as a factor junk1.mean.time.drug = aggregate(junk1[3], junk1[c(1,2)], mean) junk1.mean.time.drug$Hour [1] 0 3 5 0 3 5 ### not coded as a factor # augmented data dim(junk1) [1] 108 3 junk1[1,] Hour Drug Aldo 10P9 junk1$Hour [1] 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 [51] 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 [101] 3 5 0 3 5 0 3 5### not coded as a factor junk1.mean.time.drug = aggregate(junk1[3], junk1[c(1,2)], mean) junk1.mean.time.drug$Hour [1] 0 3 5 0 3 5 Levels: 0 3 5## coded as a factor now! ## of course, I get recode it again but I'm curious as to why this is ## changing here __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing data with different delimters
It looks like your original data may be tab seperated, if that is the case then just use read.delim or use sep='\t' in read.table or scan. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Arnold Sent: Friday, June 13, 2008 5:15 PM To: r-help@r-project.org Subject: [R] Importing data with different delimters All, I have a data file with 56 entries that looks like this: City State JanTemp Lat Long Mobile, AL 44 31.288.5 Montgomery, AL 38 32.986.8 Phoenix, AZ 35 33.6112.5 Little Rock, AR 31 35.492.8 Los Angeles, CA 47 34.3118.7 San Francisco, CA 42 38.4123.0 I would like to read this data into a dataframe. Is it possible to do without editing the datafile? D. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using spec.pgram
To get some sort of frequency which in your case seem to be cycles per distance? Is a valid use of a fourier transform as long as it is a distance that is measured in a way that would be analogous to a time series- In other words if the distance proceeds from an origin in one direction- geophysicists do this often with the realization of an earthquake picked up by sensors that are a distance away from the origin of the epicenter, but they are looking for coherencies in the signal from one place to the next in the frequency domain seperated by distance- this is called beam forming- They use the raw signal- by binning (making a histogram) the data you are loosing the signal- you are looking at frequency of occurance of certain values not for the underlying periodicities of the data (in time or space). You are fitting cos and isin function to you data to see if there is periodicity- the power is the integration of the convolution of this sin and cosine function with your data- It seems to me meaningless to preform this convolution agianst something that is not a signal (the histogram). If you want to use a frequency domain technique you have to have a frequency to investigate- a histogram does not have this- I is a frequency of occurance by bin size which is NOT what you want (your would have cycles/binlength that doesn't make any sense to me) to do this analysis on- You want a signal- dissolved oxygen curve, sunspot record, etc. through time, or distance as stated above- you are looking for the frequency of a waveform- Anyway, I may be misunderstanding- supply some code and explain the data otherwise this line of though- in my limited expertise- is a dead end, but agian I still don't know what it is that you are, exactly, trying to do- and what your dataset constits. I hope these ruminations help I recommend doing this analysis on the raw data- It doesn't matter that you don't have the same amount of data points- as long as both sets of data have circa ten times the length of (cycles/distance) what you want to detect- If things in your case are spaced by one meter then the lowest cycle perdistance that you can reliably detect if 0.5 meters, this is all speculation because you don't have a problem with reproducible code, and we have no idea what you are measuring or what your data looks like- without this information there is no way that I can say one way or the other that you approach (suggested non-histogram) would be right or wrong. Stephen On Mon, Jun 16, 2008 at 9:33 AM, Anthony Mathelier [EMAIL PROTECTED] wrote: Perhaps I'm applying spec.pgram wrong as you said. I will explain what I want, so you can tell me why I'm wrong and perhaps what I have to do to do it well. I have some points in a 1-D space and I want to know if they are spaced at a certain periodic distance. So, I computed all the distances between points in my space. Then, I would like to know if a certain distance (period), or multiples of a certain distance, is preferred to space my data. I made a histogram of the distances and apply the spec.pgram function to know the frequence (so the period) which is the most important to space the original data. But, when I have to sets of data (without necessarily the same number of observation in each set), I want to compare the importance of the period given by spec.pgram between the sets. Could I normalize the amplitude of the peaks given by spec.pgram? So, am I wrong to apply this methodology to exhibit a periodic distance between my data? If, true, what could you recommend me to do this? Thanks in advance for your answers. Best regards, Anthony On Tue, Jun 10, 2008 at 6:13 PM, stephen sefick [EMAIL PROTECTED] wrote: I from a first thought I would say that you are apply this wrong! The fourier transform convolves a function (cos(x)+isin(x) (this may not be the exact formula but I don't have my books near)) to the data and then integrates over -1/2 to 1/2 takes the modulus and plots this- the periodogram. The reason you preform a fourier transform is to look at recurring frequencies in the data, which are in the time domain. The fourier transform converts the time series into the frequency domain and viola you have a peak into the hidden/recurring parts of your signal. From your explaination your are applying this technique wrong- look at schumway, MASS4, et al. books to get a handle on how this technique is used. If you are to apply a time series analysis please use it on a time series. Maybe your logic is not flawed but I don't see how a histogram with its associated binning is a better candidate for time series analysis than the original time series if at all. good luck Stephen On Tue, Jun 10, 2008 at 8:49 AM, Matthieu Stigler [EMAIL PROTECTED] wrote: Hello I don't know exactly what you want to do but: -why do you use in your example h$counts and not h? Furthermore helpl file says it should be a time series, why
Re: [R] Importing data with different delimters
Hi David, If the delimier is tab try this. my.df-read.table(my_file.txt, head=T, sep=\t) Cheers, Miltinho Brazil -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Arnold Sent: Friday, June 13, 2008 5:15 PM To: r-help@r-project.org Subject: [R] Importing data with different delimters All, I have a data file with 56 entries that looks like this: City State JanTemp Lat Long Mobile, AL 44 31.288.5 Montgomery, AL 38 32.986.8 Phoenix, AZ 35 33.6112.5 Little Rock, AR 31 35.492.8 Los Angeles, CA 47 34.3118.7 San Francisco, CA 42 38.4123.0 I would like to read this data into a dataframe. Is it possible to do without editing the datafile? D. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Importing data with different delimters
Greg Snow wrote: It looks like your original data may be tab seperated, if that is the case then just use read.delim or use sep='\t' in read.table or scan. I think that was only half the problem. If you do that, you end up with one column containing both City and State, comma-separated. Presumably, the path of least resistance is just to do this and then use string processing with sub() or strsplit() to split the City, State strings. -pd I have a data file with 56 entries that looks like this: City State JanTemp Lat Long Mobile, AL 44 31.288.5 Montgomery, AL 38 32.986.8 Phoenix, AZ 35 33.6112.5 Little Rock, AR 31 35.492.8 Los Angeles, CA 47 34.3118.7 San Francisco, CA 42 38.4123.0 I would like to read this data into a dataframe. Is it possible to do without editing the datafile? D. -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] aggregate() function, strange behavior for augmented data
Everything was read in the same way, and str(junk1) confirms that they are the same structure. This is very strange. ## original data: str(junk1) 'data.frame': 96 obs. of 3 variables: $ Hour: int 0 3 5 0 3 5 0 3 5 0 ... $ Drug: Factor w/ 2 levels D,P: 2 2 2 1 1 1 2 2 2 1 ... $ Aldo: int 9 15 4 8 13 3 5 11 5 7 ... ## augmented data: str(junk1) 'data.frame':108 obs. of 3 variables: $ Hour: int 0 3 5 0 3 5 0 3 5 0 ... $ Drug: Factor w/ 2 levels D,P: 2 2 2 1 1 1 2 2 2 1 ... $ Aldo: int 9 15 4 8 13 3 5 11 5 7 ... On 6/16/08 11:37 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi: do str(junk1) and it will tell you what the components of junk1 are. the only thing i can think of is that you used stringsAsFactors=FALSE when you ( probably ) used read.table to read in junk but you didn't use that options when you used read.table to read in junk1 ? On Mon, Jun 16, 2008 at 11:30 AM, David Afshartous wrote: All, I'm re-running some analysis that has been augmented with additional data. When I use the exact same code for the augmented data, the behavior of the aggregate function is very strange, viz., one of the resulting variables is now coded as a factor while it was coded as numeric for the original data. Unfortunately, I cannot provide a reproducible code example since it only seems to occur with this data. I've checked and re-checked the of both the original and augmented data but nothing appears inconsistent. Any suggestions much appreciated. See below for specifics. Cheers, David # original data dim(junk1) [1] 96 3 junk1[1,] Hour Drug Aldo 10P9 junk1$Hour [1] 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 [39] 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 [77] 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 ### Not coded as a factor junk1.mean.time.drug = aggregate(junk1[3], junk1[c(1,2)], mean) junk1.mean.time.drug$Hour [1] 0 3 5 0 3 5 ### not coded as a factor # augmented data dim(junk1) [1] 108 3 junk1[1,] Hour Drug Aldo 10P9 junk1$Hour [1] 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 [51] 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 3 5 0 [101] 3 5 0 3 5 0 3 5### not coded as a factor junk1.mean.time.drug = aggregate(junk1[3], junk1[c(1,2)], mean) junk1.mean.time.drug$Hour [1] 0 3 5 0 3 5 Levels: 0 3 5## coded as a factor now! ## of course, I get recode it again but I'm curious as to why this is ## changing here __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sizing non-vector point shapes in ggplot2
On Mon, Jun 16, 2008 at 3:55 PM, hadley wickham [EMAIL PROTECTED] wrote: On Mon, Jun 16, 2008 at 7:52 AM, mfrumin [EMAIL PROTECTED] wrote: Dear all, With normal plotting, one can size a set of points in a plot using a vector argument to cex in the points() function. This works whether you are using one of the standard R symbols (i.e. 19+) or some ascii symbol, such as '/' eg: plot(1:10, 1:10, type='n'); points(1:10, 1:10, cex = 1:10, pch = '/') Trying to make the transition to ggplot2, I find that the aesthetic size mapping does not apply if i do geom_point(..., shape='/') -- the points show up looking like '/' but they are not sized. Is there anything to do about this? eg: ggplot(data = data.frame(x = 1:10, y = 1:10, size = 1:10), aes(x = x, y = y)) + geom_point(mapping = aes(size = size), shape = '/') the plot that I'm making really needs a vertically oriented mark, not a round-ish point/square/triangle that takes up a lot of area. am I totally out of luck? Hmmm, I'd never noticed this feature of grid before. To size the points, I'm using the size argument of grid.points, which doesn't seem to affect the size of character based plotting symbols (because the are using the fontsize graphical parameter). I've cc'd Paul on this email so he can confirm whether this is a bug or by design. Regardless, you can make ggplot size the symbols correctly by running the following code: GeomPoint$draw - function(., data, scales, coordinates, ...) { with(coordinates$transform(data), ggname(.$my_name(), pointsGrob(x, y, size=unit(size, mm), pch=shape, gp=gpar(col=colour, fill = fill, fontsize = size * .pt))) ) } Hadley -- http://had.co.nz/ Thanks for getting back to me so quickly. This mostly works, in that: - When I ran it just as you sent it, I get this error: Error in inherits(x, factor) : object fill not found - but when I took out fill = fill from your suggestion above, I get the desired effect. - but this does not change the shape shown in the scale for the sized points. they are still big circles. but come to think of it, even setting shape = 20 or some other vector point-type, this doesn't effect the shape shown in the scale/legend thingy. so I guess that's a separate question, I will post it under separate cover. thanks! mike [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] round(1.5) = round(2.5) = 2?
The logic behind the round to even rule is that we are trying to represent an underlying continuous value and if x comes from a truly continuous distribution, then the probability that x==2.5 is 0 and the 2.5 was probably already rounded once from any values between 2.45 and 2.54..., if we use the round up on 0.5 rule that we learned in grade school, then the double rounding means that values between 2.45 and 2.50 will all round to 3 (having been rounded first to 2.5). This will tend to bias estimates upwards. To remove the bias we need to either go back to before the rounding to 2.5 (which is often impossible to impractical), or just round up half the time and round down half the time (or better would be to round proportional to how likely we are to see values below or above 2.5 rounded to 2.5, but that will be close to 50/50 for most underlying distributions). The stochastic approach would be to have the round function randomly choose which way to round, but deterministic types are not comforatable with that, so round to even was chosen (round to odd should work about the same) as a consistent rule that rounds up and down about 50/50. If you are dealing with data where 2.5 is likely to represent an exact value (money for example), then you may do better by multiplying all values by 10 or 100 and working in integers, then converting back only for the final printing. Note that 2.5001 rounds to 3, so if you keep more digits of accuracy until the final printing, then rounding will go in the expected direction, or you can add 0.1 (or other small number) to your values just before rounding, but that can bias your estimates upwards. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Markus Didion Sent: Sunday, June 15, 2008 3:26 AM To: r-help@r-project.org Subject: [R] round(1.5) = round(2.5) = 2? Dear R-users with a bit of grief I had to repeat an extensive analysis because I did not suspect (and therefore did not read the documentation) that round was implemented as for rounding off a 5, the IEC 60559 standard is expected to be used, 'go to the even digit', resulting in round(1.5) = 2 round (2.5) = 2. As a non-mathematician I am both puzzled and intrigued by this rule as it is against what I have learned in my math courses, i.e. round(1.5) = 2 round (2.5) = 3. I would like to understand the reason behind this rule. Thanks for your comments. Markus -- Markus Didion WaldökologieForest Ecology Inst. f. Terrestrische Oekosysteme Inst. of Terrestrial Ecosystems Departement UmweltwissenschaftenDept. of Environmental Sciences Eidg. Technische Hochschule Swiss Fed. Inst. of Technology ETH-Zentrum CHN G78 ETH-Zentrum CHN G78 Universitätstr. 22 Universitaetstr. 22 CH-8092 Zürich CH-8092 Zurich Schweiz Switzerland Tel +41 (0)44 632 5629 Fax +41 (0)44 632 1358 Email [EMAIL PROTECTED] homepage: http://www.fe.ethz.ch/people/didionm [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] optim() and starting values.
Dear UseRs, I wrote the following function to estimate parameters using MLE. mlog - function(theta, nx = 1, nz = 1, dt){ beta - matrix(theta[1:(nx+1)], ncol = 1) delta - matrix(theta[(nx+2):(nx+nz+1)], ncol = 1) sigma2 - theta[nx+nz+2] gamma - theta[nx+nz+3] y - as.matrix(dt[, 1], ncol = 1) x - as.matrix(data.frame(1, as.matrix(dt[, 2:(nx+1)], ncol = 2))) z - as.matrix(dt[, (nx+2):(nx+nz+1)], ncol = nz) d - z %*% delta / (gamma * sigma2)^.5 mustar - (1-gamma) * z %*% delta - gamma * ( y - x %*% beta) sigmastar - (gamma * (1-gamma) * sigma2)^.5 dstar - mustar / sigmastar loglik - (-0.5 * nrow(x) *(log(2*pi) + log(sigma2)) -0.5 * sum(( y - x %*% beta + z %*% delta)^2/sigma2) -sum(log(pnorm(d))) + sum(log(pnorm(dstar return(-loglik) } -- To test my function, I created an artificial data set as follows: -- x1 - abs(rnorm(100))*100 x2 - abs(rnorm(100))*10 z1 - abs(rnorm(100))*5 z2 - abs(rnorm(100))*7 y - abs(0.3 + 0.3* log(x1) + 0.7* log(x2)) dat - data.frame(log(y), log(x1), log(x2), z1, z2) -- The following optimization results provides different estimates. -- theta.start1 - c(1.06, 0.08, 0.04, 0.097, 0.008, 0.08, 0.008) theta.start2 - c(1.06, 0.08, 0.04, 0.097, 0.8, 0.0008, 0.0008) out.optim - optim(theta.start1, mlog, nx = 2, nz = 2, dt = dat, hessian = T) par.theta1 - out.optim$par out.optim - optim(theta.start2, mlog, nx = 2, nz = 2, dt = dat, hessian = T) par.theta2 - out.optim$par --- How can I set up concrete starting values? Any advices will be appreciated. Looking forward to hearing from you. Sincerely, Dong-hyun Oh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R as chart engine in web-service
I think that you have to define some type of criteria on what you expect the performance to be. There is a cost/benefit tradeoff in having multiple servers with a load balancer and this all depends on how much you want to spend on a solution. You might want to prototype it in R to at least get an understanding of the data transformations that are required and then after you have some performance data and a target for usage, you can then make a better decision. On Mon, Jun 16, 2008 at 8:26 AM, Daniel Cegielka [EMAIL PROTECTED] wrote: Can you put some criteria on 'better'/'faster'. What throughput are you expecting? How many requests per second will you have to handle? It's very difficult to tell how many request per second I will have to handle. If you have normal site it will be max. 2-5 tps (on chart website) but if you have real time quotes it will be about 300 tps. In RT quotes I intend use java applet to make RT charts with independent connection. I thing about service like BigChart.com - put some symbol (GOOG, DJIA etc). http://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=djiasid=164 3 and the chart like: http://www.marketwatch.com/tools/quotes/intchart.asp?submitted=trueintflavo r=advancedsymb=DJIAorigurl=%2Ftools%2Fquotes%2Fintchart.asptime=8freq=1 startdate=enddate=hiddenTrue=comp=Enter+Symbol(s)%3Acompidx=a~0comp ind=a~0uf=7168ma=1maval=50lf=1lf2=4lf3=0type=2size=2optstyle=10 13 In this kind of web services its important how faster the chart engine is in general. If there will be to many request per second I can add more machines and use load balancer (haproxy or pound). What size/type machine will you be running on? Probably 1-2 Quad Core Intel Xeon 2x6MB Cache, 2.0GHz per machine with 8GB (or 16GB) RAM. Zope 3 as web server on Gentoo Linux (x86). Memory will be mounted as a local disk (tmpfs) and python and R binaries will by copy into RAM. Python and R are compiled with ICC compiler. Is data being accessed from a database which may influence the timing? R will connect with Tree Data Server (database): http://tree.sourceforge.net/ Data can be keep in memcached: http://www.danga.com/memcached/ So I think there is very small influence on the timing. And I think about quantmod as a R chart package: http://www.quantmod.com/examples/charting/ The main problem with R is that, R uses x11 server to render images and this way is very slow and I thing that faster would be the Cairo (or GDD) R package but I haven't tested this yet. R engine is very universal and this is the strong of R choice in this kind of web service... then begin write new (faster?) c/c++ plugin. What you think? daniel cegielka -Original Message- From: jim holtman [mailto:[EMAIL PROTECTED] Sent: Monday, June 16, 2008 1:55 AM To: Daniel Cegielka Cc: r-help@r-project.org Subject: Re: [R] R as chart engine in web-service Can you put some criteria on 'better'/'faster'. What throughput are you expecting? How many requests per second will you have to handle? What is the timing of your current method? What size/type machine will you be running on? Is data being accessed from a database which may influence the timing? So you need to give some specificity of what your requirements are. You can probably get faster (but maybe not better) with a plug-in, but I would assume that it would also be more effort. On Sun, Jun 15, 2008 at 6:39 PM, Daniel Cegielka [EMAIL PROTECTED] wrote: Hi R-users I think about some web service with stock charts and I plan use python as web framework with R as mathematical and chart engine. I use rpy to connect R with python. It works good. Is it good idea to use R as chart engine? Maybe it's better (faster) to use c/c++ plugin? Daniel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2: How to remove legend component for geom_errorbar() ?
thanks for your tip! It worked fine (though I had to use tile instead of point). I see your point to handle legends the way you do, which is a very convenient feature of ggplot. It's great for points, lines, bars etc., but in the particular case of error bars, I think it would be reasonable to omit them by default and only turn them on if someone really wants them (by using something like legend=TRUE). Just my two cents, for now, I'm happy with your workaround. Maybe this wouldn't have been such a problem if the legend for error bars actually looked like errorbars! I'll add that to my to do and think about better ways to turn legends off when desired. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] prediction intervals for random effects in nlme
Dear all, nbsp; This is a relist of my previous question. I noticed that some charactersnbsp;were nbsp;not displayed in the previous version. nbsp; nbsp; Is there a function to calculate thenbsp; prediction intervals for random effects in non-linear mixed models? I found a way to do it for linear mixed models but not for non-linearnbsp;mixed one. nbsp; Many thanks nbsp; Bernard _ o.fr [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] candisc() error message
John is correct the error message you got was clear: the error SSP matrix is of deficient rank. Possible solutions: - Regroup the factor levels to fewer and/or - Combine some of the species to broader classes so you have fewer than 17 response variables - Collect more samples hope this helps, -Michael John Fox wrote: Dear Tanya, If I follow correctly what you're trying to do, you're in effect doing a one-way MANOVA of 17 response variables on a six-level factor, with only 20 observations. That's not enough data. I'm copying to Michael Friendly in case he hasn't seen your posting and would like to comment. Regards, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tanya Yatsunenko Sent: June-15-08 8:23 PM To: r-help@r-project.org Subject: [R] candisc() error message Hi, I am doing canonical discriminant analysis using candisc function from the candisc package. My input is a table of species distribution (columns = abundance of each species in each sample) in samples that are split by categories (rows), and I want to know whether each category is associated with a particular set of species and their abundances. I have 20 rows (samples) split into 6 categories, and 17 columns (species). I am getting the following error message, which I don't understand: can-candisc(mod, data=canIN) Error in linear.hypothesis.mlm(mod, hyp.matrix.2, SSPE = SSPE, V = V, : The error SSP matrix is apparently of deficient rank = 16 17 Does anyone has any experience in candisc? -- Tanya. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Friendly Email: [EMAIL PROTECTED] Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Linear Regression ?
Hi, did you have a look at the manual An Introduction to R? (http://cran.r-project.org/doc/manuals/R-intro.html). Chapter Statistical Models in R should answer (most of) your questions concerning linear regression. kayj wrote: Also each x is a categorical variable with 4 categories so I have to introduce three variables for each x If I understood correctly what you mean (- coding of dummy variables), this is not necessary in R. If you variable is a factor, R does it for you automatically. If you are unhappy with the choice of reference category, please check: ?relevel I hope this helps, Roland __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 3d data?
Hi all! I'm very new to R, and I'm having trouble figuring out how to go from a file of points that I have to a 3d surface plot of the data. I typically have something like this: X Y Z 0.0050.02334.45 0.0035 0.63 28.48 . I've tried looking at the persp and wireframe packages, and the rgl package, but I can't seem to figure out how to use any of them. I tried to take the rgl.surface3d example and use it for myself, and this is what I have so far: setwd(.) data - read.csv(data.csv,header=T) x - data$X y - data$Y z - data$Z open3d() surface3d(x, y, z) That gives me the following error: Error in rgl.surface(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, : y length != x rows * z cols I have no idea what it is trying to tell me there. Would anyone mind helping me out? Wesley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting 3d data?
Try scatterplot3d function in the package with same name. On Mon, Jun 16, 2008 at 2:32 PM, Wesley Tansey [EMAIL PROTECTED] wrote: Hi all! I'm very new to R, and I'm having trouble figuring out how to go from a file of points that I have to a 3d surface plot of the data. I typically have something like this: X Y Z 0.0050.02334.45 0.0035 0.63 28.48 . I've tried looking at the persp and wireframe packages, and the rgl package, but I can't seem to figure out how to use any of them. I tried to take the rgl.surface3d example and use it for myself, and this is what I have so far: setwd(.) data - read.csv(data.csv,header=T) x - data$X y - data$Y z - data$Z open3d() surface3d(x, y, z) That gives me the following error: Error in rgl.surface(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, : y length != x rows * z cols I have no idea what it is trying to tell me there. Would anyone mind helping me out? Wesley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 回复: cch() and coxph() for case-coh ort
I tried to compare if cch() and coxph() can generate same result for same case cohort data Use the standard data in cch(): nwtco Since in cch contains the cohort size=4028, while ccoh.data size =1154 after selection, but coxph does not contain info of cohort size=4028. The rough estimate between coxph() and cch() is same, but the lower and upper CI and P-value are a little different. Can we exactly use coxph() to repeat cch() using with appropriate configuration in coxph()? Is SAS a better way(PHREG,CASECOH.SAS) to implement time-dependent case-cohort? summary(fit2.ccP) Call: coxph(formula = Surv(edrel, rel) ~ stage + histol + age + offset(-100 * (1 - subcohort)) + cluster(seqno), data = ccoh.data) n= 1154 coef exp(coef) se(coef) robust sez p stageII 0.7363 2.09 0.12130.1699 4.33 1.5e-05 stageIII 0.5976 1.82 0.12330.1753 3.41 6.5e-04 stageIV 1.3921 4.02 0.13390.2081 6.69 2.2e-11 histolUH 1.5059 4.51 0.09110.1644 9.16 0.0e+00 age 0.0432 1.04 0.01460.0243 1.78 7.6e-02 exp(coef) exp(-coef) lower .95 upper .95 stageII 2.09 0.479 1.497 2.91 stageIII 1.82 0.550 1.289 2.56 stageIV 4.02 0.249 2.676 6.05 histolUH 4.51 0.222 3.267 6.22 age 1.04 0.958 0.996 1.09 Rsquare= 0.273 (max possible= 1 ) Likelihood ratio test= 368 on 5 df, p=0 Wald test= 134 on 5 df, p=0 Score (logrank) test = 490 on 5 df, p=0, Robust = 165 p=0 (Note: the likelihood ratio and score tests assume independence of observations within a cluster, the Wald and robust score tests do not). summary(fit.ccSP) Case-cohort analysis,x$method, SelfPrentice with subcohort of 668 from cohort of 4028 Call: cch(formula = Surv(edrel, rel) ~ stage + histol + age, data = ccoh.data, subcoh = ~subcohort, id = ~seqno, cohort.size = 4028, method = SelfPren) Coefficients: CoefHR (95% CI) p stageII 0.736 2.088 1.491 2.925 0.000 stageIII 0.597 1.818 1.285 2.571 0.001 stageIV 1.392 4.021 2.670 6.057 0.000 histolUH 1.506 4.507 3.274 6.203 0.000 age 0.043 1.044 0.996 1.095 0.069 2008/6/12, Terry Therneau [EMAIL PROTECTED]: Jin Wang had an error. My original note specified a variable that was 1 for subjects NOT in the subcohort, so the correct coxph call is coxph(Surv(edrel, rel) ~ stage + histol + age + offset(-100*(subcohort==0)) + cluster(seqno), data =ccoh.data) This gives the same coefficients as the cch example, along with the infinitesimal jackknife or robust variance estimate. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 spec.pgram
OK, it seems like I do not succeed in expressing what I do, or want to do. So, I give you the example that bring me to this kind of analysis. I wrote the paper Chromosomal periodicity of evolutionary conserved gene pairs (which you can download at http://www.pnas.org/cgi/reprint/104/25/10559). In figure 2, they have a histogram of distances between genes on a chromosome and they make a discrete fourier transform analysis to exhibit a period of 117kb. They explain how they did in the first paragraph of Distributions of distances and positions and fourier transform (last page). I thought that this kind of analysis was made by spec.pgram with a histogram. But perhaps I am wrong because I really do not understand what they mean by the histogram was tranformed into a continuous probability density by using a Gaussian smoothing window and normalizing the total density over the entire genome to 1. A discrete Fourier transform of the data were computed from 0 to 1,000kb by using a Tukey window to taper the end (ratio of 0.5 for tapered to untapered length.. I hope it explains better what I want to obtain from my distances. Best regards, Anthony On Mon, Jun 16, 2008 at 5:25 PM, stephen sefick [EMAIL PROTECTED] wrote: To get some sort of frequency which in your case seem to be cycles per distance? Is a valid use of a fourier transform as long as it is a distance that is measured in a way that would be analogous to a time series- In other words if the distance proceeds from an origin in one direction- geophysicists do this often with the realization of an earthquake picked up by sensors that are a distance away from the origin of the epicenter, but they are looking for coherencies in the signal from one place to the next in the frequency domain seperated by distance- this is called beam forming- They use the raw signal- by binning (making a histogram) the data you are loosing the signal- you are looking at frequency of occurance of certain values not for the underlying periodicities of the data (in time or space). You are fitting cos and isin function to you data to see if there is periodicity- the power is the integration of the convolution of this sin and cosine function with your data- It seems to me meaningless to preform this convolution agianst something that is not a signal (the histogram). If you want to use a frequency domain technique you have to have a frequency to investigate- a histogram does not have this- I is a frequency of occurance by bin size which is NOT what you want (your would have cycles/binlength that doesn't make any sense to me) to do this analysis on- You want a signal- dissolved oxygen curve, sunspot record, etc. through time, or distance as stated above- you are looking for the frequency of a waveform- Anyway, I may be misunderstanding- supply some code and explain the data otherwise this line of though- in my limited expertise- is a dead end, but agian I still don't know what it is that you are, exactly, trying to do- and what your dataset constits. I hope these ruminations help I recommend doing this analysis on the raw data- It doesn't matter that you don't have the same amount of data points- as long as both sets of data have circa ten times the length of (cycles/distance) what you want to detect- If things in your case are spaced by one meter then the lowest cycle perdistance that you can reliably detect if 0.5 meters, this is all speculation because you don't have a problem with reproducible code, and we have no idea what you are measuring or what your data looks like- without this information there is no way that I can say one way or the other that you approach (suggested non-histogram) would be right or wrong. Stephen On Mon, Jun 16, 2008 at 9:33 AM, Anthony Mathelier [EMAIL PROTECTED] wrote: Perhaps I'm applying spec.pgram wrong as you said. I will explain what I want, so you can tell me why I'm wrong and perhaps what I have to do to do it well. I have some points in a 1-D space and I want to know if they are spaced at a certain periodic distance. So, I computed all the distances between points in my space. Then, I would like to know if a certain distance (period), or multiples of a certain distance, is preferred to space my data. I made a histogram of the distances and apply the spec.pgram function to know the frequence (so the period) which is the most important to space the original data. But, when I have to sets of data (without necessarily the same number of observation in each set), I want to compare the importance of the period given by spec.pgram between the sets. Could I normalize the amplitude of the peaks given by spec.pgram? So, am I wrong to apply this methodology to exhibit a periodic distance between my data? If, true, what could you recommend me to do this? Thanks in advance for your answers. Best regards, Anthony On Tue, Jun 10, 2008 at 6:13 PM, stephen sefick [EMAIL
Re: [R] ggplot2: How to remove legend component for geom_errorbar() ?
Hi Hadley, thanks for your tip! It worked fine (though I had to use tile instead of point). I see your point to handle legends the way you do, which is a very convenient feature of ggplot. It's great for points, lines, bars etc., but in the particular case of error bars, I think it would be reasonable to omit them by default and only turn them on if someone really wants them (by using something like legend=TRUE). Just my two cents, for now, I'm happy with your workaround. Thanks again, Carsten On Mon, 2008-06-16 at 09:49 -0500, hadley wickham wrote: Hi Carsten, In my eagerness to get every component of the legend working automatically, I've completed neglected a way to turn bits off of you don't want them (the philosophy is that every geom that uses an aesthetic should appear in the legend in some way). The best thing I can suggest at the moment is: GeomErrorbar$guide_geom - function(.) point to use points for the errorbar legend, which you won't see because they'll overlap with the points from the points geom. In the next version, you'll be able to do GeomLine$guide_geom - function(.) blank Or I might come up with a better way of controlling the appearance. Regards, Hadley On Mon, Jun 16, 2008 at 2:55 AM, Carsten Jaeger [EMAIL PROTECTED] wrote: Dear list (probably Hadley), I'm trying to do a plot like the following, composed of bars and error bars: df - data.frame(factor1=gl(2,5), factor2=gl(5,1), y=rnorm(10), err=0.1) ggplot(df, aes(x=factor1, y=y, fill=factor2)) + geom_bar(position=dodge, stat=identity) + geom_errorbar(aes(min=y-err, max=y+err), position=dodge, width=0.1) The plot obtained has a legend named factor2, giving as expected the colours used for the five factor levels of factor2. So far so good. However, the legend also contains solid horizontal lines, obviously representing the error bars. While I do not immediately see the sense of a legend symbol for error bars, is there any easy way to turn these off? Thanks, Carsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Lattice: Superpose bwplot on dotplot [Newbie Question]
Hello everyone I have dataset containing a monetary value (ABS) and two factors (Fct, Group). I am able to create useful using: bwplot(ABS~Group|Fct) and dotplot(ABS~Group|Fct) Question: What do I have to do to overlay the dotplot with the bwplot (same data set)? I've found a couple of posts that hinted at the possibility of doing that, and checked the panel.superpose() help, but the info was too complex for my newbie brain. Thanks for your help! LY -- View this message in context: http://www.nabble.com/Lattice%3A-Superpose-bwplot-on-dotplot--Newbie-Question--tp17867934p17867934.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in maximum likelihood estimation.
Dear UseRs, I wrote the following function to use MLE. - mlog - function(theta, nx = 1, nz = 1, dt){ beta - matrix(theta[1:(nx+1)], ncol = 1) delta - matrix(theta[(nx+2):(nx+nz+1)], ncol = 1) sigma2 - theta[nx+nz+2] gamma - theta[nx+nz+3] y - as.matrix(dt[, 1], ncol = 1) x - as.matrix(data.frame(1, as.matrix(dt[, 2:(nx+1)], ncol = 2))) z - as.matrix(dt[, (nx+2):(nx+nz+1)], ncol = nz) d - z %*% delta / (gamma * sigma2)^.5 mustar - (1-gamma) * z %*% delta - gamma * ( y - x %*% beta) sigmastar - (gamma * (1-gamma) * sigma2)^.5 dstar - mustar / sigmastar loglik - (-0.5 * nrow(x) *(log(2*pi) + log(sigma2)) -0.5 * sum(( y - x %*% beta + z %*% delta)^2/sigma2) -sum(log(pnorm(d))) + sum(log(pnorm(dstar return(-loglik) } --- Loglikelihood function is from page 21of Battese and Coelli (1993). (You can download this article athttp://www.une.edu.au/economics/publications/econometrics/emwp69.PDF ) To test the above function with an artificial data set, I created the following data.frame. --- x1 - abs(rnorm(100))*100 x2 - abs(rnorm(100))*10 z1 - abs(rnorm(100))*5 z2 - abs(rnorm(100))*7 y - abs(0.3 + 0.3* log(x1) + 0.7* log(x2)) dat - data.frame(log(y), log(x1), log(x2), z1, z2) The starting value I set up is as follows: --- theta.start - c(0.09, 0.008, 0.008, 0.023, 0.0008, 0.008, 0.008) -- Applying nlm() function to the above function with the starting values gives the following error message. out - nlm(mlog, theta.start, nx = 2 , nz = 2, dt = dat, print.level = 2, hessian\ = T, iterlim = 500) iteration = 0 Step: [1] 0 0 0 0 0 0 0 Parameter: [1] 0.0900 0.0080 0.0080 0.0230 0.0008 0.0080 0.0080 Function Value [1] 6116.2 Gradient: [1] -10704.8 -46465.7 -22536.4 47168.2 54542.9 -776512.5 579.9 Error in nlm(mlog, theta.start, nx = 2, nz = 2, dt = dat, print.level = 2, : (converted from warning) NA/Inf replaced by maximum positive value My questions are 1. Is my loglikelihood function set up appropriately? 2. How to set up starting values efficiently? I read a thread shown at https://stat.ethz.ch/pipermail/r-help/2005-September/079617.html , but I cannot figure out how to set up starting values with expand.grid() of parameters I used (beta, delta, gamma, sigma2). Thank you in advance. Sincerely, Dong-hyun Oh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] save workspace while running R on a cluster
Thanks your suggestion works -:-) From: milton ruser [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2008 2:42 PM To: Manisha Brahmachary Cc: r-help@r-project.org Subject: Re: [R] save workspace while running R on a cluster Hi Manisha, How about you incluse something like this on your script.R: setwd(/your/full/working/directory) # ?setwd save.image()# or save.image(your_workspace.RDA). By the way, I don´t know if you added the line below to run in background: R --save calculate.R script.out May be the rigth thing is R --save calculate.R script.out Good luck. miltinho Brazil On 6/12/08, Manisha Brahmachary [EMAIL PROTECTED] wrote: Hello, I have a question about running R in a cluster environment. The shell script I am running looks like this: #!/bin/bash cd /nfs/apollo/2/c2b2/users/mb0001/Data /nfs/apollo/1/shares/software/core_facility/local/x86_64_rocks/R/current/bin/ R --save calculate.R script.out I have used the -save command to save the R workspace (If, I understand it correctly) . However, I am unable to find the workspace file. Using find .RData did not help. I would be obliged if someone can help me figure out where the workspace file gets saved? Thanks manisha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Creating correlated multivariate dataset
Hello list, I am trying to test a model but for the beginning I want to do this by using simulated dataset. The model is Y_t = X_t %*% beta + e Where Y : (Nx1); X: (Nxp); beta: (0.6,0.3,0.1); e-uncorrelated normally distributed variates for each t. and later I want to use to use this dataset in a BUGS model to estimate the betas. Thank you for you consideration. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] pvclust distance matrix
Hello, I am attempting to assign significance levels to a UPGMA cluster analysis as part my doctoral research. The pvclust function works well but doesn't include the similarity index I need (morisita's) as an option for computing a distance matrix. Morisita's is available in vegdist in the VEGAN library but I am having a hard time getting the vegdist function to direct drop into pvclust as the vegdist documentation suggests. I would appreciate any suggestions. Thank you Brad Bradley N. Strobel Department of Natural Resource Management Texas Tech University Lubbock, TX (806)742-0841 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] minimizing title's police
in order to minimize the police of the title of my graph i tried to use: title(nombre de fleurs données journellement par 6 cereus peruvianus du 1/07/02 au 31/09/02,font=0) but this message appears: Erreur dans title(nombre de fleurs données journellement par 6 cereus peruvianus de 1/07/02 au 31/09/02, : valeur spécifiée pour le paramètre graphique font incorrect what's the value that should i give to the parameter font ? -- View this message in context: http://www.nabble.com/minimizing-title%27s-police-tp17870753p17870753.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dual axis labeling of a single quantity
I have a problem where I need to label the vertical axes of a Boxplot with related, but different quantities (flow height), which have a known relationship. Primarily I want to plot the variable as a flow on the left axis and on the opposing right axis, show the corresponding height. Is it possible to get the flow range (max min) of the left axis and then supply the right axis with that range (corresponding max/min) which will be plotted automatically by R? It does not matter if the opposing tick marks exactly correspond to the tick mark values on the left side as long as the scale is correct (that is the correct corresponding range). I'm not even sure where to start searching for this… Regards, Tom -- Thomas E Adams National Weather Service Ohio River Forecast Center 1901 South State Route 134 Wilmington, OH 45177 EMAIL: [EMAIL PROTECTED] VOICE: 937-383-0528 FAX:937-383-0033 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] left-aligned title?
Try with mtext: plot(rnorm(100)) mtext(text = Left, side = 3, adj = 0) On Mon, Jun 16, 2008 at 2:39 PM, Carlos Gershenson [EMAIL PROTECTED] wrote: Hi, I am trying to insert a letter in a plot corner outside the plotting area. Thus, legend and text don't seem to work. title does the trick, but I cannot find a way of moving it from the center to the left corner... I already tried with a few parameters from par, but title does not take them. Would anyone have an idea on how to pull this one off? Thank you very much, Carlos Gershenson http://homepages.vub.ac.be/~cgershen/http://homepages.vub.ac.be/%7Ecgershen/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] in axis() suppressing axis line but keeping tick marks
I've been trying to figure out a parameter that will let you separately adjust the parameters for the axis line from the tick mark. In the following example, I would like to suppress the axis line, but keep the tick marks. Thanks, Andrew foo - data.frame(x=1:3, y=4:6) plot(foo$x, foo$y, type=n, axes=F) points(foo$x, foo$y) axis(side=1, at=foo$x, lty=0) #would like to figure out way to keep tick marks, but suppress axis line [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] prediction intervals for random effects in nlme
Marc Bernard bernarduse1 at yahoo.fr writes: Is there a function to calculate thenbsp; prediction intervals for random effects in non-linear mixed models? I found a way to do it for linear mixed models but not for non-linearnbsp;mixed one. Please do not send HTML mail to the list. A discussion and a caveat by Douglas Bates for lmer/lme4 is in: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/113978.html It might work in a an analogous way for non-linear fits. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] barplot with color coding according to value
Hello, I want to use R to produce nice meteograms... For this I would need to color-code my barplot according to the value plotted say if value x 30 ... the bar is red ; if x between 20 and 10, the bar is blue etc... any ideas how to proceed ? Thank You a lot, maria __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cch() and coxph() for case-cohort
- begin included message - I tried to compare if cch() and coxph() can generate same result for same case cohort data Use the standard data in cch(): nwtco Since in cch contains the cohort size=4028, while ccoh.data size =1154 after selection, but coxph does not contain info of cohort size=4028. The rough estimate between coxph() and cch() is same, but the lower and upper CI and P-value are a little different. Can we exactly use coxph() to repeat cch() using with appropriate configuration in coxph()? Is SAS a better way(PHREG,CASECOH.SAS) to implement time-dependent case-cohort? output deleted --end included message I showed you how to do time-dependent case cohort analysis. Stop complaining and use the advice. No, SAS will not be better. It will be different due to defaults (different convergence criteria, different default ties method). Not better, not worse, just different. The code I sent results in one variance estimate type, the default cch code is another. They are asymptotically equivalent, and in your sample are essentially identical: one CI was (1.497, 2.91) the other (1.491, 2.925). Neither is 'better' or 'correct', both are good. If you feel that you must have the other estimate, then read the paper upon which cch is based (which I wrote); you can find it in the references for the cch help page. The cch output has some default information not in the coxph output and vice versa. So what? Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] barplot with color coding according to value
Perhaps something like this: x - sample(10:50, 10, rep=TRUE) cols - as.character(cut(x, breaks = c(0, 10, 20, 30,max(x)), labels = c(green, blue, yellow, red))) barplot(x, col = cols) On Mon, Jun 16, 2008 at 4:15 PM, [EMAIL PROTECTED] wrote: Hello, I want to use R to produce nice meteograms... For this I would need to color-code my barplot according to the value plotted say if value x 30 ... the bar is red ; if x between 20 and 10, the bar is blue etc... any ideas how to proceed ? Thank You a lot, maria __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in runif
Hi all I would be grateful you can help me with my problem. I try to run an optimization code . in one line I have runif in order to sample the PDF. I get this error while i run it. Error in runif(1, f$d[[n.of.u.vars + n.of.o.vars + j]][[2]][1], f$d[[n.of.u.vars + : invalid arguments Here is a part of that code: # initialize random numeber generator if (seed0) set.seed(seed) # set parameters e.abs - e e.rel - e max.value - f$opt eval - 0 last.impr - max.eval; nl - matrix(NA,k,k-1) iteration - 0 # separate unordered and ordered from continuous variables range.u - vector() range.o - vector() n.of.x.vars - 0 n.of.o.vars - 0 n.of.u.vars - 0 for (i in f$d) { if (i[[1]]==u) { range.u - c(range.u, length(i[[2]])) n.of.u.vars - n.of.u.vars + 1 } if (i[[1]]==o) { range.o - c(range.o, length(i[[2]])) n.of.o.vars - n.of.o.vars + 1 } if (i[[1]]==x) { n.of.x.vars - n.of.x.vars + 1 } } # initialize variables max.u - rep(NA,n.of.u.vars) max.o - rep(NA,n.of.o.vars) max.X - rep(NA,n.of.x.vars) max.y - -Inf p.X - vector() p.u - vector() p.o - vector() p - data.frame(v=numeric(),sd=numeric(),gr=numeric()); # randomly choose the starting population # (but based on the data given in the function definition) for (i in 1:k) { if (n.of.u.vars0) { U - vector() for (j in 1:n.of.u.vars) { U - c(U, sample(range.u[j],1)) } U - t(U) } else U - NULL if (n.of.o.vars0) { O - vector() for (j in 1:n.of.o.vars) { O - c(O, sample(range.o[j],1)) } O - t(O) } X - vector() for (j in 1:n.of.x.vars) { X - c(X, runif(1,f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][1], f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][2])) } X - t(X) Many Thanks Yasin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] minimizing title's police
On Mon, 16-Jun-2008 at 11:35AM -0700, hanen wrote: | | | in order to minimize the police of the title of my graph i tried to use: | | title(nombre de fleurs données journellement par 6 cereus peruvianus du | 1/07/02 au 31/09/02,font=0) | | but this message appears: | | Erreur dans title(nombre de fleurs données journellement par 6 cereus | peruvianus de 1/07/02 au 31/09/02, : | valeur spécifiée pour le paramètre graphique font incorrect | | what's the value that should i give to the parameter font ? 1 is probably what you want. To change the size, try changing cex, or perhaps one of the other cex.* par values. Check out ?par and search for cex. While you're there, check out how to use font. -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_Middle minds discuss events (:_~*~_:)Small minds discuss people (_)-(_) . Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 回复: cch() and coxph() for case-c ohort
Jin Wang wrote: I tried to compare if cch() and coxph() can generate same result for same case cohort data Use the standard data in cch(): nwtco Since in cch contains the cohort size=4028, while ccoh.data size =1154 after selection, but coxph does not contain info of cohort size=4028. The rough estimate between coxph() and cch() is same, but the lower and upper CI and P-value are a little different. Can we exactly use coxph() to repeat cch() using with appropriate configuration in coxph()? Is SAS a better way(PHREG,CASECOH.SAS) to implement time-dependent case-cohort? I think you need to read the literature, in particular the paper by Therneau (!) and Li, which among other things details the implementation of the Self-Prentice estimator. With that in mind, it should not be surprising that it is non-trivial how to get correct SE's out of coxph. What _is_ surprising (at least somewhat) is how close the robust SE are to those of the Self-Prentice method -- if I understand correctly, the connection is that Self-Prentice uses jackknifing for the contribution from subcohort sampling plus the standard Cox asymptotic variance and the robust method effectively uses jackknifing for both. (I'm a bit puzzled about why cch() insists on having unique id's, though. Doesn't _look_ like it would be too hard to get rid of that restriction, at least for S-P, which admittedly is the only method I spent enough time studying. And that was a some years ago.) summary(fit2.ccP) Call: coxph(formula = Surv(edrel, rel) ~ stage + histol + age + offset(-100 * (1 - subcohort)) + cluster(seqno), data = ccoh.data) n= 1154 coef exp(coef) se(coef) robust sez p stageII 0.7363 2.09 0.12130.1699 4.33 1.5e-05 stageIII 0.5976 1.82 0.12330.1753 3.41 6.5e-04 stageIV 1.3921 4.02 0.13390.2081 6.69 2.2e-11 histolUH 1.5059 4.51 0.09110.1644 9.16 0.0e+00 age 0.0432 1.04 0.01460.0243 1.78 7.6e-02 exp(coef) exp(-coef) lower .95 upper .95 stageII 2.09 0.479 1.497 2.91 stageIII 1.82 0.550 1.289 2.56 stageIV 4.02 0.249 2.676 6.05 histolUH 4.51 0.222 3.267 6.22 age 1.04 0.958 0.996 1.09 Rsquare= 0.273 (max possible= 1 ) Likelihood ratio test= 368 on 5 df, p=0 Wald test= 134 on 5 df, p=0 Score (logrank) test = 490 on 5 df, p=0, Robust = 165 p=0 (Note: the likelihood ratio and score tests assume independence of observations within a cluster, the Wald and robust score tests do not). summary(fit.ccSP) Case-cohort analysis,x$method, SelfPrentice with subcohort of 668 from cohort of 4028 Call: cch(formula = Surv(edrel, rel) ~ stage + histol + age, data = ccoh.data, subcoh = ~subcohort, id = ~seqno, cohort.size = 4028, method = SelfPren) Coefficients: CoefHR (95% CI) p stageII 0.736 2.088 1.491 2.925 0.000 stageIII 0.597 1.818 1.285 2.571 0.001 stageIV 1.392 4.021 2.670 6.057 0.000 histolUH 1.506 4.507 3.274 6.203 0.000 age 0.043 1.044 0.996 1.095 0.069 2008/6/12, Terry Therneau [EMAIL PROTECTED]: Jin Wang had an error. My original note specified a variable that was 1 for subjects NOT in the subcohort, so the correct coxph call is coxph(Surv(edrel, rel) ~ stage + histol + age + offset(-100*(subcohort==0)) + cluster(seqno), data =ccoh.data) This gives the same coefficients as the cch example, along with the infinitesimal jackknife or robust variance estimate. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Annoyance in as.numeric
Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c(1, 2, 3, 4), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x - matrix(c(1, 2, 3, 4), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] weights in lmer
I originally sent this to Doug Bates but have received no reply yet so I thought I would expand to a wider source. I've been trying to estimate linear mixed effect models in lmer() from the lme4 package using the weights option. The help and code for lmer() suggest to me that this is implemented but I can't seem to get it to do anything with weights = , no error message reported it just seems to ignore the weights option as my weighted and unweigted models are identical in all summary statistics. Below is an example of my model code. The weights are lengths of observational bouts on wild horse behavior. So is weights not really yet implemented or am I missing something? m2.wt- lmer(HD_RATE ~ NUM_PAIR + (NUM_PAIR|HMA),data=out2.5,weights=HOURS/max(HOURS), contrasts=list(NUM_PAIR=contr.treatment),family=gaussian) Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: [EMAIL PROTECTED] tel: 970 226-9326 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] surface plotting
I am new to R and what to find out which package would be best to create a surface plot, 2d or 3d if possible. I have a matrix (depth.dat) which has over 15k depth measurements from an ultrasonic corrosion mapping application. These depth measurements only have one axis (x) but I have used Octave and gnuplot providing decent results, but R seems to have a web interface with PERL which is what I am looking for. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting 3d data?
On 6/16/2008 1:32 PM, Wesley Tansey wrote: Hi all! I'm very new to R, and I'm having trouble figuring out how to go from a file of points that I have to a 3d surface plot of the data. I typically have something like this: X Y Z 0.0050.02334.45 0.0035 0.63 28.48 . I've tried looking at the persp and wireframe packages, and the rgl package, but I can't seem to figure out how to use any of them. I tried to take the rgl.surface3d example and use it for myself, and this is what I have so far: setwd(.) data - read.csv(data.csv,header=T) x - data$X y - data$Y z - data$Z open3d() surface3d(x, y, z) That gives me the following error: Error in rgl.surface(x = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, : y length != x rows * z cols I have no idea what it is trying to tell me there. Would anyone mind helping me out? surface3d (and rgl.surface) expect you to have data that corresponds to a grid defining the surface. So you need at least one of the parameters (z in surface3d, y in rgl.surface) to be a matrix with rows corresponding to x values and columns corresponding to the other variable. If your data is really a bunch of points, not on a grid, then you need to use plot3d() to plot it as points, or convert it to a surface. The interp() function in the akima package can do that. (There are lots of other possibilities too.) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Annoyance in as.numeric
hi: you can do below but i don't know if it's worth it ? newx - data.matrix(data.frame(x)) print(newx) On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c(1, 2, 3, 4), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x - matrix(c(1, 2, 3, 4), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] surface plotting
On 6/16/2008 4:40 PM, Duncan Murdoch wrote: On 6/16/2008 4:25 PM, Floyd poole wrote: I am new to R and what to find out which package would be best to create a surface plot, 2d or 3d if possible. I have a matrix (depth.dat) which has over 15k depth measurements from an ultrasonic corrosion mapping application. These depth measurements only have one axis (x) but I have used Octave and gnuplot providing decent results, but R seems to have a web interface with PERL which is what I am looking for. For static plots, scatterplot3d (in the scatterplot3d package) is best. For rotatable surfaces, persp3d in the rgl package. (See example(persp3d) for some examples.) Sorry, I changed my mind in the middle of writing that and didn't edit properly. For surfaces: persp() (in the base graphics package) for static plots persp3d() (in rgl) for rotatable plots For 3D scatterplots: scatterplot3d() (in scatterplot3d) for static plot3d() (in rgl) for rotatable. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] in axis() suppressing axis line but keeping tick marks
Andrew Yee wrote: I've been trying to figure out a parameter that will let you separately adjust the parameters for the axis line from the tick mark. In the following example, I would like to suppress the axis line, but keep the tick marks. The source code is the ultimate reference. We have in do_axis in src/main/plot.c: if (doticks) { gpptr(dd)-col = col;/*was fg */ GLine(axis_low, axis_base, axis_high, axis_base, NFC, dd); for (i = 0; i n; i++) { x = REAL(at)[i]; if (low = x x = high) { x = GConvertX(x, USER, NFC, dd); GLine(x, axis_base, x, axis_tick, NFC, dd); } } } and, as you see, there is no way the line parameters can change between the GLine calls, no hope of finding a magical par() setting. So I'm afraid you have to bite the bullet, do the relevant coordinate calculations, and use segments() do draw the ticks. (Or try convincing Paul Murrell to change the design, but that takes longer...). -- 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] in axis() suppressing axis line but keeping tick marks
Thanks for tracking this down. Andrew On Mon, Jun 16, 2008 at 4:49 PM, Peter Dalgaard [EMAIL PROTECTED] wrote: Andrew Yee wrote: I've been trying to figure out a parameter that will let you separately adjust the parameters for the axis line from the tick mark. In the following example, I would like to suppress the axis line, but keep the tick marks. The source code is the ultimate reference. We have in do_axis in src/main/plot.c: if (doticks) { gpptr(dd)-col = col;/*was fg */ GLine(axis_low, axis_base, axis_high, axis_base, NFC, dd); for (i = 0; i n; i++) { x = REAL(at)[i]; if (low = x x = high) { x = GConvertX(x, USER, NFC, dd); GLine(x, axis_base, x, axis_tick, NFC, dd); } } } and, as you see, there is no way the line parameters can change between the GLine calls, no hope of finding a magical par() setting. So I'm afraid you have to bite the bullet, do the relevant coordinate calculations, and use segments() do draw the ticks. (Or try convincing Paul Murrell to change the design, but that takes longer...). -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 3d data?
If your data is really a bunch of points, not on a grid, then you need to use plot3d() to plot it as points, or convert it to a surface. The interp() function in the akima package can do that. (There are lots of other possibilities too.) Actually, my data is on a grid. The values are something like 0 x y 0.05, with a 0.5 step for both x and y. I tried using interp() as follows: data - .. x - data$X y - data$Y z - data$Z temp - interp(x, y, z) plot.new() image(temp, add=TRUE) I figured showing an image would just verify that the grid was formed correctly, but that didn't seem to work. Wesley __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 bars within xyplot, panel = function(x,y, ....)
All, I'm trying to adapt some code provided by Deepayan Sarkar from a previous thread (https://stat.ethz.ch/pipermail/r-help/2005-October/081571.html) on this topic. ## This code produces a graph w/o error bars: xyplot(Y ~ Hr, data, groups=DRUG, panel=function(x,y,...){ panel.xyplot(x,y,..., type=c(g, l) ) panel.points(x,y,..., pch=16, type='p', col='black', cex=1) }, auto.key = list(space = top, text = c( D,P), points = FALSE, lines = TRUE, columns=2), par.settings = list(superpose.line = list(lty = c(1,5), col=c('black', 'black') ) ) ) ## this code uses the functions provided by Deepayan Sarkar to include the ## error bars for the same data: xyplot(Y ~ Hr, groups=DRUG, data=data, ly = data$lower, uy = data$upper, prepanel = prepanel.ci, panel = panel.superpose, panel.groups = panel.ci, type=b, auto.key = list(space = top, text = c( D,P), points = FALSE, lines = TRUE, columns=2), par.settings = list(superpose.line = list(lty = c(1,5), col=c('black', 'black') ) ) ) Is it possible to write the second version in the format of the first, i.e., using panel = function(x,y, ...){} ? Thanks, David ### load the following: Hr = c(0,1,2,3,4,5,0,1,2,3,4,5) DRUG = rep(c(D, P), each=6) Y = c(1,2,2,2,2,1,3, 4, 4,4, 4, 3) data = data.frame(Hr, DRUG, Y) data$lower = data$Y - .5 data$upper = data$Y + .5 prepanel.ci - function(x, y, ly, uy, subscripts, ...) { x - as.numeric(x) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = black, length = 0.25, unit = native, angle = 90, code = 3) panel.xyplot(x, y, pch = 16, ...)} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Superimposing Line over Histogram in Density Plot
I do it a bit differently: Once you've got myhist, you can plot a line on the existing histogram plot with something like: smoo-spline(myhist$breaks[1:length(myhist$breaks)-1],myhist$counts) lines(smoo$x,smoo$y,col='green') You'll have to muck a bit with scale factors to make the spline curve match up with the histogram plot's actual x-axis values. (actually, that snippet is part of my conversion from histogram data to a bar chart that looks like a histogram, with the spline curve overlaid). Carl try something like this: x - rnorm(200) hist(x, col = blue, freq = FALSE) lines(density(x), col = red, lwd = 2) I hope it helps. Best, Dimitris Currently I have a density plot generated with this snippet. Is there a way I can add a line curve on top of it? I mean in one figure __BEGIN__ myhist - hist(x col=blue, main = Density Plot, xlab = Exp Level, ) __END__ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Annoyance in as.numeric
On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PROTECTED] wrote: hi: you can do below but i don't know if it's worth it ? newx - data.matrix(data.frame(x)) print(newx) That doesn't work Mark: str(data.frame(x)) 'data.frame': 2 obs. of 2 variables: $ X1: Factor w/ 2 levels 1,2: 1 2 $ X2: Factor w/ 2 levels 3,4: 1 2 data.matrix(data.frame(x)) X1 X2 [1,] 1 1 [2,] 2 2 Which is as per documentation - the data.frame() coerces to factors and data.matrix represents factor by their internal values. One solution might be to save the dims and then reapply: mat [,1] [,2] [1,] 1 3 [2,] 2 4 dims - dim(mat) mat2 - as.numeric(mat) dim(mat) - dims mat2 [,1] [,2] [1,]13 [2,]24 You could wrap this in a function: asMatrix - function(x, ...) { dims - dim(x) x - as.double(x) dim(x) - dims return(x) } It would be logical to define a method for as.double for matrix objects. However objects of class matrix are not objects in the sense of isObject() and hence method dispatch will not work in this case. HTH G On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c(1, 2, 3, 4), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x - matrix(c(1, 2, 3, 4), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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: Superpose bwplot and dotplot [newbie question]
Hello everyone I have dataset containing a monetary value (ABS) and two factors (Fct, Group). I am able to create useful using: bwplot(ABS~Group|Fct) and dotplot(ABS~Group|Fct) Question: What do I have to do to overlay the dotplot with the bwplot (same data set)? I've found a couple of posts that hinted at the possibility of doing that, and checked the panel.superpose() help, but the info was too complex for my newbie brain. Thanks for your help! LY PS: My first attempt to send this message bounced back - I hope you don't see this twice; otherwise, mea culpa. -- View this message in context: http://www.nabble.com/Lattice%3A-Superpose-bwplot-and-dotplot--newbie-question--tp17873822p17873822.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Annoyance in as.numeric
On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? Because that's what it's documented to do! as.numeric is a generic function, but S3 methods must be written for as.double. It is identical to as.double (and as.real). And a check of the Help for as.double says: as.double attempts to coerce its argument to be of double type: like as.vector it strips attributes including names. (To ensure that an object is of double type without stripping attributes, use storage.mode). So, in particular, dim attributes of an array are stripped. To preserve them,do what the Help tells you to: x - matrix(c(1,2,3,4),2,2) x [,1] [,2] [1,] 1 3 [2,] 2 4 storage.mode(x) - double x [,1] [,2] [1,]13 [2,]24 Cheers, Bert Gunter Genentech Nonclinical Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Constrained Optimized Binning Procedure....implementation help/idea needed.
Dear R Helpers, At the moment I'm working on the project to implement optimal binning function. It will be primarily used as a tool for logistic regression. something very similar to http://www2.sas.com/proceedings/forum2008/153-2008.pdf* *but applied in diferent problem space...* *The problem might be descibed as finding optimal binning which will satisfy all of the rules imposed: - minimum and/or maximum percentage of observations per bin (good, bad, and total) - minimum and/or maximum bin width - minimum and/or maximum number of bins - minimum aggregate WOE difference between bins - monotonicity of aggregate bin WOE values (increasing, decreasing, or a combination) - etc... The idea is to use MILP (Mixed integer linear programming) and to solve problem. Any ideas how to implement this would be welcomed... even better... if someone is aware of any package which allready has this functionaly... please us me know Thanks for help. -- This e-mail and any files transmitted with it are confid...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Annoyance in as.numeric
I generally do something like storage.mode(my.matrix) - double --Todd -- Why do you recite at a play and play at a recital? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gavin Simpson Sent: Monday, June 16, 2008 2:31 PM To: [EMAIL PROTECTED] Cc: r-help@r-project.org Subject: Re: [R] Annoyance in as.numeric On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PROTECTED] wrote: hi: you can do below but i don't know if it's worth it ? newx - data.matrix(data.frame(x)) print(newx) That doesn't work Mark: str(data.frame(x)) 'data.frame': 2 obs. of 2 variables: $ X1: Factor w/ 2 levels 1,2: 1 2 $ X2: Factor w/ 2 levels 3,4: 1 2 data.matrix(data.frame(x)) X1 X2 [1,] 1 1 [2,] 2 2 Which is as per documentation - the data.frame() coerces to factors and data.matrix represents factor by their internal values. One solution might be to save the dims and then reapply: mat [,1] [,2] [1,] 1 3 [2,] 2 4 dims - dim(mat) mat2 - as.numeric(mat) dim(mat) - dims mat2 [,1] [,2] [1,]13 [2,]24 You could wrap this in a function: asMatrix - function(x, ...) { dims - dim(x) x - as.double(x) dim(x) - dims return(x) } It would be logical to define a method for as.double for matrix objects. However objects of class matrix are not objects in the sense of isObject() and hence method dispatch will not work in this case. HTH G On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c(1, 2, 3, 4), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x - matrix(c(1, 2, 3, 4), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Annoyance in as.numeric
thanks for your correction Gavin. i read ?data.matrix and neglected to pay attention to the last line of the description: Factors and ordered factors are replaced by their internal codes. On Mon, Jun 16, 2008 at 5:30 PM, Gavin Simpson wrote: On Mon, 2008-06-16 at 15:35 -0500, [EMAIL PROTECTED] wrote: hi: you can do below but i don't know if it's worth it ? newx - data.matrix(data.frame(x)) print(newx) That doesn't work Mark: str(data.frame(x)) 'data.frame': 2 obs. of 2 variables: $ X1: Factor w/ 2 levels 1,2: 1 2 $ X2: Factor w/ 2 levels 3,4: 1 2 data.matrix(data.frame(x)) X1 X2 [1,] 1 1 [2,] 2 2 Which is as per documentation - the data.frame() coerces to factors and data.matrix represents factor by their internal values. One solution might be to save the dims and then reapply: mat [,1] [,2] [1,] 1 3 [2,] 2 4 dims - dim(mat) mat2 - as.numeric(mat) dim(mat) - dims mat2 [,1] [,2] [1,]13 [2,]24 You could wrap this in a function: asMatrix - function(x, ...) { dims - dim(x) x - as.double(x) dim(x) - dims return(x) } It would be logical to define a method for as.double for matrix objects. However objects of class matrix are not objects in the sense of isObject() and hence method dispatch will not work in this case. HTH G On Mon, Jun 16, 2008 at 4:22 PM, Alberto Monteiro wrote: Why does as.numeric convert matrices and arrays to vectors? as.numeric(matrix(c(1, 2, 3, 4), 2, 2)) [1] 1 2 3 4 I could only figure out ugly ways to bypass this, like: x - matrix(c(1, 2, 3, 4), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x)) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.