[R] how to get the group mean deviation data ?
n=10;t=3 d-cbind(id=rep(1:n,each=t),y=rnorm(n*t),x=rnorm(n*t),z=rnorm(n*t)) head(d) id y x z [1,] 1 -2.1725379 0.07629954 -0.3985258 [2,] 1 -1.2383038 -2.49667038 0.6966127 [3,] 1 -1.2642401 -0.50613307 0.4895856 [4,] 2 0.2171246 0.86711864 -0.6660036 [5,] 2 2.2765760 -0.48547142 -1.4496664 [6,] 2 0.5985345 -1.06427035 2.1761071 first,i want to get the group mean of each variable,which i can use d-data.frame(d) aggregate(d,list(d$id),mean)[,-1] id y x z 1 1 -1.55836060 -0.9755013 0.26255754 2 2 1.03074502 -0.2275410 0.02014565 3 3 0.20700121 -0.7159450 1.35890176 4 4 0.17839650 1.2575891 0.04135165 5 5 -0.20012508 0.4310221 0.55458899 6 6 -0.13084185 -0.2953392 0.28229068 7 7 0.20737288 -0.8863761 -0.50793880 8 8 0.07512612 -0.6591304 -0.21656533 9 9 0.94727796 -0.6108891 0.13529884 10 10 -0.04434875 0.1332086 -0.88229808 then i want the group mean deviation data,like head(sapply(d[,2:4],function(x) x-ave(x,d$id))) y x z [1,] -0.6141773 1.0518008 -0.6610833 [2,] 0.3200568 -1.5211691 0.4340552 [3,] 0.2941205 0.4693682 0.2270281 [4,] -0.8136205 1.0946597 -0.6861493 [5,] 1.2458310 -0.2579304 -1.4698121 [6,] -0.4322105 -0.8367293 2.1559614 both above are what i want.though i can do it use the function to do it.but if n id quite large,say n=1000 and t=3, it require too much time.so i want to know any more efficient way to do it? myfun-function(x,id) { x-as.matrix(x) id-as.factor(id) xm- apply(x,2,function(y,z) tapply(y,z, mean), z=id) xdm- x[] - x-xm[id,] re-list(xm=xm, xdm=xdm) re } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] calling R from C or C++
hi all You should look into the tests directory (download the source package extract it and you'll have the tests directory) there are some exemples on how to embedded R into C. I've got the same trouble, here nobody want to do that, and i don't know why... -- Initial Header --- From : [EMAIL PROTECTED] To : Bahoo [EMAIL PROTECTED] Cc : r-help@stat.math.ethz.ch Date : Sun, 24 Jul 2005 10:27:54 -0500 Subject : Re: [R] calling R from C or C++ On 23 July 2005 at 20:18, Bahoo wrote: | Hi, | | I have C/C++ code from which I wish I could call R | to | do something useful. | | By calling I mean linking with the R shared library, | instead of R BATCH. | | In particular, I want to use regression functions such | as ridge and locfit. | | | I saw a 2003 message by Thomas saying that You can | compile R as a shared library, which allows you to | construct and evaluate R expressions from C. Any | more information would be helpful. I am looking for | some documentation that has a more step by step like | instructions. Anyone who has experience, please | point | me to some resources. | | ps. There is a document on CRAN named Writing R | extensions which seems relevant, but it was too | difficult for me to understand. Just get the Magic Wand from the Harry Potter books; that way you get the functionality for free without having to read those pesky and difficult documents we provide to explain how to do the other way -- when your Magic Wand is broken. Dirk, who still wants chocolate to grow on trees, preferably in his backyard | R-help@stat.math.ethz.ch mailing list | https://stat.ethz.ch/mailman/listinfo/r-help | PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ^ (hint !) -- Statistics: The (futile) attempt to offer certainty about uncertainty. -- Roger Koenker, 'Dictionary of Received Ideas of Statistics' __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html // Webmail Oreka : http://www.oreka.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem building R packages in windows xp
Dirk Eddelbuettel wrote: On 24 July 2005 at 19:38, Prof Brian Ripley wrote: | It is already optional, and documented as such as Uwe points out: Yup, that one I evidently didn't know ... maybe the help on --docs needs to be more explicit. Dunno. Or the section in the 'R Extensions' manual could mention it too as it doesn't seem to: [EMAIL PROTECTED]:~/src/debian/R/R-2.1.1 grep 'docs=normal' doc/manual/* [EMAIL PROTECTED]:~/src/debian/R/R-2.1.1 | You can simply avoid building chm files by saying: | | R CMD INSTALL --docs=normal MyPackage | | The reason it is on by default is that is the best option for building | packages for distribution. Hm. I find that a tad backwards as building packages for distribution is (or should) be done by scripts. And those are perfectly capable of picking a non-default value. Somehow I doubt Uwe builds the almost 600 Windows binaries by manual invocations ... Manually, hence no time to sleep left in a 32 hours day. ;-) Seriously speaking, I think the compiler is small and easy to download, and at least I am using chm help as the default help system on all my department's machines. For example, I like the contents and index views on the left of the window. Hence a good idea to stay with the default from my point of view. And it is easy to change it (Duncan pointed out an even more convinient way to disable it generally on your machine). Best, Uwe Regards, Dirk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] The steps of building library in R 2.1.1
Duncan Murdoch wrote: J. Hosking wrote: Duncan Murdoch wrote: Could you point out the specific bits that are missing from the R-Admin manual (and perhaps supply them)? It won't get better unless someone improves it. R-admin is fine. The problem is in Writing R extensions, which would benefit from containing an explicit recipe for constructing an R package, and in particular for constructing an R package under Windows in both source and binary versions. Thanks. I'll see about putting something like this into R-ext. (I'll probably not put the details about installing the tools there; it's bad to have installation instructions in more than one place. But the idea of giving a sample install seems good.) Not sure if this will happen How to install packages has been written down in an R Help Desk column with some examples on handling different libraries etc. Uwe Ligges before 2.2.0; I've got a number of higher priority things to get through first. But if someone wants to volunteer to write it up in texinfo format, I'll be appreciative. Duncan Several such recipes have been posted to the internet or R-help. The one that I have found to be the most useful was posted to R-help by Gabor Grothendieck on 2 March 2005. I am appending it below, with some trivial modifications of my own. I think it would be very useful if this information were included in the R-exts manual, perhaps at the end of the Creating R packages section. J. R. M. Hosking Making a package under Windows -- Make sure that: - you have read: Writing R Extensions manual http://www.murdoch-sutherland.com/Rtools/ - you have downloaded and installed the tools from http://www.murdoch-sutherland.com/Rtools/tools.zip. - you have installed LaTeX (fptex or MiKTeX), perl, the Microsoft help compiler, and (if the package contains C or Fortran source code) the MinGW compilers, as described at http://www.murdoch-sutherland.com/Rtools/. (MiKTeX requires some additional setup, described at http://www.murdoch-sutherland.com/Rtools/miktex.html). - your path contains the tools, htmlhelp, and the bin directories for R, LaTeX, Perl, and (if the package contains C or Fortran source code to be compiled with MinGW) MinGW. The tools directory should be the first item in the path. Assuming that the R installation is in \Program Files\R\rw 1. Assuming your source package tree is in \Rpkgs\mypackage then at a Windows command prompt: cd \Rpkgs Rcmd install mypackage which will install it to \Program Files\R\rw\library\mypackage. Or if you want to install it to a separate library: cd \Rpkgs md library Rcmd install -l library mypackage 2. Now in R: library(mypackage) ... test it out ... or if you installed it to a separate library: library(mypackage, lib.loc = /Rpkgs/library) 3. Once it seems reasonably OK, see whether it passes Rcmd check: cd \Rpkgs Rcmd check mypackage and fix it up until it does. 4. Now create versions for Unix and Windows that you can distribute: cd \Rpkgs Rcmd build mypackage Rcmd build mypackage --binary __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to get the group mean deviation data ?
if n id quite large,say n=1000 and t=3, it require too much time.so i want to know any more efficient way to do it? Why is about 0.4 second (which is what it takes on my system) too long? Given that you want to operate on 3000 cells, a second does not look unreasonable. This is a toy problem, and it is unclear what the real problem is (if any). Since you have the same number of replications for each cell (group-variable combination), I would use this as a n x 3 x t array (a simple call to dim and aperem). Then rowMeans will find the group means, and you can just subtract those to get the deviations from the means, making use of recycling. E.g. D - d[,-1] dim(D) - c(t,n,3) D - aperm(D, c(2,3,1)) gmeans - rowMeans(D, dims=2) d[,-1] - rep(gmeans, each=3) That takes under 10ms for n=1000 On Mon, 25 Jul 2005, ronggui wrote: n=10;t=3 d-cbind(id=rep(1:n,each=t),y=rnorm(n*t),x=rnorm(n*t),z=rnorm(n*t)) head(d) id y x z [1,] 1 -2.1725379 0.07629954 -0.3985258 [2,] 1 -1.2383038 -2.49667038 0.6966127 [3,] 1 -1.2642401 -0.50613307 0.4895856 [4,] 2 0.2171246 0.86711864 -0.6660036 [5,] 2 2.2765760 -0.48547142 -1.4496664 [6,] 2 0.5985345 -1.06427035 2.1761071 first,i want to get the group mean of each variable,which i can use d-data.frame(d) aggregate(d,list(d$id),mean)[,-1] id y x z 1 1 -1.55836060 -0.9755013 0.26255754 2 2 1.03074502 -0.2275410 0.02014565 3 3 0.20700121 -0.7159450 1.35890176 4 4 0.17839650 1.2575891 0.04135165 5 5 -0.20012508 0.4310221 0.55458899 6 6 -0.13084185 -0.2953392 0.28229068 7 7 0.20737288 -0.8863761 -0.50793880 8 8 0.07512612 -0.6591304 -0.21656533 9 9 0.94727796 -0.6108891 0.13529884 10 10 -0.04434875 0.1332086 -0.88229808 then i want the group mean deviation data,like head(sapply(d[,2:4],function(x) x-ave(x,d$id))) y x z [1,] -0.6141773 1.0518008 -0.6610833 [2,] 0.3200568 -1.5211691 0.4340552 [3,] 0.2941205 0.4693682 0.2270281 [4,] -0.8136205 1.0946597 -0.6861493 [5,] 1.2458310 -0.2579304 -1.4698121 [6,] -0.4322105 -0.8367293 2.1559614 both above are what i want.though i can do it use the function to do it.but if n id quite large,say n=1000 and t=3, it require too much time.so i want to know any more efficient way to do it? myfun-function(x,id) { x-as.matrix(x) id-as.factor(id) xm- apply(x,2,function(y,z) tapply(y,z, mean), z=id) xdm- x[] - x-xm[id,] re-list(xm=xm, xdm=xdm) re } -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] apply and arrays
On Mon, 25 Jul 2005, Uwe Ligges wrote: Laura Holt wrote: Hi R! I have a 3 dimensional array, which is 21 x 3 x 3 I want to use apply to sum on each 21x3 matrix, which is fine. Is there a way that I can do this in 1 step instead of a loop (3), please? Don't know which direction you mean, I guess one of the following: apply(x, c(1,2), sum) apply(x, 3, sum) Or use rowSums or colSums for clarity (and speed, irrelevant here). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Mean and variance of the right-censored data
No, it doesn't. Right-censored data are data with (so-called) censored values. E.g. there is a newsvendor and he sells newspapers for a week. Mon: 77 Tue: 56 Wed: 60 Thu: 80 Fri: 85 Sat: 59 Sun: 48 This values are numbers of sold pieces from Monday to Sunday. And he sold out newspapers on Wednesday and on Thursday. This is an example of right-censored data. He could sold more pieces in that two days. And I need the variance and mean of data like this. Thank you! On Sun, 24 Jul 2005, jim holtman wrote: does mean(a[b]) var(a[b]) do what you want? This selects just those values of 'a' that are TRUE in 'b'. On 7/24/05, Petr Mandys [EMAIL PROTECTED] wrote: Hi, I need to get mean and variance of right censored data. How can I do that? I have a vector of values (called a) and vector of booleans (whether value is censored) (called b). What to do with this? Sorry, I'm R beginner. Thank you! Pete __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Jim Holtman What the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to get the group mean deviation data ?
Yeah,I meant n=1,but i just missed a zero. If n=1,t=3,it take about 3 seconds. If n=2000,t=7,it takes about 10 seconds. I want to write a function to fit a model,and the data maybe quite large (maybe n=2,t=10).When n and t become larger and larger,the time will be much longer. It is of course reasonable.But I think there should be much pretty code to do this job,so I post here. What I really want to konw is how to optimize the code for this purpose.Of course, I can still fit my model even I use this code.and I still like R much as it's free ,flexibile and powerfull. if n id quite large,say n=1000 and t=3, it require too much time.so i want to know any more efficient way to do it? Why is about 0.4 second (which is what it takes on my system) too long? Given that you want to operate on 3000 cells, a second does not look unreasonable. This is a toy problem, and it is unclear what the real problem is (if any). Since you have the same number of replications for each cell (group-variable combination) I want to deal with the case with different number of replications for each cell too. I would use this as a n x 3 x t array (a simple call to dim and aperem). Then rowMeans will find the group means, and you can just subtract those to get the deviations from the means, making use of recycling. E.g. D - d[,-1] dim(D) - c(t,n,3) D - aperm(D, c(2,3,1)) gmeans - rowMeans(D, dims=2) d[,-1] - rep(gmeans, each=3) That takes under 10ms for n=1000 On Mon, 25 Jul 2005, ronggui wrote: n=10;t=3 d-cbind(id=rep(1:n,each=t),y=rnorm(n*t),x=rnorm(n*t),z=rnorm(n*t)) head(d) id y x z [1,] 1 -2.1725379 0.07629954 -0.3985258 [2,] 1 -1.2383038 -2.49667038 0.6966127 [3,] 1 -1.2642401 -0.50613307 0.4895856 [4,] 2 0.2171246 0.86711864 -0.6660036 [5,] 2 2.2765760 -0.48547142 -1.4496664 [6,] 2 0.5985345 -1.06427035 2.1761071 first,i want to get the group mean of each variable,which i can use d-data.frame(d) aggregate(d,list(d$id),mean)[,-1] id y x z 1 1 -1.55836060 -0.9755013 0.26255754 2 2 1.03074502 -0.2275410 0.02014565 3 3 0.20700121 -0.7159450 1.35890176 4 4 0.17839650 1.2575891 0.04135165 5 5 -0.20012508 0.4310221 0.55458899 6 6 -0.13084185 -0.2953392 0.28229068 7 7 0.20737288 -0.8863761 -0.50793880 8 8 0.07512612 -0.6591304 -0.21656533 9 9 0.94727796 -0.6108891 0.13529884 10 10 -0.04434875 0.1332086 -0.88229808 then i want the group mean deviation data,like head(sapply(d[,2:4],function(x) x-ave(x,d$id))) y x z [1,] -0.6141773 1.0518008 -0.6610833 [2,] 0.3200568 -1.5211691 0.4340552 [3,] 0.2941205 0.4693682 0.2270281 [4,] -0.8136205 1.0946597 -0.6861493 [5,] 1.2458310 -0.2579304 -1.4698121 [6,] -0.4322105 -0.8367293 2.1559614 both above are what i want.though i can do it use the function to do it.but if n id quite large,say n=1000 and t=3, it require too much time.so i want to know any more efficient way to do it? myfun-function(x,id) { x-as.matrix(x) id-as.factor(id) xm- apply(x,2,function(y,z) tapply(y,z, mean), z=id) xdm- x[] - x-xm[id,] re-list(xm=xm, xdm=xdm) re } -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] sparse data frame (crsp?)
You could try reading it in a chunk at a time and making a sparse matrix with SparseM, unless you really need some functionality of dataframes. R Koenker dear R wizards: does R have the facilities to handle sparse data frames? I am thinking of reading a data base like the daily CRSP data into R, observations being firms, columns being days, data being stock returns. but this will only fit into my memory if I can convince R to not have to store missing observations, and to return NA upon read access to missing observations. pointers appreciated. sincerely, /iaw __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Autoregressive Distributed Lag Models
Hallo to everyone, is there anyone that could kindly indicate me a package or a function to deal with Autoregressive Distributed Lag Models, e.g. y_t = a + b_0 * x_t + ... + b_k * x_(t-k) + c_1 * y_(t-1) + ... + c_h * y_(t-h) + e_t Thank you, Paolo -- Paolo Bulla Istituto di Metodi Quantitativi Università L. Bocconi Tel. +39 02.5836.5651 viale Isonzo 25 20136 Milano [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] trend estimation for cohort study
Hi R Users, I wish to estimate if there is a trend in my relative risk obtained by coxph. The best i've found is a method from Greenland and Longnecker ( Am J Epidemiology 1992 vol 135 (11) - p 1301-9 ). But all I have is my relative risk and their std error. Is there a command in R that can do this ? If there is someone with a better method ? Thanking you in advance, I look forward your reply. Claude [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] assignment of matrix
Hi, I have created a matrix and initially all elements in the matrix was assigned to NA.Then I want to assign values to some elements of this matrix. Can I use formation like matrix[i][j] - 4?if not, how can i do this? now I have three vectors y1 y2 y3 3 4 3.1 5 2 4.2 if I want to assign y3's value to matrix, where the value's row and column should correspond the y1's and y2's value, such like matrix[y1[1]][y2[1]] - y3[1] how can this be realized? thanks Hao Wu __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Autoregressive Distributed Lag Models
Check out: ?arima Also: http://cran.r-project.org/doc/contrib/Ricci-refcard-ts.pdf http://cran.r-project.org/src/contrib/Views/ Depending on what you need the dyn package, not mentioned in the above, may also be useful. On 7/25/05, Paolo Bulla [EMAIL PROTECTED] wrote: Hallo to everyone, is there anyone that could kindly indicate me a package or a function to deal with Autoregressive Distributed Lag Models, e.g. y_t = a + b_0 * x_t + ... + b_k * x_(t-k) + c_1 * y_(t-1) + ... + c_h * y_(t-h) + e_t Thank you, Paolo -- Paolo Bulla Istituto di Metodi Quantitativi Università L. Bocconi Tel. +39 02.5836.5651 viale Isonzo 25 20136 Milano [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] passing formula arguments cv.glm
I am trying to write a wrapper for the last example in help(cv.glm) that deals with leave-one-out-cross-validation (LOOCV) for a logistic model. This wrapper will be used as part of a bigger program. Here is my wrapper funtion : logistic.LOOCV.err - function( formu=NULL, data=NULL ){ cost.fn - function(cl, pred) mean( abs(cl-pred) 0.5 ) glmfit - glm( formula=formu, data=data, family=binomial ) print(glmfit is OK) err- cv.glm( data=data, glmfit=glmfit, cost=cost.fn, K=nrow(data) )$delta[2] print(cv.glm OK) } When I run the above function line by line with the arguments from below, it works fine. But when I call it as function, I get this : rm( glmfit, formu, cv.err ) # cleanup if required logistic.LOOCV.err( formu=as.formula(r~stage+xray+acid), data=nodal ) logistic.LOOCV.err( formu=as.formula(r~stage+xray+acid), data=nodal ) [1] glmfit is OK Error in model.frame(formula = formu, data = data[j.in, , drop = FALSE], : Object formu not found I think this has something to do with formula and environments but I do not know enough to solve it myself. I searched the archive without much help (perhaps I was using the wrong keywords). Any help would be very much appreciated. Thank you. Regards, -- Adaikalavan Ramasamy[EMAIL PROTECTED] Centre for Statistics in Medicine http://www.ihs.ox.ac.uk/csm/ Wolfson College Annexe Tel : 01865 284 408 Linton Road, Oxford OX2 6UD Fax : 01865 284 424 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] assignment of matrix
吴 昊 wrote: Hi, I have created a matrix and initially all elements in the matrix was assigned to NA.Then I want to assign values to some elements of this matrix. Can I use formation like matrix[i][j] - 4?if not, how can i do this? now I have three vectors y1 y2 y3 3 4 3.1 5 2 4.2 if I want to assign y3's value to matrix, where the value's row and column should correspond the y1's and y2's value, such like matrix[y1[1]][y2[1]] - y3[1] For a matrix X: X[cbind(y1, y2)] - y3 Uwe Ligges how can this be realized? thanks Hao Wu __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Non-linear linear models?
Hi, I'm new to R (though I have spent hours trying to learn how to use it) and also not very knowledgeable about statistics, so I hope you will excuse what may seem like a very basic question. I'm trying to use R to do an ANOVA analysis for some data with an unbalanced design, and while I was trying to figure that out, I got confused about the purpose of the lm. All definitions I can find of linear model are of the form: y = a + b * x + e In other words, y is only linear in the dependent variable(s) x. However, the lm model seems to support higher order polynomials, e.g.: lm(dist ~ speed + I(speed^2)+I(speed^3), cars) Is there some sense in which that model is linear, or is R's lm() providing extra functionality? Thanks, --Paul -- Mailblocks - A Better Way to Do Email http://about.mailblocks.com/info __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Non-linear linear models?
Paul: Even when the model includes polynomial terms as you have below, it is still a linear model because it is linear in the parameters. It is your coefficients that are not linear. There are other functions in R for non-linear models. help.search('non linear') -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, July 23, 2005 10:24 AM To: r-help@stat.math.ethz.ch Subject: [R] Non-linear linear models? Hi, I'm new to R (though I have spent hours trying to learn how to use it) and also not very knowledgeable about statistics, so I hope you will excuse what may seem like a very basic question. I'm trying to use R to do an ANOVA analysis for some data with an unbalanced design, and while I was trying to figure that out, I got confused about the purpose of the lm. All definitions I can find of linear model are of the form: y = a + b * x + e In other words, y is only linear in the dependent variable(s) x. However, the lm model seems to support higher order polynomials, e.g.: lm(dist ~ speed + I(speed^2)+I(speed^3), cars) Is there some sense in which that model is linear, or is R's lm() providing extra functionality? Thanks, --Paul -- Mailblocks - A Better Way to Do Email http://about.mailblocks.com/info __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] FW: LyX and Sweave
Hello R-users! I have tried to use Sweave within LyX* and found two ways to accomplish this. I have attached LyX source file for both ways. *http://www.lyx.org Lep pozdrav / With regards, Gregor Gorjanc -- University of Ljubljana Biotechnical FacultyURI: http://www.bfro.uni-lj.si/MR/ggorjan Zootechnical Department mail: gregor.gorjanc at bfro.uni-lj.si Groblje 3 tel: +386 (0)1 72 17 861 SI-1230 Domzale fax: +386 (0)1 72 17 888 Slovenia, Europe -- One must learn by doing the thing; for though you think you know it, you have no certainty until you try. Sophocles ~ 450 B.C. -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Mean and variance of the right-censored data
The survival package has functions for fitting models to right censored data. require(survival) ?survfit ?Surv -Don At 12:17 AM +0200 7/25/05, Petr Mandys wrote: Hi, I need to get mean and variance of right censored data. How can I do that? I have a vector of values (called a) and vector of booleans (whether value is censored) (called b). What to do with this? Sorry, I'm R beginner. Thank you! Pete __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Mean and variance of the right-censored data
Thank you! I'm using this: require(NADA) var_sf=survfit(Surv(a, !b)) var_result=new(cenfit, survfit=var_sf) Class cenfit has methods to get mean a variance from survfit result. Is this correct? Pete On Mon, 25 Jul 2005, Don MacQueen wrote: The survival package has functions for fitting models to right censored data. require(survival) ?survfit ?Surv -Don At 12:17 AM +0200 7/25/05, Petr Mandys wrote: Hi, I need to get mean and variance of right censored data. How can I do that? I have a vector of values (called a) and vector of booleans (whether value is censored) (called b). What to do with this? Sorry, I'm R beginner. Thank you! Pete __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Help vectorising a function
M - function(m, s, init = 0) { A - nrow(m); T - ncol(m) M - matrix(init, nrow = A, ncol = T) for(a in 1:(A-1)) { M[a+1, 2:T] - (s[a] * (M[a, ] + m[a, ]))[1:(T-1)] } M } This is from a mark-recapture study where M is an estimate of the number of marked fish in each age class (A) over each year (T). s is a vector of age dependent survival probabilities and m is a matrix containing the number of fish marked for the first time (in each age class and year). I'm pretty sure there's a much better way of doing this - but I can't see it. I'm not looking for the exact code to solve the problem - just a better way of attacking it. Any hints would be much appreciated! Hadley __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] error in gnls
Dear R users; I'm trying to fit nonlinear model (asymptotic regression model) with gnls from library nlme in R 2.1.0 with no big issues so far. However after installed the version R 2.1.1, when I tried to update the initial model including a var-cov model I've got the error: Error: Object convIter not found. This error occurs only with R 2.1.1. Any ideas? Thanks Christian Mora __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Mean and variance of the right-censored data
On Mon, 25 Jul 2005, Petr Mandys wrote: Thank you! I'm using this: require(NADA) var_sf=survfit(Surv(a, !b)) var_result=new(cenfit, survfit=var_sf) Class cenfit has methods to get mean a variance from survfit result. Is this correct? NADA is designed for left censoring. I don't know if it will work for right censoring. There is at least one problem that hasn't been mentioned yet. Unless your largest observations are uncensored you can't compute the mean or variance without a parametric model. survfit() in the survival package used to produce something it called the mean, but it wasn't. -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] computation time gls()
dear R users i try to fit a gls model to a rather large dataset with an AR(1) error structure: attach(sf.a1filt) m1.a.gls - gls(fluxt~co2+light+vpd+wind, correlation = corAR1(0.8)) summary(m1.a.gls) detach(sf.a1filt) there are approx. 5000 observations, and the computation seems to take several hours, i actually killed the process because i became too impatient. is there any way to be more efficient with R? (because really the model will be more complex, i.e. more predictors and higher autoregressive order). os: linux suse, R version: latest, machine: ibm thinkpad 42T, 1GHz RAM Sebastian Leuzinger Institute of Botany, University of Basel Schönbeinstr. 6 CH-4056 Basel ph0041 (0) 61 2673511 fax 0041 (0) 61 2673504 email [EMAIL PROTECTED] web http://pages.unibas.ch/botschoen/leuzinger __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] error in gnls
On 7/25/05, Christian Mora [EMAIL PROTECTED] wrote: Dear R users; I'm trying to fit nonlinear model (asymptotic regression model) with gnls from library nlme in R 2.1.0 with no big issues so far. However after installed the version R 2.1.1, when I tried to update the initial model including a var-cov model I've got the error: Error: Object convIter not found. This error occurs only with R 2.1.1. Any ideas? There is an error in the current version of gnls. I will upload a new version of the nlme package fixing this to CRAN today. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] how to write a periodic function in R?
My question is how to write a periodic function in R. for example if there is a function f(x) that f(x)=f(x+4), for -2x2, f(x)=x how to write it in R? thanks a lot! --- liyun (Lauren) Ma __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to write a periodic function in R?
On 7/25/2005 11:22 AM, [EMAIL PROTECTED] wrote: My question is how to write a periodic function in R. for example if there is a function f(x) that f(x)=f(x+4), for -2x2, f(x)=x how to write it in R? thanks a lot! Just write a function that does that, e.g. f - function(x) (x + 2) %% 4 - 2 The %% is the mod operator, so (x + 2) %% 4 adds 2 then maps all values into the range 0 to 4. You'll need a different formula for a different periodic function. Use plot(f, from=-7, to=7) to see that this works. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] computation time gls()
I find arima() fits such models very much faster. On Mon, 25 Jul 2005, Sebastian Leuzinger wrote: dear R users i try to fit a gls model to a rather large dataset with an AR(1) error structure: attach(sf.a1filt) m1.a.gls - gls(fluxt~co2+light+vpd+wind, correlation = corAR1(0.8)) summary(m1.a.gls) detach(sf.a1filt) there are approx. 5000 observations, and the computation seems to take several hours, i actually killed the process because i became too impatient. is there any way to be more efficient with R? (because really the model will be more complex, i.e. more predictors and higher autoregressive order). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] how to write a periodic function in R?
On Mon, 25 Jul 2005 [EMAIL PROTECTED] wrote: My question is how to write a periodic function in R. for example if there is a function f(x) that f(x)=f(x+4), for -2x2, f(x)=x how to write it in R? f((x+2)%%4 - 2) is one way. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] order of panels in xyplot
I'm having trouble with the order of the panels using xyplot. I had used this bit of code before and received the desired plot (the code was not identical, but very similar; perhaps more importantly I was working with an older version of R) . Now the panels appear right to left instead of left to right, as it says in the help files, which is what I would like. Does anyone know if this has been changed? OR has anybody encountered this problem and a way of fixing it? Below is the code I'm using (ctry_pfi and v291 are factors, with 16 and 2 levels, respectively)): superpose.line - trellis.par.get(superpose.line) superpose.line$lwd - 3 superpose.line$lty - c(1,2) trellis.par.set(superpose.line, superpose.line) trellis.strip.blank() trellis.par.set(list(background = list(col = white))) xyplot(pfi~age|ctry_pfi,groups= v291,data=pfi, panel=panel.superpose, type=c(n, smooth), span=.75, as.table=F, col=c(4,2), lwd=2, lty=c(1,2), xlab = 'Age', ylab='Progressive Feminism Index (PFI)', xlim=c(10, 100), ylim=c(10,25), key = list(lines = Rows(trellis.par.get(superpose.line), c(14, 5)), lwd=3, lty=c(2,1), text = list(lab = c('Women', 'Men')), space=bottom, border=T, columns=2)) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] FW: LyX and Sweave
On 25/07/05, Gorjanc Gregor [EMAIL PROTECTED] wrote: Hello R-users! I have tried to use Sweave within LyX* and found two ways to accomplish this. I have attached LyX source file for both ways. *http://www.lyx.org Hi Gregor, I think the mailing list strips off attachments. cheers, Sean Well ascii attachments should go through* but they are not stored in R-help list, at least I don't know how to get them. I'll cc to Friedrich Leisch and he might consider to add them to his Sweave repository at http://www.ci.tuwien.ac.at/~leisch/Sweave/ In case he doesn't like to do that I will put them on my homepage and mention that on R-help list. *I can send them once more to private e-mails if there is a need for that! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] order of panels in xyplot
[EMAIL PROTECTED] wrote: I'm having trouble with the order of the panels using xyplot. I had used this bit of code before and received the desired plot (the code was not identical, but very similar; perhaps more importantly I was working with an older version of R) . Now the panels appear right to left instead of left to right, as it says in the help files, which is what I would like. Does anyone know if this has been changed? OR has anybody encountered this problem and a way of fixing it? Below is the code I'm using (ctry_pfi and v291 are factors, with 16 and 2 levels, respectively)): superpose.line - trellis.par.get(superpose.line) superpose.line$lwd - 3 superpose.line$lty - c(1,2) trellis.par.set(superpose.line, superpose.line) trellis.strip.blank() trellis.par.set(list(background = list(col = white))) xyplot(pfi~age|ctry_pfi,groups= v291,data=pfi, panel=panel.superpose, type=c(n, smooth), span=.75, as.table=F, col=c(4,2), lwd=2, lty=c(1,2), xlab = 'Age', ylab='Progressive Feminism Index (PFI)', xlim=c(10, 100), ylim=c(10,25), key = list(lines = Rows(trellis.par.get(superpose.line), c(14, 5)), lwd=3, lty=c(2,1), text = list(lab = c('Women', 'Men')), space=bottom, border=T, columns=2)) I haven't noticed if anything's been changed. However, you can always explictly define the panel order by setting the levels of your grouping variable (i.e. ctry_pfi in your case). See ?factor. HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] poisson fit for histogram
Ups! Mr. Ripley is right. I ignored the OS in the posting. My appologies to Tom Isenbarger for the misleading answer. Regards Francisco From: Prof Brian Ripley [EMAIL PROTECTED] To: Francisco J. Zagmutt [EMAIL PROTECTED] CC: [EMAIL PROTECTED], r-help@stat.math.ethz.ch Subject: Re: [R] poisson fit for histogram Date: Sat, 23 Jul 2005 08:29:28 +0100 (BST) What does fit.dist do that fitdistr (MASS) does not in this context? (It plots, but that is very easy to do in base R. However, to see if a Poisson fits you need a test of goodness-of-fit.) BTW, `decompress and store the files in your library folder' is on no OS (you did not mention one but Thomas did) the way to install a package. Even on Windows (where it might just work) there are simpler and better ways to do it, like using a menu. Note that Lindsey does not provide pre-compiled packages for MacOS X, the platform Thomas is using (and as they use Fortran, people have reported that they are tricky to install on MacOS X), and your recipe is `seriously' misleading there. On Fri, 22 Jul 2005, Francisco J. Zagmutt wrote: I would first reccomend you to update your version of R. Then download the libraries rmutil and gnlm from Jim Lindsey at http://www.luc.ac.be/~jlindsey/rcode.html decompress and store the files in your library folder. Sorry but you will have to donwload a package unless you seriously want to re-invent the wheel. Finally try library(gnlm) ?fit.dist() Cheers Francisco From: Thomas Isenbarger [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject: [R] poisson fit for histogram Date: Wed, 20 Jul 2005 10:40:51 -0500 I haven't been an R lister for a bit, but I hope to enlist someone's help here. I think this is a simple question, so I hope the answer is not much trouble. Can you please respond directly to this email address in addition to the list (if responding to the list is warranted)? I have a histogram and I want to see if the data fit a Poisson distribution. How do I do this? It is preferable if it could be done without having to install any or many packages. I use R Version 1.12 (1622) on OS X Thank-you very much, Tom Isenbarger -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Lattice: how to make x axis to appear on only one non-bottom plot?
Hi, PM Does the following do what you want? PM xyplot(whatever) PM trellis.focus(panel, 4, 2, clip.off=TRUE, highlight=FALSE) PM panel.axis(bottom, check.overlap=TRUE, outside=TRUE) Yes, it does. Thank you very much! With the exception, that first call must be trellis.focus(panel, 3, 3, clip.off=TRUE, highlight=FALSE) PM (it would be easier to help if you could provide code that others can run) I am sorry. Here it is if any one still interested. Any other comments concerned to the R code below will be appreciated. 8 # The draw.key behaves slightly incorrect, and I have redefined it. # (this was discussed in R-help on May 19-21, 2005) source('../common_r_things/draw.key.r') # Lattice tunings, like colors, cex-s, etc. source('../common_r_things/wl_theme.r') # I need also two additional curves on each plot panel, # and a slope and its significance. # The function below plots everything. # Colors for additional curves, mentioned above. # These variables are global, as the curves will appear in the plot key, # and I would like to have a single place to define the plot and key parameters. i1.col-tomato3 i2.col-gray50 plot.panel-function(x,y,panel.counter,...){ # Plot additional curves. They are constant. i2-c(-0.7,-1.7,0.2,0.8,-0.4,-1.7,-0.8,-0.4,0.9,0.7,0.5,0.7,1.1,1.5,-1.7) i2-(i2-min(i2))*(max(y)-min(y))/(max(i2)-min(i2))+min(y) i1-c(7.39230,-0.67956,2.65596, 4.44415, 0.73161, 1.66836,-2.52039, 2.52273, -2.51820,-0.89912, 1.89464,-3.26774,3.58680, 0.58910,-2.89624) i1-(i1-min(i1))*(max(y)-min(y))/(max(i1)-min(i1))+min(y) panel.lines(x,y=i2,lwd=2,col=i2.col) panel.lines(x,y=i1,lwd=2,col=i1.col) # Plot actual data. panel.xyplot(x,y,...); # Calculate and print the slope and its significance. m-lm(y~x); v-pf(summary(m)$fstatistic[1],summary(m)$fstatistic[2], summary(m)$fstatistic[3]); if(v==NaN) v-0; if(v0.99) { sign.exp-expression(bold(S0.99)) }else{ sign.exp-substitute(expression(bold(S==V)),list(V=round(v,2))) } sl-formatC(summary(m)$coefficients[2,1]*10,digits=2,format=f); err-formatC(summary(m)$coefficients[2,2]*10,digits=2,format=f); grid.text(label=c(eval(substitute(expression(bold(paste(Slope: ,Sl%+-%Err~~dec^-1))), list(Sl=sl,Err=err))), eval(sign.exp)), x=0.1, # The place for the text is chosen so, that it appears on the empty space. # In my case, first 6 panels have empty top and the rest 5 ones have empty bottom. y=if(panel.counter7) c(1,0.85) else c(0.25,0.1), default.units=npc,just= c(left, top) ) } trellis.device(png,filename=general_plot2.png,theme=wl.theme,width=1000,height=1200) # Data frame flow contains monthly mean data and some their aggregations # That's why month variable varies from 1 to 29. # Year varies from 1990 through 2004. # However, now I need only a subset of the data. print( xyplot(A3.index~year|factor(month), strip=strip.custom(factor.levels=c(January, Integral (Jan-Feb),Integral (Jan-Mar),Integral (Jan-Apr),Integral (Jan-May),Integral (Jan-Jun), Integral (Jan-Jul),Integral (Jan-Aug),Integral (Jan-Sep),Integral (Jan-Oct),Integral (Jan-Nov))), subset=month %in% c(1,19:28), data=flow,as.table=TRUE,type=c(o,g,r),layout=c(3,4),pch=1,col=black, ylab=flow index,xlab=NULL, scales=list(x=list(alternating=1),y=list(alternating=1)), between=list(x=0.2,y=0.2), panel=plot.panel, key=list(size=2,between=2,col=black,lty=1,border=TRUE,divide=1, x=0.95,y=0.07,corner=c(1,0),columns=1, lines=list(pch=c(32,1,32,32,32,32,32),c(0,1,0,1,0,1,0),lwd=c(0,1,0,2,0,2,0), col=c(0,black,0,i1.col,0,i2.col,0),type=b), text=list(c(,Flow index,,i1 index(scaled),, i2 index (scaled),),cex=1.1) ) ) ) trellis.focus(panel, 3, 3, clip.off=TRUE, highlight=FALSE) panel.axis(bottom, check.overlap=TRUE, outside=TRUE) dev.off() 8 --- Best regards, Wladimirmailto:[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Convert quarterly data to monthly data
Hi, I am new to use R, but can anyone tell me how to tranform quarterly data to monthly data? I know SAS has this procedure, so may I assume it is also available in R? Thanks a lot! Ed __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] A one-liner to create a 3-dim array
Hi, I would like to write a one-line R code to create a 3-dim array, B, of dimension (n,n,m) from a matrix, A, of dimension (m,n) such that the i-th element of the 3-dim array, B[, , i] is the outer product of the i-th row of A. Thanks for any help, Ravi. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Lattice: reversing order of panel placement in conditional histograms
On 7/23/05, Prof Brian Ripley [EMAIL PROTECTED] wrote: From what I understand, you want to set up a factor with the levels reversed. It is not that `5 is larger than 1', but that you created a factor with the levels in alphabetic order. Lattice plots in the order of the levels. Something like f - factor(f, levels=rev(levels(f))) will do this. For the horizontal factor, give the levels in the order you want them to appear (which might not be the reverse of alphabetic). On Sat, 23 Jul 2005, Sam Ferguson wrote: I have a question about lattice in general, and histogram specfically. How do you control the ordering of factors that controls the placement of the conditional panels. I have a dataset with factors that go 'Q1','Q2',Q3','Q5' and of course I want the plot to place Question Q1 at the top and Question Q5 at the bottom of the graphical output. One additional comment: if you think top to bottom is the natural order (which lattice doesn't), try using as.table = TRUE Deepayan histogram() does the opposite as 5 is larger than 1. Similarly my 'AlertFormat' factor is a textual category, and I need the data to read from left to right (representing old to new) , with 'New A V' on the right, and 'Pre-existing A V' on the left, which is the opposite to how histogram plots. [...] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] A one-liner to create a 3-dim array
B - array(apply(A,1,function(x){x%o%x}),dim=c(nrow(A),dim(A))) cheers, Rolf Turner [EMAIL PROTECTED] Ravi Varadhan wrote: I would like to write a one-line R code to create a 3-dim array, B, of dimension (n,n,m) from a matrix, A, of dimension (m,n) such that the i-th element of the 3-dim array, B[, , i] is the outer product of the i-th row of A. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Lattice: how to get default ylim?
On 5/19/05, Deepayan Sarkar [EMAIL PROTECTED] wrote: On Thursday 19 May 2005 9:11 am, David James wrote: Deepayan Sarkar wrote: v - current.viewport()## requires R 2.1.0 (I believe) No, I think it's been there for a while. However, AFAIR the fact that viewports have components xscale and yscale that can be accessed like this is undocumented and may change if the implementation changes (which is a real possibility). Ideally, there should be exported interfaces to access this information, either in grid or lattice. One of the reasons there isn't is that you rarely Yes, I agree that such an interface is quite desirable. OK, I'll put something in the next version of lattice. For the record, lattice now has (had for a while, actually) the function current.panel.limits which returns the native scales of the current viewport (as a list with components xlim and ylim). Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] A one-liner to create a 3-dim array
I think this works: B - aperm(rep(t(A),n)*rep(A,rep(n,n*m)), perm=c(1,3,2)) Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ravi Varadhan Sent: Monday, July 25, 2005 1:39 PM To: r-help@stat.math.ethz.ch Subject: [R] A one-liner to create a 3-dim array Hi, I would like to write a one-line R code to create a 3-dim array, B, of dimension (n,n,m) from a matrix, A, of dimension (m,n) such that the i-th element of the 3-dim array, B[, , i] is the outer product of the i-th row of A. Thanks for any help, Ravi. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] alaska map?
Hello, I've installed the Becker and Wilks maps, mapdata, and mapproj packages so I can begin to try these out for some work I need to do on a map of Alaska but I don't know where to find a map of Alaska. Has anyone solved this already and could help? Thanks very much in advance, Caitlin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] ANOVA/aov question
I'm a bit confused about the anova/aov functions. Both seem to rely on data models, where the relationship between the dependent variables and the independent variables can be expressed as a formula. In what I am trying to do, all of my independent variables are qualitative, not quantitative. For example, for each of two options, option A and option B I have collected a set of measurements of the same quantity, and I wish to do an ANOVA test to see if that factor (actually I have three factors, with 2 levels each) has a significant influence on the measured quantity. Can R be used for this kind of ANOVA, or must the independent variables be quantitative in nature? If the answer is that it can be done, and that it can be done with anova/aov, how do I go about expressing the data model for qualitative factors? Thanks much, --Paul -- Mailblocks - A Better Way to Do Email http://about.mailblocks.com/info __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Don't understand plotmath behaviour (bug?)
Hello, all Please, consider the following pieces of code. 1. v-0.5 text(x=2,y=2,eval(substitute(expression(bold(S==V)),list(V=formatC(v,format=f,digits=2) This plots S=0.5 in bold. Both S and 0.5 are bold. 2. v-0.5 text(x=2,y=2,eval(substitute(expression(bold(S==V)),list(V=round(v,2) Here, only S is bold, 0.5 is usual, non-bold. Why? Thank you very much for attention and explanations. --- Best regards, Wladimirmailto:[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] alaska map?
On Mon, 25 Jul 2005, Caitlin Burgess wrote: Hello, I've installed the Becker and Wilks maps, mapdata, and mapproj packages so I can begin to try these out for some work I need to do on a map of Alaska but I don't know where to find a map of Alaska. Has anyone solved this already and could help? map(world2, USA:alaska) gives the low resolution, using the world database is split on the date line. The mapdata package has better resolution. Thanks very much in advance, Caitlin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] cubic spline curves
I have a question about how to generate monthly data from quarterly data: What I want to do is basically fits cubic spline curves to the quarterly data to form continuous-time approximations of the input series, and then generate output series (monthly data) from the spline approximations. SAS can do it using proc expand: http://support.sas.com/rnd/app/examples/ets/expa/ Anyone know how to do it in R? Any input is appreciated. Best, Ed __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] cubic spline curves
Have a look at help(spline) for starters. Reid Huntsinger -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Haibo Huang Sent: Monday, July 25, 2005 4:34 PM To: r-help@stat.math.ethz.ch Subject: [R] cubic spline curves I have a question about how to generate monthly data from quarterly data: What I want to do is basically fits cubic spline curves to the quarterly data to form continuous-time approximations of the input series, and then generate output series (monthly data) from the spline approximations. SAS can do it using proc expand: http://support.sas.com/rnd/app/examples/ets/expa/ Anyone know how to do it in R? Any input is appreciated. Best, Ed __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] ANOVA/aov question
On Mon, 25 Jul 2005 [EMAIL PROTECTED] wrote: I'm a bit confused about the anova/aov functions. Both seem to rely on data models, where the relationship between the dependent variables and the independent variables can be expressed as a formula. In what I am trying to do, all of my independent variables are qualitative, not quantitative. For example, for each of two options, option A and option B I have collected a set of measurements of the same quantity, and I wish to do an ANOVA test to see if that factor (actually I have three factors, with 2 levels each) has a significant influence on the measured quantity. Can R be used for this kind of ANOVA, or must the independent variables be quantitative in nature? If the answer is that it can be done, and that it can be done with anova/aov, how do I go about expressing the data model for qualitative factors? aov() is the model fitting function for ANOVA models. anova() is a helper function to produce ANOVA tables (or analogues like analysis of deviance tables) from one or more fitted models. The first example in ?aov has three binary explanatory variables (and one 6-way one). So it certainly can be done with factors (which in the R sense are necessarily qualitative), and the help page is a good start. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Don't understand plotmath behaviour (bug?)
On Mon, 25 Jul 2005, Wladimir Eremeev wrote: Hello, all Please, consider the following pieces of code. 1. v-0.5 text(x=2,y=2,eval(substitute(expression(bold(S==V)),list(V=formatC(v,format=f,digits=2) This plots S=0.5 in bold. Both S and 0.5 are bold. 2. v-0.5 text(x=2,y=2,eval(substitute(expression(bold(S==V)),list(V=round(v,2) Here, only S is bold, 0.5 is usual, non-bold. In case 1 you have the string 0.5, in case 2 you have the number 0.5. text(x=2,y=2, quote(bold(0.5==0.5))) shows what is happening. -thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] cluster
Dear listers: Here I have a question on clustering methods available in R. I am trying to down-sampling the majority class in a classification problem on an imbalanced dataset. Since I don't want to lose information in the original dataset, I don't want to use naive down-sampling: I think using clustering on the majority class' side to select representative samples might help. So, my question is, which clustering method should be tested to get the best result. I think the key thing might be the selection of distance considering the next step in which I would like to use decision trees. Please share your experience in using clustering (Any available implementation outside R is also welcome) weiwei -- Weiwei Shi, Ph.D Did you always know? No, I did not. But I believed... ---Matrix III __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Don't understand plotmath behaviour (bug?)
Dear Thomas, TL In case 1 you have the string 0.5, in case 2 you have the number 0.5. TLtext(x=2,y=2, quote(bold(0.5==0.5))) TL shows what is happening. I know about the different types in the cases. That is, 'bold' affects only on text strings. Am I right? --- Best regards, Wladimirmailto:[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Installing SJava
Apologies, I am a non-techie so am finding installing SJava (which I need for RMAGEML) very frustrating indeed. I am running rw2001 on WindowsXP with Java - jre1.5.0_02. Could somebody please explain to me step-by-step how to install it as I have tried all the help files. The websites (HYPERLINK http://www.omegahat.org/RSJava/http://www.omegahat.org/RSJava/) instructions for installing the Windows source are definitely not Windows commands (are they UNIX? The file is not even a zip as stated in the instructions!). I have also tried using the command R CMD INSTALL HYPERLINK http://www.omegahat.org/RSJava/SJava_0.68-0.tar.gzSJava_0.68-0.tar.gz in R but just get a syntax error. I have tried changing the file to a zip and then installing from the R GUI (install packages from local zip) but when I type library(SJava) I get Error in library(SJava) : 'SJava' is not a valid package -- installed 2.0.0?. Please could somebody explain any way to do this (step by step) to me like Im a two year old. I have no interest in actually calling Java, I just want to be able to read MAGE-ML. I have saved the source file (HYPERLINK http://www.omegahat.org/RSJava/SJava_0.68-0.tar.gzSJava_0.68-0.tar.gz) in my C drive (viz. c:\ HYPERLINK http://www.omegahat.org/RSJava/SJava_0.68-0.tar.gzSJava_0.68-0.tar.gz) wh at now? --- [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] sparse data frame (crsp?)
thank you for the hints. a matrix is and it isn't the right tool for the job. it is really a data frame, not a matrix. the columns have meanings. actually, a more general data frame would make a nice feature for the future---as if the folks doing the R development did not have enough to do ;-). one particular kind of sparse data set implementation would make sense, in which either rows or columns are assumed to be contiguous, and an internal R parameter determines the start and end. I bet there are many data sets that take the form of data that is available for a a consecutive set of columns only. the data structure implementation of such a data frame may not be too difficult, either. regards, /iaw --- ivo welch -Original Message- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Mon, 25 Jul 2005 03:58:09 -0500 (CDT) Subject: Re: [R] sparse data frame (crsp?) You could try reading it in a chunk at a time and making a sparse matrix with SparseM, unless you really need some functionality of dataframes. R Koenker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] grep help needed
Hi, In another thread (PBSmapping and shapefiles) I asked for an easy way to read shapefiles and transform them in data that PBSmapping could use. One person is exploring some ways of doing this, but it is possible I'll have to do this manually. With package maptools I am able to extract the information I need from a shapefile but it is formatted like this: [[1]] [,1] [,2] [1,] -55.99805 51.68817 [2,] -56.00222 51.68911 [3,] -56.01694 51.68911 [4,] -56.03781 51.68606 [5,] -56.04639 51.68759 [6,] -56.04637 51.69445 [7,] -56.03777 51.70207 [8,] -56.02301 51.70892 [9,] -56.01317 51.71578 [10,] -56.00330 51.73481 [11,] -55.99805 51.73840 attr(,pstart) attr(,pstart)$from [1] 1 attr(,pstart)$to [1] 11 attr(,nParts) [1] 1 attr(,shpID) [1] NA [[2]] [,1] [,2] [1,] -57.76294 50.88770 [2,] -57.76292 50.88693 [3,] -57.76033 50.88163 [4,] -57.75668 50.88091 [5,] -57.75551 50.88169 [6,] -57.75562 50.88550 [7,] -57.75932 50.88775 [8,] -57.76294 50.88770 attr(,pstart) attr(,pstart)$from [1] 1 attr(,pstart)$to [1] 8 attr(,nParts) [1] 1 attr(,shpID) [1] NA I do not quite understand the structure of this data object (list of lists I think) but at this point I resorted to printing it on the console and imported that text into Excel for further cleaning, which is easy enough. I'd like to complete the process within R to save time and to circumvent Excel's limit of around 64000 lines. But I have a hard time figuring out how to clean up this text in R. What I need to produce for PBSmapping is a file where each block of coordinates shares one ID number, called PID, and a variable POS indicates the position of each coordinate within a shape. All other lines must disappear. So the above would become: PID POS X Y 1 1 -55.99805 51.68817 1 2 -56.00222 51.68911 1 3 -56.01694 51.68911 1 4 -56.03781 51.68606 1 5 -56.04639 51.68759 1 6 -56.04637 51.69445 1 7 -56.03777 51.70207 1 8 -56.02301 51.70892 1 9 -56.01317 51.71578 1 10 -56.00330 51.73481 1 11 -55.99805 51.73840 2 1 -57.76294 50.88770 2 2 -57.76292 50.88693 2 3 -57.76033 50.88163 2 4 -57.75668 50.88091 2 5 -57.75551 50.88169 2 6 -57.75562 50.88550 2 7 -57.75932 50.88775 2 8 -57.76294 50.88770 First I imported this text file into R: test - read.csv2(test file.txt,header=F, sep=;, colClasses = character) I used sep=; to insure there would be only one variable in this file, as it contains no ; To remove lines that do not contain coordinates, I used the fact that longitudes are expressed as negative numbers, so with my very limited knowledge of grep searches, I thought of this, which is probably not the best way to go: a - rep(-, length(test$V1)) b - grep(a, test$V1) this gives me a warning (Warning message: the condition has length 1 and only the first element will be used in: if (is.na(pattern)) { but seems to do what I need anyway c - seq(1, length(test$V1)) d - c %in% b e - test$V1[d] Partial victory, now I only have lines that look like [1,] -57.76294 50.88770 But I don't know how to go further: the number in square brackets can be used for variable POS, after removing the square brackets and the comma, but this requires a better knowledge of grep than I have. Furthermore, I don't know how to add a PID (polygon ID) variable, i.e. all lines of a polygon must have the same ID, as in the example above (i.e. each time POS == 1, a new polygon starts and PID needs to be incremented by 1, and PID is kept constant for lines where POS ! 1). Any help will be much appreciated. Sincerely, Denis Chabot __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html