[R] preallocating matrices and rda read-back objects
I've read in Phil Spector's new book that it's a good idea to preallocate a big matrix, like u - matrix(0,nrow,ncol) # (1) Now, I read contents of a huge matrix from a Fortran binary dump. u - readBin(con,what=double,n=nrow*ncol) # (2) If I do (1) and then (2), u is a vector, obviously it's either reallocated or its matrix nature is lost -- overridden? overwritten? Instead, I do it now as u - matrix(readBin(con,what=double,n=nrow*ncol),nrow=nrow,ncol=ncol) # (3) What's going on with memory management here and what's the right way to make it efficient -- and how to preallocate? After that, I'm saving u as R binary object in an rda file. Does it make sense to preallocate u before reading it back now from the rda file? Cheers, Alexy __ 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] Correlation between two multi-dimensional matrices
Hi, Are there any methods for computing the correlation between two multi-dimensional matrices ? Will transforming the matrices into vectors and applying pearson be fine ? Any blind spots that I should be aware ? Thanks Stanley [[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] chi-square test
On Tuesday 08 April 2008 17:04:16 Roslina Zakaria wrote: Hi R-users, I would like to find the goodness of fit using Chi-suare test for my data below: xobs=observed data, xtwe=predicted data using tweedie, xgam=predicted data using gamma xobs - c(223,46,12,5,7,17) xtwe - c(217.33,39,14,18.33,6.67,14.67) xgam - c(224.67,37.33,12.33,15.33,5.33,15) chisq.test(xobs, xtwe = xtwe, rescale.p = TRUE) Error in chisq.test(xobs, xtwe = xtwe, rescale.p = TRUE) : unused argument(s) (xtwe = c(217.33, 39, 14, 18.33, 6.67, 14.67)) chisq.test(x, p = p, rescale.p = TRUE) I'm not sure what's wrong with it. Thank you so much for your help. Try this instead: chisq.test(xobs, p=xtwe, rescale.p = TRUE) The help file might be a little obscure. JWDougherty __ 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] distance matrix as text file - how to import?
On Tue, Apr 8, 2008 at 1:50 PM, Hans-Jörg Bibiko [EMAIL PROTECTED] wrote: I was sent a text file containing a distance matrix à la: 1 2 3 4 5 6 Thanks a lot for your hints. At the end all hints ends up more or less in my stony way to do it. Let me summarize it. The clean way is to initialize a matrix containing my distance matrix and generate a dist object by using as.dist(mat). Fine. But how to read the text data (triangular) into a matrix? #1 approach - using 'read.table' mat = read.table(test.txt, fill=T) The problem here is that the first line doesn't contain the correct number of columns of my matrix, thus 'read.table' sets the number of columns to 5 as default. Ergo I have to know the number of columns (num_cols) in beforehand in order to do this: mat = read.table(test.txt, fill=T, col.names=rep('', num_cols)) Per definitionem the last line of test.txt contains the correct number of columns. On a UNIX/Mac you can do the following: num_cols - as.numeric(system(tail -n 1 'test.txt' | wc - w,intern=TRUE)) In other words, read the last line of 'test.txt' and count the number of words if the delimiter is a space. Or one could use 'readLines' and split the last array element to get num_cols. #2 approach - using 'scan()' mat = matrix(0, num_cols, num_cols) mat[row(mat) = col(mat)] - scan(test.txt) But this also leads to my problem: 1 2 4 3 5 6 instead of 1 2 3 4 5 6 one solution The approach #2 has two advantages: it's faster than read.table AND I can calculate num_cols. The only problem is the correct order. But this is solvable via: reading the data into the upper triangle and transpose the matrix mat - matrix(0, num_cols, num_cols) mat[row(mat) = col(mat)] - scan(test.txt) mat - t(mat) Next. If I know that my text file really contains a distance matrix (i.e. the diagonals have been removed) then I can do the following: data - scan(test.txt) num_cols - (1 + sqrt(1 + 8*length(data)))/2 - 1 mat - matrix(0, num_cols, num_cols) mat[row(mat) = col(mat)] - data mat - t(mat) #Finally to get a 'dist' object: mat - rbind(0, mat) mat - cbind(mat, 0) dobj - as.dist(mat) Again, thanks a lot! --Hans __ 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] Replace values according to conditions
Greetings R-users, I have the following data called mydata in a data.frame Col1 Col2 Col3 Col4 Col5 1 2 46 7 8 8 73 5 4 4 56 7 I want to replace the data according to the following conditions Condition 1 if data = 3, replace with -1 Condition 2 if data =6, replace with 1 Condition 3if data = 4 or data =5, replace with 0 So the expected output for the example, would be Col1 Col2 Col3 Col4 Col5 -1 -1 0 1 1 1 1 1 -1 0 0 0 11 1 I have thought of using replace with each conditions, for example I tried the following myrep - replace(mydata, mydat = 3, -1 ) #Condition 1 I would have to repeat the function replace for each of the conditions to get the expected output. My questions are: 1. I would like to know if there are better ways to achieve the expected output? 2. What are the symbols for OR and AND in R? Thanks for any feedback -- Suhaila Zainudin [[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] Replace values according to conditions
I have the following data called mydata in a data.frame Col1 Col2 Col3 Col4 Col5 1 2 46 7 8 8 73 5 4 4 56 7 I want to replace the data according to the following conditions Condition 1 if data = 3, replace with -1 Condition 2 if data =6, replace with 1 Condition 3if data = 4 or data =5, replace with 0 So the expected output for the example, would be Col1 Col2 Col3 Col4 Col5 -1 -1 0 1 1 1 1 1 -1 0 0 0 11 1 ... 1. I would like to know if there are better ways to achieve the expected output? mydata[mydata=3] = -1 mydata[mydata==4 | mydata==5] = 0 mydata[mydata=6] = 1 See the Intro to R, section 2.7. 2. What are the symbols for OR and AND in R? There are two versions: | and that do elementwise logical comparisons on vectors; and || and that are quicker for scalar logical comparisons (mostly used in 'if' statement conditions). See the Intro to R, section 2.4 and 9.2.1. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped: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.
[R] publish R on gotAPI ?
I recently stumbled across www.gotAPI.com which is a really nice site to lookup infos of many different languages. - Wouldn't it be a good idea to submit a request to add R? -- Regards, Hans-Peter [[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] fuzzy merge
Hi, I would like to merge two data frames. It is just that I want the merging to be done with some kind of a fuzzy criterion. Let me explain. My first data frame looks like this : ID1 time1dt 12008-01-02 13:1110 22008-01-02 14:2020 32008-01-02 15:4230 42008-01-02 16:4540 52008-01-02 17:4250 62008-01-02 20:4060 My second data frame : ID2time2d1 1012008-01-02 14:2975 1022008-01-02 17:55105 1032008-02-07 20:018 I want the merging to be done such that time2 is in the range between time1 and (time1+15 min). That is, my merged data frame should be : ID1 time1time2 22008-01-02 14:202008-01-02 14:29 52008-01-02 17:422008-01-02 17:55 My data frames have thousands of records. If the two data frames are d1 and d2, d3-merge(d1,d2,by.x=time1,by.y=time2) will work only for exact matching. One possible option is to match the times for the date and hour times only (by filtering away the minute data). But this is only a partial solution as I am not interested in data where the time difference is more than 15 minutes. How can I make the merge to work for fuzzy matching? Would it be easier to convert the times into data classes? Or, it better to treat them as strings and use regular expresssions for doing the matching? I would appreciate any help that I can get. Thanking You, Ravi __ 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 with basic boolean selection in sequence
I have a surprising problem while selecting values in a sequence created with the seq() function... ... test2-seq(from=0,to=1,by=.1) ... test2==0.3 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE ... Does anyones has an explanation and a solution ? I suspect that this is a problem with floating point rounding errors. The values in test2 are not exactly what you requested: format(test2, nsmall=20) #[1] 0. 0.1555 0.20001110 #[4] 0.30004441 0.40002220 0.5000 #[7] 0.60008882 0.70006661 0.80004441 #[10] 0.90002220 1. A workaround is to check that the difference between test2 and the target value is very small: abs(test2 - .3) .Machine$double.eps # [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped: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.
[R] R: Replace values according to conditions
A short way (not necessairly the best way), using the coercion from logical to numeric, could be: (mydata-as.data.frame(matrix(sample(1:9, 12, repl=T), ncol=4))) -1*(mydata =3) + (mydata =6) For the second question start here: help(Logic, package=base) Stefano -Messaggio originale- Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] conto di Suhaila Zainudin Inviato: mercoledì 9 aprile 2008 9.32 A: r-help@r-project.org Oggetto: [R] Replace values according to conditions Greetings R-users, I have the following data called mydata in a data.frame Col1 Col2 Col3 Col4 Col5 1 2 46 7 8 8 73 5 4 4 56 7 I want to replace the data according to the following conditions Condition 1 if data = 3, replace with -1 Condition 2 if data =6, replace with 1 Condition 3if data = 4 or data =5, replace with 0 So the expected output for the example, would be Col1 Col2 Col3 Col4 Col5 -1 -1 0 1 1 1 1 1 -1 0 0 0 11 1 I have thought of using replace with each conditions, for example I tried the following myrep - replace(mydata, mydat = 3, -1 ) #Condition 1 I would have to repeat the function replace for each of the conditions to get the expected output. My questions are: 1. I would like to know if there are better ways to achieve the expected output? 2. What are the symbols for OR and AND in R? Thanks for any feedback -- Suhaila Zainudin [[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] problem with basic boolean selection in sequence
Dear R users, I have a surprising problem while selecting values in a sequence created with the seq() function... I've tried a lot of test before sending this here and hope I did not disturb you for a foolish mistake from me Please, have a look at the following lines: #___ test2-seq(from=0,to=1,by=.1) test2 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 test2==1 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE test2==0.9 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE test2==0.8 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE test2==0.7 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.6 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE test2==0.4 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.3 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.2 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.1 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.0 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE # there is a problem with values 0.3, 0.6 and 0.7 impossible to select in such a vector... # the same thing happens with other sequence including somme of these values test3-seq(from=0,to=1,by=0.01) test3 test3==0.3 # not working test3==0.6 # working test3==0.7 # not working # Does anyones has an explanation and a solution ? Kind regards Ben [[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] Correlation between two multi-dimensional matrices
Ng Stanley stanleyngkl at gmail.com writes: Hi, Are there any methods for computing the correlation between two multi-dimensional matrices ? Will transforming the matrices into vectors and applying pearson be fine ? Any blind spots that I should be aware ? If they were something like multi-dimensional correlation matrices (i.e., the elements weren't all independent) then you might want to do something like implementing a multidimensional Mantel test ... Ben Bolker __ 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] preallocating matrices and rda read-back objects
Alexy Khrabrov wrote: I've read in Phil Spector's new book that it's a good idea to preallocate a big matrix, like u - matrix(0,nrow,ncol) # (1) Now, I read contents of a huge matrix from a Fortran binary dump. u - readBin(con,what=double,n=nrow*ncol) # (2) If I do (1) and then (2), u is a vector, obviously it's either reallocated or its matrix nature is lost -- overridden? overwritten? Instead, I do it now as u - matrix(readBin(con,what=double,n=nrow*ncol),nrow=nrow,ncol=ncol) # (3) What's going on with memory management here and what's the right way to make it efficient -- and how to preallocate? After that, I'm saving u as R binary object in an rda file. Does it make sense to preallocate u before reading it back now from the rda file? This kind of preallocation only makes sense for loops. In your case, it does not yield benefits. Anyway, if you really want to reassign things in u, you could say: u[] - readBin(con,what=double,n=nrow*ncol) # (2) (empty brackets for indexing all elements) Best wishes, Uwe Cheers, Alexy __ 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] Odp: problem with basic boolean selection in sequence
Hi Do not use computers, they are full of such traps and do not do what we think they do. See FAQ 7.31 Why doesn't R think these numbers are equal Regards Petr [EMAIL PROTECTED] [EMAIL PROTECTED] napsal dne 09.04.2008 11:32:00: Dear R users, I have a surprising problem while selecting values in a sequence created with the seq() function... I've tried a lot of test before sending this here and hope I did not disturb you for a foolish mistake from me Please, have a look at the following lines: #___ test2-seq(from=0,to=1,by=.1) test2 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 test2==1 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE test2==0.9 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE test2==0.8 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE test2==0.7 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.6 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.5 [1] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE test2==0.4 [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.3 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.2 [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.1 [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE test2==0.0 [1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE # there is a problem with values 0.3, 0.6 and 0.7 impossible to select in such a vector... # the same thing happens with other sequence including somme of these values test3-seq(from=0,to=1,by=0.01) test3 test3==0.3 # not working test3==0.6 # working test3==0.7 # not working # Does anyones has an explanation and a solution ? Kind regards Ben [[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] Smoothing 3 D data
Ruby_Stanford hiranakshidevi at gmail.com writes: Hey. I have a set of data points (x1,y1,z1; x2,y2,z2;...xn,yn,zn). I need to smooth these in 3D. For example if these were in 2 D then one would use inverse distance weighting or moving averages. interp.loess {tgp} is easiest to use when you have equidistant grid data. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] java applets
Hi, I used Rserve http://www.rforge.net/Rserve/ to use the facilities of R in a java applet. If you know how to write an applet, there are some examples of how to talk to Rserve from Java. Thomas Kaliwe lamack lamack schrieb: Dear all, is it possible to implement some statistics data analysis based on R and javascript? I would like to construct java applets using R functions. Is it possible? Where can I find examples? Best regards. LL _ [[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] Mode Vs Class
Congratulation Bill for this very clear and useful explanation. Heinz At 14:58 08.04.2008, [EMAIL PROTECTED] wrote: 'mode' is a mutually exclusive classification of objects according to their basic structure. The 'atomic' modes are numeric, complex, charcter and logical. Recursive objects have modes such as 'list' or 'function' or a few others. An object has one and only one mode. 'class' is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it's class is usually the same as its mode, by convention. Changing the mode of an object is often called 'coercion'. The mode of an object can change without necessarily changing the class. e.g. x - 1:16 mode(x) [1] numeric dim(x) - c(4,4) mode(x) [1] numeric class(x) [1] matrix is.numeric(x) [1] TRUE mode(x) - character mode(x) [1] character class(x) [1] matrix However: x - factor(x) class(x) [1] factor mode(x) [1] numeric At this stage, even though x has mode numeric again, its new class, 'factor', inhibits it being used in arithmetic operations. In practice, mode is not used very much, other than to define a class implicitly when no explicit class has been assigned. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Tuesday, 8 April 2008 10:20 PM To: [EMAIL PROTECTED] Subject: [R] Mode Vs Class Hi R, Just came across the 'mode' of an object. What is the basic difference between ?class and ?mode ... For example: d - data.frame(a = c(1,2), b = c(5,6)) class(d) [1] data.frame mode(d) [1] list But, c - c(2,3,5,6,7) class(c) [1] numeric mode(c) [1] numeric Could anyone help me out... Thanks, shubha __ 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-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] apply lm() for all the columns of a matrix
Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ 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] fuzzy merge
Here is one way of doing it. Create a new dataframe with the values, look for the breaks in times between the two sequences and then create a results dataframe: # convert time to POSIXct d1$time1 - as.POSIXct(paste(d1[[1]], d1[[2]])) d2$time2 - as.POSIXct(paste(d2[[1]], d2[[2]])) d1$ID1 - row.names(d1) d2$ID2 - row.names(d2) d1 ID1 time1 dt 1 1 2008-01-02 13:11:00 10 2 2 2008-01-02 14:20:00 20 3 3 2008-01-02 15:42:00 30 4 4 2008-01-02 16:45:00 40 5 5 2008-01-02 17:42:00 50 6 6 2008-01-02 20:40:00 60 d2 ID2 time2 d1 101 101 2008-01-02 14:29:00 75 102 102 2008-01-02 17:55:00 105 103 103 2008-02-07 20:01:00 8 # create dataframe of times checkTime - data.frame(index=c(seq(nrow(d1)), seq(nrow(d2))), + ID=c(d1$ID1, d2$ID2), + times=c(d1$time1, d2$time2), key=c(rep(0, nrow(d1)), rep(1, nrow(d2 # sort by time checkTime - checkTime[order(checkTime$times),] # find the breaks (transition from 0 - 1) breaks - which(diff(checkTime$key) == 1) # find out which ones are withing 15 minutes dif.15 - which(difftime(checkTime$times[breaks + 1], checkTime$times[breaks], units='mins') = 15) # print out the values data.frame(ID1=checkTime$ID[breaks[dif.15]], time1=checkTime$times[breaks[dif.15]], + time2=checkTime$times[breaks[dif.15] + 1]) ID1 time1 time2 1 2 2008-01-02 14:20:00 2008-01-02 14:29:00 2 5 2008-01-02 17:42:00 2008-01-02 17:55:00 On Wed, Apr 9, 2008 at 4:53 AM, ravi [EMAIL PROTECTED] wrote: Hi, I would like to merge two data frames. It is just that I want the merging to be done with some kind of a fuzzy criterion. Let me explain. My first data frame looks like this : ID1 time1dt 12008-01-02 13:1110 22008-01-02 14:2020 32008-01-02 15:4230 42008-01-02 16:4540 52008-01-02 17:4250 62008-01-02 20:4060 My second data frame : ID2time2d1 1012008-01-02 14:2975 1022008-01-02 17:55105 1032008-02-07 20:018 I want the merging to be done such that time2 is in the range between time1 and (time1+15 min). That is, my merged data frame should be : ID1 time1time2 22008-01-02 14:202008-01-02 14:29 52008-01-02 17:422008-01-02 17:55 My data frames have thousands of records. If the two data frames are d1 and d2, d3-merge(d1,d2,by.x=time1,by.y=time2) will work only for exact matching. One possible option is to match the times for the date and hour times only (by filtering away the minute data). But this is only a partial solution as I am not interested in data where the time difference is more than 15 minutes. How can I make the merge to work for fuzzy matching? Would it be easier to convert the times into data classes? Or, it better to treat them as strings and use regular expresssions for doing the matching? I would appreciate any help that I can get. Thanking You, Ravi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply lm() for all the columns of a matrix
If you have the same design matrix then you can specify a matrix of responses in lm(), e.g., Y - matrix(rnorm(100*10), 100, 10) x - rnorm(100) fit - lm(Y ~ x) fit summary(fit) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org Sent: Wednesday, April 09, 2008 12:55 PM Subject: [R] apply lm() for all the columns of a matrix Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply lm() for all the columns of a matrix
On 4/9/2008 6:55 AM, Costas Douvis wrote: Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work The Details section of ?lm says: If response is a matrix a linear model is fitted separately by least-squares to each column of the matrix. That seems to be what you are asking for. Here is an example: lm(as.matrix(iris[,1:3]) ~ iris$Species) Call: lm(formula = as.matrix(iris[, 1:3]) ~ iris$Species) Coefficients: Sepal.Length Sepal.Width Petal.Length (Intercept) 5.006 3.4281.462 iris$Speciesversicolor 0.930-0.6582.798 iris$Speciesvirginica1.582-0.4544.090 Thank you Kostas -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ 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] question about nlminb
Hi Spencer, Sorry for not producing code as a worked example. Here's an example: == # setting the seed number set.seed(0) # creating a correlation matrix corr - diag(5) corr[lower.tri(corr)] - 0.5 corr[upper.tri(corr)] - 0.5 # Data for the minimisation mat - rmvnorm(1, mean=c(3, -20, -10, 3, 2), sd=c(0.1, 15, 4, 0.15, 0.8), cov=corr) obj.fun - function(opt, mat) { opt - c(opt, 1-sum(opt)) LinearComb - mat%*%opt obj - -min(LinearComb) obj } opt - nlminb(rep(0,4), lower=rep(-3, 4), upper=rep(3, 4), obj.fun, mat=mat) opt.x - opt$parameters opt.x - c(opt.x, 1-sum(opt.x)) # using vcov.nlminb from the MASS library to obtain the covariance matrix vcov.nlminb(opt) I have a variance-covariance matrix for 4 of the elements in the vector but not the last component. How would I go about getting the entire variance-covariance matrix? Thanks in advance for any help. Regards, John On 09/04/2008, Spencer Graves [EMAIL PROTECTED] wrote: Have you considered optimizing over x1 = x[1:(length(x)-1]? You could feed a wrapper function 'f2(x1, ...)' that computes xFull = c(x1, 1-sum(x1)) and feeds that to your 'fn'. If this makes sense, great. Else, if my answer is not useful, be so kind as to PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Spencer John Pitchard wrote: Dear All, I wanted to post some more details about the query I sent to s-news last week. I have a vector with a constraint. The constraint is that the sum of the vector must add up to 1 - but not necessarily positive, i.e. x[n] - 1 -(x[1] + ...+x[n-1]) I perform the optimisation on the vector x such that x - c(x, 1-sum(x)) In other words, fn - function(x){ x - c(x, 1 - sum(x)) # other calculations here } then feed this into nlminb() out - nlminb(x, fn) out.x - out$parameters out.x - c(out.x, 1 - sum(out.x)) out.x I would like to calculate standard errors for each of the components of x. Is this possible by outputing the Hessian matrix? Furthermore, how would I calculate this for the last component (if this is indeed possible) which has the restriction (i.e. 1-sum(out.x))? Any help would be much appreciated. Regards, John [[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] Adding text to strip in xYplot
Hello again, I have been trying to add an expression to the strips in xYplot to no avail. For example, in the code below, the text in the strips for each panel is Anls and Plts. However, I would like it to add Anls km^2 and Plants km^2 with the exponents raised. I tried resetting the name of my groups in the dataframe before plotting, but the dataframe only recognized the entire expression (e.g. expression(paste(Anls, km^2,sep= )) and not Anls km2 - which should not have surprised me. Any ideas? Thanks for any help you can provide. John x1=rseq(1,30,0.5) y1=x1^2 y2=10*(x1^2) ycomb=c(y1,y2) y.up=ycomb+0.1*ycomb y.low=ycomb-0.1*ycomb grp=rep(c(Anls,Plts),each=length(x1))) dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F) colnames(dat)=c(ycomb,y.up,y.low,x1) with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free), x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,1 __ 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] fuzzy merge
ravi wrote: d3-merge(d1,d2,by.x=time1,by.y=time2) will work only for exact matching. One possible option is to match the times for the date and hour times only (by filtering away the minute data). But this is only a partial solution as I am not interested in data where the time difference is more than 15 minutes. Why don't you, in the first pass, round each time in d2 to a corresponding date in d1: new.d2 - d2 # there may be a faster solution without loops here for (i in 1:lenght(new.d2)) { # or whatever structure is d2 for (j in 1:length(d1)) { # again delta.t - abs(new.dt2[i]$time2 - d1$time1) # get a vector of deltat's j.min - which.min(delta.t) if (delta.t[j.min] = 15 minutes) new.d2[i]$time1 - d1[j.min]$time1 } } # and now merge them d3-merge(d1, d2, by.x=time1, by.y=time1) Alberto Monteiro __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Vectorize tapply(...,cumsum) output
I would like to graph cumulative counts and use tapply(...,cumsum) to get the cumulative counts. For instance: library(lattice) t-rep(1:4,each=3)#time i-rep(1:3,times=4) #categories n-rpois(length(t),t) #count xyplot(n ~ t,groups=i, type=o,key=simpleKey(as.character(1:3),x=0,y=1,lines=T)) N-tapply(n,t,cumsum) Now, what is the best way to convert N to a vector that can be plotted? E.g. xyplot(N ~ t,groups=i, type=o,key=simpleKey(as.character(1:3),x=0,y=1,lines=T)) Or is there a better way to get cumulative graphs? Thanks, Gerrit. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] energy 1.1-0 with dcov
Dear R-users, An updated version of the energy package, energy 1.1-0, is now available on CRAN. This version has merged the dcov package (previously available from my personal web page) into energy. New functions include: dcov (distance covariance) dcor (distance correlation) DCOR (four statistics) dcov.test (distance covariance test of multivariate independence) indep.test (choice of nonparametric energy tests of multivariate independence) These functions implement the new methods introduced in our recent article: G. J. Szekely, M. L. Rizzo and N. K. Bakirov (2007) Measuring and Testing Independence by Correlation of Distances, Annals of Statistics, Vol. 35 No. 6, pp. 2769-2794. Distance correlation R is a scalar statistic for measuring and testing independence of random vectors. It satisfies 0=R=1 and R=0 only if independence holds. Distance covariance V determines a statistically consistent test of independence. The distance covariance test is theoretically related to, but different from the original test based on coefficient I_n implemented in indep.etest. The new dcov.test is faster by a factor O(n) than indep.etest. With the introduction of a second and faster test, we provide a new function indep.test with a choice of methods to obtain either test. The original indep.etest is now deprecated. Reprints of the article are available upon request. Comments and suggestions are always welcome. Maria Rizzo and Gabor Szekely ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] Odp: Vectorize tapply(...,cumsum) output
Hi it is a work for do.call try Nc-do.call(c,N) xyplot(Nc ~ t,groups=i,type=o,key=simpleKey(as.character(1:3),x=0,y=1,lines=T)) Regards Petr [EMAIL PROTECTED] [EMAIL PROTECTED] napsal dne 09.04.2008 14:53:41: I would like to graph cumulative counts and use tapply(...,cumsum) to get the cumulative counts. For instance: library(lattice) t-rep(1:4,each=3)#time i-rep(1:3,times=4) #categories n-rpois(length(t),t) #count xyplot(n ~ t,groups=i, type=o,key=simpleKey(as.character(1:3),x=0,y=1,lines=T)) N-tapply(n,t,cumsum) Now, what is the best way to convert N to a vector that can be plotted? E.g. xyplot(N ~ t,groups=i, type=o,key=simpleKey(as.character(1:3),x=0,y=1,lines=T)) Or is there a better way to get cumulative graphs? Thanks, Gerrit. __ 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] Weibull maximum likelihood estimates for censored data
I have a matrix with data and a column indicating whether it is censored or not. Is there a way to apply weibull and exponential maximum likelihood estimation directly on the censored data, like in the paper: Backtesting Value-at-Risk: A Duration-Based Approach, P Chrisoffersen and D Pelletier (October 2003) page 8? It would be easier to use the survreg function, which is part of the survival library. It will fit MLE estimates of the exponential, Weibull, log-normal, and others. library(survival) survreg(Surv(D, C) ~1, data=Interest) Coefficients: (Intercept) 5.531319 Scale= 1.303637 Loglik(model)= -12.3 Loglik(intercept only)= -12.3 Notes: 1. The survreg function uses a location/scale parameterization of the Weibull. Kalbfleisch and Prentice, The statistical analysis of failure time data is the standard text for this. There are several others. A simple online reference is a technical report from earlier versions of the survival package, TR #53 available at www.mayo.edu/biostatistics. (Somewhat dated wrt newer options in the package, but sufficient for your purposes). 2. You give page numbers but no journal name in your reference. 3. I don't know whether your variable C has 1=censored or 1=uncensored. The survreg function expects the latter. You can just change the call to survreg(Surv(D, 1-C) ~1) if yours is otherwise. 4. The rest of your message is a set of nested functions with hardly a single comment. It is very difficult for an outside reader to comment on what went wrong without further hints about what it is that you are actually trying to compute. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add background color of a 2D chart by quadrant
tom soyer [EMAIL PROTECTED] wrote: I have a 2D chart that is divided into four quadrants, I, II, III, IV: plot(1:10,ylim=c(0,10),xlim=c(0,10),type=n) abline(v=5,h=5) text(x=c(7.5,7.5,2.5,2.5),y=c(2.5,7.5,7.5,2.5),labels=c(I,II,III,IV)) I would like to fill each quadrant with a background color unique to the quadrant. Does anyone know how to do this in R? In response to a similar question no more than two weeks ago, I posted detailed code as an example. I expect it would be easy to modify my example to fit your question. If you search the group archives, you should be able to find it. The thread title was background color in scatterplots. MHP -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement. __ 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] apply lm() for all the columns of a matrix
Thank you all very much for replying. Of course you are absolutely right but unfortunately I really deal with the case of a 4-d matrix so what you said does not apply. I should have specified but being a new R user I hadn't realized the difference between a matrix and an array. So please tell me if you know a fast way (not using a loop) to perform a linear fit on all the vectors of the 4-th dimension of a 4-d array. Thanks again Kostas If you have the same design matrix then you can specify a matrix of responses in lm(), e.g., Y - matrix(rnorm(100*10), 100, 10) x - rnorm(100) fit - lm(Y ~ x) fit summary(fit) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org Sent: Wednesday, April 09, 2008 12:55 PM Subject: [R] apply lm() for all the columns of a matrix Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply lm() for all the columns of a matrix
Well, could you provide a little bit more information regarding what you are trying to do (e.g., reproducible example). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org; Mark Leeds [EMAIL PROTECTED]; Dimitris Rizopoulos [EMAIL PROTECTED] Cc: Chuck Cleland [EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 3:44 PM Subject: Re: [R] apply lm() for all the columns of a matrix Thank you all very much for replying. Of course you are absolutely right but unfortunately I really deal with the case of a 4-d matrix so what you said does not apply. I should have specified but being a new R user I hadn't realized the difference between a matrix and an array. So please tell me if you know a fast way (not using a loop) to perform a linear fit on all the vectors of the 4-th dimension of a 4-d array. Thanks again Kostas If you have the same design matrix then you can specify a matrix of responses in lm(), e.g., Y - matrix(rnorm(100*10), 100, 10) x - rnorm(100) fit - lm(Y ~ x) fit summary(fit) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org Sent: Wednesday, April 09, 2008 12:55 PM Subject: [R] apply lm() for all the columns of a matrix Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Coefficient of determination for generalized linear models
Thanks in advance for your kind attention. I am using R to fit empirical data to generalized linear models. AIC (Akaike information criterion) is a measure of the goodness of fit returned by calls to glm(). I would also like to calculate the coefficient of determination R2, although there is no consensus about the exact definition for generalized models ([1]http://en.wikipedia.org/wiki/Coefficient_of_determination). I found a package âpsclâ with a pR2 function that computes pseudo-R2 measures for various GLMs. The arguments to the call are a fitted model object of class glm, polr, or mulitnom, and then âadditional arguments to be passed to or from functionsâ. The example from the documentation works well. Browse[1] data(admit) Browse[1] require(MASS) Browse[1] ## ordered probit model Browse[1] op1 - polr(score ~ gre.quant + gre.verbal + ap + pt + female, + Hess=TRUE, + data=admit, + method=probit) Browse[1] pR2(op1) llh llhNullG2 McFadden r2ML r2CU -106.5088203 -151.0299826 89.0423245 0.2947836 0.5682989 0.6032041 Browse[1] When I try with a glm object rather than polr, I get the following error: Browse[1] class(fit[[2]]) [1] glm lm Browse[1] pR2(fit[[2]]) Error in inherits(x, data.frame) : object ds not found The ds object does exist in the environment, but I do not know how to pass it into pR2: Browse[1] class(ds) [1] data.frame Browse[1] pR2(fit[[2]], ds) Error in inherits(x, data.frame) : object ds not found Browse[1] pR2 function (object, ...) { UseMethod(pR2) } environment: namespace:pscl Browse[1] Question 1: How do I find the complete argument signature for pR2 in order to perhaps pass it the ds object? Question 2: If pR2 does not work with glm objects (for some unknown reason), is there another function I can use to calculate R-squared and adjusted R-squared for a generalized linear model? Best regards, \Eric References 1. http://en.wikipedia.org/wiki/Coefficient_of_determination __ 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] rgl build warnings and loading error on Linux
Dear R users, This is a follow-up of a recent discussion on building rgl on Gentoo Linux. Please read bellow. On Tue, Mar 18, 2008 at 7:24 PM, Charles C. Berry [EMAIL PROTECTED] wrote: Below substitute 'nvidia-drivers' or whatever you use for your-video-drivers emerge -D mesa your-video-drivers revdep-rebuild -X R install.packages(rgl) I have entirely updated my system using emerge -tva -DNu world, also meaning that I switched to R version 2.6.2. I have rebuilt all packages broken by this update using revdep-rebuild -i -tva -X. Just to make sure, afterwards I have also emerge -tva mesa xf86-video-i810. My mesa USE flags look like this: localhost liviu # eix mesa media-libs/mesa Installed versions: 7.0.2(15:23:17 09/04/08)(video_cards_i810 -debug -doc -kernel_FreeBSD -motif -nptl -pic [..]) Building and loading rgl has only switched the error message: dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) Error in dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) : unable to load shared library '/usr/lib/R/library/rgl/libs/rgl.so': /usr/lib/R/library/rgl/libs/rgl.so: undefined symbol: glNormal3f Previously it was: undefined symbol: glTexCoordPointer. Does this look like an rgl or a Gentoo Linux issue? Would any of the disabled mesa USE flags be worth enabling? Thank you in advance, Liviu __ 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] apply lm() for all the columns of a matrix
Here's a simplified example p-1:80+rnorm(80) dim(p)-c(2,2,2,10) We could say that the 4-d array p consists of 2*2*2 = 8 vectors of length 10. So what I'm asking for is a fast way to perform a linear fit to all those vectors. I'm sorry if I'm causing you to have a headache with all those dimensions :) Kostas Well, could you provide a little bit more information regarding what you are trying to do (e.g., reproducible example). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org; Mark Leeds [EMAIL PROTECTED]; Dimitris Rizopoulos [EMAIL PROTECTED] Cc: Chuck Cleland [EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 3:44 PM Subject: Re: [R] apply lm() for all the columns of a matrix Thank you all very much for replying. Of course you are absolutely right but unfortunately I really deal with the case of a 4-d matrix so what you said does not apply. I should have specified but being a new R user I hadn't realized the difference between a matrix and an array. So please tell me if you know a fast way (not using a loop) to perform a linear fit on all the vectors of the 4-th dimension of a 4-d array. Thanks again Kostas If you have the same design matrix then you can specify a matrix of responses in lm(), e.g., Y - matrix(rnorm(100*10), 100, 10) x - rnorm(100) fit - lm(Y ~ x) fit summary(fit) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org Sent: Wednesday, April 09, 2008 12:55 PM Subject: [R] apply lm() for all the columns of a matrix Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ 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] Replace values according to conditions
Thanks for all the reply. I solved the task using apply(as suggested by Hans). The tips on S-Poetry and ?Logic are very handy as well. [[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] Changing default plot behaviour
Hello, How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() Thanx, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ofri.mnr.gov.on.ca __ 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] rgl build warnings and loading error on Linux
On 4/9/2008 10:53 AM, Liviu Andronic wrote: Dear R users, This is a follow-up of a recent discussion on building rgl on Gentoo Linux. Please read bellow. On Tue, Mar 18, 2008 at 7:24 PM, Charles C. Berry [EMAIL PROTECTED] wrote: Below substitute 'nvidia-drivers' or whatever you use for your-video-drivers emerge -D mesa your-video-drivers revdep-rebuild -X R install.packages(rgl) I have entirely updated my system using emerge -tva -DNu world, also meaning that I switched to R version 2.6.2. I have rebuilt all packages broken by this update using revdep-rebuild -i -tva -X. Just to make sure, afterwards I have also emerge -tva mesa xf86-video-i810. My mesa USE flags look like this: localhost liviu # eix mesa media-libs/mesa Installed versions: 7.0.2(15:23:17 09/04/08)(video_cards_i810 -debug -doc -kernel_FreeBSD -motif -nptl -pic [..]) Building and loading rgl has only switched the error message: dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) Error in dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) : unable to load shared library '/usr/lib/R/library/rgl/libs/rgl.so': /usr/lib/R/library/rgl/libs/rgl.so: undefined symbol: glNormal3f Previously it was: undefined symbol: glTexCoordPointer. Does this look like an rgl or a Gentoo Linux issue? Would any of the disabled mesa USE flags be worth enabling? glNormal3f and glTexCoordPointer are both OpenGL entry points used by rgl, so the messages are indicating a linking problem. But I don't know enough about Linux to recognize whether that's because of something wrong with Gentoo or what you did, or something wrong with the rgl configure script. Duncan Murdoch Thank you in advance, Liviu __ 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] mgcv::predict.gam lpmatrix for prediction outside of R
This is in regards to the suggested use of type=lpmatrix in the documentation for mgcv::predict.gam. Could one not get the same result more simply by using type=terms and interpolating each term directly? What is the advantage of the lpmatrix approach for prediction outside R? Thanks. -- View this message in context: http://www.nabble.com/mgcv%3A%3Apredict.gam-lpmatrix-for-prediction-outside-of-R-tp16587009p16587009.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] Number of words in a string
Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{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] Proportional Hazard mixture cure model
Dear all, I've been trying to find a package to simulate a proportional hazard mixture cure model. I've had a look at the nltm package and the references seem to include a PHMCM method but the package doesn't seem to. I've also had a look at the package semicure (as per this thread http://tolstoy.newcastle.edu.au/R/e4/help/08/02/4090.html) but it is in s? I am pretty new to R and hence don't really know what the issues are in trying to incorporate it. Does anyone have any experience with this package and/or can point me to other packages which can do PHMCM? Regards, Michele Petteni --- Department of Epidemiology and Public Health Imperial College, St Mary's Campus Norfolk Place London W2 1PG [[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] AnnotationDBI and RSQLite installation problem
Hi All, I tried to install AnnotationDBI like so: source(http://bioconductor.org/biocLite.R;) biocLite(AnnotationDbi) and got this error: Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/RHEL3/local/lib64/R/library/ RSQLite/libs/RSQLite.so': /RHEL3/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int Error: package 'RSQLite' could not be loaded Execution halted ERROR: lazy loading failed for package 'AnnotationDbi' ** Removing '/RHEL3/local/lib64/R/library/AnnotationDbi' The downloaded packages are in /RHEL3/tmp/Rtmp6ex1Pz/downloaded_packages Updating HTML index of packages in '.Library' Warning message: In install.packages(pkgs = pkgs, repos = repos, dependencies = dependencies, : installation of package 'AnnotationDbi' had non-zero exit status However, I did install RSQLite and the installation finished with no errors. But: require(RSQLite) Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/usr/local/lib64/R/library/RSQLite/ libs/RSQLite.so': /usr/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int The library and file do exist with 755 permissions. My session info: sessionInfo() R version 2.6.2 (2008-02-08) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.U TF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF- 8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_ID ENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] DBI_0.2-4 loaded via a namespace (and not attached): [1] rcompgen_0.1-17 tools_2.6.2 Has anyone a clue? I am not a R user, just the IT person who has to install it, so if you need additional info from inside R, please let me know how to get it. Thanks a lot, Maya [[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] Coefficient of determination for generalized linear models
Asking the question usually makes one think about the workarounds J. I reviewed the pscl source and found the code for pR2. Sourcing the following internal functions allowed me to compute the pseudo R2 measures. pR2Work - function(llh,llhNull,n){ McFadden - 1 - llh/llhNull G2 - -2*(llhNull-llh) r2ML - 1 - exp(-G2/n) r2ML.max - 1 - exp(llhNull*2/n) r2CU - r2ML/r2ML.max out - c(llh=llh, llhNull=llhNull, G2=G2, McFadden=McFadden, r2ML=r2ML, r2CU=r2CU) out } pR2.glm - function(object,...){ llh - logLik(object) objectNull - update(object, ~ 1) llhNull - logLik(objectNull) n - dim(object$model)[1] pR2Work(llh,llhNull,n) } Browse[1] pR2.glm(fit[[2]]) llh llhNullG2 McFadden r2ML r2CU -1658.5890626 -2874.0411606 2430.9041961 0.4229070 0.9472917 0.9481926 Browse[1] Question 3: Is there a way to access the pR2.glm function from the library without using the source? __ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric E Harper/USABB/ABB Sent: Wednesday, April 09, 2008 10:47 AM To: r-help@r-project.org Cc: Emanuel Kolb/DECRC/ABB; Hans-Werner Borchers/DECRC/ABB Subject: [R] Coefficient of determination for generalized linear models Thanks in advance for your kind attention. I am using R to fit empirical data to generalized linear models. AIC (Akaike information criterion) is a measure of the goodness of fit returned by calls to glm(). I would also like to calculate the coefficient of determination R2, although there is no consensus about the exact definition for generalized models ([1]http://en.wikipedia.org/wiki/Coefficient_of_determination). I found a package ââ¬Åpsclââ¬Â with a pR2 function that computes pseudo-R2 measures for various GLMs. The arguments to the call are a fitted model object of class glm, polr, or mulitnom, and then ââ¬Ëadditional arguments to be passed to or from functionsââ¬â¢. The example from the documentation works well. Browse[1] data(admit) Browse[1] require(MASS) Browse[1] ## ordered probit model Browse[1] op1 - polr(score ~ gre.quant + gre.verbal + ap + pt + female, + Hess=TRUE, + data=admit, + method=probit) Browse[1] pR2(op1) llh llhNull G2 McFadden r2ML r2CU -106.5088203 -151.0299826 89.0423245 0.2947836 0.5682989 0.6032041 Browse[1] When I try with a glm object rather than polr, I get the following error: Browse[1] class(fit[[2]]) [1] glm lm Browse[1] pR2(fit[[2]]) Error in inherits(x, data.frame) : object ds not found The ds object does exist in the environment, but I do not know how to pass it into pR2: Browse[1] class(ds) [1] data.frame Browse[1] pR2(fit[[2]], ds) Error in inherits(x, data.frame) : object ds not found Browse[1] pR2 function (object, ...) { UseMethod(pR2) } Browse[1] Question 1: How do I find the complete argument signature for pR2 in order to perhaps pass it the ds object? Question 2: If pR2 does not work with glm objects (for some unknown reason), is there another function I can use to calculate R-squared and adjusted R-squared for a generalized linear model? Best regards, \Eric References 1. http://en.wikipedia.org/wiki/Coefficient_of_determination __ 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] Number of words in a string
Would this: sapply(strsplit(C, ), length) work for? Markus Gesmann │Associate Director│Libero Ventures Ltd, One Broadgate, London EC2M 2QS tel: +44 (0)207 826 9080│ dir: +44 (0)207 826 9085│fax: +44 (0)207 826 9090 │www.libero.uk.com A Lehman Brothers Company AUTHORISED AND REGULATED BY THE FINANCIAL SERVICES AUTHORITY -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: 09 April 2008 16:21 To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{dropped:13}} This message is intended for the personal and confidential use for the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction or as an official statement of Libero Ventures Ltd. Email transmissions cannot be guaranteed to be secure or error-free. Therefore we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. __ 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] Changing default plot behaviour
How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() Use a custom plotting function, e.g. myplot - function(..., sidesforlabels) { #sidesforlabels should be a numeric vector containing the sides that you want labels on plot(..., axes=FALSE) par(tcl=0.5) for(i in 1:4) { axis(i, labels=i %in% sidesforlabels) } box() } myplot(1:10, sidesforlabels=1:2) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped: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] Number of words in a string
To put in more general, C=c(My Dog, Its really good, Beautiful) And the resultant output should be [1] 2 3 1 ...the number of words Thank you... Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, April 09, 2008 8:51 PM To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{dropped:13}} This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] Number of words in a string
On 9 Apr 2008, at 17:29, Markus Gesmann wrote: Would this: sapply(strsplit(C, ), length) work for? or length(unlist(strsplit(C, ))) --Hans __ 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] Number of words in a string
Exactly...this is what I wanted... Can we also extract/remove the last word of the strings? Example: C=c(My Dog, Its really good, Beautiful) sapply(strsplit(C, ), length) [1] 2 3 1 Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: Markus Gesmann [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 9:00 PM To: Shubha Vishwanath Karanth; [EMAIL PROTECTED] Subject: RE: [R] Number of words in a string Would this: sapply(strsplit(C, ), length) work for? Markus Gesmann │Associate Director│Libero Ventures Ltd, One Broadgate, London EC2M 2QS tel: +44 (0)207 826 9080│ dir: +44 (0)207 826 9085│fax: +44 (0)207 826 9090 │www.libero.uk.com A Lehman Brothers Company AUTHORISED AND REGULATED BY THE FINANCIAL SERVICES AUTHORITY -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: 09 April 2008 16:21 To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{dropped:13}} This message is intended for the personal and confidential use for the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction or as an official statement of Libero Ventures Ltd. Email transmissions cannot be guaranteed to be secure or error-free. Therefore we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Any views or opinions presented are solely those of the author and do not necessarily represent those of Amba Holdings Inc., and/or its affiliates. Important additional terms relating to this email can be obtained at http://www.ambaresearch.com/disclaimer __ 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] Number of words in a string
length(unlist(strsplit(C, ' '))) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, April 09, 2008 11:21 AM To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San Josi * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Number of words in a string
Something like that? gsub( {1,}\w+$, , C) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R beginner - how to apply function to more than one matrix / data.array / ...
I would like to apply a simple function, like is.matrix to more than one data.frame How can I call on more than one data.frame? (are there any wildcards, etc?) I am a true beginner and have tried to look this up in help files, but cannot figure it out. Thank you. [[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] Number of words in a string
Got all the answers using ?strsplit... Is there any way without using string split?... More specifically... How can I just extract the last word in all the strings without using ?strsplit ? Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans-Joerg Bibiko Sent: Wednesday, April 09, 2008 9:10 PM To: [EMAIL PROTECTED] Subject: Re: [R] Number of words in a string On 9 Apr 2008, at 17:29, Markus Gesmann wrote: Would this: sapply(strsplit(C, ), length) work for? or length(unlist(strsplit(C, ))) --Hans __ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] Number of words in a string
To put it simple, C=c(My Dog, Its really good, Beautiful) Now, SOMEFUNCTION(C) should give: c(My, Its really, ) Thanks, Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, April 09, 2008 9:01 PM To: Markus Gesmann; [EMAIL PROTECTED] Subject: Re: [R] Number of words in a string Exactly...this is what I wanted... Can we also extract/remove the last word of the strings? Example: C=c(My Dog, Its really good, Beautiful) sapply(strsplit(C, ), length) [1] 2 3 1 Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: Markus Gesmann [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 9:00 PM To: Shubha Vishwanath Karanth; [EMAIL PROTECTED] Subject: RE: [R] Number of words in a string Would this: sapply(strsplit(C, ), length) work for? Markus Gesmann │Associate Director│Libero Ventures Ltd, One Broadgate, London EC2M 2QS tel: +44 (0)207 826 9080│ dir: +44 (0)207 826 9085│fax: +44 (0)207 826 9090 │www.libero.uk.com A Lehman Brothers Company AUTHORISED AND REGULATED BY THE FINANCIAL SERVICES AUTHORITY -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: 09 April 2008 16:21 To: [EMAIL PROTECTED] Subject: [R] Number of words in a string Hi R, A quick question: How do we find the number of words in a string? Example: C=Have a nice day And the number of words should be 4. any built in function or?... Thanks, Shubha Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com This e-mail may contain confidential and/or privileged i...{{dropped:13}} This message is intended for the personal and confidential use for the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction or as an official statement of Libero Ventures Ltd. Email transmissions cannot be guaranteed to be secure or error-free. Therefore we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Any views or opinions presented are solely those of the author and do not necessarily represent those of Amba Holdings Inc., and/or its affiliates. Important additional terms relating to this email can be obtained at http://www.ambaresearch.com/disclaimer __ 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. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Any views or opinions presented are solely those of the author and do not necessarily represent those of Amba Holdings Inc., and/or its affiliates. Important additional terms relating to this email can be obtained at http://www.ambaresearch.com/disclaimer __ 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] Number of words in a string
On 9 Apr 2008, at 17:44, Shubha Vishwanath Karanth wrote: Got all the answers using ?strsplit... Is there any way without using string split?... More specifically... How can I just extract the last word in all the strings without using ?strsplit ? Oops, sorry. gsub( *\w+$, , C) should work. --Hans __ 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] Number of words in a string
See strapply in the gsubfn package and the gsubfn home page at gsubfn.googlecode.com. Here we extract the words, the last word and all but the last word: library(gsubfn) strapply(C, \\w+) [[1]] [1] My Dog [[2]] [1] Itsreally good [[3]] [1] Beautiful sapply(strapply(C, \\w+), tail, 1) [1] Dog good Beautiful sapply(strapply(C, \\w+), tail, -1) [[1]] [1] Dog [[2]] [1] really good [[3]] character(0) On Wed, Apr 9, 2008 at 11:44 AM, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: Got all the answers using ?strsplit... Is there any way without using string split?... More specifically... How can I just extract the last word in all the strings without using ?strsplit ? Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans-Joerg Bibiko Sent: Wednesday, April 09, 2008 9:10 PM To: [EMAIL PROTECTED] Subject: Re: [R] Number of words in a string On 9 Apr 2008, at 17:29, Markus Gesmann wrote: Would this: sapply(strsplit(C, ), length) work for? or length(unlist(strsplit(C, ))) --Hans __ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] R beginner - how to apply function to more than one matrix / data.array / ...
Yes, it is exactly 'apply', and its friends. E.g. you can collect the objects into a list and then do sapply(mylist, is.matrix) G. On Wed, Apr 09, 2008 at 11:52:08AM -0400, Mon Mag wrote: I would like to apply a simple function, like is.matrix to more than one data.frame How can I call on more than one data.frame? (are there any wildcards, etc?) I am a true beginner and have tried to look this up in help files, but cannot figure it out. Thank you. [[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. -- Csardi Gabor [EMAIL PROTECTED]UNIL DGM __ 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] rgl build warnings and loading error on Linux
We'll need to see the output from install.packages(rgl) to have much idea: R CMD ldd /usr/lib/R/library/rgl/libs/rgl.so would also be informative. On Wed, 9 Apr 2008, Duncan Murdoch wrote: On 4/9/2008 10:53 AM, Liviu Andronic wrote: Dear R users, This is a follow-up of a recent discussion on building rgl on Gentoo Linux. Please read bellow. On Tue, Mar 18, 2008 at 7:24 PM, Charles C. Berry [EMAIL PROTECTED] wrote: Below substitute 'nvidia-drivers' or whatever you use for your-video-drivers emerge -D mesa your-video-drivers revdep-rebuild -X R install.packages(rgl) I have entirely updated my system using emerge -tva -DNu world, also meaning that I switched to R version 2.6.2. I have rebuilt all packages broken by this update using revdep-rebuild -i -tva -X. Just to make sure, afterwards I have also emerge -tva mesa xf86-video-i810. My mesa USE flags look like this: localhost liviu # eix mesa media-libs/mesa Installed versions: 7.0.2(15:23:17 09/04/08)(video_cards_i810 -debug -doc -kernel_FreeBSD -motif -nptl -pic [..]) Building and loading rgl has only switched the error message: dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) Error in dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) : unable to load shared library '/usr/lib/R/library/rgl/libs/rgl.so': /usr/lib/R/library/rgl/libs/rgl.so: undefined symbol: glNormal3f Previously it was: undefined symbol: glTexCoordPointer. Does this look like an rgl or a Gentoo Linux issue? Would any of the disabled mesa USE flags be worth enabling? glNormal3f and glTexCoordPointer are both OpenGL entry points used by rgl, so the messages are indicating a linking problem. But I don't know enough about Linux to recognize whether that's because of something wrong with Gentoo or what you did, or something wrong with the rgl configure script. Duncan Murdoch Thank you in advance, Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Number of words in a string
Actually the last example was all but the first word, not all but the last word. All but the last word is: sapply(strapply(C, \\w+), head, -1) [[1]] [1] My [[2]] [1] Itsreally [[3]] character(0) On Wed, Apr 9, 2008 at 11:56 AM, Gabor Grothendieck [EMAIL PROTECTED] wrote: See strapply in the gsubfn package and the gsubfn home page at gsubfn.googlecode.com. Here we extract the words, the last word and all but the last word: library(gsubfn) strapply(C, \\w+) [[1]] [1] My Dog [[2]] [1] Itsreally good [[3]] [1] Beautiful sapply(strapply(C, \\w+), tail, 1) [1] Dog good Beautiful sapply(strapply(C, \\w+), tail, -1) [[1]] [1] Dog [[2]] [1] really good [[3]] character(0) On Wed, Apr 9, 2008 at 11:44 AM, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: Got all the answers using ?strsplit... Is there any way without using string split?... More specifically... How can I just extract the last word in all the strings without using ?strsplit ? Shubha Karanth | Amba Research Ph +91 80 3980 8031 | Mob +91 94 4886 4510 Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hans-Joerg Bibiko Sent: Wednesday, April 09, 2008 9:10 PM To: [EMAIL PROTECTED] Subject: Re: [R] Number of words in a string On 9 Apr 2008, at 17:29, Markus Gesmann wrote: Would this: sapply(strsplit(C, ), length) work for? or length(unlist(strsplit(C, ))) --Hans __ 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. This e-mail may contain confidential and/or privileged i...{{dropped:10}} __ 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] Adding text to strip in xYplot
Hi John, a solution to your problem would be using strip.custom like this: ... with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free),x=list(alternating=c(1,1,1))), ylim=list(c(0,1200),c(0,1)), strip=strip.custom(factor.levels=c(expression(Anls km^2),expression(Plants km^2) Best wishes, Christoph Wednesday, April 9, 2008, 2:39:09 PM, you wrote: Hello again, I have been trying to add an expression to the strips in xYplot to no avail. For example, in the code below, the text in the strips for each panel is Anls and Plts. However, I would like it to add Anls km^2 and Plants km^2 with the exponents raised. I tried resetting the name of my groups in the dataframe before plotting, but the dataframe only recognized the entire expression (e.g. expression(paste(Anls, km^2,sep= )) and not Anls km2 - which should not have surprised me. Any ideas? Thanks for any help you can provide. John x1=rseq(1,30,0.5) y1=x1^2 y2=10*(x1^2) ycomb=c(y1,y2) y.up=ycomb+0.1*ycomb y.low=ycomb-0.1*ycomb grp=rep(c(Anls,Plts),each=length(x1))) dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F) colnames(dat)=c(ycomb,y.up,y.low,x1) with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free), x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.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.
[R] How to estimate a hazard ratio using an external hazard function
Hi, I would like to compare the hazard functions of two samples using the Cox proportional hazards model. For sample 1 I have individual time-to- event data. For sample 2 I don't have individual data, but grouped data that allows to obtain a hazard function. I am wondering if there is an R function that allows to obtain a hazard ratio of the two hazard funtions (under the proportionality assumption) taking into account the censoring of the data? I am aware of survexp and survdiff functions, but I am not sure if that is the best way to do what I need. Any help will be highly appreciated. Montse Rue Department of Basic Medical Sciences University of Lleida (Spain) __ 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] Number of words in a string
On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote: To put it simple, C=c(My Dog, Its really good, Beautiful) Now, SOMEFUNCTION(C) should give: c(My, Its really, ) SOMEFUNCTION - function(x) gsub( *\\w+$, , x) But be aware that this won't work for instance for combining diacritics. If you have this: C - c(My Dog, Its really good, Beautiful, Tuli faŝda) in fasda above the s is a combining circumfix ^ would give [1] My Its reallyTuli faŝ Then one should use the strsplit approach. Cheers, --Hans __ 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] Adding text to strip in xYplot
Hello Christoph, Oops, I see that the factor.levels function is in the help menu for strip.default. I had tried it, but not specified it correctly. Thanks again for you help, John Christoph Meyer wrote: Hi John, a solution to your problem would be using strip.custom like this: ... with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free),x=list(alternating=c(1,1,1))), ylim=list(c(0,1200),c(0,1)), strip=strip.custom(factor.levels=c(expression(Anls km^2),expression(Plants km^2) Best wishes, Christoph Wednesday, April 9, 2008, 2:39:09 PM, you wrote: Hello again, I have been trying to add an expression to the strips in xYplot to no avail. For example, in the code below, the text in the strips for each panel is Anls and Plts. However, I would like it to add Anls km^2 and Plants km^2 with the exponents raised. I tried resetting the name of my groups in the dataframe before plotting, but the dataframe only recognized the entire expression (e.g. expression(paste(Anls, km^2,sep= )) and not Anls km2 - which should not have surprised me. Any ideas? Thanks for any help you can provide. John x1=rseq(1,30,0.5) y1=x1^2 y2=10*(x1^2) ycomb=c(y1,y2) y.up=ycomb+0.1*ycomb y.low=ycomb-0.1*ycomb grp=rep(c(Anls,Plts),each=length(x1))) dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F) colnames(dat)=c(ycomb,y.up,y.low,x1) with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), data=dat,type=l, method=bands, scales=list(y=list(relation=free), x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** Dr. Christoph Meyer Institute of Experimental Ecology University of Ulm Albert-Einstein-Allee 11 D-89069 Ulm Germany Phone: ++49-(0)731-502-2675 Fax:++49-(0)731-502-2683 Mobile: ++49-(0)1577-156-7049 E-mail: [EMAIL PROTECTED] http://www.uni-ulm.de/nawi/nawi-bio3.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.
[R] permutation/randomization
Hello, I have what I suspect might be an easy problem but I am new to R and stumped. I have a data set that looks something like this b-c(2,3,4,5,6,7,8,9) x-c(2,3,4,5,6,7,8,9) y-c(9,8,7,6,5,4,3,2) z-c(9,8,7,6,1,2,3,4) data-cbind(x,y,z) row.names(data)-c('a','b','c','d','e','f','g','h') which gives: x y z a 2 9 9 b 3 8 8 c 4 7 7 d 5 6 6 e 6 5 1 f 7 4 2 g 8 3 3 h 9 2 4 I would like to randomize data within columns. The closest I have been able to come permutes data within the columns but keeps rows together along with row names(example below). For some context, eventually I would like use this to generate many data sets and perform calculations on these random data sets (I think I know how to do this but we'll see). So ideally I would like row names to remain the same (in order a through h) and column data to randomize within columns but independently of the other columns. Just shuffle the data deck I guess data[permute(1:length(data[,1])),] x y z b 3 8 8 c 4 7 7 h 9 2 4 e 6 5 1 f 7 4 2 a 2 9 9 g 8 3 3 d 5 6 6 Thanks in advance for the help and also for the good advice earlier this week. Cheers [[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] GLM fitting in R and Statistica
Hi, I have a problem concerning discrepances between R (which I use) and Statistica (which uses my supervisor). I can't say what is the origin of these differences but unfortunately my supervisor doesn't know that either. Our response variable is number (or presence/absence) of parasites in rodents and explanatory variables are presence/absence of several alleles. The rodents were sampled in three sites and the sites differ in parasite frequency so we decided to include site as a factor. The problem concerns calculations of factor variable. In Statistica output there is only one term, just site, and in R there are two contrats site A, site B. I realized that I can obtain similar results in Statistica clicking on Estimate button instead of 1LR (what does my supervisor which gives only log-likelihood and p of variables but doesn't estimate parameter). But there is still one problem I can't explain. When we fit interaction terms (site x allele1, site x allele2 and so on) the results are completely different. I tried several different contrasts in R, such as contr.SAS, contr.treatment etc but I couldn't get nothing similar to Statistica output. Have anybody any idea how to deal with that? Or how to explain why R results are different (and hopefully better)? I tried to argue that I did everything according to Crawley's R Book so probably the models are constructed correctly but my supervisor wasn't convinced... Looking forward any suggestions, Agnieszka -- Agnieszka Kloch Instytute of Environmental Sciences, Jagielonian University ul. Gronostajowa 7, 30-387 Krakow, Poland, tel. (12) 664 51 51 __ 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 do I get the parameters out of e1071's svm?
Hi all, I'm trying to get a simple, linear decision surface from e1071's svm. I've run it like this: svm(as.factor(slow) ~ SLICE.3 + PSGR.7 + SOLUTIONS.6 + DR.10, y, kernel='linear', cost=1e6, class.weights=c('FALSE'=1, 'TRUE'=10)) According to the docs, kernel='linear' has a kernel u'v. Since I have 4 independent variables, I'd expect to have four coefficients plus a threshold, with 4 total degrees of freedom. But the only numeric vectors of length 4 in the result are the scaling and center, and those are done before the fitting so each one has zero mean and unit variance. I know svms don't need to put every point through the kernel function, and can even handle infinite dimensional kernels. But don't they need to compute the coefficients? Best, Martin __ 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] Changing default plot behaviour
On Wed, Apr 9, 2008 at 10:12 AM, Thompson, David (MNR) [EMAIL PROTECTED] wrote: Hello, How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? It's generally not a very good idea to put the tick marks inside the plot (as e.g. matlab does) because sometimes your data and tick marks will overlap - not good! Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Skipping specified rows in scan or read.table
Hi, I have a data file, certain lines of which are character fields. I would like to skip these rows, and read the data file as a numeric data frame. I know that I can skip lines at the beginning with read.table and scan, but is there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19, 20, 28, 29, etc.) ? If I read the entire data file, and then delete the character fields, the values are still kept as factors, with each value denoted by its level. Since, I have continuous variables, there are as many levels as there are values. I am unable to coerce this to numeric mode. Is there a way to do this so that I can then manipulate the numeric data frame? Thanks for any help. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html [[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] diagonally fill a rectangle with color gradient
Here are a couple of ways using base graphics: library(TeachingDemos) x - y - seq(0,1,length.out=100) tmp - expand.grid(x=x,y=y) z - matrix( tmp$x + tmp$y, 100 ) plot( 0:1, 0:1, type='n', xlab='x', ylab='y' ) subplot( image(x,y,z, col=topo.colors(100), axes=FALSE, xlab='', ylab=''), + c(0.2,0.4), c(0.2,0.7) ) clipplot( image(x,y,z, col=topo.colors(100), add=TRUE), + c(0.7,0.9), c(0.3,0.8) ) In version 2.7 there is also the option to use the clip function (instead of clipplot in TeachingDemos) like: clip( 0.3, 0.8, 0.9, 1.0 ) image(x,y,z, col=topo.colors(100), add=TRUE) However the help for clip notes that it can be hard to predict when the clipping region will be reset, so this sometimes works (my tests had it work if I did the above 2 lines after the subplot example) and sometimes does not (my tests did not work when used after the clipplot example, or on a new plot). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of tom soyer Sent: Tuesday, April 08, 2008 12:24 PM To: r-help@r-project.org Subject: [R] diagonally fill a rectangle with color gradient Hi, Is it possible to diagonally fill a rectangle with a color gradient? I noticed that the gradient.rect of plotrix could fill a rect either up and down or from side to side. I am looking for something similar but fills diagonally instead, e.g., from the upper left corner to the bottom right. Does anyone know how to do it in R? Thanks, -- Tom [[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] rgl build warnings and loading error on Linux
Dear Duncan and Brian, thank you for the quick replies. Please see bellow. On Wed, Apr 9, 2008 at 6:11 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: We'll need to see the output from install.packages(rgl) to have much idea: localhost liviu # R CMD INSTALL /home/liviu/inst/dwn_R/rgl_0.77.tar.gz [ http://www.geocities.com/landroni/rgl_build.txt ] R CMD ldd /usr/lib/R/library/rgl/libs/rgl.so localhost liviu # R CMD ldd /usr/lib/R/library/rgl/libs/rgl.so linux-gate.so.1 = (0xe000) libR.so = /usr/lib/R/lib/libR.so (0xb7c9a000) libstdc++.so.6 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libstdc++.so.6 (0xb7b92000) libm.so.6 = /lib/libm.so.6 (0xb7b6c000) libgcc_s.so.1 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc_s.so.1 (0xb7b6) libc.so.6 = /lib/libc.so.6 (0xb7a2f000) libblas.so.0 = /usr/lib/libblas.so.0 (0xb79dd000) libgfortran.so.1 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgfortran.so.1 (0xb7962000) libreadline.so.5 = /lib/libreadline.so.5 (0xb793) libpcre.so.0 = /usr/lib/libpcre.so.0 (0xb7909000) libbz2.so.1 = /lib/libbz2.so.1 (0xb78f9000) libz.so.1 = /lib/libz.so.1 (0xb78e6000) libdl.so.2 = /lib/libdl.so.2 (0xb78e2000) /lib/ld-linux.so.2 (0x8000) libncurses.so.5 = /lib/libncurses.so.5 (0xb789e000) __ 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] Skipping specified rows in scan or read.table
Read the file in as lines of text (readLines), 'grep' through the character vector and delete the lines you want and then use: read.table(textConntection(yourvector)) to read the corrected data in. On 4/9/08, Ravi Varadhan [EMAIL PROTECTED] wrote: Hi, I have a data file, certain lines of which are character fields. I would like to skip these rows, and read the data file as a numeric data frame. I know that I can skip lines at the beginning with read.table and scan, but is there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19, 20, 28, 29, etc.) ? If I read the entire data file, and then delete the character fields, the values are still kept as factors, with each value denoted by its level. Since, I have continuous variables, there are as many levels as there are values. I am unable to coerce this to numeric mode. Is there a way to do this so that I can then manipulate the numeric data frame? Thanks for any help. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rgl build warnings and loading error on Linux
On Wed, 9 Apr 2008, Liviu Andronic wrote: Dear R users, This is a follow-up of a recent discussion on building rgl on Gentoo Linux. Please read bellow. On Tue, Mar 18, 2008 at 7:24 PM, Charles C. Berry [EMAIL PROTECTED] wrote: Below substitute 'nvidia-drivers' or whatever you use for your-video-drivers emerge -D mesa your-video-drivers revdep-rebuild -X R install.packages(rgl) I have entirely updated my system using emerge -tva -DNu world, also meaning that I switched to R version 2.6.2. I have rebuilt all packages broken by this update using revdep-rebuild -i -tva -X. Just to make sure, afterwards I have also emerge -tva mesa xf86-video-i810. My mesa USE flags look like this: localhost liviu # eix mesa media-libs/mesa Installed versions: 7.0.2(15:23:17 09/04/08)(video_cards_i810 -debug -doc -kernel_FreeBSD -motif -nptl -pic [..]) Building and loading rgl has only switched the error message: dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) Error in dyn.load(/usr/lib/R/library/rgl/libs/rgl.so) : unable to load shared library '/usr/lib/R/library/rgl/libs/rgl.so': /usr/lib/R/library/rgl/libs/rgl.so: undefined symbol: glNormal3f Previously it was: undefined symbol: glTexCoordPointer. Does this look like an rgl or a Gentoo Linux issue? Would any of the disabled mesa USE flags be worth enabling? A couple of guesses here. --- Does 'glxgears' work or give you a similar error message?? Obviously, if it breaks, your system is the issue. --- You can get some sense of what is going on by setting export LD_DEBUG_OUTPUT=tmp.debug export LD_DEBUG=all running something - like glxgears or R (invoking library(rgl)) then grep glNormal3f tmp.debug.* For one of my gentoo systems running an ati video card, I get this after glxgears [EMAIL PROTECTED] ~ $ grep glNormal3f tmp.debug.* 6846: symbol=glNormal3f; lookup in file=glxgears [0] 6846: symbol=glNormal3f; lookup in file=/usr/lib/libglut.so.3 [0] 6846: symbol=glNormal3f; lookup in file=/usr/lib/libGLU.so.1 [0] 6846: symbol=glNormal3f; lookup in file=//usr/lib64/opengl/ati/lib/libGL.so.1 [0] 6864: binding file glxgears [0] to //usr/lib64/opengl/ati/lib/libGL.so.1 [0]: normal symbol `glNormal3f' and after R return library(rgl) I get many more lines, but again ending with this long (wrapped) line 6857: binding file /home/cberry/lib.loc/rgl/libs/rgl.so [0] to //usr/lib64/opengl/ati/lib/libGL.so.1 [0]: normal symbol `glNormal3f' Maybe this helps: http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html --- Have you tried opengl-update? HTH, Chuck Thank you in advance, Liviu __ 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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ 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] permutation test assumption?
A few comments, My first impression on reading that abstract was that it was complete nonsense. After thinking a bit about it and skimming the full article I decided that it was nonsense, but nonsense that is important to research and discuss (and therefore the paper is useful). Why is it nonsense? The permutation test is a test of the null hypothesis that the 2 (or k) groups are from the same distribution (or identically distributed, or exchangable). The abstract says that they looked at the type I error rate when the 2 groups had different variances or other differences. The type I error is defined when the null hypothesis is true, so computing a type I error rate when the null is by definition false does not make sense. However, statisticians often do analyses where all the assumptions are not necessarily true (is any population really distributed as a normal), but the tests are close enough. So with modern tools it is not suprising to see people doing permutation tests without understanding what they are really testing and the results may be close enough (or they might not be). The contribution of this paper is to test and see if the results are close enough or not when you use a permutation test to test the null that the means are equal when there are other differences in the groups. Their answer is that no, the results are not close enough and they suggest that if you want to test for equality of means, but not identical distributions, then don't use a permutation test. To expand on Thierry's original answer: If you are testing the correct hypotheses and doing a permutation test correctly, then You can do permutation tests on an unbalanced design and it will still be a correct test. Unbalance could affect the power, which you would want to take into account when designing a study, but does not affect the correctness of the test (when used properly). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of João Fadista Sent: Tuesday, April 08, 2008 4:10 PM To: ONKELINX, Thierry; r-help@r-project.org Subject: Re: [R] permutation test assumption? Dear Thierry, Thanks for the reply. But as you may read in the paper http://bioinformatics.oxfordjournals.org/cgi/content/abstract/ 22/18/2244 when the sample sizes are not the same there may be an increase in the Type I error rate. Comments will be appreciated. Best regards, João Fadista De: ONKELINX, Thierry [mailto:[EMAIL PROTECTED] Enviada: ter 08-04-2008 15:27 Para: João Fadista; r-help@r-project.org Assunto: RE: [R] permutation test assumption? Dear João, You can do permutation tests on an unbalanced design. HTH, Thierry -- -- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens João Fadista Verzonden: dinsdag 8 april 2008 15:18 Aan: r-help@r-project.org Onderwerp: [R] permutation test assumption? Dear all, Can I do a permutation test if the number of individuals in one group is much bigger than in the other group? I searched the literature but I didin´t find any assumption that refers to this subject for permutation tests. Best regards João Fadista Ph.d. student UNIVERSITY OF AARHUS Faculty of Agricultural Sciences Dept. of Genetics and Biotechnology Blichers Allé 20, P.O. BOX 50 DK-8830 Tjele Phone: +45 8999 1900 Direct: +45 8999 1900 E-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Web: www.agrsci.org http://www.agrsci.org/ DJF now offers new degree programmes http://www.agrsci.org/content/view/full/34133 . News and news media http://www.agrsci.org/navigation/nyheder_og_presse . This email may contain information that is confidential. Any use or publication of this email without written permission from Faculty of Agricultural Sciences is not allowed. If you
Re: [R] Changing default plot behaviour
This may be a bit simple minded but why not change those commmands into a single function something like this and run it rather than the actual plot command? myfunction - function(a) { plot(a, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() } --- Thompson, David (MNR) [EMAIL PROTECTED] wrote: Hello, How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() Thanx, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ofri.mnr.gov.on.ca __ 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. __ [[elided Yahoo spam]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] creating expression with for-loop
Dear listmembers I would like to create an expression that looks like labl = expression(10^1,10^2,10^3,10^4,10^5) using a for-loop. However for (i in 1:5){ labl[i]=expression(10^i) } does not do the right thing. Does anybody knows help? Thanks Thomas __ 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] Changing default plot behaviour
Thank you all for your help. I successfully used Richard's suggestion (much like John's) and continued with my work, neglecting to respond to the list. Sorry about that. Thanx again, DaveT. -Original Message- From: John Kane [mailto:[EMAIL PROTECTED] Sent: April 9, 2008 03:16 PM To: Thompson, David (MNR); r-help@r-project.org Subject: Re: [R] Changing default plot behaviour This may be a bit simple minded but why not change those commmands into a single function something like this and run it rather than the actual plot command? myfunction - function(a) { plot(a, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() } --- Thompson, David (MNR) [EMAIL PROTECTED] wrote: Hello, How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3, tcl=0.5, labels=FALSE) axis(4, tcl=0.5, labels=FALSE) box() Thanx, DaveT. * Silviculture Data Analyst Ontario Forest Research Institute Ontario Ministry of Natural Resources [EMAIL PROTECTED] http://ofri.mnr.gov.on.ca __ 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. __ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ __ 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] Skipping specified rows in scan or read.table
On Wed, 9 Apr 2008, Ravi Varadhan wrote: Hi, I have a data file, certain lines of which are character fields. I would like to skip these rows, and read the data file as a numeric data frame. I know that I can skip lines at the beginning with read.table and scan, but is there a way to skip a specified sequence of lines (e.g., 1, 2, 10, 11, 19, 20, 28, 29, etc.) ? Not within scan, but you can do it within the connection that scan reads. If the file is small, just read it all with readLines, select the lines you want (mydata[-c(1,2,10,11...)]) and use that as the input to a textConnection. If it is large, read a line at a time, discard when it is one to be skipped otherwise write to an anonymous file() connection. Then read.table on the anonymous connection. Or use perl/awk within a pipe() connection. If I read the entire data file, and then delete the character fields, the values are still kept as factors, with each value denoted by its level. Since, I have continuous variables, there are as many levels as there are values. I am unable to coerce this to numeric mode. Is there a way to do this so that I can then manipulate the numeric data frame? Why does FAQ Q7.10 not apply? Thanks for any help. Best, Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] creating expression with for-loop
On 4/9/2008 3:22 PM, Thomas Hoffmann wrote: Dear listmembers I would like to create an expression that looks like labl = expression(10^1,10^2,10^3,10^4,10^5) using a for-loop. However for (i in 1:5){ labl[i]=expression(10^i) } does not do the right thing. Does anybody knows help? labl - expression() for (i in 1:5) labl[[i]] - bquote(10^.(as.numeric(i))) (The as.numeric() might not be necessary if you don't care if the exponent prints as 1L, 2L, etc. plotmath() handles it fine.) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply lm() for all the columns of a matrix
It is still not clear what is your response (y) variable and exactly what is your predictor (x) variable(s). If you have a separate vector of length 10 that is the response and you want to regress it with each of the 8 vectors mentioned, then here is one way to do that: p-1:80+rnorm(80) dim(p)-c(2,2,2,10) y - 1:10 my.data - data.frame( y=rep(y,8), x=c(aperm(p,4:1)), g=gl(8,10) ) library(nlme) fits - lmList( y ~ x | g, data=my.data ) Now 'fits' is a list with the 8 regressions, you can access each regression with fits[[1]] and the like, or there are some summaries that you can get from the entire list. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Costas Douvis Sent: Wednesday, April 09, 2008 8:54 AM To: Dimitris Rizopoulos; r-help@r-project.org Subject: Re: [R] apply lm() for all the columns of a matrix Here's a simplified example p-1:80+rnorm(80) dim(p)-c(2,2,2,10) We could say that the 4-d array p consists of 2*2*2 = 8 vectors of length 10. So what I'm asking for is a fast way to perform a linear fit to all those vectors. I'm sorry if I'm causing you to have a headache with all those dimensions :) Kostas Well, could you provide a little bit more information regarding what you are trying to do (e.g., reproducible example). Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org; Mark Leeds [EMAIL PROTECTED]; Dimitris Rizopoulos [EMAIL PROTECTED] Cc: Chuck Cleland [EMAIL PROTECTED] Sent: Wednesday, April 09, 2008 3:44 PM Subject: Re: [R] apply lm() for all the columns of a matrix Thank you all very much for replying. Of course you are absolutely right but unfortunately I really deal with the case of a 4-d matrix so what you said does not apply. I should have specified but being a new R user I hadn't realized the difference between a matrix and an array. So please tell me if you know a fast way (not using a loop) to perform a linear fit on all the vectors of the 4-th dimension of a 4-d array. Thanks again Kostas If you have the same design matrix then you can specify a matrix of responses in lm(), e.g., Y - matrix(rnorm(100*10), 100, 10) x - rnorm(100) fit - lm(Y ~ x) fit summary(fit) I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Costas Douvis [EMAIL PROTECTED] To: r-help@r-project.org Sent: Wednesday, April 09, 2008 12:55 PM Subject: [R] apply lm() for all the columns of a matrix Hi all, My question is not really urgent. I can write a loop and solve the problem. But I know that I'll be in a similar situation many more times so it would be useful to find out the answer Is there a fast way to perform linear fit to all the columns of a matrix? (or in the one dimension of a multi-dimensional array.) I'm talking about many single linear fits, not about a multiple fit. I thought that a combination of apply and lm would do it but I can't make it work Thank you Kostas -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm -- Kostas Douvis PhD Student University of Athens - Department of Geography and Climatology Academy of Athens - Research Centre for Atmospheric Physics and Climatology email: [EMAIL PROTECTED] tel: +30-210-8832048 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] GLM fitting in R and Statistica
I have a problem concerning discrepances between R (which I use) and Statistica (which uses my supervisor). --- can this be submitted as a fortune? any other programs around that use supervisors, it's always good to have a couple of those around ingmar [[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] read table not reading lines containing single quotes
Hi, * I am using read.table command as follow kegg-read.table(c:/IDs.tab,header =TRUE,quote= ', sep=\t) * Fragment of file is as follow: ID Pathway 04916Melanogenesis 04920Adipocytokine signaling pathway 04930Type II diabetes mellitus 04940Type I diabetes mellitus 04950Maturity onset diabetes of the young 05010Alzheimer's disease 05020Parkinson's disease 05030Amyotrophic lateral sclerosis (ALS) 05040Huntington's disease 05050Dentatorubropallidoluysian atrophy (DRPLA) *It doesnot read from Alzheimer's disease. Due the single qoutes in it. Can you please suggest something so that I can read full file. * Thank you Vidhu [[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] permutation/randomization
Grant Gillis wrote: Hello, I have what I suspect might be an easy problem but I am new to R and stumped. I have a data set that looks something like this b-c(2,3,4,5,6,7,8,9) x-c(2,3,4,5,6,7,8,9) y-c(9,8,7,6,5,4,3,2) z-c(9,8,7,6,1,2,3,4) data-cbind(x,y,z) row.names(data)-c('a','b','c','d','e','f','g','h') which gives: x y z a 2 9 9 b 3 8 8 c 4 7 7 d 5 6 6 e 6 5 1 f 7 4 2 g 8 3 3 h 9 2 4 I would like to randomize data within columns. The closest I have been able to come permutes data within the columns but keeps rows together along with row names(example below). For some context, eventually I would like use this to generate many data sets and perform calculations on these random data sets (I think I know how to do this but we'll see). So ideally I would like row names to remain the same (in order a through h) and column data to randomize within columns but independently of the other columns. Just shuffle the data deck I guess data[permute(1:length(data[,1])),] x y z b 3 8 8 c 4 7 7 h 9 2 4 e 6 5 1 f 7 4 2 a 2 9 9 g 8 3 3 d 5 6 6 I changed 'data' to 'mymat' as 'data' is a function in R (see ?data) and added the row names after permuting: someMatrix - cbind(x, y, z) permutedMat - apply(someMatrix, 2, sample) row.names(permutedMat)-c('a','b','c','d','e','f','g','h') permutedMat HTH, Tobias __ 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] permutation/randomization
On Wed, Apr 09, 2008 at 11:08:28AM -0700, Grant Gillis wrote: I would like to randomize data within columns. I think the following line does what you want (minus preserving the row labels): apply(data, 2, sample) Maybe someone smarter than me knows how to preserve the row names. I would probably just steal them from the original data frame: nam = row.names(data) apply(data, 2, sample) row.names(foo) = nam cu Philipp -- Dr. Philipp Pagel Tel. +49-8161-71 2131 Lehrstuhl für Genomorientierte Bioinformatik Fax. +49-8161-71 2186 Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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] read table not reading lines containing single quotes
On Wed, Apr 09, 2008 at 04:09:57PM -0400, Vidhu Choudhary wrote: kegg-read.table(c:/IDs.tab,header =TRUE,quote= ', sep=\t) * *It doesnot read from Alzheimer's disease. Due the single qoutes in it. You have almost given the answer yourself: you are declaring the single quote to be a quotation character in your read.table call. Either turn quoting off entirely (quote=) or restrict it to double quotes (quote =\) cu Philipp -- Dr. Philipp Pagel Tel. +49-8161-71 2131 Lehrstuhl für Genomorientierte Bioinformatik Fax. +49-8161-71 2186 Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany and Institut für Bioinformatik und Systembiologie / MIPS Helmholtz Zentrum München - Deutsches Forschungszentrum für Gesundheit und Umwelt Ingolstädter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/staff/pagel __ 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] permutation/randomization
You can randomize the order (permute) of a single column with something like: x - cbind( x=1:10, y=101:110, z=201:210 ) rownames(x) - letters[1:10] new.x - x new.x[,1] - sample(new.x[,1]) new.x x y z a 8 101 201 b 10 102 202 c 5 103 203 d 9 104 204 e 3 105 205 f 1 106 206 g 7 107 207 h 4 108 208 i 2 109 209 j 6 110 210 You could do that for each of the columns that you want randomized. A quick way to do a separate randomization on each column is: new.x - apply(x, 2, sample) rownames(new.x) - letters[1:10] new.x x y z a 2 101 203 b 3 107 204 c 6 102 205 d 1 104 207 e 4 105 208 f 7 108 201 g 10 110 206 h 8 106 209 i 5 103 210 j 9 109 202 Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Grant Gillis Sent: Wednesday, April 09, 2008 12:08 PM To: r-help@r-project.org Subject: [R] permutation/randomization Hello, I have what I suspect might be an easy problem but I am new to R and stumped. I have a data set that looks something like this b-c(2,3,4,5,6,7,8,9) x-c(2,3,4,5,6,7,8,9) y-c(9,8,7,6,5,4,3,2) z-c(9,8,7,6,1,2,3,4) data-cbind(x,y,z) row.names(data)-c('a','b','c','d','e','f','g','h') which gives: x y z a 2 9 9 b 3 8 8 c 4 7 7 d 5 6 6 e 6 5 1 f 7 4 2 g 8 3 3 h 9 2 4 I would like to randomize data within columns. The closest I have been able to come permutes data within the columns but keeps rows together along with row names(example below). For some context, eventually I would like use this to generate many data sets and perform calculations on these random data sets (I think I know how to do this but we'll see). So ideally I would like row names to remain the same (in order a through h) and column data to randomize within columns but independently of the other columns. Just shuffle the data deck I guess data[permute(1:length(data[,1])),] x y z b 3 8 8 c 4 7 7 h 9 2 4 e 6 5 1 f 7 4 2 a 2 9 9 g 8 3 3 d 5 6 6 Thanks in advance for the help and also for the good advice earlier this week. Cheers [[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] GLM fitting in R and Statistica
Can you get fitted values out of Statistica? If the 2 models are equivalent, just using different encodings of the categorical variables, then the fitted values will be the same (within roundoff error) even though the coefficient estimates may differ. So as a first step you should compare the fitted values or predicted values for new points and see if those are close or not. Also, make sure that Statistica is treating site as a categorical variable (does it show 2 degrees of freedom?), if it is seeing it as a linear variable rather than a categorical, then it would show 1 line and everything would be messed up. Hope this helps, If not, can you send code/output from both using a sample dataset? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Agnieszka Kloch Sent: Wednesday, April 09, 2008 12:09 PM To: R help Subject: [R] GLM fitting in R and Statistica Hi, I have a problem concerning discrepances between R (which I use) and Statistica (which uses my supervisor). I can't say what is the origin of these differences but unfortunately my supervisor doesn't know that either. Our response variable is number (or presence/absence) of parasites in rodents and explanatory variables are presence/absence of several alleles. The rodents were sampled in three sites and the sites differ in parasite frequency so we decided to include site as a factor. The problem concerns calculations of factor variable. In Statistica output there is only one term, just site, and in R there are two contrats site A, site B. I realized that I can obtain similar results in Statistica clicking on Estimate button instead of 1LR (what does my supervisor which gives only log-likelihood and p of variables but doesn't estimate parameter). But there is still one problem I can't explain. When we fit interaction terms (site x allele1, site x allele2 and so on) the results are completely different. I tried several different contrasts in R, such as contr.SAS, contr.treatment etc but I couldn't get nothing similar to Statistica output. Have anybody any idea how to deal with that? Or how to explain why R results are different (and hopefully better)? I tried to argue that I did everything according to Crawley's R Book so probably the models are constructed correctly but my supervisor wasn't convinced... Looking forward any suggestions, Agnieszka -- Agnieszka Kloch Instytute of Environmental Sciences, Jagielonian University ul. Gronostajowa 7, 30-387 Krakow, Poland, tel. (12) 664 51 51 __ 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] rgl build warnings and loading error on Linux
Right, that shows that the rgl configure script is not being run and no linking is being done to any GL libraries. I've never seen that. Is there something unusual about the filesystem so it does not recognize rgl/configure is executable? (We've seen that on SMB filesystems with the wrong mount options.) What I suggest you try is - unpack the rgl tarball. - cd rgl - R CMD ./configure - cd .. - R CMD INSTALL rgl Hopefully that will either configure or explain why it is not being run. On Wed, 9 Apr 2008, Liviu Andronic wrote: Dear Duncan and Brian, thank you for the quick replies. Please see bellow. On Wed, Apr 9, 2008 at 6:11 PM, Prof Brian Ripley [EMAIL PROTECTED] wrote: We'll need to see the output from install.packages(rgl) to have much idea: localhost liviu # R CMD INSTALL /home/liviu/inst/dwn_R/rgl_0.77.tar.gz [ http://www.geocities.com/landroni/rgl_build.txt ] R CMD ldd /usr/lib/R/library/rgl/libs/rgl.so localhost liviu # R CMD ldd /usr/lib/R/library/rgl/libs/rgl.so linux-gate.so.1 = (0xe000) libR.so = /usr/lib/R/lib/libR.so (0xb7c9a000) libstdc++.so.6 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libstdc++.so.6 (0xb7b92000) libm.so.6 = /lib/libm.so.6 (0xb7b6c000) libgcc_s.so.1 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc_s.so.1 (0xb7b6) libc.so.6 = /lib/libc.so.6 (0xb7a2f000) libblas.so.0 = /usr/lib/libblas.so.0 (0xb79dd000) libgfortran.so.1 = /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgfortran.so.1 (0xb7962000) libreadline.so.5 = /lib/libreadline.so.5 (0xb793) libpcre.so.0 = /usr/lib/libpcre.so.0 (0xb7909000) libbz2.so.1 = /lib/libbz2.so.1 (0xb78f9000) libz.so.1 = /lib/libz.so.1 (0xb78e6000) libdl.so.2 = /lib/libdl.so.2 (0xb78e2000) /lib/ld-linux.so.2 (0x8000) libncurses.so.5 = /lib/libncurses.so.5 (0xb789e000) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] vectorized way to combine levels of a factor
Hi Gurus: If I have a large dataset of the form of: x - data.frame(V1 = runif(10), V2 = sample(c('A','B','C'),10,T)) x V1 V21 0.2691580 A2 0.8711267 B3 0.2674728 C4 0.3278876 A5 0.1809152 A6 0.2499651 C7 0.9155174 A8 0.8004974 B9 0.7885516 A10 0.9301630 A And I want a V3 that =V2 if V2=A, and =D if V2=B or C. In other words I want to use a vectorized way to combine some levels, rather than having to loop through a large dataset. Similarly, if I want to group V1 into levels, what is a fast way to do it? Thank you! Karen _ If you like crossword puzzles, then you'll love Flexicon, a game which comb[[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] If statements for vectors
Dear Sirs, I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the 'standard' R-package. I am trying to select a list of genes which all have expression values below a certain threshold. I have done this by creating a vector which has 0s where the expression is greater than the threshold and 1s where it is less than or equal to it. Multiplying this vector by the expression values produces a list of 0s and expression values below the threshold value. However, now I need to remove the 0s. I thought that this would be relatively trivial but it appears it isn't!!! The dimension of the list (with the 0s and values) is 506994. So I wrote the following: for(i in 1:506994) { if(exp2[i] 0) { exp3 - append(1,exp2[i]) } return(exp3) } where exp2 is the vector of 0s and threshold values. However I have since discovered that 'if' does not work on vectors. The suggestions I have seen on this forum include 'ifelse' which I don't believe to be relevant in this situation and 'sapply' which again I don't think is relevant. Can anyone therefore tell me how I can produce a new vector from an old one by removing the 0 entries? Thank you for your help, Laura University of Warwick [[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] vectorized way to combine levels of a factor
For your first problem, you can probably do it in 2 statements: V3 = ifelse(V2==A,V2,V3) V3 = ifelse(V2==B|V2==C,D,V3) If you want to split V1 into (0,a],(a,b],(b,c],(c,1], you can do, quite simply V1.factor = cut(V1, c(0,a,b,c,1)) Abhijit On Wed, 9 Apr 2008 13:58:17 -0700 Chang Liu [EMAIL PROTECTED] wrote: Hi Gurus: If I have a large dataset of the form of: x - data.frame(V1 = runif(10), V2 = sample(c('A','B','C'),10,T)) x V1 V21 0.2691580 A2 0.8711267 B3 0.2674728 C4 0.3278876 A5 0.1809152 A6 0.2499651 C7 0.9155174 A8 0.8004974 B9 0.7885516 A10 0.9301630 A And I want a V3 that =V2 if V2=A, and =D if V2=B or C. In other words I want to use a vectorized way to combine some levels, rather than having to loop through a large dataset. Similarly, if I want to group V1 into levels, what is a fast way to do it? Thank you! Karen _ If you like crossword puzzles, then you'll love Flexicon, a game which comb[[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Abhijit Dasgupta __ 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] Number of words in a string
On Apr 9, 2008, at 1:27 PM, Hans-Jörg Bibiko wrote: On 09.04.2008, at 17:46, Shubha Vishwanath Karanth wrote: To put it simple, C=c(My Dog, Its really good, Beautiful) Now, SOMEFUNCTION(C) should give: c(My, Its really, ) SOMEFUNCTION - function(x) gsub( *\\w+$, , x) But be aware that this won't work for instance for combining diacritics. If you have this: C - c(My Dog, Its really good, Beautiful, Tuli faŝda) in fasda above the s is a combining circumfix ^ would give [1] My Its reallyTuli faŝ Then one should use the strsplit approach. How about: SOMEFUNCTION - function(x) gsub( *\\S+$, , x) Cheers, --Hans Haris Skiadas Department of Mathematics and Computer Science Hanover College __ 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] If statements for vectors
On Wed, Apr 9, 2008 at 4:07 PM, Laura Bonnett [EMAIL PROTECTED] wrote: Dear Sirs, I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the 'standard' R-package. I am trying to select a list of genes which all have expression values below a certain threshold. I have done this by creating a vector which has 0s where the expression is greater than the threshold and 1s where it is less than or equal to it. Multiplying this vector by the expression values produces a list of 0s and expression values below the threshold value. However, now I need to remove the 0s. I thought that this would be relatively trivial but it appears it isn't!!! Without a working example from you, I have no way to test this proposal. But if I were you, I would get the index values of the right cases in one step, and then use that to choose the ones I want. theGoodOnes - which(exp2 = 0) exp3 - exp2[theGoodOnes] This can be crammed into one line, but I'd do it in two just to make sure it is correct, at least the first time. My example: x - rnorm(100) which(x = 0) [1] 9 11 12 13 14 16 19 20 21 22 24 25 28 30 32 34 35 36 38 40 41 42 43 44 46 [26] 47 49 50 53 54 57 59 61 63 64 66 68 69 70 72 75 78 80 81 82 83 88 90 97 98 theGoodOnes - which(x=0) newX - x[theGoodOnes] newX [1] 0.89285908 0.51753998 1.18485887 2.10003705 0.54535841 1.28313738 [7] 1.34092172 0.76064356 0.02201121 0.80808363 0.04578730 0.23045983 [13] 1.04306626 0.12694184 0.89706863 0.86302992 1.53471660 0.51192410 [19] 1.00366834 1.76923470 0.49508470 1.27888454 0.76706729 1.46340483 [25] 1.69315538 0.50537603 0.18422329 0.72968629 0.45490526 2.18208183 [31] 0.71926926 0.68915832 1.49076770 0.48763971 0.39273110 0.80709549 [37] 0.22099019 0.38103757 0.14626929 0.63933750 1.26643194 3.33091910 [43] 2.50341609 2.05286611 0.31986095 0.64548972 0.34712937 0.04075135 [49] 0.07206342 0.20325505 -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ 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] loading an updated version of a package during an active R session?
I am developing a package and I want to be able to load an updated version of the package from within an active R session. Suppose, for example, I have a function f within a package X. In my active R session, I have already loaded X. Then I change the R source code of f within X and rebuild the package as a .tar.gz file on the command line with R CMD build X Within my R session, is there a way to reload X such that the updated definition of f will be used? I have tried: detach(package:X) install.packages(X.tar.gz, repos=NULL, type=source) library(X) but this seems to use the old version of f. Any suggestions would be much appreciated! Many thanks in advance! Roger __ 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] simple intro to cluster analysis using R
I am looking for simple introduction to cluster analysis using R, that would be understandable to a novice in statistics. Or, could someone perhaps help me understand how to proceed in my analysis? I am very new to both statistics and R, but am trying hard to avoid having to use SPSS as everyone around me... I have dataset on people presenting their opinions on different religious communities coded on 5 point scale, and I want to see if those communities can be grouped (clustered) in some way that would be illuminatin for my research purposes. So, I have data that looks like this: describe(R12) R12 18 Variables 1035 Observations --- R12.1 n missing unique 416 619 5 More negative (51, 12%), More positive (112, 27%) Completely negative (41, 10%), Completely positive (23, 6%) Neutral (189, 45%) skip R12.12 n missing unique 451 584 5 More negative (111, 25%), More positive (43, 10%) Completely negative (79, 18%), Completely positive (5, 1%) Neutral (213, 47%) and so on So you can see there is a lot (more than half) at times NA's in this questionnairre. Here is also a correlation matrix (only part is displayed): x=cor(R12, use=pairwise.complete.obs) round(x,2) R12.1 R12.2 R12.3 R12.4 R12.5 R12.6 R12.7 R12.8 R12.9 R12.10 R12.11 R12.1 1.00 0.57 0.57 0.61 0.57 0.48 0.43 0.38 0.52 0.58 0.58 R12.2 0.57 1.00 0.82 0.78 0.73 0.62 0.43 0.49 0.64 0.69 0.75 R12.3 0.57 0.82 1.00 0.89 0.90 0.73 0.54 0.57 0.70 0.77 0.78 R12.4 0.61 0.78 0.89 1.00 0.91 0.68 0.51 0.56 0.65 0.80 0.76 R12.5 0.57 0.73 0.90 0.91 1.00 0.73 0.53 0.55 0.68 0.78 0.74 R12.6 0.48 0.62 0.73 0.68 0.73 1.00 0.59 0.62 0.68 0.79 0.78 R12.7 0.43 0.43 0.54 0.51 0.53 0.59 1.00 0.62 0.55 0.65 0.65 R12.8 0.38 0.49 0.57 0.56 0.55 0.62 0.62 1.00 0.55 0.65 0.62 R12.9 0.52 0.64 0.70 0.65 0.68 0.68 0.55 0.55 1.00 0.79 0.82 R12.10 0.58 0.69 0.77 0.80 0.78 0.79 0.65 0.65 0.79 1.00 0.88 R12.11 0.58 0.75 0.78 0.76 0.74 0.78 0.65 0.62 0.82 0.88 1.00 R12.12 0.47 0.59 0.64 0.65 0.60 0.61 0.56 0.50 0.68 0.77 0.83 R12.13 0.62 0.69 0.77 0.70 0.74 0.76 0.65 0.61 0.78 0.81 0.82 R12.14 0.58 0.70 0.71 0.75 0.70 0.74 0.64 0.62 0.78 0.86 0.86 R12.15 0.58 0.61 0.72 0.72 0.71 0.72 0.64 0.59 0.73 0.83 0.79 R12.16 0.56 0.67 0.77 0.72 0.78 0.75 0.57 0.54 0.75 0.85 0.80 R12.17 0.61 0.69 0.79 0.77 0.75 0.73 0.56 0.57 0.74 0.82 0.80 R12.18 0.63 0.73 0.84 0.82 0.83 0.71 0.54 0.64 0.68 0.71 0.74 so you can see there is a lot of correlation in the opinions. I doubt clusterization would be meaningfull, but I still want to try. How do I proceed with this? -- Donatas Glodenis __ 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] LSODA not accurate when RK4 is; what's going on?
I'm solving the differential equation dy/dx = xy-1 with y(0) = sqrt(pi/2). This can be used in computing the tail of the normal distribution. (The actual solution is y(x) = exp(x^2/2) * Integral_x_inf {exp(-t^2/2) dt} = Integral_0_inf {exp (-xt - t^2/2) dt}. For large x, y ~ 1/x, starting around x~2.) I'm testing both lsoda and rk4 from the package odesolve. rk4 is accurate using step length 10^-2 and probably would be with even larger steps. lsoda is pretty accurate out to about x=4, then starts acting strangely. For step length 10^-3, y suddenly starts to increase after 4, when it should be strictly decreasing. For step length 10^-4, y instead turns down and start dropping precipitously. Any ideas why lsoda would go off the rails when rk4 does so well? I will soon be using R to solve more complicated systems of ODEs which I don't understand as well, so I want to know when it can mislead me. Code: t4 - seq(0, 5, by=.0001) fn function(t,y,parms=0){return(list(t*y-1))} s4 - lsoda(sqrt(pi/2), t4, fn, 0) [[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] Huber-white cluster s.e. after optim?
I've used optim to analyze some data I have with good results, but need to correct the var-cov matrix for possible effects of clustering of observations (respondents) in small groups (non-independence). Is there any function to adjust the matrix? I heard some time ago that the vcovHC function would have a cluster capability added to it, but I don't see that in my fairly recent version. Cheers, Peter __ 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] Computing time when calling C functions - why does an extra function call induce such an overhead?
Dear list, I am a little puzzled by computing time in connection with calling C functions. With the function mysolve1 given below I solve Ax=B, where the actual matrix operation takes place in mysolve2. Doing this 5000 times takes 3.51 secs. However, if I move the actual matrix inversion part into mysolve1 (by uncommenting the two commented lines and skip the call to mysolve2) then the computations take only 0.03 secs. Can anyone tell me why there is such a time-overhead in introducing the extra function call to mysolve2? I am on windows XP using R 2.6.1 Best regards Søren SEXP mysolve1(SEXP Ain, SEXP Bin, SEXP tolin) { int *Adims, *Bdims; double tol = asReal(tolin); SEXP A, B; PROTECT(A = duplicate(Ain)); PROTECT(B = duplicate(Bin)); Adims = INTEGER(coerceVector(getAttrib(A, R_DimSymbol), INTSXP)); Bdims = INTEGER(coerceVector(getAttrib(B, R_DimSymbol), INTSXP)); int nrA, ncB; double *Ap, *Bp; nrA = Adims[0]; ncB = Bdims[1]; Ap = REAL(A); Bp = REAL(B); /* int info, *ipiv = (int *) R_alloc(nrA, sizeof(int)); */ /* F77_CALL(dgesv)(nrA, ncB, Ap, nrA, ipiv, Bp, nrA, info); */ mysolve2(Ap, nrA, Bp, ncB, tol); UNPROTECT(2); return B; } void mysolve2(double *A, int *nrA, double *B, int *ncB, double *tolin) { int info; int *ipiv = (int *) R_alloc((int) nrA, sizeof(int)); F77_CALL(dgesv)(nrA, ncB, A, nrA, ipiv, B, nrA, info); } __ 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] If statements for vectors
Le mer. 9 avr. à 18:00, Paul Johnson a écrit : On Wed, Apr 9, 2008 at 4:07 PM, Laura Bonnett [EMAIL PROTECTED] wrote: Dear Sirs, I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the 'standard' R-package. I am trying to select a list of genes which all have expression values below a certain threshold. I have done this by creating a vector which has 0s where the expression is greater than the threshold and 1s where it is less than or equal to it. Multiplying this vector by the expression values produces a list of 0s and expression values below the threshold value. However, now I need to remove the 0s. I thought that this would be relatively trivial but it appears it isn't!!! Without a working example from you, I have no way to test this proposal. But if I were you, I would get the index values of the right cases in one step, and then use that to choose the ones I want. theGoodOnes - which(exp2 = 0) exp3 - exp2[theGoodOnes] This can be crammed into one line, but I'd do it in two just to make sure it is correct, at least the first time. This type of extraction is so common that it has become idiomatic to write exp3 - exp2[exp2 = 0] Also, Laura, if you want to truncate (not eliminate) values to a certain threshold or limit, use the vectorized functions pmax() and pmin(). For the type of manipulation you needed to do it's almost never necessary to use for() loops. HTH Vincent My example: x - rnorm(100) which(x = 0) [1] 9 11 12 13 14 16 19 20 21 22 24 25 28 30 32 34 35 36 38 40 41 42 43 44 46 [26] 47 49 50 53 54 57 59 61 63 64 66 68 69 70 72 75 78 80 81 82 83 88 90 97 98 theGoodOnes - which(x=0) newX - x[theGoodOnes] newX [1] 0.89285908 0.51753998 1.18485887 2.10003705 0.54535841 1.28313738 [7] 1.34092172 0.76064356 0.02201121 0.80808363 0.04578730 0.23045983 [13] 1.04306626 0.12694184 0.89706863 0.86302992 1.53471660 0.51192410 [19] 1.00366834 1.76923470 0.49508470 1.27888454 0.76706729 1.46340483 [25] 1.69315538 0.50537603 0.18422329 0.72968629 0.45490526 2.18208183 [31] 0.71926926 0.68915832 1.49076770 0.48763971 0.39273110 0.80709549 [37] 0.22099019 0.38103757 0.14626929 0.63933750 1.26643194 3.33091910 [43] 2.50341609 2.05286611 0.31986095 0.64548972 0.34712937 0.04075135 [49] 0.07206342 0.20325505 -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ 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. --- Vincent Goulet, Associate Professor École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca __ 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] question about nlminb
Hi, John: I just got the following error right after the attempt to use 'rmvnorm'. Error: could not find function rmvnorm I tried 'library(mvtnorm)', but the 'rmvnorm' in that package gave me the following: Error in rmvnorm(1, mean = c(3, -20, -10, 3, 2), sd = c(0.1, 15, 4, : unused argument(s) (sd = c(0.1, 15, 4, 0.15, 0.8), cov = c(1, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 1)) Then I got 87 hits to RSiteSearch(rmvnorm, 'fun'). Regarding, How would I go about getting the entire variance-covariance matrix?, this is really easy: Just define a 5 x 4 matrix A so the 5-dimensional 'opt' you want is a constant plus A times the 4-dimensional restricted 'opt'. [Please don't use the same name for two different things like 'opt' in your function below. Half a century ago, when Fortran was young, that was very smart programming. Today, it's primary effect it to make it difficult for mere mortals to understand your code. Use something like 'opt5' for one and 'opt4' for the other.] Then Sig5 = A %*% vcov.nlminb(opt) %*% t(A). I believe the A matrix you want is as follows: A = matrix(NA, dim=c(5, 4)) A[1:4, 1:4] - diag(4) A[5, ] - (-1) However, since your example was not self contained, I have not tested this. Hope this helps. Spencer John Pitchard wrote: Hi Spencer, Sorry for not producing code as a worked example. Here's an example: == # setting the seed number set.seed(0) # creating a correlation matrix corr - diag(5) corr[lower.tri(corr)] - 0.5 corr[upper.tri(corr)] - 0.5 # Data for the minimisation mat - rmvnorm(1, mean=c(3, -20, -10, 3, 2), sd=c(0.1, 15, 4, 0.15, 0.8), cov=corr) obj.fun - function(opt, mat) { opt - c(opt, 1-sum(opt)) LinearComb - mat%*%opt obj - -min(LinearComb) obj } opt - nlminb(rep(0,4), lower=rep(-3, 4), upper=rep(3, 4), obj.fun, mat=mat) opt.x - opt$parameters opt.x - c(opt.x, 1-sum(opt.x)) # using vcov.nlminb from the MASS library to obtain the covariance matrix vcov.nlminb(opt) I have a variance-covariance matrix for 4 of the elements in the vector but not the last component. How would I go about getting the entire variance-covariance matrix? Thanks in advance for any help. Regards, John On 09/04/2008, Spencer Graves [EMAIL PROTECTED] wrote: Have you considered optimizing over x1 = x[1:(length(x)-1]? You could feed a wrapper function 'f2(x1, ...)' that computes xFull = c(x1, 1-sum(x1)) and feeds that to your 'fn'. If this makes sense, great. Else, if my answer is not useful, be so kind as to PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Spencer John Pitchard wrote: Dear All, I wanted to post some more details about the query I sent to s-news last week. I have a vector with a constraint. The constraint is that the sum of the vector must add up to 1 - but not necessarily positive, i.e. x[n] - 1 -(x[1] + ...+x[n-1]) I perform the optimisation on the vector x such that x - c(x, 1-sum(x)) In other words, fn - function(x){ x - c(x, 1 - sum(x)) # other calculations here } then feed this into nlminb() out - nlminb(x, fn) out.x - out$parameters out.x - c(out.x, 1 - sum(out.x)) out.x I would like to calculate standard errors for each of the components of x. Is this possible by outputing the Hessian matrix? Furthermore, how would I calculate this for the last component (if this is indeed possible) which has the restriction (i.e. 1-sum(out.x))? Any help would be much appreciated. Regards, John [[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-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] Huber-white cluster s.e. after optim?
optim is a general purpose optimiser. You don't reallly use it to 'analyze' data and you cannot get a variance matrix directly from the result, even using vcov. If you ask, it will give you the hessian matrix of the objective function at the optimum value, from which you can get a variance matrix if you wish, provided the objective function that you optimised was the negative of a log-likelihood function. So the recommended way of going about things in your case is probably a) calculate the negative log-likelihood from the non-independence model that accommodates the kind of clustering you suspect may be happening, b) use optim to optimise it, requesting the hessian and c) invert the hessian to get the variance matrix. In many cases a) often looks difficult, but on closer inspection turns out to be impossible, (typicall because it involves too much numerical integration). In this case you need to use an alternative approach which probably will not involve using optim at all. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Muhlberger Sent: Thursday, 10 April 2008 10:16 AM To: [EMAIL PROTECTED] Subject: [R] Huber-white cluster s.e. after optim? I've used optim to analyze some data I have with good results, but need to correct the var-cov matrix for possible effects of clustering of observations (respondents) in small groups (non-independence). Is there any function to adjust the matrix? I heard some time ago that the vcovHC function would have a cluster capability added to it, but I don't see that in my fairly recent version. Cheers, Peter __ 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] Huber-white cluster s.e. after optim?
On 10/04/2008, at 2:02 PM, [EMAIL PROTECTED] wrote: In many cases a) often looks difficult, but on closer inspection turns out to be impossible I nominate this for a fortune. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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] Huber-white cluster s.e. after optim?
I concur! Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rolf Turner Sent: Wednesday, April 09, 2008 10:22 PM To: R-help List Subject: Re: [R] Huber-white cluster s.e. after optim? On 10/04/2008, at 2:02 PM, [EMAIL PROTECTED] wrote: In many cases a) often looks difficult, but on closer inspection turns out to be impossible I nominate this for a fortune. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ 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.