Re: [R] Axes Alignment Problem for Multiple Plots
Dear Matthieu, thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem! Best Regards Guido Barbaglia From: mat [matthieu.stig...@gmail.com] Sent: 19 April 2011 22:58 To: John Kane Cc: r-help@r-project.org; Barbaglia, Guido (ESA) Subject: Re: [R] Axes Alignment Problem for Multiple Plots Ok, I can replicate your problem, with following code: dat - 1:10 barplot(dat, beside=TRUE,ylim=c(0,100)); par()$usr; par(new=T); plot(dat, ylim=c(0,100), type=l); par()$usr; So it looks like even if you specify yourself ylim, the resulting effective ylim (usr[3:4] ) will be different! More surprinsingly, setting the usr parameter before is not effective: par(new=T, usr=c(0,11,0,100)); this will not preventpar()$usr; to be different than fixed :-( No idea, but hopefully someone else on the list will be able to provide advice! Matthieu Le 19. 04. 11 20:47, John Kane a écrit : What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest to supply working code and sample data. --- On Tue, 4/19/11, Barbaglia, Guido (ESA)guido.barbag...@fao.org wrote: From: Barbaglia, Guido (ESA)guido.barbag...@fao.org Subject: [R] Axes Alignment Problem for Multiple Plots To: r-help@r-project.orgr-help@r-project.org Cc: Stigler, Matthieu (EST)matthieu.stig...@fao.org Received: Tuesday, April 19, 2011, 11:42 AM Dear all, I'm trying to plot, in the same window, two different series, using barplot() for the first one and plot() for the second. What happens is that the second chart has a different axes origin, therefore the final plot is wrong. This piece of code shows the differences between the values of par()$usr: barplot(coredata(Z0), beside=TRUE, ylim=c(0,100)); par()$usr; par(new=T); plot(coredata(Z0), ylim=c(0,100)); par()$usr; I would like to know how it is possible to edit the values of par()$usr[3:4] of the second chart in order to be the same of the first one or, alternatively, how can I plot together bar and line series within the same reference system. Best Regards Guido Barbaglia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] counting values in multiple columns
Hello, I have a table that has 2000 rows and 8 columns. The headings of columns are: yearjel.code.1jel.code.2jel.code.3jel.code.4jel.code.5jel.code.6 jel.code.7. Under each column, there are either numbers or blank spaces corresponding to the given year. For instance, my 10th row is:1019838242824382609170 I want to count how many times each code appears in total and how many times it appears in each year. I don't think I can use table function. What can I do? Sincerely, Yosub Jung. [[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] How to check if a value of a variable is in a list
Hi all, I am working with some social network analysis in R and ran into a problem I just cannot solve. Each observation in my data consists of a respondent, some characteristics and up to five friends. The problem is that all of these five friends might no show up later as a respondent (observation). Therefore I might not have characteristics on all the friends listed in the data and I want to restrict my data to only those friends that I also have as respondents. The data (without characteristics) look like this: *resp f1 f2 f3 f4 f5* ID1 ID5 ID37 ID6ID2 ID53 ID2 ID1ID4ID17 NANA ... Now, let's say that ID37 never appears as a respondent, then I want to replace that value with a NA so that it looks like this: *resp f1 f2 f3 f4 f5* ID1 ID5NAID6ID2 ID53 ID2 ID1ID4ID17 NANA I thought I could check if for each entry, the value goes again in a list of the respondents. How do I do this? Kind regards, Frederik [[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] Saving run time in loop
Hi r users, I am trying to compute the moving variance of a large matrix. I now use a loop but I am looking for a faster solution. Here is a sample of the code. Source= matrix(rnorm(400),ncol=100) variances= matrix(rep(NA,4*100),ncol=100) for (i in 1:80) {variances[,i]=apply(Source[,i:(i+80)],1,var)} any idea? Many thanks in advance. Vincent. -- View this message in context: http://r.789695.n4.nabble.com/Saving-run-time-in-loop-tp3462228p3462228.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] counting values in multiple columns
Hi Yosub, Here is one way it can be done (assuming I got you right): # invent data set.seed(24) tbl - matrix(sample(c(, letters[1:4]), 20*8, replace = T), 20,8) # getting the number of codes for all years: table(c(tbl)) # getting the number of codes per year: apply(tbl,2,table) Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, Apr 20, 2011 at 6:05 AM, Yosub Jung yosubj...@berkeley.edu wrote: Hello, I have a table that has 2000 rows and 8 columns. The headings of columns are: yearjel.code.1jel.code.2jel.code.3jel.code.4jel.code.5jel.code.6 jel.code.7. Under each column, there are either numbers or blank spaces corresponding to the given year. For instance, my 10th row is:1019838242824382609170 I want to count how many times each code appears in total and how many times it appears in each year. I don't think I can use table function. What can I do? Sincerely, Yosub Jung. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Saving run time in loop
On 20/04/11 18:30, vincent.deluard wrote: Hi r users, I am trying to compute the moving variance of a large matrix. I now use a loop but I am looking for a faster solution. Here is a sample of the code. Source= matrix(rnorm(400),ncol=100) variances= matrix(rep(NA,4*100),ncol=100) for (i in 1:80) {variances[,i]=apply(Source[,i:(i+80)],1,var)} any idea? Many thanks in advance. It's not at all clear what you are actually trying to do, and the sample code that you give does not work. I.e. it throws an error. Be more careful and think more clearly. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splom, plotmath: how to add three lines of information with alignment?
Dear Baptiste, thank you for your help. I tried to built in your suggestions into the splom. Below is the result. I decided to create the plotmath-expressions outside the function splom2, this will allow me later to horizontally shift (via phantom, for example) the table entries so that they will be vertically aligned according to the = signs. Although an array is allowed to contain expressions, I could not manage to create it properly. Do you know a solution? Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## expr.arr: array of expressions [(i,j,) entry contains expressions which are ## plotted in a grid table in the lower panel (i,j)] splom2 - function(x, expr.arr){ ## function for creating table table.fun - function(vec){ # single values for one panel grid.table(vec, parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(expr.arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) expr.arr - array(, dim=c(d,d,3), dimnames=c(i,j,val)) # d x d x 3 elements for(i in 1:d){ for(j in 1:d){ # expr.arr[i,j,] - expression(italic(a)==0, italic(bbb)==0, italic(c)==0) # does no work expr.arr[i,j,] - c(bquote(italic(a)==.(0)), bquote(italic(bbb)==.(0)), bquote(italic(c)==.(0))) # same here } } ## plot splom2(x, expr.arr) On 2011-04-20, at 01:33 , baptiste auguie wrote: Hi, You may want to wait advice from someone who actually understands (the labyrinth that is) lattice's help for splom, but the following might be a start. I didn't understand what values you actually wanted displayed in the lower triangle panels, so I made up some random ones in a 3x3 matrix of 3-vectors. library(lattice) library(gridExtra) info - function(x){ grid.table(c(bquote(italic(a)==.(x[1])), bquote(italic(b)==.(x[2])), bquote(italic(c)==.(x[3]))), core.just=left, parse=TRUE) } U - matrix(runif(3000), ncol=3) splom(U, superpanel=function(z, ...){ ## dummy 3x3 matrix of 3 values to diplay values - replicate(9, round(rnorm(3), 3), simplify=FALSE) dummy - matrix(values, ncol=3, byrow=F) panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i, j, ...){ print(paste(i,j)) # current panel indices info(dummy[i,j] [[1]]) # access the list elements }, ...) }) HTH, baptiste On 20 April 2011 10:17, Marius Hofert m_hof...@web.de wrote: Dear Baptiste, there is one tricky part left: how can I create a matrix with the grid.table() objects as output? Is this possible? If not, maybe one can try to work with panel.splom (which can address single panels and thus call info() for each row-column index pair (i,j)), but I'm not sure if this will work. Cheers, Marius library(lattice) library(gridExtra) splom2 - function(x, a, b, c){ ## function for the additional information info - function(a., b., c.){ # single values for one panel grid.table(c(bquote(italic(a)==.(a.)), bquote(italic(b)==.(b.)), bquote(italic(c)==.(c.)) ), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=right) # justification of labels ) } labs - matrix(, nrow=ncol(x), ncol=ncol(x)) # should be a matrix of grid.table() objects for(i in 1:ncol(x)) for(j in 1:ncol(x)) labs[i,j] - info(a.=a[i,j], b.=b[i,j], c.=c[i,j]) ## splom splom(x, superpanel=function(z,...){ df=data.frame(rows=as.vector(row(a)), columns=as.vector(col(a)), labs=as.vector(labs)) df=subset(df,columnsrows) # subset for lower left triangle with(df,{ panel.text(x=rows, y=columns, labels=labs) }) panel.pairs(z, upper.panel=panel.splom, lower.panel=function(...){}, ...) }) } ## generate data U - matrix(runif(3000), ncol=3) ## build information a - cor(U, method=kendall) b - diag(ncol=3, nrow=3) c - diag(ncol=3, nrow=3) ## plot with information splom2(U, a, b, c) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
[R] Error Installing or Updating Packages (Maybe because of a proxy)
Dear R Helpers, (I am using Ubuntu lucid and R 2.13.0 When I try to update packages I get this error: update.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done Error in ret[i, ] - c(pkgs[i], lib, desc) : number of items to replace is not a multiple of replacement length I had no problem before (case 1) but now (case 2) I cannot get it to work, googleing did not help: case 1: * connecting directly without any proxy setting (at my university) * using R 2.12.2 case 2: * connecting through proxy setting (at my workplace) * using R 2.13.0 I set the proxy in terminal too but it does not help (echo $http_proxy gives me http://192.168.0.1:8080/) -- Majid Einian PhD Candidate in Economics Graduate School of Management and Economics Sharif University of Technology [[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] Axes Alignment Problem for Multiple Plots
Guido You missed William's e-mails, which solved the problem: use yaxs=i in second call. Also, William made the good point that you can rather just use lines() in second call. Good William! Mat Le 20/04/2011 08:00, Barbaglia, Guido (ESA) a écrit : Dear Matthieu, thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem! Best Regards Guido Barbaglia From: mat [matthieu.stig...@gmail.com] Sent: 19 April 2011 22:58 To: John Kane Cc: r-help@r-project.org; Barbaglia, Guido (ESA) Subject: Re: [R] Axes Alignment Problem for Multiple Plots Ok, I can replicate your problem, with following code: dat- 1:10 barplot(dat, beside=TRUE,ylim=c(0,100)); par()$usr; par(new=T); plot(dat, ylim=c(0,100), type=l); par()$usr; So it looks like even if you specify yourself ylim, the resulting effective ylim (usr[3:4] ) will be different! More surprinsingly, setting the usr parameter before is not effective: par(new=T, usr=c(0,11,0,100)); this will not preventpar()$usr; to be different than fixed :-( No idea, but hopefully someone else on the list will be able to provide advice! Matthieu Le 19. 04. 11 20:47, John Kane a écrit : What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest to supply working code and sample data. --- On Tue, 4/19/11, Barbaglia, Guido (ESA)guido.barbag...@fao.org wrote: From: Barbaglia, Guido (ESA)guido.barbag...@fao.org Subject: [R] Axes Alignment Problem for Multiple Plots To: r-help@r-project.orgr-help@r-project.org Cc: Stigler, Matthieu (EST)matthieu.stig...@fao.org Received: Tuesday, April 19, 2011, 11:42 AM Dear all, I'm trying to plot, in the same window, two different series, using barplot() for the first one and plot() for the second. What happens is that the second chart has a different axes origin, therefore the final plot is wrong. This piece of code shows the differences between the values of par()$usr: barplot(coredata(Z0), beside=TRUE, ylim=c(0,100)); par()$usr; par(new=T); plot(coredata(Z0), ylim=c(0,100)); par()$usr; I would like to know how it is possible to edit the values of par()$usr[3:4] of the second chart in order to be the same of the first one or, alternatively, how can I plot together bar and line series within the same reference system. Best Regards Guido Barbaglia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What to do with positive likelihoods
Michael, It's not entirely clear what you are doing from the text (and the code is incompplete), so just a few remarks. I assume you are after the log likelihood rather than the likelihood (otherwise the issue of positive/negative would not show up, dnorm always returns positive numbers). Taking the sum of log's is not the same as taking the log of a sum: sum(log(1:10)) [1] 15.10441 log(sum(1:10)) [1] 4.007333 Positive log likelihoods are not problematic; as you note, when variances are small, log likelihoods may turn positive; this does not change the use of the log likelihood (eg using it for estimating parameters by maximizing it, or for testing models). hth, Ingmar On Wed, Apr 20, 2011 at 4:13 AM, Turchin, Michael michael.turc...@childrens.harvard.edu wrote: Hi all, I'll preface this with saying I've gone through the archives, and am still in need of some help. I've been using this likelihood model with mean = 0 and s.d. = sqrt( (c + ( 1 / N1 ) + ( 1 / N2 ) ) * x * ( 1 - x )), where c is a genetic drift parameter (usually very small, like between .005 - .001), N1 and N2 are my population sizes (~200), and x is a value between 0 and 1. The values I'm testing are usually between -.25 to .25, so my command looks like dnorm(.1, 0, sqrt( (c + ( 1 / N1 ) + ( 1 / N2 ) ) * x * ( 1 - x ))) Originally, I was doing this over multiple data points at once, summing up the values I was going to test and their variances, and just running the likelihood on these summed values once (getting one final likelihood in return). I've recently switched this over to running the likelihood on each data point and its associated variance one at a time, and summing the likelihoods afterwards. However, upon doing this, I'm now getting positive likelihoods since the individual variances are so small (.01 to .09, for instance). I'm not sure what to do, because I think these small variances are messing up the behavior of my final data -- the patterns I'm getting are not what I expected, whereas my previous method of summing multiple data points and just taking one likelihood value did return what I expected. I'm not sure if getting positive likelihoods somewhat implies that the behavior of the model / results are off. Should I be using a different function than dnorm, now that my variances are so small? Using pnorm instead returns my data to what's expected, but my understanding is that pnorm gets me a probability now, not a likelihood. Could I use the output from pnorm in a likelihood ratio test (which was my original plan)? Thanks for any help, ~Michael Turchin Children's Hospital Boston __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Allocation of memory to a data frame
Hello gRoup, A while back I was advised that overallocating an object and filling it up is better than rbind. I am trying to optimize some code. I have the following object (empty which I know in advance). Is there an easy to create an empty data frame with 100,000 empty rows based on the structure below? dput(d) structure(list(A = character(0), B = character(0), C = numeric(0), D = character(0), E = character(0), F = character(0), G = character(0), H = structure(numeric(0), class = Date), I = numeric(0), J = integer(0)), .Names = c(A, B, C, D, E, F, G, H, I, J), row.names = integer(0), class = data.frame) I can use dataFrame in R.utils and do it explicitly but wondering if there an easier way since I have the structure with me. Thank you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sweave stops when opening X11 device fails
Hi all, I've run into the following problem with Sweave: I frequently run Sweave from a xterm console within an X session owned by a different user, i.e. my colleague is logged in on this computer and I do su with my username and start R and Sweave afterwards. Now, when Sweave comes to a figure chunk, it sees that there is an X server running and tries to show whatever I plot in that chunk on the screen, additionally to writing a pdf file. The problem is that I am not logged into the X session myself, and the script fails with a message saying someting like could not open device X11 (I have German messages, so I do not know what the exact phrase would be in English). When I log in with putty, where there is no X11 at all, everything works fine. Is there a way to prevent Sweave from failing in the former case? Would this even account as a bug? I think it would be nice if the script just kept on running without plotting on the screen if opening X11 fails, just like it does when no X11 is available at all. Best regards, Andreas -- Andreas Borg Medizinische Informatik UNIVERSITÄTSMEDIZIN der Johannes Gutenberg-Universität Institut für Medizinische Biometrie, Epidemiologie und Informatik Obere Zahlbacher Straße 69, 55131 Mainz www.imbei.uni-mainz.de Telefon +49 (0) 6131 175062 E-Mail: b...@imbei.uni-mainz.de Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen ist nicht gestattet. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Saving run time in loop
Hi: Perhaps rollapply() in the zoo package might be helpful. Dennis On Tue, Apr 19, 2011 at 11:30 PM, vincent.deluard vincent.delu...@trimtabs.com wrote: Hi r users, I am trying to compute the moving variance of a large matrix. I now use a loop but I am looking for a faster solution. Here is a sample of the code. Source= matrix(rnorm(400),ncol=100) variances= matrix(rep(NA,4*100),ncol=100) for (i in 1:80) {variances[,i]=apply(Source[,i:(i+80)],1,var)} any idea? Many thanks in advance. Vincent. -- View this message in context: http://r.789695.n4.nabble.com/Saving-run-time-in-loop-tp3462228p3462228.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] BMA, logistic regression, odds ratio, model reduction etc
Hi everybody, I apologize for long mail in advance. I have data of 104 patients, which consists of 15 explanatory variables and one binary outcome (poor/good). The outcome consists of 25 poor results and 79 good results. I tried to analyze the data with logistic regression. However, the 15 variables and 25 events means events per variable (EPV) is much less than 10 (rule of thumb). Therefore, I used R package, BMA to perform logistic regression with BMA to avoid this problem. model 1 (full model): x1, x2, x3, x4 are continuous variables and others are binary data. x16.bic.glm - bic.glm(outcome ~ ., data=x16.df, glm.family=binomial, OR20, strict=FALSE) summary(x16.bic.glm) (The output below has been cut off at the right edge to save space) 62 models were selected Best 5 models (cumulative posterior probability = 0.3606 ): p!=0EV SDmodel 1model2 Intercept100-5.1348545 1.652424-4.4688 -5.15 -5.1536 age3.3 0.0001634 0.007258 . sex4.0 .M -0.0243145 0.220314 . side 10.8 .R 0.0811227 0.301233 . procedure 46.9 -0.5356894 0.685148 . -1.163 symptom3.8 -0.0099438 0.129690 . . stenosis 3.4 -0.0003343 0.005254 . x13.7 -0.0061451 0.144084 . x2 100.0 3.1707661 0.892034 3.2221 3.11 x351.3 -0.4577885 0.551466-0.9154 . HT 4.6 .positive 0.0199299 0.161769 . . DM 3.3 .positive -0.0019986 0.105910 . . IHD3.5 .positive 0.0077626 0.122593 . . smoking9.1 .positive 0.0611779 0.258402 . . hyperlipidemia16.0 .positive 0.1784293 0.512058 . . x4 8.2 0.0607398 0.267501 . . nVar 2 2 1 3 3 BIC -376.9082 -376.5588 -376.3094 -375.8468 -374.5582 post prob0.104 0.087 0.077 0.061 0.032 [Question 1] Is it O.K to calculate odds ratio and its 95% confidence interval from EV (posterior distribution mean) and“SD”(posterior distribution standard deviation)? For example, 95%CI of EV of x2 can be calculated as; exp(3.1707661) [1] 23.82573 - odds ratio exp(3.1707661+1.96*0.892034) [1] 136.8866 exp(3.1707661-1.96*0.892034) [1] 4.146976 -- 95%CI (4.1 to 136.9) Is this O.K.? [Question 2] Is it permissible to delete variables with small value of p!=0 and EV, such as age (3.3% and 0.0001634) to reduce the number of explanatory variables and reconstruct new model without those variables for new session of BMA? model 2 (reduced model): I used R package, pvclust, to reduce the model. The result suggested x1, x2 and x4 belonged to the same cluster, so I picked up only x2. Based on the subject knowledge, I made a simple unweighted sum, by counting the number of clinical features. For 9 features (sex, side, HT2, hyperlipidemia, DM, IHD, smoking, symptom, age), the sum ranges from 0 to 9. This score was defined as ClinicalScore. Consequently, I made up new data set (x6.df), which consists of 5 variables (stenosis, x2, x3, procedure, and ClinicalScore) and one binary outcome (poor/good). Then, for alternative BMA session... BMAx6.glm - bic.glm(postopDWI_HI ~ ., data=x6.df, glm.family=binomial, OR=20, strict=FALSE) summary(BMAx6.glm) (The output below has been cut off at the right edge to save space) Call: bic.glm.formula(f = postopDWI_HI ~ ., data = x6.df, glm.family = binomial, strict = FALSE, OR = 20) 13 models were selected Best 5 models (cumulative posterior probability = 0.7626 ): p!=0EV SD model 1model 2 Intercept 100-5.6918362 1.81220-4.4688-6.3166 stenosis 8.1 -0.0008417 0.00815 . . x2 100.0 3.0606165 0.87765 3.2221 3.1154 x3 46.5 -0.3998864 0.52688-0.9154 . procedure 49.3 0.5747013 0.70164 . 1.1631 ClinicalScore 27.1 0.0966633 0.19645 . . nVar 2 2 1 3 3 BIC -376.9082 -376.5588 -376.3094 -375.8468 -375.5025 post prob 0.208 0.175 0.154 0.122 0.103 [Question 3] Am I doing it correctly or not? I mean this kind of model
Re: [R] splom, plotmath: how to add three lines of information with alignment?
On 20 April 2011 19:23, Marius Hofert m_hof...@web.de wrote: Dear Baptiste, thank you for your help. I tried to built in your suggestions into the splom. Below is the result. I decided to create the plotmath-expressions outside the function splom2, this will allow me later to horizontally shift (via phantom, for example) the table entries so that they will be vertically aligned according to the = signs. Although an array is allowed to contain expressions, I could not manage to create it properly. Do you know a solution? Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## expr.arr: array of expressions [(i,j,) entry contains expressions which are ## plotted in a grid table in the lower panel (i,j)] splom2 - function(x, expr.arr){ ## function for creating table table.fun - function(vec){ # single values for one panel grid.table(vec, parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(expr.arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) expr.arr - array(, dim=c(d,d,3), dimnames=c(i,j,val)) # d x d x 3 elements for(i in 1:d){ for(j in 1:d){ # expr.arr[i,j,] - expression(italic(a)==0, italic(bbb)==0, italic(c)==0) # does no work expr.arr[i,j,] - c(bquote(italic(a)==.(0)), bquote(italic(bbb)==.(0)), bquote(italic(c)==.(0))) # same here } } ## plot splom2(x, expr.arr) Initializing your array with a list seems to work for whatever reason that's well above my head, expr.arr - array(list(NA,NA,NA), dim=c(d,d,3), dimnames=c(i,j,val)) As for the alignment, there should be a better way using multiple columns in grid.table, but parse is struggling to interpret the = sign on its own. Again, I'm not sure why, this is deep magic to me. library(gridExtra) d = matrix(c(italic(a)==phantom(''), round(pi,4), italic(b)==phantom(), round(pi,6)), ncol=2, byrow=T) grid.table(d, parse=T,theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), core.just=left, padding.h = unit(0, mm) )) HTH, baptiste On 2011-04-20, at 01:33 , baptiste auguie wrote: Hi, You may want to wait advice from someone who actually understands (the labyrinth that is) lattice's help for splom, but the following might be a start. I didn't understand what values you actually wanted displayed in the lower triangle panels, so I made up some random ones in a 3x3 matrix of 3-vectors. library(lattice) library(gridExtra) info - function(x){ grid.table(c(bquote(italic(a)==.(x[1])), bquote(italic(b)==.(x[2])), bquote(italic(c)==.(x[3]))), core.just=left, parse=TRUE) } U - matrix(runif(3000), ncol=3) splom(U, superpanel=function(z, ...){ ## dummy 3x3 matrix of 3 values to diplay values - replicate(9, round(rnorm(3), 3), simplify=FALSE) dummy - matrix(values, ncol=3, byrow=F) panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i, j, ...){ print(paste(i,j)) # current panel indices info(dummy[i,j] [[1]]) # access the list elements }, ...) }) HTH, baptiste On 20 April 2011 10:17, Marius Hofert m_hof...@web.de wrote: Dear Baptiste, there is one tricky part left: how can I create a matrix with the grid.table() objects as output? Is this possible? If not, maybe one can try to work with panel.splom (which can address single panels and thus call info() for each row-column index pair (i,j)), but I'm not sure if this will work. Cheers, Marius library(lattice) library(gridExtra) splom2 - function(x, a, b, c){ ## function for the additional information info - function(a., b., c.){ # single values for one panel grid.table(c(bquote(italic(a)==.(a.)), bquote(italic(b)==.(b.)), bquote(italic(c)==.(c.)) ), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=right) # justification of labels ) } labs - matrix(, nrow=ncol(x), ncol=ncol(x)) # should be a matrix of grid.table() objects for(i in 1:ncol(x)) for(j in 1:ncol(x)) labs[i,j] - info(a.=a[i,j], b.=b[i,j], c.=c[i,j]) ## splom splom(x, superpanel=function(z,...){
Re: [R] Allocation of memory to a data frame
On 20.04.2011 09:46, santosh wrote: Hello gRoup, A while back I was advised that overallocating an object and filling it up is better than rbind. I am trying to optimize some code. I have the following object (empty which I know in advance). Is there an easy to create an empty data frame with 100,000 empty rows based on the structure below? dput(d) structure(list(A = character(0), B = character(0), C = numeric(0), D = character(0), E = character(0), F = character(0), G = character(0), H = structure(numeric(0), class = Date), I = numeric(0), J = integer(0)), .Names = c(A, B, C, D, E, F, G, H, I, J), row.names = integer(0), class = data.frame) Replace the zeros by your number of rows? Uwe Ligges I can use dataFrame in R.utils and do it explicitly but wondering if there an easier way since I have the structure with me. Thank you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Axes Alignment Problem for Multiple Plots
I've missed William's e-mail indeed, I've tested it and works great, thanks a lot!!! Many Thanks Guido From: Matthieu Stigler [matthieu.stig...@gmail.com] Sent: 20 April 2011 09:30 To: Barbaglia, Guido (ESA) Cc: wdun...@tibco.com; r-help@r-project.org Subject: Re: [R] Axes Alignment Problem for Multiple Plots Guido You missed William's e-mails, which solved the problem: use yaxs=i in second call. Also, William made the good point that you can rather just use lines() in second call. Good William! Mat Le 20/04/2011 08:00, Barbaglia, Guido (ESA) a écrit : Dear Matthieu, thanks for your clarification! Basically, what I need to do is to plot different series on the same chart using different types of plot (lines, barplot, ...) and it is fundamental that the various charts have the same reference system. I hope that someone in the list is able to fix my problem! Best Regards Guido Barbaglia From: mat [matthieu.stig...@gmail.com] Sent: 19 April 2011 22:58 To: John Kane Cc: r-help@r-project.org; Barbaglia, Guido (ESA) Subject: Re: [R] Axes Alignment Problem for Multiple Plots Ok, I can replicate your problem, with following code: dat- 1:10 barplot(dat, beside=TRUE,ylim=c(0,100)); par()$usr; par(new=T); plot(dat, ylim=c(0,100), type=l); par()$usr; So it looks like even if you specify yourself ylim, the resulting effective ylim (usr[3:4] ) will be different! More surprinsingly, setting the usr parameter before is not effective: par(new=T, usr=c(0,11,0,100)); this will not preventpar()$usr; to be different than fixed :-( No idea, but hopefully someone else on the list will be able to provide advice! Matthieu Le 19. 04. 11 20:47, John Kane a écrit : What is Coredata(Z0)? It would be very useful. as the posting guidelines suggest to supply working code and sample data. --- On Tue, 4/19/11, Barbaglia, Guido (ESA)guido.barbag...@fao.org wrote: From: Barbaglia, Guido (ESA)guido.barbag...@fao.org Subject: [R] Axes Alignment Problem for Multiple Plots To: r-help@r-project.orgr-help@r-project.org Cc: Stigler, Matthieu (EST)matthieu.stig...@fao.org Received: Tuesday, April 19, 2011, 11:42 AM Dear all, I'm trying to plot, in the same window, two different series, using barplot() for the first one and plot() for the second. What happens is that the second chart has a different axes origin, therefore the final plot is wrong. This piece of code shows the differences between the values of par()$usr: barplot(coredata(Z0), beside=TRUE, ylim=c(0,100)); par()$usr; par(new=T); plot(coredata(Z0), ylim=c(0,100)); par()$usr; I would like to know how it is possible to edit the values of par()$usr[3:4] of the second chart in order to be the same of the first one or, alternatively, how can I plot together bar and line series within the same reference system. Best Regards Guido Barbaglia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Error Installing or Updating Packages (Maybe because of a proxy)
If the internet connection from R works, can you please verify that you do not have any R base package from an old R version in a current R library that you may have in the .libPaths() already? Uwe Ligges On 20.04.2011 09:25, Majid Einian wrote: Dear R Helpers, (I am using Ubuntu lucid and R 2.13.0 When I try to update packages I get this error: update.packages() --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done Error in ret[i, ]- c(pkgs[i], lib, desc) : number of items to replace is not a multiple of replacement length I had no problem before (case 1) but now (case 2) I cannot get it to work, googleing did not help: case 1: * connecting directly without any proxy setting (at my university) * using R 2.12.2 case 2: * connecting through proxy setting (at my workplace) * using R 2.13.0 I set the proxy in terminal too but it does not help (echo $http_proxy gives me http://192.168.0.1:8080/) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to check if a value of a variable is in a list
On 20.04.2011 05:00, Frederik Lang wrote: Hi all, I am working with some social network analysis in R and ran into a problem I just cannot solve. Each observation in my data consists of a respondent, some characteristics and up to five friends. The problem is that all of these five friends might no show up later as a respondent (observation). Therefore I might not have characteristics on all the friends listed in the data and I want to restrict my data to only those friends that I also have as respondents. The data (without characteristics) look like this: *resp f1 f2 f3 f4 f5* ID1 ID5 ID37 ID6ID2 ID53 ID2 ID1ID4ID17 NANA ... Now, let's say that ID37 never appears as a respondent, then I want to replace that value with a NA so that it looks like this: *resp f1 f2 f3 f4 f5* ID1 ID5NAID6ID2 ID53 ID2 ID1ID4ID17 NANA I thought I could check if for each entry, the value goes again in a list of the respondents. How do I do this? See ?%in% Uwe Ligges Kind regards, Frederik [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loading a package shared lib works in 2.12 but not 2.11
On 13.04.2011 17:32, Von Der Hirschheydt, Juergen wrote: Hi, I have a problem with an external library on a previous R version. We've created our own package containing a mixture of C++ as well as R code which works fine under R 2.12.1. However, trying to install the very same package ZIP file on R 2.11.1 will issue an error when loading a library: A zip file is a binary package that has been compiled for an almost fixed triple (R version, OS, hardware), where OS is Windows in 32-bit, 64-bit or (exclusive) both of them in this case. Therefore, you have to download a zip that was made for R-2.11.x which is available from yourCRANmirror/bin/windows/contrib/2.11 or more easily just via install.packages() that picks uop the correct repository. Alternatively, install from sources - and read the R Installation and Administration manual. Uwe Ligges utils:::menuInstallLocal() package 'quasar' successfully unpacked and MD5 sums checked require(quasar) Loading required package: quasar Error in library.dynam(lib, package, package.lib) : shared library 'quasar' not found In addition: Warning message: package 'quasar' was built under R version 2.12.1 (quasar being the name of the package). Does anyone have some pointers why it works under 2.12.1 but not 2.11.1 ? I've looked over the changelog but couldn't find any clue there. Has the mechanism for useDynLib(quasar) in the NAMESPACE file changed ? Thanks for your time, Cheers, Juergen === Please access the attached hyperlink for an important el...{{dropped:4}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] having trouble with R CMD INSTALL
Not sure what you are really doing, but R --vanilla CMD INSTALL something runs in a vanilla style. I just tested with a local .Rprofile under with R-2.13.0 under Windows. Perhaps it is specific to the package your are talking about? Perhaps you can make it available for further inspection of this problem? Uwe Ligges On 19.04.2011 01:55, Gene Leynes wrote: Hello, I was having trouble passing in command line options when doing an package install earlier. From An Introduction in R In addition, you can use25http://cran.r-project.org/doc/manuals/R-intro.html#fn-25options --arch=, --no-environ, --no-init-file, --no-site-file and --vanillabetween R and CMD: these affect any R processes run by the tools. (Here --vanillais equivalent to --no-environ --no-site-file --no-init-file.) R CMD cmd arg When I tried doing this, two unexpected things happened: 1. --vanilla doesn't have an effect when used with R CMD (R --vanilla CMD INSTALL rj_0.5.2-1.tar.gz) 2. When loading my functions from Rprofile.site that seems to interfere with the INSTALL command. I temporarily deleted the Rprofile.site contents, and the install worked as expected. Maybe it's because I'm also parsing the arguments after the --args flag? The second item is probably user error on my part. The first item seems like a possible R bug, but I'm not ruling out user error. See ?user.error for a sample error message I finally got the package installed, but wanted to report this if it really is a bug. The lines below come from a DOS prompt: c:\Users\gene.leynes\Downloadsdir /B gdata_2.8.1.zip rj_0.5.2-1.tar.gz c:\Users\gene.leynes\DownloadsR --vanilla R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. R.Version() $platform [1] i386-pc-mingw32 $arch [1] i386 $os [1] mingw32 $system [1] i386, mingw32 $status [1] $major [1] 2 $minor [1] 13.0 $year [1] 2011 $month [1] 04 $day [1] 13 $`svn rev` [1] 55427 $language [1] R $version.string [1] R version 2.13.0 (2011-04-13) q() c:\Users\gene.leynes\DownloadsR --vanilla CMD INSTALL rj_0.5.2-1.tar.gz Function_II.R : Function_IM.R : Function_NAsummary.R : Function_YahooAdjCloseAsZoo.R : Function_addbg.R : Function_bgfun.R : Function_boxplot2.R : Function_clipdir.R : Function_clipper.R : Function_clipstar.R : Function_comma.R : Function_count.na.R : Function_dftab.R : Function_enclose.R : Function_eye.R : Function_factors.R : Function_finder.R : Function_headstr.R : Function_inin.R : Function_lll.R : Function_loader.R : Function_ma.R : Function_makebm.R : Function_makegm.R : Function_makegroups.R : Function_plot100colors.R : Function_plotRunningSd.R : Function_saver.R : Function_sourcedir.R : Function_stacker.R : Function_subzoo.R : Function_svr.R : Function_tictoc.R : Function_writexls.R : Function_wtt_3.0.R : heatplot.R : loadfuns.R : Opening: nextArgrj_0.5.2-1.tar.gz Warning in file(file, r, encoding = encoding) : cannot open file 'nextArgrj_0.5.2-1.tar.gz': No such file or directory Error in file(file, r, encoding = encoding) : cannot open the connection Calls: source - file Execution halted c:\Users\gene.leynes\Downloads [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] coercion
Dear ALL I don't know why I can see this error in run this sentences. In paste(V, 1L:cols, sep = ) : NAs introduced by coercion DATA-read.delim (D:\\DATA\\GeneExpression.txt,header=FALSE) I will be glad if you help me. Best Regards, Stat Consult [[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] odfWeave \ odfTable and encoding
Dear All, I usually use the package Sweave and Latex, but I want to explore the opportunities available with odfWeave. So I started exploring this new package. I find myself hang while attempting to insert tables in the document odt. I built a data.frame to present the results of statistical analysis, more complex than a conventional contingency table. Now when I run the command odfWeave, I get the following error that appears. Post-processing the contents Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0x6D 0x69 0x6E Erreur : 1: Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0x6D 0x69 0x6E It seems to be an encoding problem since I managed to turn the function odfWeave with another type of table less complex no accent, no % ... Here is my current configuration, on Windows 7, SessionInfo () R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=French_France.1252LC_CTYPE=French_France.1252LC_MONETARY=French_France.1252 LC_NUMERIC=CLC_TIME=French_France.1252 attached base packages: [1] gridsplinesstatsgraphicsgrDevices utilsdatasetsmethodsbase other attached packages: [1] MASS_7.3-4survival_2.35-7 chron_2.3-38xtable_1.5-6gdata_2.8.0odfWeave_0.7.11 XML_3.2-0lattice_0.17-26 loaded via a namespace (and not attached): [1] gtools_2.6.2 tools_2.10.1 I also found this function that allows me to know the encoding in place l10n_info R (). $MBCS [1] FALSE $`UTF-8` [1] FALSE $`Latin-1` [1] TRUE $codepage [1] 1252 I wanted to know if you knew how to change the encoding of reference in R? Thank you very much. Kristell -- Kristell DESSEAUX Biostatisticienne Département de Biostatistique et Informatique Médicale Hôpital Saint Louis, 1 avenue Claude Vellefaux 75475 PARIS Cedex 10 Tel : +33 (0)1 42 49 97 48 Sec : +33 (0)1 42 49 97 42 Fax : +33 (0)1 42 49 97 45 [[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] How to get R plots with FastRweb
Dear friends, I am working in a web service project which uses integration of Java with R. I have used RJava to connect with Java and that is working fine. As R produces more interactive plots, I would also like to pipe plots generate from R on web page. I came to know that FastRWeb, R2HTML, brew and WebGraphics, Cairo together can be used to do that. I have installed all those successfully. I am developing my web service project with NetBeans. For testing purpose I have used the excersie (kmeans) given in the FastRWeb document.I have put the kmeans.png.R program in my netbeansProject/R directory where other java code runs properly. student@mlscubl30:~/NetBeansProjects/R$ ls build build.xml dist kmeans.png.R nbproject src test web student@mlscubl30:~/NetBeansProjects/R$ When i try to execute it with http://localhost:8080/R/kmeans.png in browser it does not execute it. Hence can you please tell me what exactly i have to do in order to make it up and run? thanks in advance. Regards, Devi Manipal Life Sciences Center [[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] user input
Dear users, I have looked on different sources and found different functions to prompt the user to provide input. However, I couldn't find one that does exactly what I'm looking for. select.list() and menu() are nice because a graphic window appears to prompt the user. However, the user can only choose from a predefined list of choices. readline() and scan() are more free in the input but prompt the user in the console. Examples: a - select.list(choices=c(0.0,0.1,0.2), title=select number) a## I cannot choose 0.15 [1] 0.1 b - readline(prompt=select number ) select number 0.2## in the console, not really visible b [1] 0.2 I would like both free input and a pop-up window. Is there a function for this? Thanks in advance, Ivan -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] grid.table + splom: how to nicely align panel entries
Dear expeRts, is there a way to get the entries in each panel correctly aligned according to the equality signs? Here is the wish-list: (1) the equality signs in each panel should be vertically aligned (2) the numbers should be aligned on the decimal point One could adjust the phantom()-arguments by hand to achieve (1), but is there a simpler solution? For (2) I have no idea. Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## arr: array of containing expressions which are plotted in a grid table in the ## lower panel (i,j)] splom2 - function(x, arr){ ## function for creating table table.fun - function(vec){ # vector containing lines for table for *one* panel grid.table(matrix(vec, ncol=2, byrow=TRUE), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left, padding.h=unit(0,mm)) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) # data to be plotted with splom arr - array(list(rep(NA, 3*2)), dim=c(d,d,3*2), dimnames=c(i,j,val)) # array containing the table entries per panel f - function(i,j) (i+j)*10+0.1 # dummy function for(i in 1:d){ for(j in 1:d){ arr[i,j,] - c(alpha==phantom(), round(pi,4), italic(bbb)==phantom(), round(pi,6), gamma==phantom(), f(i,j)) } } ## plot splom2(x, arr) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splom, plotmath: how to add three lines of information with alignment?
Dear Baptiste, many thanks, that worked :-) For the alignment, I made a new minimal example and posted it under the subject grid.table + splom: how to nicely align panel entries. Cheers, Marius On 2011-04-20, at 10:22 , baptiste auguie wrote: On 20 April 2011 19:23, Marius Hofert m_hof...@web.de wrote: Dear Baptiste, thank you for your help. I tried to built in your suggestions into the splom. Below is the result. I decided to create the plotmath-expressions outside the function splom2, this will allow me later to horizontally shift (via phantom, for example) the table entries so that they will be vertically aligned according to the = signs. Although an array is allowed to contain expressions, I could not manage to create it properly. Do you know a solution? Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## expr.arr: array of expressions [(i,j,) entry contains expressions which are ## plotted in a grid table in the lower panel (i,j)] splom2 - function(x, expr.arr){ ## function for creating table table.fun - function(vec){ # single values for one panel grid.table(vec, parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(expr.arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) expr.arr - array(, dim=c(d,d,3), dimnames=c(i,j,val)) # d x d x 3 elements for(i in 1:d){ for(j in 1:d){ # expr.arr[i,j,] - expression(italic(a)==0, italic(bbb)==0, italic(c)==0) # does no work expr.arr[i,j,] - c(bquote(italic(a)==.(0)), bquote(italic(bbb)==.(0)), bquote(italic(c)==.(0))) # same here } } ## plot splom2(x, expr.arr) Initializing your array with a list seems to work for whatever reason that's well above my head, expr.arr - array(list(NA,NA,NA), dim=c(d,d,3), dimnames=c(i,j,val)) As for the alignment, there should be a better way using multiple columns in grid.table, but parse is struggling to interpret the = sign on its own. Again, I'm not sure why, this is deep magic to me. library(gridExtra) d = matrix(c(italic(a)==phantom(''), round(pi,4), italic(b)==phantom(), round(pi,6)), ncol=2, byrow=T) grid.table(d, parse=T,theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), core.just=left, padding.h = unit(0, mm) )) HTH, baptiste On 2011-04-20, at 01:33 , baptiste auguie wrote: Hi, You may want to wait advice from someone who actually understands (the labyrinth that is) lattice's help for splom, but the following might be a start. I didn't understand what values you actually wanted displayed in the lower triangle panels, so I made up some random ones in a 3x3 matrix of 3-vectors. library(lattice) library(gridExtra) info - function(x){ grid.table(c(bquote(italic(a)==.(x[1])), bquote(italic(b)==.(x[2])), bquote(italic(c)==.(x[3]))), core.just=left, parse=TRUE) } U - matrix(runif(3000), ncol=3) splom(U, superpanel=function(z, ...){ ## dummy 3x3 matrix of 3 values to diplay values - replicate(9, round(rnorm(3), 3), simplify=FALSE) dummy - matrix(values, ncol=3, byrow=F) panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i, j, ...){ print(paste(i,j)) # current panel indices info(dummy[i,j] [[1]]) # access the list elements }, ...) }) HTH, baptiste On 20 April 2011 10:17, Marius Hofert m_hof...@web.de wrote: Dear Baptiste, there is one tricky part left: how can I create a matrix with the grid.table() objects as output? Is this possible? If not, maybe one can try to work with panel.splom (which can address single panels and thus call info() for each row-column index pair (i,j)), but I'm not sure if this will work. Cheers, Marius library(lattice) library(gridExtra) splom2 - function(x, a, b, c){ ## function for the additional information info - function(a., b., c.){ # single values for one panel grid.table(c(bquote(italic(a)==.(a.)), bquote(italic(b)==.(b.)), bquote(italic(c)==.(c.)) ), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=right) #
Re: [R] coercion
See the body of all messages to R-help: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. and we do not know what D:\\DATA\\GeneExpression.txt is. Uwe Ligges On 20.04.2011 08:56, Stat Consult wrote: Dear ALL I don't know why I can see this error in run this sentences. In paste(V, 1L:cols, sep = ) : NAs introduced by coercion DATA-read.delim (D:\\DATA\\GeneExpression.txt,header=FALSE) I will be glad if you help me. Best Regards, Stat Consult [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] user input
Thanks for your answer. But I don't understand anything, I would say it's far beyond my current knowledge. Could you please explain me in more details how this works? Ivan Le 4/20/2011 11:40, Juan Carlos Borrás a écrit : An alternative is to run your R programs as scripts (#!/usr/bin/env Rscript) and pass user input as command line parameters. After all you can already set runtime params if you're developing with you IDE of choice, right? Cheers, jcb! ___ http://twitter.com/jcborras On Wed, Apr 20, 2011 at 12:00 PM, Ivan Calandra ivan.calan...@uni-hamburg.de wrote: Dear users, I have looked on different sources and found different functions to prompt the user to provide input. However, I couldn't find one that does exactly what I'm looking for. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] user input
Hi Ivan, there are also data.entry() and edit(), which are more tailored to data frames and might look awkward for entering a single value. You could also take a look at CRAN, maybe there is a GUI package that does what you want. Andreas Ivan Calandra schrieb: Dear users, I have looked on different sources and found different functions to prompt the user to provide input. However, I couldn't find one that does exactly what I'm looking for. select.list() and menu() are nice because a graphic window appears to prompt the user. However, the user can only choose from a predefined list of choices. readline() and scan() are more free in the input but prompt the user in the console. Examples: a - select.list(choices=c(0.0,0.1,0.2), title=select number) a## I cannot choose 0.15 [1] 0.1 b - readline(prompt=select number ) select number 0.2## in the console, not really visible b [1] 0.2 I would like both free input and a pop-up window. Is there a function for this? Thanks in advance, Ivan -- Andreas Borg Medizinische Informatik UNIVERSITÄTSMEDIZIN der Johannes Gutenberg-Universität Institut für Medizinische Biometrie, Epidemiologie und Informatik Obere Zahlbacher Straße 69, 55131 Mainz www.imbei.uni-mainz.de Telefon +49 (0) 6131 175062 E-Mail: b...@imbei.uni-mainz.de Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und löschen Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail und der darin enthaltenen Informationen ist nicht gestattet. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] grid.table + splom: how to nicely align panel entries
On 20 April 2011 21:16, Marius Hofert m_hof...@web.de wrote: Dear expeRts, is there a way to get the entries in each panel correctly aligned according to the equality signs? Here is the wish-list: (1) the equality signs in each panel should be vertically aligned You can put the equal signs in their own column, library(gridExtra) d = matrix(c(italic(a), phantom()==phantom(), round(pi,4), italic(b), phantom()==phantom(), round(pi,6)), ncol=3, byrow=T) grid.table(d, parse=T,theme=theme.list(core.just=left)) (2) the numbers should be aligned on the decimal point You could place some phantom()s to do this, align.digits = function(l) { sp - strsplit(as.character(l), \\.) chars - sapply(sp, function(x) nchar(x)[1]) n = max(chars) - chars l0 = sapply(n, function(x) paste(rep(0, x), collapse=)) labels = sapply(seq_along(sp), function(i) { as.expression(bquote(phantom(.(l0[i])) * .(sp[[i]][1])*.*.(sp[[i]][2])))}) return(labels) } library(gridExtra) d - align.digits(l = c(125.3, 1.2344)) grid.table(d, parse=T,core.just=left) HTH, baptiste One could adjust the phantom()-arguments by hand to achieve (1), but is there a simpler solution? For (2) I have no idea. Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## arr: array of containing expressions which are plotted in a grid table in the ## lower panel (i,j)] splom2 - function(x, arr){ ## function for creating table table.fun - function(vec){ # vector containing lines for table for *one* panel grid.table(matrix(vec, ncol=2, byrow=TRUE), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left, padding.h=unit(0,mm)) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) # data to be plotted with splom arr - array(list(rep(NA, 3*2)), dim=c(d,d,3*2), dimnames=c(i,j,val)) # array containing the table entries per panel f - function(i,j) (i+j)*10+0.1 # dummy function for(i in 1:d){ for(j in 1:d){ arr[i,j,] - c(alpha==phantom(), round(pi,4), italic(bbb)==phantom(), round(pi,6), gamma==phantom(), f(i,j)) } } ## plot splom2(x, arr) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] coercion
On Wed, Apr 20, 2011 at 11:26:19AM +0430, Stat Consult wrote: Dear ALL I don't know why I can see this error in run this sentences. In paste(V, 1L:cols, sep = ) : NAs introduced by coercion Check, what cols is. This warning may be obtained, if cols is a character value. For example cols - a paste(V, 1L:cols, sep = ) Error in 1L:cols : NA/NaN argument In addition: Warning message: In paste(V, 1L:cols, sep = ) : NAs introduced by coercion DATA-read.delim (D:\\DATA\\GeneExpression.txt,header=FALSE) What is the relationship of this to the command above? If you include a reproducible example, you have a better chance to get a useful answer. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] odfWeave \ odfTable and encoding
This has been a long-lasting issue without good solution for windows because windows does not support UTF-8 encoding. If you are using Linux, you can set UTF-8 locale through Sys.setlocale. Regards On 20 April 2011 16:51, kristell.desseaux kristell.desse...@univ-paris-diderot.fr wrote: Dear All, I usually use the package Sweave and Latex, but I want to explore the opportunities available with odfWeave. So I started exploring this new package. I find myself hang while attempting to insert tables in the document odt. I built a data.frame to present the results of statistical analysis, more complex than a conventional contingency table. Now when I run the command odfWeave, I get the following error that appears. Post-processing the contents Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0x6D 0x69 0x6E Erreur : 1: Input is not proper UTF-8, indicate encoding ! Bytes: 0xE9 0x6D 0x69 0x6E It seems to be an encoding problem since I managed to turn the function odfWeave with another type of table less complex no accent, no % ... Here is my current configuration, on Windows 7, SessionInfo () R version 2.10.1 (2009-12-14) i386-pc-mingw32 locale: [1] LC_COLLATE=French_France.1252LC_CTYPE=French_France.1252LC_MONETARY=French_France.1252 LC_NUMERIC=CLC_TIME=French_France.1252 attached base packages: [1] gridsplinesstatsgraphicsgrDevices utilsdatasetsmethodsbase other attached packages: [1] MASS_7.3-4survival_2.35-7 chron_2.3-38xtable_1.5-6gdata_2.8.0odfWeave_0.7.11 XML_3.2-0lattice_0.17-26 loaded via a namespace (and not attached): [1] gtools_2.6.2 tools_2.10.1 I also found this function that allows me to know the encoding in place l10n_info R (). $MBCS [1] FALSE $`UTF-8` [1] FALSE $`Latin-1` [1] TRUE $codepage [1] 1252 I wanted to know if you knew how to change the encoding of reference in R? Thank you very much. Kristell -- Kristell DESSEAUX Biostatisticienne Département de Biostatistique et Informatique Médicale Hôpital Saint Louis, 1 avenue Claude Vellefaux 75475 PARIS Cedex 10 Tel : +33 (0)1 42 49 97 48 Sec : +33 (0)1 42 49 97 42 Fax : +33 (0)1 42 49 97 45 [[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. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://asrr.r-forge.r-project.org/rghuang.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Whole genome searching of 100bp D sequence
Thanks, I've done so. -- View this message in context: http://r.789695.n4.nabble.com/Whole-genome-searching-of-100bp-D-sequence-tp3452765p3462574.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] Fibonacci
Hi! I am trying to work out the code to get a Fibonacci sequence, using the while() loop and only one variable. And I can't figure it out. Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) } How can I tell R to take the value one before the max value? (Without defining another variable) (Probably super easy... I am a beginner...) Thanks, Georgie [[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] Integrate na.rm in own defined functions
It`s probably an easy question, but couldn`t figure it out. I`ve defined a function like: rmse-function (x){ dquared-x^2 sum1-sum(x^2) rmse-sqrt((1/length(x))*sum1) rmse} My problem is, that I have NA Values in x and the above function returns NA. I`m looking for a way to use na.rm=TRUE like in for instance mean(x,na.rm=TRUE). Does anybody know how to do this? Thank you very much. Mauro -- View this message in context: http://r.789695.n4.nabble.com/Integrate-na-rm-in-own-defined-functions-tp3462492p3462492.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] 'Record' row values every time the binary value in a collumn changes
My question is twofold. Part 1: My data looks like this: (example set, real data has 2*10^6 rows) binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) Chromosome start binary [1,] 112 1 [2,] 117 1 [3,] 118 1 [4,] 120 0 [5,] 125 0 [6,] 136 0 [7,] 212 1 [8,] 215 1 [9,] 216 1 [10,] 217 0 [11,] 219 0 As output I need a shortlist for each binary block: giving me the starting and ending position of each block. Which for these example would look like this: Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Part 2: Based on the output of part 1, I need to assign the binary to rows of another data set. If the position value in this second data set falls in one of the blocks defined in the shortlist made in part1,the binary value of the shortlist should be assigned to an extra column for this row. This would look something like this: Chromosome3 position Value binary3 [1,] 1 12 a 1 [2,] 1 13 b 1 [3,] 1 14 c 1 [4,] 1 15 d 1 [5,] 1 16 e 1 [6,] 1 18 f 1 [7,] 1 20 g 0 [8,] 1 21 h 0 [9,] 1 22 i 0 [10,] 1 23 j 0 [11,] 1 25 k 0 [12,] 1 35 l 0 [13,] 2 12 m 1 [14,] 2 13 n 1 [15,] 2 14 o 1 [16,] 2 15 p 1 [17,] 2 16 q 1 [18,] 2 17 s 0 [19,] 2 18 d 0 [20,] 2 19 f 0 Many thanks in advance, Niels -- View this message in context: http://r.789695.n4.nabble.com/Record-row-values-every-time-the-binary-value-in-a-collumn-changes-tp3462496p3462496.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] make a shortlist of data based on blocks of binary values in one column
My question is twofold. Part 1: My data looks like this: (example set, real data has 2*10^6 rows) binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) Chromosome start binary [1,] 112 1 [2,] 117 1 [3,] 118 1 [4,] 120 0 [5,] 125 0 [6,] 136 0 [7,] 212 1 [8,] 215 1 [9,] 216 1 [10,] 217 0 [11,] 219 0 As output I need a shortlist for each binary block: giving me the starting and ending position of each block. Which for these example would look like this: Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Part 2: Based on the output of part 1, I need to assign the binary to rows of another data set. If the position value in this second data set falls in one of the blocks defined in the shortlist made in part1,the binary value of the shortlist should be assigned to an extra column for this row. This would look something like this: Chromosome3 position Value binary3 [1,] 1 12 a 1 [2,] 1 13 b 1 [3,] 1 14 c 1 [4,] 1 15 d 1 [5,] 1 16 e 1 [6,] 1 18 f 1 [7,] 1 20 g 0 [8,] 1 21 h 0 [9,] 1 22 i 0 [10,] 1 23 j 0 [11,] 1 25 k 0 [12,] 1 35 l 0 [13,] 2 12 m 1 [14,] 2 13 n 1 [15,] 2 14 o 1 [16,] 2 15 p 1 [17,] 2 16 q 1 [18,] 2 17 s 0 [19,] 2 18 d 0 [20,] 2 19 f 0 Many thanks in advance, Niels -- View this message in context: http://r.789695.n4.nabble.com/make-a-shortlist-of-data-based-on-blocks-of-binary-values-in-one-column-tp3462500p3462500.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] Yearly aggregates and matrices
As a follow up on this post, I am trying to slightly adjust the solution kindly provided by Gabor. However, I am getting some results that I do not understand. Example: # devel version of zoo install.packages(zoo, repos = http://r-forge.r-project.org;) library(zoo) DF1 = data.frame(read.table(textConnection(B C D E F G 8025 1995 0 4 1 2 8025 1997 1 1 3 4 8026 1995 0 7 0 0 8026 1996 1 2 3 0 8026 1997 1 2 3 1 8026 1998 6 0 0 4 8026 1999 3 7 0 3 8027 1997 1 2 3 9 8027 1998 1 2 3 1 8027 1999 6 0 0 2 8028 1999 3 7 0 0 8029 1995 0 2 3 3 8029 1998 1 2 3 2 8029 1999 6 0 0 1),head=TRUE,stringsAsFactors=FALSE)) a - read.zoo(DF1, split = 1, index = 2, FUN = identity) sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA b - rollapply(a, 3, sum.na, align = right, partial = TRUE) newDF - lapply(1:nrow(b), function(i) prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) names(newDF) - time(a) c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 Now I would like the elements e in c to be equal to 1-e. However, c-lapply(newDF, function(mat) 1 - tcrossprod(mat / sqrt(rowSums(mat^2 gives a value of 2.220446e-16 for as.data.frame(c['1999'])[2,2] instead of 0 What am I doing wrong here? Thanks a lot! First we use read.zoo to reform DF into a multivariate time series and use rollapply (where we have used the devel version of zoo since it supports the partial= argument on rollapply). We then reform each resulting row into a matrix converting each row of each matrix to proportions. Finally we form the desired scaled cross product. # devel version of zoo install.packages(zoo, repos = http://r-forge.r-project.org;) library(zoo) z - read.zoo(DF, split = 2, index = 3, FUN = identity) sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA r - rollapply(z, 3, sum.na, align = right, partial = TRUE) newDF - lapply(1:nrow(r), function(i) prop.table(na.omit(matrix(r[i,], nc = 4, byrow = TRUE, dimnames = list(unique(DF$B), names(DF)[-2:-3]))[, -1]), 1)) names(newDF) - time(z) lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 -- View this message in context: http://r.789695.n4.nabble.com/Yearly-aggregates-and-matrices-tp3438140p3462564.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] How to replace 'star (*)' with blank space?
Hi There I'm not very sure how to replace the stars in a character vector For example: a character vector (n rows by 1 col) [1] -27 -21 -25-28 * -29 [2] -27 -28 * -29 . . . . . . [n] -1*** I wish to replace all the *s with a blank, result as per below [1] -27 -21 -25-28 -29 [2] -27 -28 -29 . . . . . . [n] -1 I have tried to use gsub( ) like: gsub(*, , x) but doesn't seem to be working...please advise Thank you Ruby [[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] Integrate na.rm in own defined functions
This should work!! rmse-function (x){ dquared-x^2 sum1-sum(x^2,na.rm=TRUE) rmse-sqrt((1/length(x))*sum1) rmse} -- View this message in context: http://r.789695.n4.nabble.com/Integrate-na-rm-in-own-defined-functions-tp3462492p3462615.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] Fibonacci
The easy solution to compute the Fibonacci numbers is fibo - function(n,a=1,b=1){ if (n == 1) return(a) if (n == 2) return(b) return(fibo(n-1,b,a+b)) } It avoids double recursion. It is, however, not as resource efficient as a loop since R does not do tail recursion elimination. On Apr 20, 2011, at 11:42 AM, Georgina Imberger wrote: Hi! I am trying to work out the code to get a Fibonacci sequence, using the while() loop and only one variable. And I can't figure it out. Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) } How can I tell R to take the value one before the max value? (Without defining another variable) (Probably super easy... I am a beginner...) Thanks, Georgie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fibonacci
On Wed, Apr 20, 2011 at 11:42:38AM +0200, Georgina Imberger wrote: Hi! I am trying to work out the code to get a Fibonacci sequence, using the while() loop and only one variable. And I can't figure it out. Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) } How can I tell R to take the value one before the max value? (Without defining another variable) Is it allowed to use length() function? If so, then try the following Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, Fibonacci[length(Fibonacci) - 1] + Fibonacci[length(Fibonacci)]) } Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cut histogram
On 04/20/2011 12:32 AM, Santosh wrote: Dear Rxperts, Below is a small sample of values (cut short due to space considerations while posting).. I was wondering if it is possible to construct boundaries (or intervals) based on the distribution of points. Is it anything similar to boundary detection of distributions? x1- c(0.00,0.25,0.50,1.00,2.00,3.00,4.00,5.00,7.03,10.00,14.01,21.00,28.02,14.00,28.00,7.00,29.00,7.01,10.02,6.97,10.06,21.03,28.01,14.10,28.14, 10.03,7.05,35.00,21.01,10.05,14.02,21.07,7.02,14.12,10.04,0.02,0.06,0.10,0.27,0.52,1.02,2.02,3.02,4.02,5.02,21.02,21.10,0.11,28.04,28.12, 27.98,14.04,21.06,14.05,28.03,8.00,13.99,27.99,21.04,5.28,28.11,28.05,13.98,2.01,5.99,15.02,28.06,3.07,1.01,6.04,6.01,7.99,13.96,0.99,3.01, 20.98,34.99,13.97,6.14,7.07,28.10,2.99,6.00,6.99,14.03,34.98,4.01,4.99,20.99,27.97,0.98,6.07,28.09,20.97,0.93,1.93,5.01,6.96,20.94,0.92, 20.95,8.07,14.07,27.95,34.95,2.97,4.96,20.96,27.96,34.96,2.96,33.99,34.00,6.72,27.71,6.91,25.91,26.02,7.14,26.16,26.19,6.94,28.95,28.98,6.82, 27.85,6.85,27.88,6.86,28.88,6.93,27.91,11.92,20.92,7.94,28.92,9.76,32.81,10.94,31.92,6.95,29.94,29.96,8.94,28.94,6.89,28.96,9.69,30.79,30.80, 6.90,29.91,9.93,30.95,6.88,7.89,31.97,31.98,3.92,7.91,31.72,6.83,29.88,29.80,29.81,27.90,32.94,28.93,28.97,7.83,28.76,28.77,6.98,34.01,10.97) hist(x1,brea=200), # arbitrarily chosen high number of breakpoints Would highly appreciate your thoughts/suggestions... Hi Santosh, Have a look at the classInt package. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Integrate na.rm in own defined functions
Am 20.04.2011 10:59, schrieb Mauro: It`s probably an easy question, but couldn`t figure it out. I`ve defined a function like: rmse-function (x){ dquared-x^2 sum1-sum(x^2) rmse-sqrt((1/length(x))*sum1) rmse} My problem is, that I have NA Values in x and the above function returns NA. I`m looking for a way to use na.rm=TRUE like in for instance mean(x,na.rm=TRUE). If you had no sum function to give the na.rm=TRUE parameter, you can add the tiny line to your code: x - x[!is.na(x)] Or give your function a na.rm parameter yourself: rmse-function (x, na.rm=FALSE){ if(na.rm==TRUE){ x - x[!is.na(x)] } dquared-x^2 sum1-sum(x^2) rmse-sqrt((1/length(x))*sum1) rmse } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace 'star (*)' with blank space?
gsub(\\*, ,x) should do. Please read about regular expression as used by gsub(). Uwe Ligges On 20.04.2011 12:00, Ruby Chu wrote: Hi There I'm not very sure how to replace the stars in a character vector For example: a character vector (n rows by 1 col) [1] -27 -21 -25-28 * -29 [2] -27 -28 * -29 . . . . . . [n] -1*** I wish to replace all the *s with a blank, result as per below [1] -27 -21 -25-28 -29 [2] -27 -28 -29 . . . . . . [n] -1 I have tried to use gsub( ) like: gsub(*, , x) but doesn't seem to be working...please advise Thank you Ruby [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace 'star (*)' with blank space?
On Apr 20, 2011, at 6:00 AM, Ruby Chu wrote: Hi There I'm not very sure how to replace the stars in a character vector For example: a character vector (n rows by 1 col) [1] -27 -21 -25-28 * -29 [2] -27 -28 * -29 . . . . . . [n] -1*** I wish to replace all the *s with a blank, result as per below [1] -27 -21 -25-28 -29 [2] -27 -28 -29 . . . . . . [n] -1 I have tried to use gsub( ) like: gsub(*, , x) * is an operator in regex, so you need to double escape it in the pattern argument (but may not need to escape it in the replace argument. gsub(\\*, , test) [1] test gsub(\\., *, test......) [1] test****** but doesn't seem to be working...please advise Thank you Ruby [[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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] S: expert mailing list for general statistical questions
Hello R users and experts Once in a while I have got questions that are not so much R-related but related to (social scientific) statistics in general. R-help would be the wrong list for such posts, and I am looking for a similar mailing list or newsgroup (nntp). (It is just a personal taste that I don't like web forums.) I have googled and found a variety here: http://mathstore.ac.uk/?q=node/1447 -- e.g. the list stats-discuss (which failed to load), and the newsgroups sci.stat.consult and sci.stat.edu. However, before stumbling around, could you give a good recommendation on a mailing list or newsgroup appropriate for such issues? Thanks for your tips. Regards, *S* -- Sascha Vieweg, saschav...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] S: expert mailing list for general statistical questions
On Apr 20, 2011, at 7:44 AM, Sascha Vieweg wrote: Hello R users and experts Once in a while I have got questions that are not so much R-related but related to (social scientific) statistics in general. snipped However, before stumbling around, could you give a good recommendation on a mailing list or newsgroup appropriate for such issues? http://stats.stackexchange.com/ David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] user input
On 2011-04-20 02:51, Andreas Borg wrote: Hi Ivan, there are also data.entry() and edit(), which are more tailored to data frames and might look awkward for entering a single value. You could also take a look at CRAN, maybe there is a GUI package that does what you want. Ivan, have a look at the rpanel package. Might give you some ideas. Peter Ehlers Andreas Ivan Calandra schrieb: Dear users, I have looked on different sources and found different functions to prompt the user to provide input. However, I couldn't find one that does exactly what I'm looking for. select.list() and menu() are nice because a graphic window appears to prompt the user. However, the user can only choose from a predefined list of choices. readline() and scan() are more free in the input but prompt the user in the console. Examples: a- select.list(choices=c(0.0,0.1,0.2), title=select number) a## I cannot choose 0.15 [1] 0.1 b- readline(prompt=select number ) select number 0.2## in the console, not really visible b [1] 0.2 I would like both free input and a pop-up window. Is there a function for this? Thanks in advance, Ivan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fibonacci
Fibonacci - c(1, 1) while (max (Fibonacci) 500){ Fibonacci - c(Fibonacci, sum(tail(Fibonacci, 2))) } -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Georgina Imberger Sent: Wednesday, April 20, 2011 5:43 AM To: r-help@r-project.org Subject: [R] Fibonacci Hi! I am trying to work out the code to get a Fibonacci sequence, using the while() loop and only one variable. And I can't figure it out. Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) } How can I tell R to take the value one before the max value? (Without defining another variable) (Probably super easy... I am a beginner...) Thanks, Georgie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. === Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2010). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{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.
[R] Extrapolating data points for individuals who lack them
Hi, We have an experiment where individuals responses were measured over 5 days. Some responses were not obtained because we only allowed individuals to respond within a limited time-frame. These individuals are given the maximum response time as they did not respond, yet we feel they may have done if given time (and by looking at the rest of their responses over time, the non-response days stand out). We therefore want to extrapolate data points for individuals, on days when they didn't respond, using a regression of days when they did. Does anyone know how we could do this quickly and easily in R? Thanks very much Dave [[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] SPDEP Package, neighbours list for Moran's I on large grid dataset
There is a recent thread on the R-sig-geo list that addresses your need, using a focal function in the raster package. The thread is at: https://stat.ethz.ch/pipermail/r-sig-geo/2011-April/011444.html That list may be a better place to post on this topic. Hope this helps, Roger Laurent Jégou wrote: Hello list members, i'd like to calculate the Moran I on a large dataset, a 8640x3432 grid of values. When i try to create the neighbours list with the cell2nb function, on such a scale, R works for several hours and seems to crash. I'm using the last version (2.13), 64 bits, on a mac pro with 4go of memory. I think that i'm doing it wrong :-) I'd like to use a moving window weight matrix instead of a full scale one, but i was not lucky enough to find a solution in the docs. Thanks for any help, Laurent -- Laurent Jégou Cartographe et enseignant UTM - Dépt. Géographie 31058 TOULOUSE Cedex 9 - 05.61.50.43.89 http://www.univ-tlse2.fr/geoprdc [[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. - Roger Bivand Economic Geography Section Department of Economics Norwegian School of Economics and Business Administration Helleveien 30 N-5045 Bergen, Norway -- View this message in context: http://r.789695.n4.nabble.com/SPDEP-Package-neighbours-list-for-Moran-s-I-on-large-grid-dataset-tp3460184p3462767.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] lapply sequence
Good day, My question is: Does the lapply function guarantee a particular sequence in which elements are mapped? And, are we guaranteed that lapply will always be sequential (i.e. never map elements in parallel) ? The reason I ask is if I use lapply with the mapping function set to something that has side-effects that need to be executed in a particular sequence. If this is not possible, is there an alternate method other than using a for loop? -- Dean Marks [[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] Yearly aggregates and matrices
On Wed, Apr 20, 2011 at 5:49 AM, mathijsdevaan mathijsdev...@gmail.com wrote: As a follow up on this post, I am trying to slightly adjust the solution kindly provided by Gabor. However, I am getting some results that I do not understand. Example: # devel version of zoo install.packages(zoo, repos = http://r-forge.r-project.org;) library(zoo) DF1 = data.frame(read.table(textConnection( B C D E F G 8025 1995 0 4 1 2 8025 1997 1 1 3 4 8026 1995 0 7 0 0 8026 1996 1 2 3 0 8026 1997 1 2 3 1 8026 1998 6 0 0 4 8026 1999 3 7 0 3 8027 1997 1 2 3 9 8027 1998 1 2 3 1 8027 1999 6 0 0 2 8028 1999 3 7 0 0 8029 1995 0 2 3 3 8029 1998 1 2 3 2 8029 1999 6 0 0 1),head=TRUE,stringsAsFactors=FALSE)) a - read.zoo(DF1, split = 1, index = 2, FUN = identity) sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA b - rollapply(a, 3, sum.na, align = right, partial = TRUE) newDF - lapply(1:nrow(b), function(i) prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) names(newDF) - time(a) c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 Now I would like the elements e in c to be equal to 1-e. However, c-lapply(newDF, function(mat) 1 - tcrossprod(mat / sqrt(rowSums(mat^2 gives a value of 2.220446e-16 for as.data.frame(c['1999'])[2,2] instead of 0 What am I doing wrong here? Thanks a lot! See FAQ 7.31 at: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem reading csv file
Thank you. r-help-boun...@r-project.org napsal dne 19.04.2011 22:00:56: Not attached. You might succeed if you rename the file with a .txt extension and re-post. Almost surely an encoding issue. We may need your session Info to get locale. Maybe you are right. After some further thorough documentation search I tried encoding, which was not success. After that I tried fileEncoding = UCS-2LE and bingo, that was it. From file help page The encodings ‘UCS-2LE’ and ‘UTF-16LE’ are treated specially, as they are appropriate values for Windows ‘Unicode’ text files. If the first two bytes are the Byte Order Mark ‘0xFFFE’ then these are removed as some implementations of ‘iconv’ do not accept BOMs. ˙ţ1 looks in hex editor like that 0xFFFE so the problem is solved for now. Thanks again Petr -- David On Apr 19, 2011, at 2:47 PM, Petr Pikal wrote: Dear all I have several files which claim to be *.csv (one attached, maybe it will come through) . They can be read to Open Office without much problem, however I can not read them into R. I tried read.table(H2O.CSV, sep=,, dec=.) V1 1 ˙ţ1 2 3 read.table(H2O.CSV, sep=,, dec=., skip=1) Error in read.table(H2O.CSV, sep = ,, dec = ., skip = 1) : empty beginning of file readLines(H2O.CSV, 1) [1] ˙ţ1 readLines(H2O.CSV, 5) [1] ˙ţ1 readChar(H2O.CSV, 10) [1] ˙ţ1 readBin(H2O.CSV, 10) [1] 9.456937e-308 This is how first two lines appear in Notepad 1,1.77436423301697,BV , 91.0779418945313,7.35872077941895,0.178956836462021,1.70007145404816,1.90102112293243 2,1.94783389568329,VV , 1341.51489257812,9.04244899749756,1.76539707183838,1.90102112293243,3.52783703804016 The problem seems to be in first item ˙ţ1 which somehow blocks further values to be read. Does anybody have idea what to do or where to look for some help? I do not want to transfer files through spreadsheet manually. Best regards Petr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] BMA, logistic regression, odds ratio, model reduction etc
Deleting variables is a bad idea unless you make that a formal part of the BMA so that the attempt to delete variables is penalized for. Instead of BMA I recommend simple penalized maximum likelihood estimation (see the lrm function in the rms package) or pre-modeling data reduction that is blinded to the outcome variable. Frank 細田弘吉 wrote: Hi everybody, I apologize for long mail in advance. I have data of 104 patients, which consists of 15 explanatory variables and one binary outcome (poor/good). The outcome consists of 25 poor results and 79 good results. I tried to analyze the data with logistic regression. However, the 15 variables and 25 events means events per variable (EPV) is much less than 10 (rule of thumb). Therefore, I used R package, BMA to perform logistic regression with BMA to avoid this problem. model 1 (full model): x1, x2, x3, x4 are continuous variables and others are binary data. x16.bic.glm - bic.glm(outcome ~ ., data=x16.df, glm.family=binomial, OR20, strict=FALSE) summary(x16.bic.glm) (The output below has been cut off at the right edge to save space) 62 models were selected Best 5 models (cumulative posterior probability = 0.3606 ): p!=0EV SDmodel 1model2 Intercept100-5.1348545 1.652424-4.4688 -5.15 -5.1536 age3.3 0.0001634 0.007258 . sex4.0 .M -0.0243145 0.220314 . side 10.8 .R 0.0811227 0.301233 . procedure 46.9 -0.5356894 0.685148 . -1.163 symptom3.8 -0.0099438 0.129690 . . stenosis 3.4 -0.0003343 0.005254 . x13.7 -0.0061451 0.144084 . x2 100.0 3.1707661 0.892034 3.2221 3.11 x351.3 -0.4577885 0.551466-0.9154 . HT 4.6 .positive 0.0199299 0.161769 . . DM 3.3 .positive -0.0019986 0.105910 . . IHD3.5 .positive 0.0077626 0.122593 . . smoking9.1 .positive 0.0611779 0.258402 . . hyperlipidemia16.0 .positive 0.1784293 0.512058 . . x4 8.2 0.0607398 0.267501 . . nVar 2 2 1 3 3 BIC -376.9082 -376.5588 -376.3094 -375.8468 -374.5582 post prob0.104 0.087 0.077 0.061 0.032 [Question 1] Is it O.K to calculate odds ratio and its 95% confidence interval from EV (posterior distribution mean) and“SD”(posterior distribution standard deviation)? For example, 95%CI of EV of x2 can be calculated as; exp(3.1707661) [1] 23.82573 - odds ratio exp(3.1707661+1.96*0.892034) [1] 136.8866 exp(3.1707661-1.96*0.892034) [1] 4.146976 -- 95%CI (4.1 to 136.9) Is this O.K.? [Question 2] Is it permissible to delete variables with small value of p!=0 and EV, such as age (3.3% and 0.0001634) to reduce the number of explanatory variables and reconstruct new model without those variables for new session of BMA? model 2 (reduced model): I used R package, pvclust, to reduce the model. The result suggested x1, x2 and x4 belonged to the same cluster, so I picked up only x2. Based on the subject knowledge, I made a simple unweighted sum, by counting the number of clinical features. For 9 features (sex, side, HT2, hyperlipidemia, DM, IHD, smoking, symptom, age), the sum ranges from 0 to 9. This score was defined as ClinicalScore. Consequently, I made up new data set (x6.df), which consists of 5 variables (stenosis, x2, x3, procedure, and ClinicalScore) and one binary outcome (poor/good). Then, for alternative BMA session... BMAx6.glm - bic.glm(postopDWI_HI ~ ., data=x6.df, glm.family=binomial, OR=20, strict=FALSE) summary(BMAx6.glm) (The output below has been cut off at the right edge to save space) Call: bic.glm.formula(f = postopDWI_HI ~ ., data = x6.df, glm.family = binomial, strict = FALSE, OR = 20) 13 models were selected Best 5 models (cumulative posterior probability = 0.7626 ): p!=0EV SD model 1model 2 Intercept 100-5.6918362 1.81220-4.4688-6.3166 stenosis 8.1 -0.0008417 0.00815 . . x2 100.0 3.0606165 0.87765 3.2221 3.1154 x3 46.5 -0.3998864 0.52688-0.9154 . procedure 49.3 0.5747013
Re: [R] lapply sequence
On 20/04/2011 7:26 AM, Dean Marks wrote: Good day, My question is: Does the lapply function guarantee a particular sequence in which elements are mapped? And, are we guaranteed that lapply will always be sequential (i.e. never map elements in parallel) ? No. The reason I ask is if I use lapply with the mapping function set to something that has side-effects that need to be executed in a particular sequence. Use a for loop. If this is not possible, is there an alternate method other than using a for loop? while or repeat. 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.
[R] Two Questions
Sorry for the somewhat nondescript subject line, but I have two questions: 1.What is a really good book on R for a nonprogrammer? 2. How do I open more than one R Graphics: Device 2(ACTIVE). That what is the R command that I can use to keep more than one plot open. I am running a script from a book on Chemometrics that results in more than one graph during the execution, but it seems that R deletes each graph when the script calls for the next plot. Thanks in advance Stephen P. Molnar, Ph.D. Life is a fuzzy set Foundation for Chemistry Stochastic and multivariate http://www.FoundationForChemistry.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about symbols()
David Winsemius dwinsemius at comcast.net writes: On Apr 19, 2011, at 10:51 PM, murilofm wrote: Thanks for the answer; I see that col=c(blue,red)[inv$c+1] creates a vector of red and blue associated with the binnary c. But still I got everything red. If you want tested solution, submit test data. David also suggests (off-lists) that you use bg instead of col as the argument name. (Another strategy is to go to ?symbols and search for colour -- I wouldn't expect a new user to guess the c(blue,red)[inv$c+1] stuff, but you probably could go to the help page and figure out that the appropriate argument name is bg ...) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about symbols()
The link to the csv file is http://www.filedropper.com/data_5 I use the d variable to create the radius: radius - sqrt( inv$d/ pi ) and i tried symbols(inv$a, inv$b, circles=radius, inches=0.35, fg=white, bg=red, xlab=aa, ylab=bb, col=c(blue,red)[inv$c+1]) Thanks for the help. -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-about-symbols-tp3461676p3462882.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] SPDEP Package, neighbours list for Moran's I on large grid dataset
Laurent Jégou wrote: Hello list members, i'd like to calculate the Moran I on a large dataset, a 8640x3432 grid of values. When i try to create the neighbours list with the cell2nb function, on such a scale, R works for several hours and seems to crash. I'm using the last version (2.13), 64 bits, on a mac pro with 4go of memory. I think that i'm doing it wrong :-) I'd like to use a moving window weight matrix instead of a full scale one, but i was not lucky enough to find a solution in the docs. I confronted this problem recently, and decided to roll my own. For a large dataset, an exhaustive computation of Moran's I is very time-consuming, as you say; but an estimate of it, based on a subset of pairs chosen randomly, seemed (for my data, at least) to converge quite nicely. Here's my code. It assumes a square grid, so you'll need to adapt it for your non-square grid, but that should be trivial. To determine the right number of pairs for a good estimate in my application, I called this function with various numbers of pairs, and plotted the estimate produced as a function of the number of pairs used, and observed good convergence by 200,000 pairs. You will probably want to do this yourself, for your dataset. 200,000 pairs took just a second or two to run, on my machine, so this is much, much faster than an exhaustive calculation. As a bonus, this code also gives you Geary's C. Oh, and the code below assumes a wraparound lattice (i.e. a torus, i.e. periodic boundaries), which may not be what you want; just get rid of the d_wraparound stuff and the following pmax() call if you want non-wraparound boundaries, and that should work fine, I think. Not sure what you mean by the moving window thing, so I leave that as an exercise for the reader. :- I've never made an R package, and I'm not sure there's much demand for this code (is there?), so I'm presently unlikely to package it up. However, if someone who owns a package related to this problem would like to adopt this code, generalize it to non-square lattices, add a flag to choose periodic or non-periodic boundaries, etc., feel free to do so; I hereby place it in the public domain. I'd just like to hear about it if someone does this, and receive credit somewhere, that's all. I'm not super-good in R, either, so if there's a better way to do some things, like the somewhat hacked random index generation (trying to avoid floating point issues when generating a random integer), please let me know. I'm always interested in learning how to do things better. And of course this code is provided without warranty, may have bugs, etc. Enjoy! Ben Haller McGill University correlation_stats - function(p, n_pairs=20) { # Compute Moran's I and Geary's C for the landscape p. This is tricky because the exact calculation # would be far too time-consuming, as it involves comparison of every point to every other point. # So I am trying to estimate it here with a small subset of all possible point comparisons. p_size - NROW(p) # 512 p_length - length(p) # 262144 mean_p - mean(p) pv - as.vector(p) # select points and look up their values; for speed, points are selected by their vector index p1ix - floor(runif(n_pairs, min=0, max=p_length - 0.001)) p1x - (p1ix %/% p_size) + 1 p1y - (p1ix %% p_size) + 1 p1ix - p1ix + 1 p2ix - floor(runif(n_pairs, min=0, max=p_length - 0.001)) p2x - (p2ix %/% p_size) + 1 p2y - (p2ix %% p_size) + 1 p2ix - p2ix + 1 v1 - pv[p1ix] - mean_p v2 - pv[p2ix] - mean_p # Calculate distances between point pairs, both directly and wrapping around # The average direct distance is much smaller than the average wraparound distance, # because points near the center vertically have a maximum direct distance near 256, # but a minimum wraparound distance near 256. The Moran's I estimate from wraparound # distances is different, as a result. Rupert recommends taking the shorter of the # two distances, whichever it is, because that keeps us within the meaningful scale # of our space, before it just starts repeating due to periodicity. d_direct - 1 / sqrt(((p1x - p2x) ^ 2) + ((p1y - p2y) ^ 2)) d_direct[is.infinite(d_direct)] - 0 d_wraparound - 1 / sqrt(((p1x - p2x) ^ 2) + ((p_size - abs(p1y - p2y)) ^ 2)) d_wraparound[is.infinite(d_wraparound)] - 0 d - pmax(d_direct, d_wraparound) # max because we want the min distance, and these are 1/distance # precalculate some shared terms sum_d - sum(d) sum_v1_sq - sum(v1 ^ 2) # Moran's I: -1 is perfect dispersion, 1 is perfect correlation, 0 is a random spatial pattern M_I - (n_pairs
Re: [R] Two Questions
On 20/04/2011 9:23 AM, Stephen P Molnar wrote: Sorry for the somewhat nondescript subject line, but I have two questions: 1.What is a really good book on R for a nonprogrammer? Any book that teaches you the basics of programming would be good, it doesn't need to be about R. If you want to use R and remain as a nonprogrammer, you will not have any easy time. 2. How do I open more than one R Graphics: Device 2(ACTIVE). That what is the R command that I can use to keep more than one plot open. I am running a script from a book on Chemometrics that results in more than one graph during the execution, but it seems that R deletes each graph when the script calls for the next plot. dev.new() will open a new plot window, and subsequent plotting commands will be drawn there. dev.set() lets you switch back to drawing on the original one. Duncan Murdoch Thanks in advance Stephen P. Molnar, Ph.D. Life is a fuzzy set Foundation for Chemistry Stochastic and multivariate http://www.FoundationForChemistry.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two Questions
On Apr 20, 2011, at 9:23 AM, Stephen P Molnar wrote: Sorry for the somewhat nondescript subject line, but I have two questions: 1.What is a really good book on R for a nonprogrammer? 2. How do I open more than one R Graphics: Device 2(ACTIVE). That what is the R command that I can use to keep more than one plot open. You can have more than one device available, but you need to address them serially. Only one device can receive input at a time. ?Devices ?dev.set I am running a script from a book on Chemometrics that results in more than one graph during the execution, but it seems that R deletes each graph when the script calls for the next plot. More likely you are seeing one graph displayed at a time on the screen device. On my screen device the cmd-left-arrow will bring up prior plots to a depth of 15 earlier results. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Test email: Please disregard
Having trouble posting. Thought it might have something to do with the particular message I'm sending. Sending this message to test that possibility. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Yearly aggregates and matrices
Thanks for clarifying that. Best Gabor Grothendieck wrote: On Wed, Apr 20, 2011 at 5:49 AM, mathijsdevaan lt;mathijsdev...@gmail.comgt; wrote: As a follow up on this post, I am trying to slightly adjust the solution kindly provided by Gabor. However, I am getting some results that I do not understand. Example: # devel version of zoo install.packages(zoo, repos = http://r-forge.r-project.org;) library(zoo) DF1 = data.frame(read.table(textConnection( B C D E F G 8025 1995 0 4 1 2 8025 1997 1 1 3 4 8026 1995 0 7 0 0 8026 1996 1 2 3 0 8026 1997 1 2 3 1 8026 1998 6 0 0 4 8026 1999 3 7 0 3 8027 1997 1 2 3 9 8027 1998 1 2 3 1 8027 1999 6 0 0 2 8028 1999 3 7 0 0 8029 1995 0 2 3 3 8029 1998 1 2 3 2 8029 1999 6 0 0 1),head=TRUE,stringsAsFactors=FALSE)) a - read.zoo(DF1, split = 1, index = 2, FUN = identity) sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA b - rollapply(a, 3, sum.na, align = right, partial = TRUE) newDF - lapply(1:nrow(b), function(i) prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) names(newDF) - time(a) c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 Now I would like the elements e in c to be equal to 1-e. However, c-lapply(newDF, function(mat) 1 - tcrossprod(mat / sqrt(rowSums(mat^2 gives a value of 2.220446e-16 for as.data.frame(c['1999'])[2,2] instead of 0 What am I doing wrong here? Thanks a lot! See FAQ 7.31 at: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Yearly-aggregates-and-matrices-tp3438140p3463000.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] Simple question about symbols()
On Apr 20, 2011, at 8:45 AM, murilofm wrote: The link to the csv file is http://www.filedropper.com/data_5 I use the d variable to create the radius: radius - sqrt( inv$d/ pi ) and i tried symbols(inv$a, inv$b, circles=radius, inches=0.35, fg=white, bg=red, xlab=aa, ylab=bb, col=c(blue,red)[inv$c+1]) You should follow the Posting Guide's advice and offer the full code you used to read in that data. It's _not_ comma separated, and for some reason even using read.csv2 to properly read a semi-colon separated file, I also needed to to convert the first two variables from factor to numeric ... please also read the FAQ item on this topic. Once that was done this works, since col is _not_ the proper argument for coloring with that function: ?symbols plot.new() symbols(inv$a, inv$b, circles=radius, inches=0.35, bg=c(blue,red)[inv$c+1]) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Extrapolating data points for individuals who lack them
From: de...@exeter.ac.uk To: r-help@r-project.org Date: Wed, 20 Apr 2011 12:41:29 +0100 Subject: [R] Extrapolating data points for individuals who lack them Hi, We have an experiment where individuals responses were measured over 5 days. Some responses were not obtained because we only allowed individuals to respond within a limited time-frame. These individuals are given the maximum response time as they did not respond, yet we feel they may have done if given time (and by looking at the rest of their responses over time, the non-response days stand out). We therefore want to extrapolate data points for individuals, on days when they didn't respond, using a regression of days when they did. Does anyone know how we could do this quickly and easily in R? You are probably talking about right censoring. See things like this, ( you may have good luck just with R rather than CRAN ) http://www.google.com/#sclient=psyhl=ensource=hpq=CRAN+informative+%22right+censoring%22 If you post data maybe someone can try a few things. It isn't hard to take data subsets, fit models, and replace data with model predictions but easier and more interesting to illustrate with your data. Personally I would avoid making up data and of course extrapolation tends to be the most error prone way of doing that. Thanks very much Dave __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] BMA, logistic regression, odds ratio, model reduction etc
Dear Prof. Harrel, Thank you very much for your quick advice. I will try rms package. Regarding model reduction, is my model 2 method (clustering and recoding that are blinded to the outcome) permissible? Sincerely, -- KH (11/04/20 22:01), Frank Harrell wrote: Deleting variables is a bad idea unless you make that a formal part of the BMA so that the attempt to delete variables is penalized for. Instead of BMA I recommend simple penalized maximum likelihood estimation (see the lrm function in the rms package) or pre-modeling data reduction that is blinded to the outcome variable. Frank 細田弘吉 wrote: Hi everybody, I apologize for long mail in advance. I have data of 104 patients, which consists of 15 explanatory variables and one binary outcome (poor/good). The outcome consists of 25 poor results and 79 good results. I tried to analyze the data with logistic regression. However, the 15 variables and 25 events means events per variable (EPV) is much less than 10 (rule of thumb). Therefore, I used R package, BMA to perform logistic regression with BMA to avoid this problem. model 1 (full model): x1, x2, x3, x4 are continuous variables and others are binary data. x16.bic.glm- bic.glm(outcome ~ ., data=x16.df, glm.family=binomial, OR20, strict=FALSE) summary(x16.bic.glm) (The output below has been cut off at the right edge to save space) 62 models were selected Best 5 models (cumulative posterior probability = 0.3606 ): p!=0EV SDmodel 1model2 Intercept100-5.1348545 1.652424-4.4688 -5.15 -5.1536 age3.3 0.0001634 0.007258 . sex4.0 .M -0.0243145 0.220314 . side 10.8 .R 0.0811227 0.301233 . procedure 46.9 -0.5356894 0.685148 . -1.163 symptom3.8 -0.0099438 0.129690 . . stenosis 3.4 -0.0003343 0.005254 . x13.7 -0.0061451 0.144084 . x2 100.0 3.1707661 0.892034 3.2221 3.11 x351.3 -0.4577885 0.551466-0.9154 . HT 4.6 .positive 0.0199299 0.161769 . . DM 3.3 .positive -0.0019986 0.105910 . . IHD3.5 .positive 0.0077626 0.122593 . . smoking9.1 .positive 0.0611779 0.258402 . . hyperlipidemia16.0 .positive 0.1784293 0.512058 . . x4 8.2 0.0607398 0.267501 . . nVar 2 2 1 3 3 BIC -376.9082 -376.5588 -376.3094 -375.8468 -374.5582 post prob0.104 0.087 0.077 0.061 0.032 [Question 1] Is it O.K to calculate odds ratio and its 95% confidence interval from EV (posterior distribution mean) and“SD”(posterior distribution standard deviation)? For example, 95%CI of EV of x2 can be calculated as; exp(3.1707661) [1] 23.82573 - odds ratio exp(3.1707661+1.96*0.892034) [1] 136.8866 exp(3.1707661-1.96*0.892034) [1] 4.146976 -- 95%CI (4.1 to 136.9) Is this O.K.? [Question 2] Is it permissible to delete variables with small value of p!=0 and EV, such as age (3.3% and 0.0001634) to reduce the number of explanatory variables and reconstruct new model without those variables for new session of BMA? model 2 (reduced model): I used R package, pvclust, to reduce the model. The result suggested x1, x2 and x4 belonged to the same cluster, so I picked up only x2. Based on the subject knowledge, I made a simple unweighted sum, by counting the number of clinical features. For 9 features (sex, side, HT2, hyperlipidemia, DM, IHD, smoking, symptom, age), the sum ranges from 0 to 9. This score was defined as ClinicalScore. Consequently, I made up new data set (x6.df), which consists of 5 variables (stenosis, x2, x3, procedure, and ClinicalScore) and one binary outcome (poor/good). Then, for alternative BMA session... BMAx6.glm- bic.glm(postopDWI_HI ~ ., data=x6.df, glm.family=binomial, OR=20, strict=FALSE) summary(BMAx6.glm) (The output below has been cut off at the right edge to save space) Call: bic.glm.formula(f = postopDWI_HI ~ ., data = x6.df, glm.family = binomial, strict = FALSE, OR = 20) 13 models were selected Best 5 models (cumulative posterior probability = 0.7626 ): p!=0EV SD model 1model 2 Intercept 100-5.6918362 1.81220-4.4688-6.3166 stenosis 8.1
[R] Random Relabelling
I have 4000 observations that I need to randomly relabel 1000 times and then calculate the mean of the 1000 values at each of the 4000 points. Any ideas for where to begin? Thanks Kevin -- View this message in context: http://r.789695.n4.nabble.com/Random-Relabelling-tp3463100p3463100.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] Fibonacci
Another solution: while (Fibonacci[1] 500) Fibonacci - c(sum(Fibonacci[c(1,2)]), Fibonacci) While this adds the sum before the existing values, the length or tail function or avoided, but even with reordering, its faster (Fibonacci[length(Fibonacci):1]) Best regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Fibonacci-tp3462636p3463050.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] Matrix package transpose
Hi, Since I installed R 2.13 I cannot use the transpose method t on sparse matrices inside my package. Outside the package works. Is there something new that I have to import methods? Can I then import everything from the Matrix package? The problem is that R tries to use t.default which of course doesn't work. Happy easter, Tobias -- Tobias Abenius Ph.D. Student, M.Sc. in Computer Science Mathematical Statistics Mathematical Sciences University of Gothenburg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Unlist command drops all my column names in the first row and adopts NAs
Hi Everyone, I am having trouble turning my data.frame into a matrix format. Because I wanted to change my data.frame with mostly factor variables into a numeric matrix, I used the following code -- UN2010frame-data.matrix(lapply(UN2010,as.numeric)) However when i checked the mode of the UN2010frame, it still showed up as a list. Because the code I want to run (Ordrating) does not accept data in a list format, I used UN2010matrix - unlist(UN2010frame) to unlist my matrix. When I did this, my first row ( which was formerly a row with column names) turned into NAs. This was a problem for me because when I tried to run an ordinal IRT model using this data set, I got the following error message. Error in 1:nrow(Y) : argument of length 0 I think it is because all the values in my first row are now gone If you could help me on any front, It would be deeply appreciated. Thank you very much! Haillie -- View this message in context: http://r.789695.n4.nabble.com/Unlist-command-drops-all-my-column-names-in-the-first-row-and-adopts-NAs-tp3463294p3463294.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] grid.table + splom: how to nicely align panel entries
Dear Baptiste, very nice, indeed! Two minor issues that remain, are: (1) I tried to omit the decimal dot for those numbers that do not have digits after the decimal dot. But somehow it does not work... (2) Do you know how one can decrease the text size for the text appearing in the lower panel? I tried to work with cex=0.5... but it was ignored all the time. Cheers, Marius library(lattice) library(grid) library(gridExtra) ## function for correct digit alignment align.digits - function(l){ sp - strsplit(as.character(l), \\.) chars - sapply(sp, function(x) nchar(x)[1]) n - max(chars)-chars l0 - sapply(n, function(x) paste(rep(0, x), collapse=)) sapply(seq_along(sp), function(i){ if(length(sp[[1]])==1){ as.expression(bquote(phantom(.(l0[i])) * .(sp[[i]][1]))) }else{ as.expression(bquote(phantom(.(l0[i])) * .(sp[[i]][1])*.*.(sp[[i]][2]))) } }) } ## splom with customized lower.panel ## x: data ## arr: array of containing expressions which are plotted in a grid table in the ## lower panel (i,j)] splom2 - function(x, arr, nr){ ## function for creating table table.fun - function(vec){ # vector containing lines for table for *one* panel grid.table(matrix(vec, nrow=nr, byrow=TRUE), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left, padding.h=unit(0,mm)) # justification of labels ) } ## splom splom(x, varname.cex=1.2, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) # data to be plotted with splom nr - 3 # number of rows for the panel entries nc - 3 # number of cols for the panel entries arr - array(list(rep(NA,nr*nc)), dim=c(d,d,nr*nc), dimnames=c(i,j,val)) # array containing the table entries per panel f - function(i,j) (i+j)*10 # dummy function eq - phantom()==phantom() for(i in 1:d){ for(j in 1:d){ numbers - align.digits(c(round(pi,4), round(pi, 6), f(i,j))) arr[i,j,] - c(alpha, eq, numbers[1], italic(bbb), eq, numbers[2], gamma, eq, numbers[3]) } } ## plot splom2(x, arr, nr=3) On 2011-04-20, at 11:56 , baptiste auguie wrote: On 20 April 2011 21:16, Marius Hofert m_hof...@web.de wrote: Dear expeRts, is there a way to get the entries in each panel correctly aligned according to the equality signs? Here is the wish-list: (1) the equality signs in each panel should be vertically aligned You can put the equal signs in their own column, library(gridExtra) d = matrix(c(italic(a), phantom()==phantom(), round(pi,4), italic(b), phantom()==phantom(), round(pi,6)), ncol=3, byrow=T) grid.table(d, parse=T,theme=theme.list(core.just=left)) (2) the numbers should be aligned on the decimal point You could place some phantom()s to do this, align.digits = function(l) { sp - strsplit(as.character(l), \\.) chars - sapply(sp, function(x) nchar(x)[1]) n = max(chars) - chars l0 = sapply(n, function(x) paste(rep(0, x), collapse=)) labels = sapply(seq_along(sp), function(i) { as.expression(bquote(phantom(.(l0[i])) * .(sp[[i]][1])*.*.(sp[[i]][2])))}) return(labels) } library(gridExtra) d - align.digits(l = c(125.3, 1.2344)) grid.table(d, parse=T,core.just=left) HTH, baptiste One could adjust the phantom()-arguments by hand to achieve (1), but is there a simpler solution? For (2) I have no idea. Cheers, Marius library(lattice) library(grid) library(gridExtra) ## splom with customized lower.panel ## x: data ## arr: array of containing expressions which are plotted in a grid table in the ## lower panel (i,j)] splom2 - function(x, arr){ ## function for creating table table.fun - function(vec){ # vector containing lines for table for *one* panel grid.table(matrix(vec, ncol=2, byrow=TRUE), parse=TRUE, # parse labels as expressions theme=theme.list( gpar.corefill=gpar(fill=NA, col=NA), # make bg transparent core.just=left, padding.h=unit(0,mm)) # justification of labels ) } ## splom splom(x, varname.cex=1.4, superpanel=function(z, ...){ panel.pairs(z, upper.panel=panel.splom, lower.panel=function(i,j){ table.fun(arr[i,j,]) }, ...) }) } ## create data and array of expressions d - 4 x - matrix(runif(d*1000), ncol=d) # data to be plotted with splom arr - array(list(rep(NA, 3*2)), dim=c(d,d,3*2), dimnames=c(i,j,val)) # array containing the table
Re: [R] How to get R plots with FastRweb
Devi, FastRWeb doesn't use Java - it is entirely R based so all you need is a web server with either CGI or PHP. The client it uses is either a C++ client (part of FastRWeb in the cgi-bin directory of the installed package - just copy to you server's cgi-bin) or a PHP client (in Rserve/src/client/php/simple.php - simply uncomment process_FastRWeb()). The location of the R scripts it serves is defined by PROJECT_ROOT at the time you compile FastRWeb which is by default /var/FastRWeb so by default foo.png.R would be /var/FastRWeb/web.R/foo.png.R Clearly, you could use Java to connect to the Rserve serving FastRWeb but it sort of defeats the purpose, because FastRWeb does all the work for you consisting of parsing the request and running the scripts. If you still have issues, I can point you to a sample configuration including the setup etc. (for a unix server) if that helps. Cheers, Simon PS: please use stats-rosuda-devel mailing list - I'm not monitoring R-help. On Apr 20, 2011, at 3:14 AM, MLSC MANIPAL wrote: Dear friends, I am working in a web service project which uses integration of Java with R. I have used RJava to connect with Java and that is working fine. As R produces more interactive plots, I would also like to pipe plots generate from R on web page. I came to know that FastRWeb, R2HTML, brew and WebGraphics, Cairo together can be used to do that. I have installed all those successfully. I am developing my web service project with NetBeans. For testing purpose I have used the excersie (kmeans) given in the FastRWeb document.I have put the kmeans.png.R program in my netbeansProject/R directory where other java code runs properly. student@mlscubl30:~/NetBeansProjects/R$ ls build build.xml dist kmeans.png.R nbproject src test web student@mlscubl30:~/NetBeansProjects/R$ When i try to execute it with http://localhost:8080/R/kmeans.png in browser it does not execute it. Hence can you please tell me what exactly i have to do in order to make it up and run? thanks in advance. Regards, Devi Manipal Life Sciences Center __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Unlist command drops all my column names in the first row and adopts NAs
Why not just data.matrix(UN2010) ? --- On Wed, 4/20/11, Haillie n...@princeton.edu wrote: From: Haillie n...@princeton.edu Subject: [R] Unlist command drops all my column names in the first row and adopts NAs To: r-help@r-project.org Received: Wednesday, April 20, 2011, 11:05 AM Hi Everyone, I am having trouble turning my data.frame into a matrix format. Because I wanted to change my data.frame with mostly factor variables into a numeric matrix, I used the following code -- UN2010frame-data.matrix(lapply(UN2010,as.numeric)) However when i checked the mode of the UN2010frame, it still showed up as a list. Because the code I want to run (Ordrating) does not accept data in a list format, I used UN2010matrix - unlist(UN2010frame) to unlist my matrix. When I did this, my first row ( which was formerly a row with column names) turned into NAs. This was a problem for me because when I tried to run an ordinal IRT model using this data set, I got the following error message. Error in 1:nrow(Y) : argument of length 0 I think it is because all the values in my first row are now gone If you could help me on any front, It would be deeply appreciated. Thank you very much! Haillie -- View this message in context: http://r.789695.n4.nabble.com/Unlist-command-drops-all-my-column-names-in-the-first-row-and-adopts-NAs-tp3463294p3463294.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question about symbols()
Thank you for the answer and sorry about the bad post i'll remember that in the future. By the way, the line code i used to read the data was inv - read.csv(data.csv, header=TRUE, sep=;) I tried before to use the bg, but for some reason it wasn't working out for me. But now i got it. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-about-symbols-tp3461676p3463373.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] How can I 'predict' from an nls model with a fit specified for separate groups?
Following an example on p 111 in 'Nonlinear Regression with R' by Ritz Streibig, I have been fitting nls models using square brackets with the grouping variable inside. In their book is this example, in which 'state' is a factor indicating whether a treatment has been used or not: Puromycin.m1 - nls(rate ~ Vm[state] * + conc/(K[state] + conc), data = Puromycin, + start = list(K = c(0.1, 0.1), + Vm = c(200, 200))) What I cannot figure out is how to specify the value of the grouping variable in a 'predict' statement. In my own example, I can only seem to get the predictions for the 1st specified level of the grouping variable. I promise that I have read the documentation, and have tried a number of things, but cannot get the correct predictions. Thank you for any help. Yours - Stuart -- /**/ Stuart Rosen, PhD Professor of Speech and Hearing Science UCL Speech, Hearing and Phonetic Sciences __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Test email #2: Please ignore
Having trouble posting. This is a second test email to help determine if the problem has been resolved. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Random Relabelling
Can you explain this a bit more. At the moment I don't see what you are trying to achieve. calculate the mean of the 1000 values at each of the 4000 points does not seem to make sense. --- On Wed, 4/20/11, kmatthews kevin-matth...@uiowa.edu wrote: From: kmatthews kevin-matth...@uiowa.edu Subject: [R] Random Relabelling To: r-help@r-project.org Received: Wednesday, April 20, 2011, 10:04 AM I have 4000 observations that I need to randomly relabel 1000 times and then calculate the mean of the 1000 values at each of the 4000 points. Any ideas for where to begin? Thanks Kevin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sweave
Hello, I never used Sweave before but now I try and got: rnwfile - system.file(Sweave, example-1.Rnw, package = utils) Sweave(rnwfile) Writing to file example-1.tex Processing code chunks with options ... 1 : echo term verbatim 2 : term verbatim pdf You can now run (pdf)latex on 'example-1.tex' tools::texi2dvi(example-1.tex, pdf = TRUE) Error in tools::texi2dvi(example-1.tex, pdf = TRUE) : pdflatex is not available The code is from Sweave.pdf file in utils/doc I am using R-2.13.0 in Win7 Toshiba laptop Please any help? R.Heberto Ghezzo Ph.D. Montreal - 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] Sweave
Hi, On Wed, Apr 20, 2011 at 12:11 PM, R Heberto Ghezzo, Dr heberto.ghe...@mcgill.ca wrote: Hello, I never used Sweave before but now I try and got: Have you installed LaTeX on your computer? It doesn't come installed on Windows machines by default. I would suggest MiKTeX http://www.miktex.org/ but people who use Windows more often than I do may have other ideas. Sarah rnwfile - system.file(Sweave, example-1.Rnw, package = utils) Sweave(rnwfile) Writing to file example-1.tex Processing code chunks with options ... 1 : echo term verbatim 2 : term verbatim pdf You can now run (pdf)latex on 'example-1.tex' tools::texi2dvi(example-1.tex, pdf = TRUE) Error in tools::texi2dvi(example-1.tex, pdf = TRUE) : pdflatex is not available The code is from Sweave.pdf file in utils/doc I am using R-2.13.0 in Win7 Toshiba laptop Please any help? R.Heberto Ghezzo Ph.D. Montreal - Canada __ -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Class htest with non-numeric p-values
Hi everyone, For some tests, tables of critical values are readily available while the algorithm to compute those critical values is not. In such cases, only a range for the p-value can be evaluated (e.g. 0.05 p 0.1) from the table of critical values and the statistic. Is there anyway to include that in an object of class htest? I see in print.htest() that the p.value element goes through format.pval() which expect a numeric argument. Is there any workaround? Thank you in advance. Sincerely, JiHO --- http://maururu.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two Questions
From: Stephen P Molnar s.mol...@sbcglobal.net Subject: [R] Two Questions To: R-help r-help@r-project.org Received: Wednesday, April 20, 2011, 9:23 AM 1. What is a really good book on R for a nonprogrammer? Have a look at the books listed on the R website. Books by Peter Dalgaard, Phil Spector, Michael Crawley John Verzani are all possibilities. Also haved a look at the Contributed Documentation page on the site. It has some very useful material. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] survexp with weights
Hello, I probably have a syntax error in trying to generate an expected survival curve from a weighted cox model, but I can't see it. I used the help sample code to generate a weighted model, with the addition of a weights=albumin argument (I only chose albumin because it had no missing values, not because of any real relevance). Below are my code with the resulting error messages. Thanks in advance! pfit - coxph(Surv(time,status0) ~ trt + log(bili) + log(protime) + age + + + platelet, data=pbc + ) pfit Call: coxph(formula = Surv(time, status 0) ~ trt + log(bili) + log(protime) + age + +platelet, data = pbc) coef exp(coef) se(coef)z p trt -0.000624 0.999 0.17304 -0.00360 1. log(bili) 0.985497 2.679 0.08949 11.01262 0. log(protime) 2.79400116.346 0.95289 2.93215 0.0034 age 0.020590 1.021 0.00805 2.55666 0.0110 platelet -0.001699 0.998 0.00085 -2.00130 0.0450 Likelihood ratio test=164 on 5 df, p=0 n= 308, number of events= 143 (110 observations deleted due to missingness) plot(survfit(Surv(time, status0) ~ trt, data=pbc)) lines(survexp( ~ trt, ratetable=pfit, data=pbc), col='purple') pfit.wtd - coxph(Surv(time,status0) ~ trt + log(bili) + log(protime) + age + + + platelet, weights=albumin, data=pbc + ) pfit.wtd Call: coxph(formula = Surv(time, status 0) ~ trt + log(bili) + log(protime) + age + +platelet, data = pbc, weights = albumin) coef exp(coef) se(coef) z p trt -0.01354 0.987 0.094204 -0.144 8.9e-01 log(bili) 0.99282 2.699 0.048690 20.391 0.0e+00 log(protime) 2.5413612.697 0.525797 4.833 1.3e-06 age 0.01913 1.019 0.004398 4.350 1.4e-05 platelet -0.00165 0.998 0.000462 -3.578 3.5e-04 Likelihood ratio test=535 on 5 df, p=0 n= 308, number of events= 143 (110 observations deleted due to missingness) plot(survfit(Surv(time, status0) ~ trt, data=pbc)) lines(survexp( ~ trt, ratetable=pfit.wtd, data=pbc), col='purple') Error in eval(expr, envir, enclos) : object 'albumin' not found lines(survexp( ~ trt, ratetable=pfit.wtd, weights=albumin, data=pbc), col='purple') Error in eval(expr, envir, enclos) : object 'albumin' not found In addition: Warning message: In survexp(~trt, ratetable = pfit.wtd, weights = albumin, data = pbc) : Weights ignored lines(survexp( ~ trt, ratetable=pfit.wtd, weights=pbc$albumin, data=pbc), col='purple') Error in eval(expr, envir, enclos) : object 'albumin' not found In addition: Warning message: In survexp(~trt, ratetable = pfit.wtd, weights = pbc$albumin, data = pbc) : Weights ignored __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Partial Least Squares Regression independent variables
Hi, I'm running PLSR on the PLS package. I have 507 independent and one dependent variable. model-plsr(y~x1+x2+x3.., data = mydata, validation = CV) the problem with this is writing in 507 variable names is not realistic as I run out of line space in the command window. I cannot run the model thus: model-plsr(dataframeY~dataframeX...) as is it is specifically warned against in the documentation. In the example the independent variables have been collated and are represented by a single name (NIR, represents numerous variables labelled NIR.1, NIR,2 etc). Can anyone advise on how this is done? Thanks Tommy McDermott -- View this message in context: http://r.789695.n4.nabble.com/Partial-Least-Squares-Regression-independent-variables-tp3463478p3463478.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] Fibonacci
Thank-you all!! Very helpful. -- Forwarded message -- From: Bart Joosen bartjoo...@hotmail.com Date: 20 April 2011 15:46 Subject: Re: [R] Fibonacci To: r-help@r-project.org Another solution: while (Fibonacci[1] 500) Fibonacci - c(sum(Fibonacci[c(1,2)]), Fibonacci) While this adds the sum before the existing values, the length or tail function or avoided, but even with reordering, its faster (Fibonacci[length(Fibonacci):1]) Best regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Fibonacci-tp3462636p3463050.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.htmlhttp://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] 'Record' row values every time the binary value in a collumn changes
Here is an answer to part 1: binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) # determine where the start/end of each group is # use indices since the size is large startEnd - lapply(split(seq(nrow(Table)) + , list(Table[, Chromosome], Table[, 'binary']) + , drop = TRUE + ) + , function(.indx){ + se - range(.indx) + c(Chromosome2 = unname(Table[se[1L], Chromosome]) + , position_start = unname(Table[se[1L], 'start']) + , position_end = unname(Table[se[2L], 'start']) + , binary2 = unname(Table[se[1L], 'binary']) + ) + }) do.call(rbind, startEnd) Chromosome2 position_start position_end binary2 1.0 1 20 36 0 2.0 2 17 19 0 1.1 1 12 18 1 2.1 2 12 16 1 On Wed, Apr 20, 2011 at 5:01 AM, baboon2010 nielsvande...@live.be wrote: My question is twofold. Part 1: My data looks like this: (example set, real data has 2*10^6 rows) binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) Chromosome start binary [1,] 1 12 1 [2,] 1 17 1 [3,] 1 18 1 [4,] 1 20 0 [5,] 1 25 0 [6,] 1 36 0 [7,] 2 12 1 [8,] 2 15 1 [9,] 2 16 1 [10,] 2 17 0 [11,] 2 19 0 As output I need a shortlist for each binary block: giving me the starting and ending position of each block. Which for these example would look like this: Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Part 2: Based on the output of part 1, I need to assign the binary to rows of another data set. If the position value in this second data set falls in one of the blocks defined in the shortlist made in part1,the binary value of the shortlist should be assigned to an extra column for this row. This would look something like this: Chromosome3 position Value binary3 [1,] 1 12 a 1 [2,] 1 13 b 1 [3,] 1 14 c 1 [4,] 1 15 d 1 [5,] 1 16 e 1 [6,] 1 18 f 1 [7,] 1 20 g 0 [8,] 1 21 h 0 [9,] 1 22 i 0 [10,] 1 23 j 0 [11,] 1 25 k 0 [12,] 1 35 l 0 [13,] 2 12 m 1 [14,] 2 13 n 1 [15,] 2 14 o 1 [16,] 2 15 p 1 [17,] 2 16 q 1 [18,] 2 17 s 0 [19,] 2 18 d 0 [20,] 2 19 f 0 Many thanks in advance, Niels -- View this message in context: http://r.789695.n4.nabble.com/Record-row-values-every-time-the-binary-value-in-a-collumn-changes-tp3462496p3462496.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. -- Jim Holtman Data Munger Guru What is the problem that 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.
[R] Expanding a VCV Matrix
Dear all, I have special task to expand a given VCV matrix, however could not accomplice yet. Let say I have following VCV matrix mat - matrix(c(1,2,0,2,5,0.5,0,0.5,3), 3, 3) colnames(mat) - rownames(mat) - paste(variable, 1:3) mat variable 1 variable 2 variable 3 variable 1 12.00.0 variable 2 25.00.5 variable 3 00.53.0 Now, say I have a general string vector like this: Str - c(paste(variable, 1:4), variable2) Str [1] variable 1 variable 2 variable 3 variable 4 variable 2 Now according to this string, I want my previous VCV matrix also expands. Therefore, as variable 4 is not there in VCV matrix, so it will be ignored. Therefore final VCV matrix will be of order 4, and will look like: variable 1 variable 2 variable 3 variable 2 variable 1 1 2 0 2 variable 2 2 5 0.5 5 variable 3 0 0.5 3 0.5 variable 2 2 5 0.5 5 However, I do not think it is just some straightforward expansion, which could be done just by the subsetting mechanism of R. Is there any idea on how can I do it for general case? Thanks for your time, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 'Record' row values every time the binary value in acollumn changes
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman Sent: Wednesday, April 20, 2011 9:59 AM To: baboon2010 Cc: r-help@r-project.org Subject: Re: [R] 'Record' row values every time the binary value in acollumn changes Here is an answer to part 1: binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) # determine where the start/end of each group is # use indices since the size is large startEnd - lapply(split(seq(nrow(Table)) + , list(Table[, Chromosome], Table[, 'binary']) + , drop = TRUE + ) + , function(.indx){ + se - range(.indx) + c(Chromosome2 = unname(Table[se[1L], Chromosome]) + , position_start = unname(Table[se[1L], 'start']) + , position_end = unname(Table[se[2L], 'start']) + , binary2 = unname(Table[se[1L], 'binary']) + ) + }) do.call(rbind, startEnd) Chromosome2 position_start position_end binary2 1.0 1 20 36 0 2.0 2 17 19 0 1.1 1 12 18 1 2.1 2 12 16 1 The following will likely be quicker way to find where a column changes values than that lapply() when there are lots of rows: f1 - function (Table) { isFirstInRun - function(x) c(TRUE, x[-1] != x[-length(x)]) isLastInRun - function(x) c(x[-1] != x[-length(x)], TRUE) with(data.frame(Table), { first - isFirstInRun(binary) last - isLastInRun(binary) cbind(Chromosome2 = Chromosome[first], position_start = start[first], position_end = start[last], binary2 = binary[first]) }) } E.g., f1(Table) Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com On Wed, Apr 20, 2011 at 5:01 AM, baboon2010 nielsvande...@live.be wrote: My question is twofold. Part 1: My data looks like this: (example set, real data has 2*10^6 rows) binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) Chromosome start binary [1,] 1 12 1 [2,] 1 17 1 [3,] 1 18 1 [4,] 1 20 0 [5,] 1 25 0 [6,] 1 36 0 [7,] 2 12 1 [8,] 2 15 1 [9,] 2 16 1 [10,] 2 17 0 [11,] 2 19 0 As output I need a shortlist for each binary block: giving me the starting and ending position of each block. Which for these example would look like this: Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Part 2: Based on the output of part 1, I need to assign the binary to rows of another data set. If the position value in this second data set falls in one of the blocks defined in the shortlist made in part1,the binary value of the shortlist should be assigned to an extra column for this row. This would look something like this: Chromosome3 position Value binary3 [1,] 1 12 a 1 [2,] 1 13 b 1 [3,] 1 14 c 1 [4,] 1 15 d 1 [5,] 1 16 e 1 [6,] 1 18 f 1 [7,] 1 20 g 0 [8,] 1 21 h 0 [9,] 1 22 i 0 [10,] 1 23 j 0 [11,] 1 25 k 0 [12,] 1 35 l 0 [13,] 2 12 m 1 [14,] 2 13 n 1 [15,] 2 14 o 1 [16,] 2 15 p 1 [17,] 2 16 q 1 [18,] 2 17 s 0 [19,] 2 18 d 0 [20,] 2 19 f 0 Many thanks in advance, Niels -- View this message in context: http://r.789695.n4.nabble.com/Record-row-values-every-time-the -binary-value-in-a-collumn-changes-tp3462496p3462496.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can I 'predict' from an nls model with a fit specified for separate groups?
On Apr 20, 2011, at 17:04 , Stuart Rosen wrote: Following an example on p 111 in 'Nonlinear Regression with R' by Ritz Streibig, I have been fitting nls models using square brackets with the grouping variable inside. In their book is this example, in which 'state' is a factor indicating whether a treatment has been used or not: Puromycin.m1 - nls(rate ~ Vm[state] * + conc/(K[state] + conc), data = Puromycin, + start = list(K = c(0.1, 0.1), + Vm = c(200, 200))) What I cannot figure out is how to specify the value of the grouping variable in a 'predict' statement. In my own example, I can only seem to get the predictions for the 1st specified level of the grouping variable. I promise that I have read the documentation, and have tried a number of things, but cannot get the correct predictions. What's the problem? If I continue your example with plot(Puromycin$conc, predict(Puromycin.m1), col=(1:2)[Puromycin$state]) I get a black and a red set of points, distinctly different. It's difficult to say what you did wrong in the number of things that you tried, but I suspect you didn't set up your newdata properly: myconc - seq(0,1.2,,11) lv - levels(Puromycin$state) predict(Puromycin.m1, newdata=data.frame(conc=myconc,state=factor(untreated,levels=lv))) [1] 0. 114.6850 133.7022 141.5248 145.7897 148.4743 150.3196 151.6661 [9] 152.6918 153.4993 154.1514 predict(Puromycin.m1, newdata=data.frame(conc=myconc,state=factor(treated,levels=lv))) [1] 0. 138.6154 167.8413 180.5289 187.6203 192.1490 195.2916 197.6000 [9] 199.3674 200.7641 201.8956 -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 'Record' row values every time the binary value in a collumn changes
Hi: Here are a couple more options using packages plyr and data.table. The labels in the second part are changed because they didn't make sense in a 2M line file (well, mine may not either, but it's a start). You can always change them to something more pertinent. # Question 1: Table - data.frame(binary, chromosome = Chromosome, start) library(plyr) (df - ddply(Table, .(chromosome, binary), summarise, position_start = min(start), position_end = max(start))) chromosome binary position_start position_end 1 1 0 20 36 2 1 1 12 18 3 2 0 17 19 4 2 1 12 16 library(data.table) dTable - data.table(Table, key = 'chromosome, binary') (dt - dTable[, list(position_start = min(start), position_end = max(start)), by = 'chromosome, binary']) chromosome binary position_start position_end [1,] 1 0 20 36 [2,] 1 1 12 18 [3,] 2 0 17 19 [4,] 2 1 12 16 ## Question 2: For plyr, it's easy to write a function that takes a generic input data frame (in this case, a single line) and then outputs a data frame with positions and labels. tfun - function(df) { diff - with(df, position_end - position_start + 1) position - with(df, seq(position_start, position_end)) value - paste(df$chromosome, df$binary, letters[1:diff], sep = '.') data.frame(chromosome = df$chromosome, position, value, binary = df$binary) } # Then: ddply(df, .(chromosome, binary), tfun) chromosome position value binary 1 1 20 1.0.a 0 2 1 21 1.0.b 0 3 1 22 1.0.c 0 4 1 23 1.0.d 0 5 1 24 1.0.e 0 6 1 25 1.0.f 0 7 1 26 1.0.g 0 8 1 27 1.0.h 0 9 1 28 1.0.i 0 10 1 29 1.0.j 0 11 1 30 1.0.k 0 12 1 31 1.0.l 0 13 1 32 1.0.m 0 14 1 33 1.0.n 0 15 1 34 1.0.o 0 16 1 35 1.0.p 0 17 1 36 1.0.q 0 18 1 12 1.1.a 1 19 1 13 1.1.b 1 20 1 14 1.1.c 1 21 1 15 1.1.d 1 22 1 16 1.1.e 1 23 1 17 1.1.f 1 24 1 18 1.1.g 1 25 2 17 2.0.a 0 26 2 18 2.0.b 0 27 2 19 2.0.c 0 28 2 12 2.1.a 1 29 2 13 2.1.b 1 30 2 14 2.1.c 1 31 2 15 2.1.d 1 32 2 16 2.1.e 1 # For data.table, one can apply the internals of tfun directly: dt[, list(chromosome = chromosome, position = seq(position_start, position_end), value = paste(chromosome, binary, letters[1:(position_end - position_start + 1)], sep = '.'), binary = binary), by = 'chromosome, binary'] chromosome binary chromosome.1 position value binary.1 1 01 20 1.0.a0 1 01 21 1.0.b0 1 01 22 1.0.c0 1 01 23 1.0.d0 1 01 24 1.0.e0 1 01 25 1.0.f0 1 01 26 1.0.g0 1 01 27 1.0.h0 1 01 28 1.0.i0 1 01 29 1.0.j0 1 01 30 1.0.k0 1 01 31 1.0.l0 1 01 32 1.0.m0 1 01 33 1.0.n0 1 01 34 1.0.o0 1 01 35 1.0.p0 1 01 36 1.0.q0 1 11 12 1.1.a1 1 11 13 1.1.b1 1 11 14 1.1.c1 1 11 15 1.1.d1 1 11 16 1.1.e1 1 11 17 1.1.f1 1 11 18 1.1.g1 2 02 17 2.0.a0 2 02 18 2.0.b0 2 02 19 2.0.c0 2 12 12 2.1.a1 2 12 13 2.1.b1 2 12 14
Re: [R] Two Questions
When running a large number of commands from a script that produces multiple plots it is often best to send the plots to the pdf device (or other system) that you can then page through after it is finished. You could also specify par(ask=TRUE) then you would be prompted before changing the plot (but other code would not execute either). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Stephen P Molnar Sent: Wednesday, April 20, 2011 7:23 AM To: R-help Subject: [R] Two Questions Sorry for the somewhat nondescript subject line, but I have two questions: 1.What is a really good book on R for a nonprogrammer? 2. How do I open more than one R Graphics: Device 2(ACTIVE). That what is the R command that I can use to keep more than one plot open. I am running a script from a book on Chemometrics that results in more than one graph during the execution, but it seems that R deletes each graph when the script calls for the next plot. Thanks in advance Stephen P. Molnar, Ph.D. Life is a fuzzy set Foundation for Chemistry Stochastic and multivariate http://www.FoundationForChemistry.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 'Record' row values every time the binary value in a collumn changes
Here's one way to do part 1: rr = rle(Table[,'binary']) cc = cumsum(rr$lengths)+1 thestarts = c(1,cc[cc=nrow(Table)]) theends = cc-1 answer = cbind(Table[thestarts,'Chromosome'],Table[thestarts,'start'],Table[theends,'start'],rr$values) answer [,1] [,2] [,3] [,4] [1,]1 12 181 [2,]1 20 360 [3,]2 12 161 [4,]2 17 190 If I understand you correctly, here's a way to do part 2: Next = matrix(c(rep(1,12),rep(2,8),c(12,13,14,15,16,18,20,21,22,23,25,35,12,13,14,15,16,17,18,19)),ncol=2) apply(Next,1,function(x)answer[answer[,1]==x[1] x[2] = answer[,2] x[2] = answer[,3],4]) [1] 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Wed, Apr 20, 2011 at 5:01 AM, baboon2010 nielsvande...@live.be wrote: My question is twofold. Part 1: My data looks like this: (example set, real data has 2*10^6 rows) binary-c(1,1,1,0,0,0,1,1,1,0,0) Chromosome-c(1,1,1,1,1,1,2,2,2,2,2) start-c(12,17,18,20,25,36,12,15,16,17,19) Table-cbind(Chromosome,start,binary) Chromosome start binary [1,] 1 12 1 [2,] 1 17 1 [3,] 1 18 1 [4,] 1 20 0 [5,] 1 25 0 [6,] 1 36 0 [7,] 2 12 1 [8,] 2 15 1 [9,] 2 16 1 [10,] 2 17 0 [11,] 2 19 0 As output I need a shortlist for each binary block: giving me the starting and ending position of each block. Which for these example would look like this: Chromosome2 position_start position_end binary2 [1,] 1 12 18 1 [2,] 1 20 36 0 [3,] 2 12 16 1 [4,] 2 17 19 0 Part 2: Based on the output of part 1, I need to assign the binary to rows of another data set. If the position value in this second data set falls in one of the blocks defined in the shortlist made in part1,the binary value of the shortlist should be assigned to an extra column for this row. This would look something like this: Chromosome3 position Value binary3 [1,] 1 12 a 1 [2,] 1 13 b 1 [3,] 1 14 c 1 [4,] 1 15 d 1 [5,] 1 16 e 1 [6,] 1 18 f 1 [7,] 1 20 g 0 [8,] 1 21 h 0 [9,] 1 22 i 0 [10,] 1 23 j 0 [11,] 1 25 k 0 [12,] 1 35 l 0 [13,] 2 12 m 1 [14,] 2 13 n 1 [15,] 2 14 o 1 [16,] 2 15 p 1 [17,] 2 16 q 1 [18,] 2 17 s 0 [19,] 2 18 d 0 [20,] 2 19 f 0 Many thanks in advance, Niels -- View this message in context: http://r.789695.n4.nabble.com/Record-row-values-every-time-the-binary-value-in-a-collumn-changes-tp3462496p3462496.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. -- Jim Holtman Data Munger Guru What is the problem that 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Random Relabelling
There is probably a better way to do this but a for loop like this should work. You would just need to change the numbers to yours and then add on the locations = scores - 1:5 mydata - matrix(data=NA, nrow=5, ncol=10) for(i in 1:10) { mydata[,i] - sample(scores, 5, replace=FALSE) } = --- On Wed, 4/20/11, Kevin Matthews kevin-matth...@uiowa.edu wrote: From: Kevin Matthews kevin-matth...@uiowa.edu Subject: Re: [R] Random Relabelling To: John Kane jrkrid...@yahoo.ca Cc: r-help@r-project.org Received: Wednesday, April 20, 2011, 1:22 PM I have a map of Iowa of with 4000 locations. At each location, I have a cancer mortality rate. I need to test my null hypothesis; that the spatial distribution of the mortality rates is random. For this test, I need to establish a spatial reference distribution. My reference distribution will be created by some random relabelling algorithm. The 4000 locations would remain fixed, but the observed mortality rates would be randomly redistributed. Then, I want 1000 permutations of the same algorithm. For each of those 1000 times, I would record the redistributed mortality rate at each location. Then, I would calculate the mean of the 1000 points. The result would be a spatial reference distribution with a mean value of the random permutations at each of the 4000 locations. Thanks for the response,Kevin On Wed, Apr 20, 2011 at 11:08 AM, John Kane jrkrid...@yahoo.ca wrote: Can you explain this a bit more. At the moment I don't see what you are trying to achieve. calculate the mean of the 1000 values at each of the 4000 points does not seem to make sense. --- On Wed, 4/20/11, kmatthews kevin-matth...@uiowa.edu wrote: From: kmatthews kevin-matth...@uiowa.edu Subject: [R] Random Relabelling To: r-help@r-project.org Received: Wednesday, April 20, 2011, 10:04 AM I have 4000 observations that I need to randomly relabel 1000 times and then calculate the mean of the 1000 values at each of the 4000 points. Any ideas for where to begin? Thanks Kevin [[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] Matrix package transpose
On Wed, Apr 20, 2011 at 8:37 AM, Tobias Abenius tobias.aben...@chalmers.se wrote: Since I installed R 2.13 I cannot use the transpose method t on sparse matrices inside my package. Outside the package works. Is there something new that I have to import methods? Can I then import everything from the Matrix package? The problem is that R tries to use t.default which of course doesn't work. As the tag line on each message says: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Please provide an example. It will also help to include the output of sessionInfo() so we can determine exactly which version of R and the Matrix package you are using on what platform. Also try find(t) [1] package:Matrix package:base to see which version of t is the first on the search path. It seems to still be working for me, but outside the package. library(Matrix) Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det sessionInfo() R version 2.13.0 (2011-04-13) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Matrix_0.9996875-0 lattice_0.19-17 loaded via a namespace (and not attached): [1] grid_2.13.0 example(spMatrix) ... output omitted A 10 x 20 sparse Matrix of class dgTMatrix [1,] . 7 . . . . . . . . . . . . . . . . . . [2,] . . . . . . . . . . . . . . . . . . . . [3,] . . . . . . . . 14 . . . . . . . . . . . [4,] . . . . . 21 . . . . . . . . . . . . . . [5,] . . . . . . 28 . . . . . . . . . . . . . [6,] . . . . . . . 35 . . . . . . . . . . . . [7,] . . . . . . . . 42 . . . . . . . . . . . [8,] . . . . . . . . . 49 . . . . . . . . . . [9,] . . . . . . . . . . . . . . . . . . . . [10,] . . . . . . . . . . . . . . . . . . . . t(A) 20 x 10 sparse Matrix of class dgTMatrix [1,] . . . . . . . . . . [2,] 7 . . . . . . . . . [3,] . . . . . . . . . . [4,] . . . . . . . . . . [5,] . . . . . . . . . . [6,] . . . 21 . . . . . . [7,] . . . . 28 . . . . . [8,] . . . . . 35 . . . . [9,] . . 14 . . . 42 . . . [10,] . . . . . . . 49 . . [11,] . . . . . . . . . . [12,] . . . . . . . . . . [13,] . . . . . . . . . . [14,] . . . . . . . . . . [15,] . . . . . . . . . . [16,] . . . . . . . . . . [17,] . . . . . . . . . . [18,] . . . . . . . . . . [19,] . . . . . . . . . . [20,] . . . . . . . . . . __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Random Relabelling
Kevin, The following follows John's suggestion, but without the loop. It's quick for me. Jeremy Jeremy T. Hetzel Boston University ## Generate sample data n - 4000 rep - 1000 rate - rnorm(n, mean = 15, sd = 2) / 10 # Mortality rates around 15/100k ## Create an empty matrix with appropriate dimensions permutations - matrix(ncol = n, nrow = rep) ## Use apply() to resample permutations - apply(permutations, 1, function(x) { sample(rate, size = n, replace = F) }) ## Look at the matrix dim(permutations) head(permutations) ## Find the column means means - apply(permutations, 1, mean) means On Wednesday, April 20, 2011 1:56:35 PM UTC-4, John Kane wrote: There is probably a better way to do this but a for loop like this should work. You would just need to change the numbers to yours and then add on the locations = scores - 1:5 mydata - matrix(data=NA, nrow=5, ncol=10) for(i in 1:10) { mydata[,i] - sample(scores, 5, replace=FALSE) } = --- On Wed, 4/20/11, Kevin Matthews kevin-m...@uiowa.edu wrote: From: Kevin Matthews kevin-m...@uiowa.edu Subject: Re: [R] Random Relabelling To: John Kane jrkr...@yahoo.ca Cc: r-h...@r-project.org Received: Wednesday, April 20, 2011, 1:22 PM I have a map of Iowa of with 4000 locations. At each location, I have a cancer mortality rate. I need to test my null hypothesis; that the spatial distribution of the mortality rates is random. For this test, I need to establish a spatial reference distribution. My reference distribution will be created by some random relabelling algorithm. The 4000 locations would remain fixed, but the observed mortality rates would be randomly redistributed. Then, I want 1000 permutations of the same algorithm. For each of those 1000 times, I would record the redistributed mortality rate at each location. Then, I would calculate the mean of the 1000 points. The result would be a spatial reference distribution with a mean value of the random permutations at each of the 4000 locations. Thanks for the response,Kevin On Wed, Apr 20, 2011 at 11:08 AM, John Kane jrkr...@yahoo.ca wrote: Can you explain this a bit more. At the moment I don't see what you are trying to achieve. calculate the mean of the 1000 values at each of the 4000 points does not seem to make sense. --- On Wed, 4/20/11, kmatthews kevin-m...@uiowa.edu wrote: From: kmatthews kevin-m...@uiowa.edu Subject: [R] Random Relabelling To: r-h...@r-project.org Received: Wednesday, April 20, 2011, 10:04 AM I have 4000 observations that I need to randomly relabel 1000 times and then calculate the mean of the 1000 values at each of the 4000 points. Any ideas for where to begin? Thanks Kevin [[alternative HTML version deleted]] __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Crouts algorithm
R-listers Quick question for the group. Is there any LU decomposition that makes use of Crout's algorithm in R. I've been looking for it and I really haven't seen it among the R packages. A -- Adrienne Wootten Graduate Research Assistant State Climate Office of North Carolina Department of Marine, Earth and Atmospheric Sciences North Carolina State University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] polynomial question
Dear R People: Suppose I have (x-1)*(x-2) and would like to produce x^2 - 3x + 2. I have tried polynomial(c(1,1)*c(2,1)) 2 + x from the polynom library, but as you can see, that doesn't do it. Is there a function to do this please? I'm sure that I've done this before, but I can't remember the correct way. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Polynomial question solved.
Dear R People: Here is the solution: polynomial(c(-2,1))*polynomial(c(-1,1)) 2 - 3*x + x^2 Sorry for the trouble. Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.