Re: [R] R on Multicore for Linux

2011-07-22 Thread Gabor Grothendieck
On Thu, Jul 21, 2011 at 3:20 PM, Madana_Babu madana_b...@infosys.com wrote:
 Hi all,

 Currently i am trying to this on R which is running on multicore processor.
 I am not sure how to use mclapply() function on this task. Can anyone help
 me.


 # Setting up directory
 setwd(/XXX////2011/07/20)
 library(sqldf)

 # Data is available in the form of multiple structured log files (nearly 10K
 log files)

 # I am using the following syntax to get required fields and aggregations
 from the logs and creating a file called DF (with 3 columns V2, V14 and
 Min(V16))

 a - list.files(path = ., pattern = 2011-07-20, all.files = FALSE,
 full.names = FALSE, recursive = FALSE, ignore.case = FALSE)

 DF - NULL
 for (f in a)
 {
        dat - read.csv(f, header=FALSE, sep=\t, na.strings=,dec=.,
 strip.white=TRUE, fill=TRUE)
        data_1 - sqldf(SELECT V2, V14, MIN(V16) FROM dat WHERE V6=104 GROUP 
 BY
 V2, V14)
        DF - rbind(DF, data_1)
 }

 # Currently this process is taking almost 3 Hrs for me.

 Can anyone help me to use mclapply() on this operation and get this process
 completed asap.


Try this:

data_1 - read.csv.sql(a, sql = select ..., header = FALSE, dbname =
:memory:, sep = \t, ...whatever...)

That has two advantages (a) you will be  using sqlite's read routines
rather than R's and they may be faster and (b) instead of:  File -- R
-- sqlite -- R  it will be just File -- sqlite -- R.

See ?read.csv.sql since the arguments are not identical to read.table
(as they are based on sqlite's read routines, not R's.)Above we
have assumed each file is individually small enough to fit into memory
but if that is not the case omit the dbname= argument and it will use
files instead.  sqlite's read routines can't cope with everything R
can but if your file format is sufficiently vanilla it should work.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] loops and simulation

2011-07-22 Thread Dylan Beaudette
On Wed, Jul 20, 2011 at 10:43 PM, David Winsemius
dwinsem...@comcast.net wrote:

 On Jul 21, 2011, at 1:04 AM, Daniel Malter wrote:

 http://mlg.eng.cam.ac.uk/dave/rmbenchmark.php

 I haven't ever tried it myself, but online sources suggest that Matlab
 possibly gains speed by internally avoiding loops rather than looping
 faster. What would stand at the end if this were true, however, is improved
 end user speed.

 When I ran the Toeplitz matrix creation test on a 3 year-old Mac, not the
 fastest available at the time, inside their 20 run test with the outer()
 function I get:
 -
 b - outer(j, k, function(j,k)  abs(j - k) + 1)

 Creation of a 220x220 Toeplitz matrix (loops)___ (sec):  0.0034
 -
 When I run their code I get a number very similar to theirs:

 ---
  for (j in 1:220) {
      for (k in 1:220) {
         b[k,j] - abs(j - k) + 1
       }
     }

 Creation of a 220x220 Toeplitz matrix (loops)___ (sec):  0.2338
 ---

 So I guess that suggests that either the loop construct or the 220 x 220
 assignments  are the holdup  since the calculation and single assignment
 don't take much time.

Probably the assignment. See the archives.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Random number generation

2011-07-22 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Dennis Murphy
 Sent: Thursday, July 21, 2011 8:55 PM
 To: karena
 Cc: r-help@r-project.org
 Subject: Re: [R] Random number generation
 
 Hi:
 
 Here's one way using uniform(0, 1) pseudo-random numbers, but there
 are many ways you could go about this.
 
 # each row comprises a set of three pseudo-random numbers
 u - matrix(runif(30), nrow = 10)
 # divide each element in a row by its row sum
 v - t(apply(u, 1, function(x) x/sum(x)))
 rowSums(v)
  [1] 1 1 1 1 1 1 1 1 1 1
 
 # An equivalent way (about equally fast) is
 u/outer(rowSums(u), rep(1, 3))
 
 Now try
 
 hist(unlist(v))
 
 and notice that the distribution of the constrained sets is not really
 uniform. This is a consequence of setting a constraint on the sum of
 each sample. Another way to see this is to plot
 
 plot(sort(unlist(v)))
 
 A 'truly' uniform random sample would lie approximately on a straight
 line in this plot.
 
 It would seem to me that a better approach would be to sample from a
 simplex embedded in the unit cube. I'd suggest looking into the
 compositions package (because you are effectively generating
 compositional data) and look into its capabilities. At least a couple
 of the references in the package's overview page seem to be germane to
 the problem.
 The pair of runif.* functions appear to be relevant.
 
 HTH,
 Dennis
 
 
 
 On Thu, Jul 21, 2011 at 4:18 PM, karena dr.jz...@gmail.com wrote:
  Hi,
 
  I want to generate multiple sets of random numbers.
  The requirement is that:
  1) each set have 3 random numbers;
  2) the sum of the three number is always 1.
 
  how to do this?
 
  thank you,
 
  karena
 

Karena,

if you search the R-help archive you will find a couple of threads discussing 
this topic.  Here is one URL to get you started.

  http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2520.html

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] nested loop for

2011-07-22 Thread paloma ruiz benito

Dear Dennins,

Many thanks for you reply. Sorry for the convoluted loops, but I am starting to 
learn some programming and the loops are a bit complicated for me. Finally, a 
collegue help me with the code, and one code that works is like follow:

Pma-rep (1:40)
P-seq(1,4, 1)
Plot-rep(P,10)
dbh2-rnorm(40, mean=200, sd=5)
SBA2-rnorm(40, mean=10, sd=1)

BAL2-rep(0,length(Pma))

data-data.frame(Pma,Plot,dbh2,SBA2,BAL2)

for (p in 1:length(unique(Plot))){ 
index.stand-which(data$Plot==p)  
data.aux-data[ index.stand , ] 
result.aux-numeric() 
for (i in 1:length(data.aux$Pma)){
result.aux[i] -sum(data.aux$SBA2[which(data.aux$dbh2 data.aux[i , 
]$dbh2)]) }
data$BAL2[ index.stand]-result.aux 
rm(data.aux)
rm(result.aux) 
}
data

Best,

Paloma

 Date: Thu, 21 Jul 2011 14:18:37 -0700
 Subject: Re: [R] nested loop for
 From: djmu...@gmail.com
 To: paloma_...@hotmail.com
 CC: r-help@r-project.org
 
 Hi:
 
 I *think* this is what you're after, but I get dizzy trying to read
 convoluted loops. Try this instead;
 
 # Function to find the total SBA2 for all dbh2 larger than the given one:
 foo - function(d) {
 d - d[order(d$dbh2), ]
 d - transform(d, BAL2 = sum(SBA2) - cumsum(SBA2))
 d
   }
 
 library('plyr')
 ddply(kk, .(Plot), foo)
Pma Plot dbh2  SBA2  BAL2
 1   291 185.8568  9.055821 91.530165
 2   331 186.4623 10.762347 80.767818
 311 192.8324 10.741988 70.025830
 4   171 196.2093  9.484601 60.541229
 5   211 204.0971 11.389817 49.151412
 6   131 204.5070  9.644655 39.506756
 791 205.3079 11.014892 28.491864
 8   251 206.5908 10.041878 18.449986
 951 206.8110  8.602678  9.847307
 10  371 211.1735  9.847307  0.00
 ...
 
 # If you want the groupwise sum in the output, use the following
 version instead:
 foo - function(d) {
 d - d[order(d$dbh2), ]
 d - transform(d, BAL2 = sum(SBA2) - cumsum(SBA2),
  aa = sum(SBA2))
 d
   }
 
 HTH,
 Dennis
 
 On Thu, Jul 21, 2011 at 4:13 AM, paloma ruiz benito
 paloma_...@hotmail.com wrote:
 
  Hi everyone,
 
  I have been working some days in a nested loop in R but I can't find the 
  solution.
 
  I have a data.frame with an unique ID for individuals and unique ID for 
  different stands, for each indiviadual I have a dbh record and a SBA (stand 
  basal area) field.
 
  Pma-rep (1:40)
  P-seq(1,4, 1)
  Plot-rep(P,10)
  dbh2-rnorm(40, mean=200, sd=5)
  SBA2-rnorm(40, mean=10, sd=1)
 
  As I want to calculate the basal area of larger trees in each stand (i.e., 
  the compare tree to tree the dbh and for each individual sum the stand 
  basal area of larger trees)
 
  BAL2-rep(0,length(Pma))
  aa-rep(0,length(Pma))
 
  Now I have programed a for loop to do this calculation, and one plot it 
  works quite well:
 
  kk-data.frame(Pma, Plot, dbh2, SBA2, BAL2, aa)
  kkk-kk[kk$Plot==1,]
 
 
  The loop:
 
 for(j in 1:length(kkk$Pma)){
 for(i in 1:length(kkk$Pma)){
 if(kkk$dbh2[j]kkk$dbh2[i])
 kkk$aa[i]-kkk$SBA2[i]
 else temp_data$aa[i]-0
 kkk$BAL2[j]-sum(kkk$aa)
 }
 }
 
  But, I have tried a million of forms to calculate this for each stand... 
  and no one looks fine. The closest code that I have got is:
 
  for(k in 1:length(kk)){
 temp_data-kk[kk$Plot==Plot[k],]
 
 for(j in 1:length(temp_data$Pma)){
 #I have selected the individuals to calculate the BAL in each plot
 for(i in 1:length(temp_data$Pma)){
 if(temp_data$dbh2[j]temp_data$dbh2[i])
 temp_data$aa[i]-temp_data$SBA2[i]
 else temp_data$aa[i]-0
 temp_data$BAL2[j]-sum(temp_data$aa)
 
 
 }
 
 ###Some suggestion to save the temporal data of each stand and group 
  it together
 }
 
  }
 
  Any advise or suggestion will be very welcome,
 
  Thanks in advance,
 
  Paloma
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] GARCH IN THE MEAN Model in R

2011-07-22 Thread zoe_zhang
Dear All,
Sorry to bother. I'd like to estimate GARCH-M( GARCH IN THE MEAN) model. And
find that a package called rgarch could help. But I always can't instal
rgarch package successfully. I posted my problems and got some suggestions
but still failed. Does any one knows other method that could do GARCH-M
model?

I appreciate your time and help!

Cheers,
Xi

--
View this message in context: 
http://r.789695.n4.nabble.com/GARCH-IN-THE-MEAN-Model-in-R-tp3686083p3686083.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread Rainer M Krug
On Fri, Jul 22, 2011 at 12:44 AM, Duncan Murdoch
murdoch.dun...@gmail.comwrote:

 On 11-07-21 5:17 PM, pilchat wrote:

 thank you guys for your reply.

 i was sure that it was related to changes in the generation of ps
 files with the latest R release.

 now the question is: how can i restore the old behavior in R2.13?


 Peter told you.


True - but editing each file ps won't be an option when creating many ps
files.

A true solution would be to include an optional argument into postscript(),
e.g. sRGB=TRUE, which uses the old implementation if sRGB==FALSE. Otherwise,
I do not think there is an *easy* solution, as postscript calls compiled
code to do the actual work.

Cheers,

Rainer


 Duncan Murdoch



 thanks

 gaetano

 On 7/21/11, Ted Hardingted.harding@wlandres.**netted.hard...@wlandres.net
  wrote:

 Yes, Peter, your suggestion does the trick (at any rate with
 Gaetano's files).

 I edited his volc2.13.eps (the slow one) as follows (the original
 commented out with %%##) making just the following change:

 %%## /setrgb { srgb setcolor } def
 /setrgb { setrgbcolor } def
 %%## End of editing

 (at line 53 of the prologue). The result is a file that produces
 exactly the same picture as the other (fast) one, and renders
 (to within my perceptual resolution) in exactly the same time,
 i.e. just under one second (as opposed to about 18 before).

 Thanks, Peter!
 Ted.

 On 21-Jul-11 18:59:58, peter dalgaard wrote:

 This is due to the introduction of sRGB. Since this actually does
 something (Google for sRGB and you will be approximately as wise as
 me...), I don't think it is likely to be taken out. You can, however,
 always edit .ps.prolog. (I would expect that the line

 /setrgb { setrgbcolor } def

 instead of what is already there would reinstate the old behavior, but
 no guarantees.
 )


 On Jul 21, 2011, at 17:26 , (Ted Harding) wrote:

  On 21-Jul-11 13:24:32, Duncan Murdoch wrote:

 On 11-07-21 3:23 AM, pilchat wrote:

 Dear R users,

 I have a desktop computer and a laptop, both of them
 with Ubuntu Lucid. The former has R2.10 installed from
 Ubuntu repositories (this is the most recent version
 in the repositories), while the latter has R2.13 from
 the CRAN repositories.

 I noticed that postscript files generated with R2.10
 are better than files generated with the latest release
 of R, in particular for plots with colored areas, such
 as the output of image or persp. The thing is that my ps
 viewer (e.g. gv or evince) is very slow in opening ps
 files from R2.13, while it smoothly displays ps files
 from R2.10, regardless of encapsulation.

 I think this is related to differences in the way the
 ps file is generated by the two versions of R, but I
 don't know how to go deeper in the matter.


 Postscript files are mostly text, so you can compare the
 two files and  see what the differences are. The NEWS
 file shows a number of changes since 2.10.0, but I can't
 see any that would cause problems for viewers.

 Duncan Murdoch

  Is there anyone experiencing the same issue? Is there
 any solution?

 Thank you in advance

 Cheers
 Gaetano


 Gaetano has now sent me two files, generated (as he posted
 just now on R-help) by the same commands:

  setEPS()
  postscript (file=volc.eps,width=5,**height=4)
  image(volcano)
  dev.off()

 on his two machines:

 volc2.10.eps generated using R-2.10 on his desktop
  (the EPS file with fast rendering)

 volc2.13.eps generated using R-2.13 on his laptop
  (the EPS file with slow rendering)

 I have viewed both files on the same machine, and the
 result indeed is that while volc2.10.eps renders very
 quickly, volc2.13.eps does render very slowly (painting
 in by vertical strips which move jerkily from left
 to right). I estimate that 'gv volc2.10.eps' does the
 rendering in less than 1 second, while 'gv volc2.13.eps'
 takes about 18 seconds.

 Comparing the two files, I think I have found the reason.

 A 'diff' on the two files shows a basic difference in
 definitions of a function used in the plotting:

 [A] In file volc2.10.eps (the fast one):

  /rgb { setrgbcolor } def

 [B] In file volc2.13.eps (the slow one):

  /srgb { [ /CIEBasedABC
  /DecodeLMN
 [ { dup 0.03928 le
  {12.92321 div}
  {0.055 add 1.055 div 2.4 exp }
   ifelse
   } bind dup dup
 ]
   /MatrixLMN [0.412457 0.212673 0.019334
   0.357576 0.715152 0.119192
   0.180437 0.072175 0.950301]
   /WhitePoint [0.9505 1.0 1.0890]


] setcolorspace } def
  /setrgb { srgb setcolor } def


 Then [A] volc2.10.eps (the fast one) uses commands like:

  /bg { 1 0 0 rgb } def

 while [B] volc2.13.eps (the slow one) uses commands like:

  /bg { 1 0 0 setrgb } def

 in each case for exactly the same purpose. Thus [B] the
 slow one uses repeatedly (1157 times) a function setrgb
 which has much higher 

Re: [R] score test for logistic regression

2011-07-22 Thread peter dalgaard

On Jul 21, 2011, at 23:11 , David Winsemius wrote:

 
 On Jul 21, 2011, at 3:38 PM, zlu wrote:
 
 Hi Peter,
 
 I'm not sure how many people still have 9 month old postings on their mail 
 client and will know that Peter Dalgaard is the intended recipient.
 
 Do you have any idea or codes of construct a score test based confidence
 interval for coefficients in logistic regression?
 
 I realize that Peter knows more than I about this, so take this as working 
 hypothesis and believe anything he says more than what I say. My idea: set 
 the glm control ..., maxit=1, so you only get one iteration and then use the 
 deviance results with the usual chi-square assuptions. I fear this could be 
 too easy or else Peter would have already thought of this dodge.
 

I did think along those lines but couldn't convince myself that it would work. 
Rather, what you need is the deviance (SSD) of the approximating weighted 
regression analysis. Anyways, anova(..., test=Rao) has been implemented in 
R-devel for a while. 

This doesn't do confidence intervals, though.  That is a somewhat harder 
problem -- you'd basically need to redo the likelihood profiling code with a 
different criterion. 

For a slow and dirty technique, you could see if a parameter value beta0 is in 
the CI by including an offset of beta0*x and computing the score test for 
whether the shifted parameter (beta-beta0) is zero. Then use uniroot().

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread peter dalgaard

On Jul 22, 2011, at 09:04 , Rainer M Krug wrote:

 On Fri, Jul 22, 2011 at 12:44 AM, Duncan Murdoch
 murdoch.dun...@gmail.comwrote:
 
 On 11-07-21 5:17 PM, pilchat wrote:
 
 thank you guys for your reply.
 
 i was sure that it was related to changes in the generation of ps
 files with the latest R release.
 
 now the question is: how can i restore the old behavior in R2.13?
 
 
 Peter told you.
 
 
 True - but editing each file ps won't be an option when creating many ps
 files.
 

That's not what Peter said.

 A true solution would be to include an optional argument into postscript(),
 e.g. sRGB=TRUE, which uses the old implementation if sRGB==FALSE. Otherwise,
 I do not think there is an *easy* solution, as postscript calls compiled
 code to do the actual work.


The .ps.prolog is not in C code but in an R character vector.

 
 Cheers,
 
 Rainer
 
 
 Duncan Murdoch
 
 
 
 thanks
 
 gaetano
 
 On 7/21/11, Ted 
 Hardingted.harding@wlandres.**netted.hard...@wlandres.net
 wrote:
 
 Yes, Peter, your suggestion does the trick (at any rate with
 Gaetano's files).
 
 I edited his volc2.13.eps (the slow one) as follows (the original
 commented out with %%##) making just the following change:
 
 %%## /setrgb { srgb setcolor } def
 /setrgb { setrgbcolor } def
 %%## End of editing
 
 (at line 53 of the prologue). The result is a file that produces
 exactly the same picture as the other (fast) one, and renders
 (to within my perceptual resolution) in exactly the same time,
 i.e. just under one second (as opposed to about 18 before).
 
 Thanks, Peter!
 Ted.
 
 On 21-Jul-11 18:59:58, peter dalgaard wrote:
 
 This is due to the introduction of sRGB. Since this actually does
 something (Google for sRGB and you will be approximately as wise as
 me...), I don't think it is likely to be taken out. You can, however,
 always edit .ps.prolog. (I would expect that the line
 
 /setrgb { setrgbcolor } def
 
 instead of what is already there would reinstate the old behavior, but
 no guarantees.
 )
 
 
 On Jul 21, 2011, at 17:26 , (Ted Harding) wrote:
 
 On 21-Jul-11 13:24:32, Duncan Murdoch wrote:
 
 On 11-07-21 3:23 AM, pilchat wrote:
 
 Dear R users,
 
 I have a desktop computer and a laptop, both of them
 with Ubuntu Lucid. The former has R2.10 installed from
 Ubuntu repositories (this is the most recent version
 in the repositories), while the latter has R2.13 from
 the CRAN repositories.
 
 I noticed that postscript files generated with R2.10
 are better than files generated with the latest release
 of R, in particular for plots with colored areas, such
 as the output of image or persp. The thing is that my ps
 viewer (e.g. gv or evince) is very slow in opening ps
 files from R2.13, while it smoothly displays ps files
 from R2.10, regardless of encapsulation.
 
 I think this is related to differences in the way the
 ps file is generated by the two versions of R, but I
 don't know how to go deeper in the matter.
 
 
 Postscript files are mostly text, so you can compare the
 two files and  see what the differences are. The NEWS
 file shows a number of changes since 2.10.0, but I can't
 see any that would cause problems for viewers.
 
 Duncan Murdoch
 
 Is there anyone experiencing the same issue? Is there
 any solution?
 
 Thank you in advance
 
 Cheers
 Gaetano
 
 
 Gaetano has now sent me two files, generated (as he posted
 just now on R-help) by the same commands:
 
 setEPS()
 postscript (file=volc.eps,width=5,**height=4)
 image(volcano)
 dev.off()
 
 on his two machines:
 
 volc2.10.eps generated using R-2.10 on his desktop
 (the EPS file with fast rendering)
 
 volc2.13.eps generated using R-2.13 on his laptop
 (the EPS file with slow rendering)
 
 I have viewed both files on the same machine, and the
 result indeed is that while volc2.10.eps renders very
 quickly, volc2.13.eps does render very slowly (painting
 in by vertical strips which move jerkily from left
 to right). I estimate that 'gv volc2.10.eps' does the
 rendering in less than 1 second, while 'gv volc2.13.eps'
 takes about 18 seconds.
 
 Comparing the two files, I think I have found the reason.
 
 A 'diff' on the two files shows a basic difference in
 definitions of a function used in the plotting:
 
 [A] In file volc2.10.eps (the fast one):
 
 /rgb { setrgbcolor } def
 
 [B] In file volc2.13.eps (the slow one):
 
 /srgb { [ /CIEBasedABC
 /DecodeLMN
[ { dup 0.03928 le
 {12.92321 div}
 {0.055 add 1.055 div 2.4 exp }
  ifelse
  } bind dup dup
]
  /MatrixLMN [0.412457 0.212673 0.019334
  0.357576 0.715152 0.119192
  0.180437 0.072175 0.950301]
  /WhitePoint [0.9505 1.0 1.0890]
 
 
   ] setcolorspace } def
 /setrgb { srgb setcolor } def
 
 
 Then [A] volc2.10.eps (the fast one) uses commands like:
 
 /bg { 1 0 0 rgb } def
 
 while [B] volc2.13.eps (the slow 

Re: [R] comparing SAS and R survival analysis with time-dependent covariates

2011-07-22 Thread Göran Broström
2011/7/21 Abdullah OUESLATI abouesl...@gmail.com:
 quote author=Göran Broström
 [...]
 I do not understand why you expect to get comparable results with SAS
 discrete and coxph exact. They are two different approaches to
 handling ties (as Terry explained; of course, some comparability
 should be expected in normal cases).
 [...]
 /quote

 I didn't know precisely the specifities of each approximation method.
 I thus came back to section 3.3 of Therneau and Grambsch, Extending the Cox
 Model. I think I now see things more clearly. If I have understood
 correctly, both discrete option and exact functions assume true
 discrete event times in a model approximating the Cox model. Cox partial
 likelihood cannot be exactly maximized, or even written, when there are some
 ties, am I right ?

 In my sample, many of the ties (those whithin a single observation of the
 process) are due to the fact that continuous event times are grouped into
 intervals.

 So I think the logistic approximation may not be the best for my problem
 despite the estimate on my real data set (shown on my previous post) do give
 interessant results regarding to the context of my data set !

I would say that you should use the discrete option (ml or mppl in
coxreg). Compare that with what you get with Efron's approximation.
You should forget about the 'exact' method with large data sets. Maybe
that's what Terry meant..

Göran
 I was thinking about distributing the events uniformly in each interval.
 What do you think about this option ? Can I expect a better approximation
 than directly applying Breslow or Efron method directly with the grouped
 event data ? Finally, it becomes a model problem more than a computationnal
 or algorithmic one I guess.

 quote author=Terry Therneau-2
 [...]
 I never use the discrete option, having found the Efron
 approximation to be sufficient in every practical situation.
 [...]
 /quote

 Which criteria would you use to determinate if Efron approximation is good
 or not with grouped event data ? Is it possible to compare appproximation
 models by the results and not by the model assumption ?

 Thank you very much.




-- 
Göran Broström

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 convert 3-digits hours

2011-07-22 Thread Dieter Menne

Wonjae Lee wrote:
 
 strptime('20110101 0900',%Y%m%d %H%M) 
 [1] 2011-01-01 09:00:00 
 strptime('20110101 900',%Y%m%d %H%M) 
 [1] NA
 
 If I have a 3-digit hour like '900', please show me how to convert it to
 09:00:00.
 

d = c('20110101 900', '20110101 1900')
d1=  gsub( (\\d\\d\\d)$, 0\\1,d)
strptime(d1,%Y%m%d %H%M)

Dieter


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-convert-3-digits-hours-tp3685436p3686257.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread Ted Harding
On 22-Jul-11 08:02:40, peter dalgaard wrote:
 [much snip]
 
 The .ps.prolog is not in C code but in an R character vector.

While '?postscript' says (uder Details:):


  Most of the PostScript prologue used is taken from the
  R character vector '.ps.prolog'.  This is marked in the
  output, and can be changed by changing that vector.
  (This is only advisable for PostScript experts: the
  standard version is in ?namespace:grDevices?.)

I have not been able to get my hands on that vector in an
R session. What is the incantation for locating it, please?

With thanks,
Ted.


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 22-Jul-11   Time: 10:08:34
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread Rainer M Krug
On Fri, Jul 22, 2011 at 10:02 AM, peter dalgaard pda...@gmail.com wrote:


 On Jul 22, 2011, at 09:04 , Rainer M Krug wrote:

  On Fri, Jul 22, 2011 at 12:44 AM, Duncan Murdoch
  murdoch.dun...@gmail.comwrote:
 
  On 11-07-21 5:17 PM, pilchat wrote:
 
  thank you guys for your reply.
 
  i was sure that it was related to changes in the generation of ps
  files with the latest R release.
 
  now the question is: how can i restore the old behavior in R2.13?
 
 
  Peter told you.
 
 
  True - but editing each file ps won't be an option when creating many ps
  files.
 

 That's not what Peter said.


Sincere apologies from Rainer to Peter.



  A true solution would be to include an optional argument into
 postscript(),
  e.g. sRGB=TRUE, which uses the old implementation if sRGB==FALSE.
 Otherwise,
  I do not think there is an *easy* solution, as postscript calls compiled
  code to do the actual work.


 The .ps.prolog is not in C code but in an R character vector.


Rainer should really read the posts properly before replying 



 
  Cheers,
 
  Rainer
 
 
  Duncan Murdoch
 
 
 
  thanks
 
  gaetano
 
  On 7/21/11, Ted Hardingted.harding@wlandres.**net
 ted.hard...@wlandres.net
  wrote:
 
  Yes, Peter, your suggestion does the trick (at any rate with
  Gaetano's files).
 
  I edited his volc2.13.eps (the slow one) as follows (the original
  commented out with %%##) making just the following change:
 
  %%## /setrgb { srgb setcolor } def
  /setrgb { setrgbcolor } def
  %%## End of editing
 
  (at line 53 of the prologue). The result is a file that produces
  exactly the same picture as the other (fast) one, and renders
  (to within my perceptual resolution) in exactly the same time,
  i.e. just under one second (as opposed to about 18 before).
 
  Thanks, Peter!
  Ted.
 
  On 21-Jul-11 18:59:58, peter dalgaard wrote:
 
  This is due to the introduction of sRGB. Since this actually does
  something (Google for sRGB and you will be approximately as wise as
  me...), I don't think it is likely to be taken out. You can, however,
  always edit .ps.prolog. (I would expect that the line
 
  /setrgb { setrgbcolor } def
 
  instead of what is already there would reinstate the old behavior,
 but
  no guarantees.
  )
 
 
  On Jul 21, 2011, at 17:26 , (Ted Harding) wrote:
 
  On 21-Jul-11 13:24:32, Duncan Murdoch wrote:
 
  On 11-07-21 3:23 AM, pilchat wrote:
 
  Dear R users,
 
  I have a desktop computer and a laptop, both of them
  with Ubuntu Lucid. The former has R2.10 installed from
  Ubuntu repositories (this is the most recent version
  in the repositories), while the latter has R2.13 from
  the CRAN repositories.
 
  I noticed that postscript files generated with R2.10
  are better than files generated with the latest release
  of R, in particular for plots with colored areas, such
  as the output of image or persp. The thing is that my ps
  viewer (e.g. gv or evince) is very slow in opening ps
  files from R2.13, while it smoothly displays ps files
  from R2.10, regardless of encapsulation.
 
  I think this is related to differences in the way the
  ps file is generated by the two versions of R, but I
  don't know how to go deeper in the matter.
 
 
  Postscript files are mostly text, so you can compare the
  two files and  see what the differences are. The NEWS
  file shows a number of changes since 2.10.0, but I can't
  see any that would cause problems for viewers.
 
  Duncan Murdoch
 
  Is there anyone experiencing the same issue? Is there
  any solution?
 
  Thank you in advance
 
  Cheers
  Gaetano
 
 
  Gaetano has now sent me two files, generated (as he posted
  just now on R-help) by the same commands:
 
  setEPS()
  postscript (file=volc.eps,width=5,**height=4)
  image(volcano)
  dev.off()
 
  on his two machines:
 
  volc2.10.eps generated using R-2.10 on his desktop
  (the EPS file with fast rendering)
 
  volc2.13.eps generated using R-2.13 on his laptop
  (the EPS file with slow rendering)
 
  I have viewed both files on the same machine, and the
  result indeed is that while volc2.10.eps renders very
  quickly, volc2.13.eps does render very slowly (painting
  in by vertical strips which move jerkily from left
  to right). I estimate that 'gv volc2.10.eps' does the
  rendering in less than 1 second, while 'gv volc2.13.eps'
  takes about 18 seconds.
 
  Comparing the two files, I think I have found the reason.
 
  A 'diff' on the two files shows a basic difference in
  definitions of a function used in the plotting:
 
  [A] In file volc2.10.eps (the fast one):
 
  /rgb { setrgbcolor } def
 
  [B] In file volc2.13.eps (the slow one):
 
  /srgb { [ /CIEBasedABC
  /DecodeLMN
 [ { dup 0.03928 le
  {12.92321 div}
  {0.055 add 1.055 div 2.4 exp }
   ifelse
   } bind dup dup
 ]
   /MatrixLMN [0.412457 0.212673 0.019334
   0.357576 0.715152 

Re: [R] R versions and PostScript files

2011-07-22 Thread Ted Harding
On 22-Jul-11 09:20:23, peter dalgaard wrote:
 
 On Jul 22, 2011, at 11:08 , (Ted Harding) wrote:
 
 On 22-Jul-11 08:02:40, peter dalgaard wrote:
 [much snip]
 
 The .ps.prolog is not in C code but in an R character vector.
 
 While '?postscript' says (uder Details:):
 
 
  Most of the PostScript prologue used is taken from the
  R character vector '.ps.prolog'.  This is marked in the
  output, and can be changed by changing that vector.
  (This is only advisable for PostScript experts: the
  standard version is in ?namespace:grDevices?.)
 
 I have not been able to get my hands on that vector in an
 R session. What is the incantation for locating it, please?
 
 grDevices:::.ps.prolog
 
 as in:
 
 .ps.prolog - grDevices:::.ps.prolog
 .ps.prolog[39] - /setrgb { setrgbcolor } def
 postscript()
 image(volcano)
 dev.off()
 
 -- 
 Peter Dalgaard

Ah, thanks! I wasn't using sufficiently many :'s!
Apologies for the fumble.
Ted.


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 22-Jul-11   Time: 10:27:37
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread peter dalgaard

On Jul 22, 2011, at 11:08 , (Ted Harding) wrote:

 On 22-Jul-11 08:02:40, peter dalgaard wrote:
 [much snip]
 
 The .ps.prolog is not in C code but in an R character vector.
 
 While '?postscript' says (uder Details:):
 
 
  Most of the PostScript prologue used is taken from the
  R character vector '.ps.prolog'.  This is marked in the
  output, and can be changed by changing that vector.
  (This is only advisable for PostScript experts: the
  standard version is in ?namespace:grDevices?.)
 
 I have not been able to get my hands on that vector in an
 R session. What is the incantation for locating it, please?

grDevices:::.ps.prolog

as in:

.ps.prolog - grDevices:::.ps.prolog
.ps.prolog[39] - /setrgb { setrgbcolor } def
postscript()
image(volcano)
dev.off()
 

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread Rainer M Krug
On Fri, Jul 22, 2011 at 9:55 AM, pilchat pilc...@gmail.com wrote:

 I tried with the option sRGB=F in the postscript() command, but I got the
 error message unused argument(s) (sRGB = F)


True - because that option is not there, but to include one wopuld be an
option.



 I think that Peter's solution is the best one, as it consists, as far as I
 understand, in changing the default content of .ps.postscript.


I am quite sure that he refers to editing the resulting postscript file -
but I might be wrong. As far as I can see, the creation is done in compiled
code, so it would not be that straightforward to change this behavior.



 The problem is that I don't know how to do that!!! I am still at the
 beginner level with R. PLease, can anyone help me?


 Thanks a lot

 G


 On Fri, Jul 22, 2011 at 9:04 AM, Rainer M Krug r.m.k...@gmail.com wrote:



 On Fri, Jul 22, 2011 at 12:44 AM, Duncan Murdoch 
 murdoch.dun...@gmail.com wrote:

 On 11-07-21 5:17 PM, pilchat wrote:

 thank you guys for your reply.

 i was sure that it was related to changes in the generation of ps
 files with the latest R release.

 now the question is: how can i restore the old behavior in R2.13?


 Peter told you.


 True - but editing each file ps won't be an option when creating many ps
 files.

 A true solution would be to include an optional argument into
 postscript(), e.g. sRGB=TRUE, which uses the old implementation if
 sRGB==FALSE. Otherwise, I do not think there is an *easy* solution, as
 postscript calls compiled code to do the actual work.

 Cheers,

 Rainer


 Duncan Murdoch



 thanks

 gaetano

 On 7/21/11, Ted 
 Hardingted.harding@wlandres.**netted.hard...@wlandres.net
  wrote:

 Yes, Peter, your suggestion does the trick (at any rate with
 Gaetano's files).

 I edited his volc2.13.eps (the slow one) as follows (the original
 commented out with %%##) making just the following change:

 %%## /setrgb { srgb setcolor } def
 /setrgb { setrgbcolor } def
 %%## End of editing

 (at line 53 of the prologue). The result is a file that produces
 exactly the same picture as the other (fast) one, and renders
 (to within my perceptual resolution) in exactly the same time,
 i.e. just under one second (as opposed to about 18 before).

 Thanks, Peter!
 Ted.

 On 21-Jul-11 18:59:58, peter dalgaard wrote:

 This is due to the introduction of sRGB. Since this actually does
 something (Google for sRGB and you will be approximately as wise as
 me...), I don't think it is likely to be taken out. You can, however,
 always edit .ps.prolog. (I would expect that the line

 /setrgb { setrgbcolor } def

 instead of what is already there would reinstate the old behavior, but
 no guarantees.
 )


 On Jul 21, 2011, at 17:26 , (Ted Harding) wrote:

  On 21-Jul-11 13:24:32, Duncan Murdoch wrote:

 On 11-07-21 3:23 AM, pilchat wrote:

 Dear R users,

 I have a desktop computer and a laptop, both of them
 with Ubuntu Lucid. The former has R2.10 installed from
 Ubuntu repositories (this is the most recent version
 in the repositories), while the latter has R2.13 from
 the CRAN repositories.

 I noticed that postscript files generated with R2.10
 are better than files generated with the latest release
 of R, in particular for plots with colored areas, such
 as the output of image or persp. The thing is that my ps
 viewer (e.g. gv or evince) is very slow in opening ps
 files from R2.13, while it smoothly displays ps files
 from R2.10, regardless of encapsulation.

 I think this is related to differences in the way the
 ps file is generated by the two versions of R, but I
 don't know how to go deeper in the matter.


 Postscript files are mostly text, so you can compare the
 two files and  see what the differences are. The NEWS
 file shows a number of changes since 2.10.0, but I can't
 see any that would cause problems for viewers.

 Duncan Murdoch

  Is there anyone experiencing the same issue? Is there
 any solution?

 Thank you in advance

 Cheers
 Gaetano


 Gaetano has now sent me two files, generated (as he posted
 just now on R-help) by the same commands:

  setEPS()
  postscript (file=volc.eps,width=5,**height=4)
  image(volcano)
  dev.off()

 on his two machines:

 volc2.10.eps generated using R-2.10 on his desktop
  (the EPS file with fast rendering)

 volc2.13.eps generated using R-2.13 on his laptop
  (the EPS file with slow rendering)

 I have viewed both files on the same machine, and the
 result indeed is that while volc2.10.eps renders very
 quickly, volc2.13.eps does render very slowly (painting
 in by vertical strips which move jerkily from left
 to right). I estimate that 'gv volc2.10.eps' does the
 rendering in less than 1 second, while 'gv volc2.13.eps'
 takes about 18 seconds.

 Comparing the two files, I think I have found the reason.

 A 'diff' on the two files shows a basic difference in
 definitions of a function used in the plotting:

 [A] In file volc2.10.eps (the fast one):

  /rgb { setrgbcolor } def

 [B] In file volc2.13.eps 

[R] Randomisation as an alternative to correction for multiple testing

2011-07-22 Thread January Weiner
Dear all,

randomisation or resampling is viewed by some as an alternative to
correction for multiple testing such as Bonferroni or Holm.

Is there any package implementing such an approach in microarray analysis?

Cheers,

j.

-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread pilchat
I tried with the option sRGB=F in the postscript() command, but I got the
error message unused argument(s) (sRGB = F)

I think that Peter's solution is the best one, as it consists, as far as I
understand, in changing the default content of .ps.postscript.

The problem is that I don't know how to do that!!! I am still at the
beginner level with R. PLease, can anyone help me?

Thanks a lot

G

On Fri, Jul 22, 2011 at 9:04 AM, Rainer M Krug r.m.k...@gmail.com wrote:



 On Fri, Jul 22, 2011 at 12:44 AM, Duncan Murdoch murdoch.dun...@gmail.com
  wrote:

 On 11-07-21 5:17 PM, pilchat wrote:

 thank you guys for your reply.

 i was sure that it was related to changes in the generation of ps
 files with the latest R release.

 now the question is: how can i restore the old behavior in R2.13?


 Peter told you.


 True - but editing each file ps won't be an option when creating many ps
 files.

 A true solution would be to include an optional argument into postscript(),
 e.g. sRGB=TRUE, which uses the old implementation if sRGB==FALSE. Otherwise,
 I do not think there is an *easy* solution, as postscript calls compiled
 code to do the actual work.

 Cheers,

 Rainer


 Duncan Murdoch



 thanks

 gaetano

 On 7/21/11, Ted 
 Hardingted.harding@wlandres.**netted.hard...@wlandres.net
  wrote:

 Yes, Peter, your suggestion does the trick (at any rate with
 Gaetano's files).

 I edited his volc2.13.eps (the slow one) as follows (the original
 commented out with %%##) making just the following change:

 %%## /setrgb { srgb setcolor } def
 /setrgb { setrgbcolor } def
 %%## End of editing

 (at line 53 of the prologue). The result is a file that produces
 exactly the same picture as the other (fast) one, and renders
 (to within my perceptual resolution) in exactly the same time,
 i.e. just under one second (as opposed to about 18 before).

 Thanks, Peter!
 Ted.

 On 21-Jul-11 18:59:58, peter dalgaard wrote:

 This is due to the introduction of sRGB. Since this actually does
 something (Google for sRGB and you will be approximately as wise as
 me...), I don't think it is likely to be taken out. You can, however,
 always edit .ps.prolog. (I would expect that the line

 /setrgb { setrgbcolor } def

 instead of what is already there would reinstate the old behavior, but
 no guarantees.
 )


 On Jul 21, 2011, at 17:26 , (Ted Harding) wrote:

  On 21-Jul-11 13:24:32, Duncan Murdoch wrote:

 On 11-07-21 3:23 AM, pilchat wrote:

 Dear R users,

 I have a desktop computer and a laptop, both of them
 with Ubuntu Lucid. The former has R2.10 installed from
 Ubuntu repositories (this is the most recent version
 in the repositories), while the latter has R2.13 from
 the CRAN repositories.

 I noticed that postscript files generated with R2.10
 are better than files generated with the latest release
 of R, in particular for plots with colored areas, such
 as the output of image or persp. The thing is that my ps
 viewer (e.g. gv or evince) is very slow in opening ps
 files from R2.13, while it smoothly displays ps files
 from R2.10, regardless of encapsulation.

 I think this is related to differences in the way the
 ps file is generated by the two versions of R, but I
 don't know how to go deeper in the matter.


 Postscript files are mostly text, so you can compare the
 two files and  see what the differences are. The NEWS
 file shows a number of changes since 2.10.0, but I can't
 see any that would cause problems for viewers.

 Duncan Murdoch

  Is there anyone experiencing the same issue? Is there
 any solution?

 Thank you in advance

 Cheers
 Gaetano


 Gaetano has now sent me two files, generated (as he posted
 just now on R-help) by the same commands:

  setEPS()
  postscript (file=volc.eps,width=5,**height=4)
  image(volcano)
  dev.off()

 on his two machines:

 volc2.10.eps generated using R-2.10 on his desktop
  (the EPS file with fast rendering)

 volc2.13.eps generated using R-2.13 on his laptop
  (the EPS file with slow rendering)

 I have viewed both files on the same machine, and the
 result indeed is that while volc2.10.eps renders very
 quickly, volc2.13.eps does render very slowly (painting
 in by vertical strips which move jerkily from left
 to right). I estimate that 'gv volc2.10.eps' does the
 rendering in less than 1 second, while 'gv volc2.13.eps'
 takes about 18 seconds.

 Comparing the two files, I think I have found the reason.

 A 'diff' on the two files shows a basic difference in
 definitions of a function used in the plotting:

 [A] In file volc2.10.eps (the fast one):

  /rgb { setrgbcolor } def

 [B] In file volc2.13.eps (the slow one):

  /srgb { [ /CIEBasedABC
  /DecodeLMN
 [ { dup 0.03928 le
  {12.92321 div}
  {0.055 add 1.055 div 2.4 exp }
   ifelse
   } bind dup dup
 ]
   /MatrixLMN [0.412457 0.212673 0.019334
   0.357576 0.715152 

[R] Mean and Timeseries modelling

2011-07-22 Thread Marko
Hello,
i have following problem and I hope you can help me a little bit


My dataframe looks like:

df
a   m  d   typvalue
1950  1  15  -4.1
1950  1  29   2.7
1950  1  33  -1.3
1950  1  45  -1.9
1950  1  52   0.2
1950  1  68   0.5
1951  1  14   1.3


It consists by daily observations from 1950- 2009.

Now, I get with

for (i in df$V5)
neu - tapply(df[,5],list(df$V4,df$V1),mean)

the yearly means of the types (1-18) for every year.

The new df looks like:

new
typ   1950   1951   1952195319541955
1956...   2009
1   0.40588235 -0.1714286 -1.811   5.400  -0.956  2.6583
2  -3.1778  1.4130435 -0.917  -4.900   0.290  3.54285714
3   0.0889 -2.000 -2.967   2.200  -1.860 -0.5000
...
18


Now, i would like to generate a timeseries with the means, according to the
different types.
For example: For all days in the year 1950 with the typ 1, I would like to
write the mean value for Typ 1 in year 1950. In year 1951 I would like to
write the mean value for typ 1 in 1951 etc. (for all 18 types)

The output should look like as following:

erg
a   m  d   typvalue   mean_typ_year
1950  1  11  -4.1  0,4
1950  1  22   2.7  Mean (Typ2 1950)
1950  1  31  -1.3  0,4
1950  1  45  -1.9  Mean (Typ5 1950)
1950  1  52   0.2  ...
1950  1  68   0.5  ...
1951  1  11   1.3  -0,17
1951  1  22   2.1  Mean (Typ2 1951)


I hope you can help me by solving this problem 

Best regards,
Marko

--
View this message in context: 
http://r.789695.n4.nabble.com/Mean-and-Timeseries-modelling-tp3686326p3686326.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] Mean and modelling values

2011-07-22 Thread Marko
Hello,
i have following problem and I hope you can help me a little bit


My dataframe looks like:

df
a   m  d   typvalue
1950  1  15  -4.1
1950  1  29   2.7
1950  1  33  -1.3
1950  1  45  -1.9
1950  1  52   0.2
1950  1  68   0.5
1951  1  14   1.3


It consists by daily observations from 1950- 2009.

Now, I get with

for (i in df$V5)
neu - tapply(df[,5],list(df$V4,df$V1),mean)

the yearly means of the types (1-18) for every year.

The new df looks like:

new
typ   1950   1951   1952195319541955
1956...   2009
1   0.40588235 -0.1714286 -1.811   5.400  -0.956  2.6583
2  -3.1778  1.4130435 -0.917  -4.900   0.290  3.54285714
3   0.0889 -2.000 -2.967   2.200  -1.860 -0.5000
...
18


Now, i would like to generate a timeseries with the means, according to the
different types.
For example: For all days in the year 1950 with the typ 1, I would like to
write the mean value for Typ 1 in year 1950. In year 1951 I would like to
write the mean value for typ 1 in 1951 etc. (for all 18 types)

The output should look like as following:

erg
a   m  d   typvalue   mean_typ_year
1950  1  11  -4.1  0,4
1950  1  22   2.7  Mean (Typ2 1950)
1950  1  31  -1.3  0,4
1950  1  45  -1.9  Mean (Typ5 1950)
1950  1  52   0.2  ...
1950  1  68   0.5  ...
1951  1  11   1.3  -0,17
1951  1  22   2.1  Mean (Typ2 1951)


I hope you can help me by solving this problem

Best regards,
Marko 

--
View this message in context: 
http://r.789695.n4.nabble.com/Mean-and-modelling-values-tp3686341p3686341.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Random number generation

2011-07-22 Thread karena
Thank you guys for all the help. I appreciate!

--
View this message in context: 
http://r.789695.n4.nabble.com/Random-number-generation-tp3685463p3686392.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] Mclapply prints once

2011-07-22 Thread Alaios
Dear all
I have the following code that works in paraller (and is pretty fast actually)

The only problem I still have is that every core just prints only once.

dimz-1000

Shadowlist-mclapply(1:dimz, function(i) {
  print(sprintf('Creating the %d map',i));
  createField(x=x, y=y, model=model, 
grid=TRUE,param=c(mean,variance,nugget,scale))
    }
    )



In a four core system you will only receive four print messages while this 
works for 1000 iterations

What might be causing this one time printing?


BR
Alex


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] cv.glm and longer object length is not a multiple of shorter object length error

2011-07-22 Thread Peter Ehlers

On 2011-07-21 17:29, askantik wrote:

Hi,

I've done some searching where others have had trouble with this error (or
warning actually), but I'm unable to solve my problem.  I have a data
sheet with 13 columns and 36 rows.  Each column has exactly the same number
of rows.  I've created glms and now want to do cross-validation on 2 of
them.  Please be gentle-- I'm new to R (and statistics, too, for that
matter).  Any help is greatly appreciated.  Here's my code:

/library(boot)
n-length(total_species)
cv13.err- cv.glm(nests,glm13)
cv13.err.5- cv.glm(nests,glm13,K=5)
cv18.err- cv.glm(nests,glm18)
cv18.err.5- cv.glm(nests,glm18,K=5)/


I get errors starting with the glm18 part.  glm13 is
*total_species~RH+elev+RH*elev* and glm18 is *total_species~per_cover+RH*

Does it have something to do with the two glms having different numbers of
parameters?  I'm not sure why it seems okay with what I've done for glm13,
but not glm18.  Thanks again for any help.

*Warning messages:
1: In y - yhat :
   longer object length is not a multiple of shorter object length*


My guess is that per_cover contains at least one missing value.
You could try

 cv.glm(na.omit(nests), glm18)

I tried glm(..., na.action = na.exclude) but cv.glm() appears not (yet)
to be coded to handle padding of missing values.

Peter Ehlers



--
View this message in context: 
http://r.789695.n4.nabble.com/cv-glm-and-longer-object-length-is-not-a-multiple-of-shorter-object-length-error-tp3685622p3685622.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installation of XMLPRC package

2011-07-22 Thread Mitra, Sumona
Dear R users,

I am trying to download the XMLRPC package for R from www.omegahat.org without 
any success. Any pointers?

Sumona
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 set Color scale for color2D.matplot()

2011-07-22 Thread Jim Lemon

On 07/22/2011 01:42 AM, Youcheng Lin wrote:

Hello, everyone.

I am trying to show the correlation matrix using
color2D.matplot(). And I want to map (0,1) to (dark red to dark green).

But by default color2D.matplot() will map(min element of given matrix,
  max  element of given matrix) to (dark red to dark green).


Hi Youcheng,
If I understand your question, you have a correlation matrix with some 
values below zero, but you want to map only those values greater than or 
equal to zero as dark red - dark green. I'll assume that you want 
another set of colors for the negative values (purple to dark blue). 
Here's how:


corr.matrix-matrix(runif(100,-1,1),nrow=10)
cellcolors-matrix(NA,nrow=10,ncol=10)
cellcolors[corr.matrix = 0]-
 color.scale(corr.matrix[corr.matrix = 0],
 cs1=c(0.7,0),cs2=c(0,0.7),cs3=0)
cellcolors[corr.matrix  0]-
 color.scale(corr.matrix[corr.matrix  0],
 cs1=c(0.7,0),cs2=0,cs3=0.7)
color2D.matplot(corr.matrix,cellcolors=cellcolors,
 show.values=TRUE)

I've included the values in the example so that you can see that the 
positive and negative values are getting the correct colors.


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Changing Y axis in R

2011-07-22 Thread Jim Lemon

On 07/22/2011 07:16 AM, David Winsemius wrote:

Context added back in:



SamiC wrote:

Hi,

So I am trying to plot my results of a model. what i have is the
majority
of the data between the values of 0 and 30, then one outlier at 80 and
another at 130. the model plots a nice line through the data between
0 to
30, however given the outliers you cant seen this unless you change
the y
axis using ylim=c(0,30) but then you can only see the data points in
this
range. What I would like to do is plot a y axis with a multiple
scale, so
if i have 10 equally spaced ticks, 0 to 8 would be the data between
0 and
30, and then tick 9 would be 80 and tick 10 130, so that the two
outliers
would be show in the graph. I think what i have seen is a graph with
the
axis on one scale, then a squiggly line to another scale, and a
squiggly
like to a third scale.




DW wrote:

I seem to remember a post from Sarkar that there is no provision for
broken axes in lattice, so you will perhaps need to stay with base
graphics. The places to look for this sort of request are in plotrix
and TeachingDemos packages. I seem to remember such a question in the
past, so if that isn't immediately effective (actually it was when I
just checked so I am leaving it as an exercise for the poster), then
do some searching in the archives. And I see you are on posting from
Nabble. Nabble is not a particularly good place to do searches. Use
Baron's site, or Rseek, or sos::findFn, or Markmail or gmane. They
are all bette for searching. You might want to read the Posting Guide
too.



On Jul 21, 2011, at 4:51 PM, SamiC wrote:


Hi, couldn't find much in the archives. I had checked before posting.
Anyway the plotrix package was a good hint. So anyone who reads this in
future, i ended up using the gap.plot function in the plotrix package,
which
does the trick. Thanks


Interesting ... I had thought it was axis.break that would do the job,
but it looks as though the two are interdependent.

Yes, the gap* functions use the gap style of axis break to separate the 
different areas of the plot.


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Cox model approximaions (was comparing SAS and R survival....)

2011-07-22 Thread Terry Therneau
 For time scale that are truly discrete Cox proposed the exact partial
likelihood.  I call that the exact method and SAS calls it the
discrete method.  What we compute is precisely the same, however they
use a clever algorithm which is faster.  To make things even more
confusing, Prentice introduced an exact marginal likelihood which is
not implemented in R, but which SAS calls the exact method.

  Data is usually not truly discrete, however.  More often ties are the
result of imprecise measurement or grouping.  The Efron approximation
assumes that the data are actually continuous but we see ties because of
this; it also introduces an approximation at one point in the
calculation which greatly speeds up the computation; numerically the
approximation is very good.  
  In spite of the irrational love that our profession has for anything
branded with the word exact, I currently see no reason to ever use
that particular computation in a Cox model.  I'm not quite ready to
remove the option from coxph, but certainly am not going to devote any
effort toward improving that part of the code.

  The Breslow approximation is less accurate, but is the easiest to
program and therefore was the only method in early Cox model programs;
it persists as the default in many software packages because of history.
Truth be told, unless the number of tied deaths is quite large the
difference in results between it and the Efron approx will be trivial.

  The worst approximation, and the one that can sometimes give seriously
strange results, is to artificially remove ties from the data set by
adding a random value to each subject's time.

Terry T


--- begin quote --
I didn't know precisely the specifities of each approximation method.
I thus came back to section 3.3 of Therneau and Grambsch, Extending the
Cox
Model. I think I now see things more clearly. If I have understood
correctly, both discrete option and exact functions assume true
discrete event times in a model approximating the Cox model. Cox partial
likelihood cannot be exactly maximized, or even written, when there are
some
ties, am I right ?

In my sample, many of the ties (those whithin a single observation of
the
process) are due to the fact that continuous event times are grouped
into
intervals.

So I think the logistic approximation may not be the best for my problem
despite the estimate on my real data set (shown on my previous post) do
give
interessant results regarding to the context of my data set !
I was thinking about distributing the events uniformly in each interval.
What do you think about this option ? Can I expect a better
approximation
than directly applying Breslow or Efron method directly with the grouped
event data ? Finally, it becomes a model problem more than a
computationnal
or algorithmic one I guess.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Randomisation / resampling and correction for multiple testing

2011-07-22 Thread January Weiner
Dear all,

randomisation or resampling is viewed by some as an alternative to
correction for multiple testing such as Bonferroni or Holm.

Is there any package implementing such an approach in microarray analysis?

Cheers,

j.

-- 
 Dr. January Weiner 3 --
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin, Germany
Web   : www.mpiib-berlin.mpg.de
Tel     : +49-30-28460514

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installation of XMLPRC package

2011-07-22 Thread Prof Brian Ripley

On Fri, 22 Jul 2011, Mitra, Sumona wrote:


Dear R users,

I am trying to download the XMLRPC package for R from 
www.omegahat.org without any success. Any pointers?


The posting guide (see the footer of this message).

We have absolutely no idea what problems you encountered, what 
platform you used, what version of R ... nor what the maintainer of 
the package/site (the same person) said.


FWIW, it worked for me just now (R 2.13.1, Linux).



Sumona
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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,  rip...@stats.ox.ac.uk
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] Cox model approximaions (was comparing SAS and R survival....)

2011-07-22 Thread Mike Marchywka












 From: thern...@mayo.edu
 To: abouesl...@gmail.com
 Date: Fri, 22 Jul 2011 07:04:15 -0500
 CC: r-help@r-project.org
 Subject: Re: [R] Cox model approximaions (was comparing SAS and R 
 survival)

 For time scale that are truly discrete Cox proposed the exact partial
 likelihood. I call that the exact method and SAS calls it the
 discrete method. What we compute is precisely the same, however they
 use a clever algorithm which is faster. To make things even more
 confusing, Prentice introduced an exact marginal likelihood which is
 not implemented in R, but which SAS calls the exact method.

 Data is usually not truly discrete, however. More often ties are the
 result of imprecise measurement or grouping. The Efron approximation
 assumes that the data are actually continuous but we see ties because of
 this; it also introduces an approximation at one point in the
 calculation which greatly speeds up the computation; numerically the
 approximation is very good.
 In spite of the irrational love that our profession has for anything
 branded with the word exact, I currently see no reason to ever use
 that particular computation in a Cox model. I'm not quite ready to
 remove the option from coxph, but certainly am not going to devote any
 effort toward improving that part of the code.

 The Breslow approximation is less accurate, but is the easiest to
 program and therefore was the only method in early Cox model programs;
 it persists as the default in many software packages because of history.
 Truth be told, unless the number of tied deaths is quite large the
 difference in results between it and the Efron approx will be trivial.

 The worst approximation, and the one that can sometimes give seriously
 strange results, is to artificially remove ties from the data set by
 adding a random value to each subject's time.

Care to elaborate on this at all? First of course I would agree that doing
anything to the data, or making up data, and then handing it to an analysis 
tool that doesn't
know you maniplated it can be a problem ( often called interpolation or 
something 
with a legitimate name LOL).  However, it is not unreasonable to do a 
sensitivity
analysis by adding noise and checking the results.  Presumaably adding 
noise to remove things the algorighm doesn't happen to like would
work but you would need to take many samples and examine stats
of how your broke the ties. Now if the model is bad to begin with or
the data is so coarsely binned that you can't get much out of it then ok.

I guess in this case, having not thought about it too much, ties would
be most common either with lots of data or if hazards spiked over time scales 
simlar to your
measurement precision or if the measurement resolution is not comparable to 
hazard
rate. In the latter 2 cases of course the approach is probably quite  limited . 
Consider turning
exponential curves into step functions for example. 


 Terry T


 --- begin quote --
 I didn't know precisely the specifities of each approximation method.
 I thus came back to section 3.3 of Therneau and Grambsch, Extending the
 Cox
 Model. I think I now see things more clearly. If I have understood
 correctly, both discrete option and exact functions assume true
 discrete event times in a model approximating the Cox model. Cox partial
 likelihood cannot be exactly maximized, or even written, when there are
 some
 ties, am I right ?

 In my sample, many of the ties (those whithin a single observation of
 the
 process) are due to the fact that continuous event times are grouped
 into
 intervals.

 So I think the logistic approximation may not be the best for my problem
 despite the estimate on my real data set (shown on my previous post) do
 give
[[elided Hotmail spam]]
 I was thinking about distributing the events uniformly in each interval.
 What do you think about this option ? Can I expect a better
 approximation
 than directly applying Breslow or Efron method directly with the grouped
 event data ? Finally, it becomes a model problem more than a
 computationnal
 or algorithmic one I guess.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] User input(unknown name and number of files)

2011-07-22 Thread Bansal, Vikas
Dear all,

I need your help as I was not able to find out the solution.

The thing is-
I am having a code which is reading file with this code-

df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
 but as am making a tool so that user can use it and can do analysis on his 
file.But the name of the file will not be Case2.pileup and I want to use this 
code so that user can input as many files as he want.My code is like this-

df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
df$V9 -  apply(df, 1, function(x) gsub(\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10, 
,x[9]))
df$V10 - sapply(df$V10, function(a)  
 paste(as.integer(charToRaw(a)), collapse = ' '))
capture.output(print.data.frame(df,row.names=F), file = end.txt, append = 
FALSE)

I know it should do it with for loop and an array.I want that if user input 12 
files,the dataframe name df should be different for all the 12 files.

Can you please tell me how can I do this.


Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lattice: place ticks only on y-axis

2011-07-22 Thread marcel
I notice that with this solution there are still y-axis tick marks on both
sides of the plot. Is there a way to remove the ones on the right side?

--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-place-ticks-only-on-y-axis-tp3684094p3686638.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installation of XMLPRC package

2011-07-22 Thread Mitra, Sumona
Dear all,

Apologies for not being specific earlier.
The R version I am using is 2.12.2. 

Everytime I try installing XMLRPC using the following command:-


 install.packages(repos = http://www.omegahat.org/XMLRPC/XMLRPC_0.2-4.tar.gz;)

I get the following error

Warning: unable to access index for repository 
http://www.omegahat.org/XMLRPC/XMLRPC_0.2-4.tar.gz/bin/windows/contrib/2.12
Error in length(pkgs) : 'pkgs' is missing

Best
Sumona
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread pilchat
That's great! Thank you all!!

Final question: how can I edit permanently the .ps.prolog? Is the .First()
function an option?

Please, tell me every detail as I am a total dumb!

Many thanks

Gaetano

On Fri, Jul 22, 2011 at 11:27 AM, Ted Harding ted.hard...@wlandres.netwrote:

 On 22-Jul-11 09:20:23, peter dalgaard wrote:
 
  On Jul 22, 2011, at 11:08 , (Ted Harding) wrote:
 
  On 22-Jul-11 08:02:40, peter dalgaard wrote:
  [much snip]
 
  The .ps.prolog is not in C code but in an R character vector.
 
  While '?postscript' says (uder Details:):
 
 
   Most of the PostScript prologue used is taken from the
   R character vector '.ps.prolog'.  This is marked in the
   output, and can be changed by changing that vector.
   (This is only advisable for PostScript experts: the
   standard version is in ?namespace:grDevices?.)
 
  I have not been able to get my hands on that vector in an
  R session. What is the incantation for locating it, please?
 
  grDevices:::.ps.prolog
 
  as in:
 
  .ps.prolog - grDevices:::.ps.prolog
  .ps.prolog[39] - /setrgb { setrgbcolor } def
  postscript()
  image(volcano)
  dev.off()
 
  --
  Peter Dalgaard

 Ah, thanks! I wasn't using sufficiently many :'s!
 Apologies for the fumble.
 Ted.

 
 E-Mail: (Ted Harding) ted.hard...@wlandres.net
 Fax-to-email: +44 (0)870 094 0861
 Date: 22-Jul-11   Time: 10:27:37
 -- XFMail --

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lattice: place ticks only on y-axis

2011-07-22 Thread Bert Gunter
See the alternating parameter in the scales parameter list of
?xyplot. Presumably, something like:

xyplot( ...,
scales = list(...,  alternating = 1),... )

is what you want.

-- Bert

On Fri, Jul 22, 2011 at 6:07 AM, marcel marcelcur...@gmail.com wrote:
 I notice that with this solution there are still y-axis tick marks on both
 sides of the plot. Is there a way to remove the ones on the right side?

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Lattice-place-ticks-only-on-y-axis-tp3684094p3686638.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.




-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Find pattern in matrix

2011-07-22 Thread csrabak
This kind of problem can be addressed with branch and cut or similar 
Operations Research methods.


Get a look at the CRAN task view Optimization and Mathematical 
Programming specially the packages for Integer Programming and Mixed 
Integer Programming.


Depending on the demands you have in your project, you may want to 
consult with a local OR expert.


Em 21/7/2011 19:12, Q escreveu:

Hello all,

I'm trying to find all combinations of 4 numbers that satisfy 4 criteria,
inside of a matrix (62 x 25).  I've found a way to do this using for loops,
but it is extremely slow because it involves checking every possible
combination of numbers (567300) to see if the criteria are satisfied.  Do
you think there is a faster method of doing this?  Or some functions that
might help me out?

The matrix is of species abundances, with each row representing a species
(A,B,C...) and each column representing a site (1,2,3...).  The numbers in
the matrix tell the abundance of the species at that site:




 1  2  3...
A  0  5  6...
B  7  8  2...
C  4  1  3...
...



I'm trying to find combinations of species/sites such that
A1B1,A1A2,B2B1,B2A2

I have used expand.grid to get all combinations of species pairs and site
pairs, and then checked to see if the inequalities are satisfied.  However,
as I said, it takes forever.

I tried to write a function that would take vectors and trick R into
searching for my pattern:




count- function(i,j,k,l){
length(matrix[matrix[i,k]  matrix[i,l]
matrix[i,k]  matrix[j,k]
matrix[j,l]  matrix[j,k]
matrix[j,l]  matrix[i,l]])
}



That didn't work.  So I wonder if anyone has any ideas of another way to
proceed or functions I could look up that would head me in the right
direction.  Something fully fleshed out isn't necessary.

Thanks!

Q

--
View this message in context: 
http://r.789695.n4.nabble.com/Find-pattern-in-matrix-tp3685278p3685278.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] Lattice: distance of Y-axis label from plot

2011-07-22 Thread marcel
Basic question: I looked around quite a bit, still having a little trouble
manipulating the distance between the Y-axis label and the plot. In this
case, I would like to move the Y axis title closer to the plot. 


# Data
tC - textConnection(
Time Type1 Type2 Type3
1.3 .50 .10 .40
4.5 .45 .20 .35
5.2 .40 .30 .30
)

data1 - read.table(header=TRUE, tC)
data2 - data.frame(Time=rep(data1$Time, 3), stack(data1[,2:4]))
close.connection(tC)
rm(tC)

#PLOT 1 lattice bar plot
require(lattice)
plot1-xyplot(values ~ Time, ylab=list(label=Move this title closer to
plot, fontsize=9), scales=list(y=list(relation=free, rot=0, cex=0.7), x =
list(draw = FALSE)), group=ind, data=data2, stack=TRUE, horizontal=FALSE,
panel=panel.barchart, box.width=0.1, axes=FALSE, ylim=c(0.03,0.98),
xlim=c(-0.2, 6.25), main=, xlab=)

#position X1,Y1, X2,Y2
print(plot1, position=c(-0.018,0.221,0.741,0.466))


--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-distance-of-Y-axis-label-from-plot-tp3686855p3686855.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] help

2011-07-22 Thread kimberly sels
Hi,

I need to calculate the average length of a trait per individual. I am not
used to working with R so I could use some help.
The table goes like this:

indtrait
1   3.6
1   3.8
1   3.9
1   3.6
2   5.5
2   5.2
3   4.8
3   4.5

and so on...

If I type mean(trait) it will give me the average of all the individuals and
I need a list of averages per individual.
Can you help me please?

Kim

[[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] squared pie chart - is there such a thing?

2011-07-22 Thread Naomi Robbins
Hello!
It's a shoot in the dark, but I'll try. If one has a total of 100
(e.g., %), and three components of the total, e.g.,
mytotal=data.frame(x=50,y=30,z=20), - one could build a pie chart with
3 sectors representing x, y, and z according to their proportions in
the total.
I am wondering if it's possible to build something very similar, but
not on a circle but in a square - such that the total area of the
square is the sum of the components and the components (x, y, and z)
are represented on a square as shapes with right angles (squares,
rectangles, L-shapes, etc.). I realize there are many possible
positions and shapes - even for 3 components. But I don't really care
where components are located within the square - as long as they are
there.

Is there a package that could do something like that?
Thanks a lot!

-

I included waffle charts in Creating More Effective Graphs.
The reaction was very negative; many readers let me know
that they didn't like them. To create them I just drew a table
in Word with 10 rows and 10 columns. Then I shaded the
backgrounds of cells so for your example we would shade
50 cells one color, 30 another, and 20 a third color.

Naomi

-


Naomi B. Robbins
11 Christine Court
Wayne, NJ 07470
973-694-6009

na...@nbr-graphs.com mailto:na...@nbr-graphs.com

http://www.nbr-graphs.com

Author of Creating More Effective Graphs 
http://www.nbr-graphs.com/bookframe.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] help

2011-07-22 Thread Kenneth Frost
Hi, Kim-
For starters you might have a look at

?by
?tapply
?aggregate

Ken

On 07/22/11, kimberly sels   wrote:
 Hi,
 
 I need to calculate the average length of a trait per individual. I am not
 used to working with R so I could use some help.
 The table goes like this:
 
 indtrait
 1   3.6
 1   3.8
 1   3.9
 1   3.6
 2   5.5
 2   5.2
 3   4.8
 3   4.5
 
 and so on...
 
 If I type mean(trait) it will give me the average of all the individuals and
 I need a list of averages per individual.
 Can you help me please?
 
 Kim
 
   [[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] Installation of XMLPRC package

2011-07-22 Thread Uwe Ligges



On 22.07.2011 15:45, Mitra, Sumona wrote:

Dear all,

Apologies for not being specific earlier.
The R version I am using is 2.12.2.

Everytime I try installing XMLRPC using the following command:-



install.packages(repos = http://www.omegahat.org/XMLRPC/XMLRPC_0.2-4.tar.gz;)


What you specified in repos is not a repository nor a path to the 
package. You probably just want to setRepositories(), choose Omegahat 
and then install.packages(XMLRPC) or directly:


install.packages(XMLRPC, repos=http://www.omegahat.org/R;)

Uwe Ligges




I get the following error

Warning: unable to access index for repository 
http://www.omegahat.org/XMLRPC/XMLRPC_0.2-4.tar.gz/bin/windows/contrib/2.12
Error in length(pkgs) : 'pkgs' is missing

Best
Sumona
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error: bad index in plotmo functions for MARS model (package earth)

2011-07-22 Thread Stephen Milborrow

On 2011-07-28 12:14:32, Cleber N.Borges wrote:


I am tring make a simple surface plot ( 2 by 2 terms of a MARS model
(with earth package) but I get the follow error message:

   library( earth )
  data( gasoline, package='pls' )
  nir - gasoline$NIR
  class( nir )
 [1] AsIs
  oct - gasoline$octane
  mars - earth(  oct ~ nir, nk=300, nfold=10, degree=3, trace=0 )
  plotmo(  mars )
Error: bad index (missing column in x?)


The plotmo function is understandably confused by the fact that the class of
gasoline$NIR is AsIs.  Here is a work around:

g - data.frame(octane=gasoline$octane, as.matrix(data.frame(gasoline$NIR)))
colnames(g) - sub(gasoline.NIR., , colnames(g))
mars - earth(octane ~ ., data=g, degree=2)
plotmo(mars, clip=F)

Earth is not suited to highly collinear data like this.  Note that
summary(lm(octane ~ ., data=g)) gives
ALL 60 residuals are 0: no residual degrees of freedom

I will issue a new version of plotmo with better error handling for this
problem.  I have cc'ed this email to the maintainer of the pls package to
let them know that the gasoline data has a strange class.  Cleber, per the
posting guide you should have sent your email directly to me, the author of
the plotmo package, and not to r-help, so let's continue any further
discussion off the list.  Feel free to contact me if you have further
questions.

Regards,
Steve Milborrow
www.milbo.users.sonic.net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tcltk

2011-07-22 Thread R Heberto Ghezzo, Dr

Hello, I am trying to build some dialog boxes but I am having problems. I'm 
using R-2.13.1 in Windows 7
I want to have 4 numerical entry boxes and 3 radiobuttons in a row ( 4 rows) 
for entry data
and 2 rows for output with a button for 'compute' and another for ;quit'
Can somebody indicate a tutorial or an example with similar type of dialogs?
Thanks

R.Heberto Ghezzo Ph.D.
Montreal - Canada
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Summing daily values by weekday and weekend

2011-07-22 Thread Hu, Yinghua
Jeff,

Thanks for the hint. It is a good solution.

Thanks!

From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us]
Sent: Thursday, July 21, 2011 7:00 PM
To: Hu, Yinghua; r-help@r-project.org
Subject: Re: [R] Summing daily values by weekday and weekend

Clue: make a column representing the desired classification, and then use any 
of the methods you considered to do the summarizing.

One possible approach:
myframe$wend - as.factor(ifelse(weekday( myframe$dates) %in% 
c(Saturday,Sunday), Weekend, Weekday))

---
Jeff Newmiller The . . Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---
Sent from my phone. Please excuse my brevity.
Hu, Yinghua yinghua...@ask.com wrote:

(Sorry for reposting. Please delete previous msgs. Thanks!)

Hi, all

Here I created a data frame like

mydates- seq(as.Date(2010-05-29), length = 43, by = day)
myvalues-runif(43,0,1)
myframe-data.frame(dates=mydates, day=weekdays(dates), value=myvalues)

dates   day  value
1  2010-05-29  Saturday 0.14576143
2  2010-05-30Sunday 0.37669604
3  2010-05-31Monday 0.74813943
4  2010-06-01   Tuesday 0.34677680

…

39 2010-07-06   Tuesday 0.69944349
40 2010-07-07 Wednesday 0.62712550
41 2010-07-08  Thursday 0.76714978
42 2010-07-09Friday 0.72078298
43 2010-07-10  Saturday 0.80048954

How do I add weekday and weekend value in each week? I want a resulting data 
frame like

Datesday v

 alue
2010-05-29  weekend 0.5225
2010-05-31  weekday 2.2352

…

2010-07-05  weekday 3.
2010-07-10  weekend 0.8005


The closest I find is

http://www.mail-archive.com/r-help@r-project.org/msg130580.html

But this one only summing values in each week, it does not sum values by 
weekday and weekend. I have been thinking of using functions such as aggregate, 
ddply, but without a clue. Anybody who can give some suggestions will be highly 
appreciated. Thanks!

Yinghua



R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lattice: place ticks only on y-axis

2011-07-22 Thread Peter Ehlers

On 2011-07-22 07:42, Bert Gunter wrote:

See the alternating parameter in the scales parameter list of
?xyplot. Presumably, something like:

xyplot( ...,
scales = list(...,  alternating = 1),... )


I would just use tck=c(1,0):

 xyplot(...,
   scales = list(tck = c(1,0), x = list(draw = FALSE)), ...)

Peter Ehlers



is what you want.

-- Bert

On Fri, Jul 22, 2011 at 6:07 AM, marcelmarcelcur...@gmail.com  wrote:

I notice that with this solution there are still y-axis tick marks on both
sides of the plot. Is there a way to remove the ones on the right side?

--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-place-ticks-only-on-y-axis-tp3684094p3686638.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.







__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk

2011-07-22 Thread Greg Snow
The tkexamp function in the TeachingDemos package can help with creating tcltk 
dialog boxes.  There are also several other functions in that package that use 
tcltk dialogs that you could use as examples to build your own if tkexamp is 
not enough for you.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of R Heberto Ghezzo, Dr
 Sent: Friday, July 22, 2011 9:50 AM
 To: r-help@r-project.org
 Subject: [R] tcltk
 
 
 Hello, I am trying to build some dialog boxes but I am having problems.
 I'm using R-2.13.1 in Windows 7
 I want to have 4 numerical entry boxes and 3 radiobuttons in a row ( 4
 rows) for entry data
 and 2 rows for output with a button for 'compute' and another for
 ;quit'
 Can somebody indicate a tutorial or an example with similar type of
 dialogs?
 Thanks
 
 R.Heberto Ghezzo Ph.D.
 Montreal - Canada
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Indexing problem with matrix

2011-07-22 Thread Bogaso Christofer
Dear all, assume I have a matrix with just 1 row. Now suppose I want to
fetch 1st few rows from that matrix, however resulting object becomes
vector. Here is 1 such example:

 

 matrix(1:5, 1)

 [,1] [,2] [,3] [,4] [,5]

[1,]12345

 

 matrix(1:5, 1)[,-1]

[1] 2 3 4 5

 

Can somebody point me how to keep resulting object as matrix with same row?
Ofcourse I again make legitimate matrix with something like as.matrix()
function. However I believe there must be some more directly way with
indexing in some better way!

 

Thanks,


[[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] Indexing problem with matrix

2011-07-22 Thread Joshua Wiley
On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer
bogaso.christo...@gmail.com wrote:
 Dear all, assume I have a matrix with just 1 row. Now suppose I want to
 fetch 1st few rows from that matrix, however resulting object becomes

I'm assuming you mean the first few columns.  The place to look is
?[ where you would find the drop argument.

matrix(1:5, 1)[, -1, drop = FALSE]

Cheers,

Josh

 vector. Here is 1 such example:



 matrix(1:5, 1)

     [,1] [,2] [,3] [,4] [,5]

 [1,]    1    2    3    4    5



 matrix(1:5, 1)[,-1]

 [1] 2 3 4 5



 Can somebody point me how to keep resulting object as matrix with same row?
 Ofcourse I again make legitimate matrix with something like as.matrix()
 function. However I believe there must be some more directly way with
 indexing in some better way!



 Thanks,


        [[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Indexing problem with matrix

2011-07-22 Thread Bert Gunter
See the drop argument (and link) in  ?[

-- Bert

On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer
bogaso.christo...@gmail.com wrote:
 Dear all, assume I have a matrix with just 1 row. Now suppose I want to
 fetch 1st few rows from that matrix, however resulting object becomes
 vector. Here is 1 such example:



 matrix(1:5, 1)

     [,1] [,2] [,3] [,4] [,5]

 [1,]    1    2    3    4    5



 matrix(1:5, 1)[,-1]

 [1] 2 3 4 5



 Can somebody point me how to keep resulting object as matrix with same row?
 Ofcourse I again make legitimate matrix with something like as.matrix()
 function. However I believe there must be some more directly way with
 indexing in some better way!



 Thanks,


        [[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.




-- 
Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions.

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics
467-7374

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Mean and Timeseries modelling

2011-07-22 Thread Dennis Murphy
Hi:


On Fri, Jul 22, 2011 at 2:28 AM, Marko markho1...@googlemail.com wrote:
 Hello,
 i have following problem and I hope you can help me a little bit


 My dataframe looks like:

 df
 a       m  d   typ    value
 1950  1  1    5      -4.1
 1950  1  2    9       2.7
 1950  1  3    3      -1.3
 1950  1  4    5      -1.9
 1950  1  5    2       0.2
 1950  1  6    8       0.5
 1951  1  1    4       1.3
 

 It consists by daily observations from 1950- 2009.

 Now, I get with

 for (i in df$V5)
 neu - tapply(df[,5],list(df$V4,df$V1),mean)

 the yearly means of the types (1-18) for every year.

Other ways to do this, which output data frames rather than matrices,
would include

# the formula interface below works with R-2.11.0 +
aggregate(value ~ a + typ, data = df, FUN = mean)

library(plyr)
ddply(df, .(a, typ), summarise, m = mean(value))

Both would give you the 'long form' of the data. One could use the
cast() function in the reshape[2] package or the reshape() function
from the base package to convert it to 'wide' form.

 The new df looks like:

 new
 typ       1950       1951       1952        1953        1954        1955
 1956            ...       2009
 1   0.40588235 -0.1714286 -1.811   5.400  -0.956  2.6583
 2  -3.1778  1.4130435 -0.917  -4.900   0.290  3.54285714
 3   0.0889 -2.000 -2.967   2.200  -1.860 -0.5000
 ...
 18


 Now, i would like to generate a timeseries with the means, according to the
 different types.
 For example: For all days in the year 1950 with the typ 1, I would like to
 write the mean value for Typ 1 in year 1950. In year 1951 I would like to
 write the mean value for typ 1 in 1951 etc. (for all 18 types)

 The output should look like as following:

 erg
 a       m  d   typ    value   mean_typ_year
 1950  1  1    1      -4.1      0,4
 1950  1  2    2       2.7      Mean (Typ2 1950)
 1950  1  3    1      -1.3      0,4
 1950  1  4    5      -1.9      Mean (Typ5 1950)
 1950  1  5    2       0.2      ...
 1950  1  6    8       0.5      ...
 1951  1  1    1       1.3      -0,17
 1951  1  2    2       2.1      Mean (Typ2 1951)
 

 I hope you can help me by solving this problem

It sounds like you want something like ave(). One approach (untested)
might be as follows:

ddply(df, .(a, typ), transform, mean_typ_year = mean(value))

You may want to re-sort the data afterward because ddply() will sort
by a x typ combinations rather than a x m x d. You could also use the
transform() function, perhaps something like

transform(df, mean_typ_year = ave(value, list(a, typ), FUN = mean))

##--
Here's a toy example to illustrate:

df - data.frame(a = factor(rep(LETTERS[1:3], each = 6)),
  b = factor(rep(letters[1:3], each = 2)),
  d = rep(1:6, 3),
  val = rnorm(18, m = 40))
library('plyr')
ddply(df, .(a, b), transform, m = mean(val))
transform(df, m = ave(val, list(a, b), FUN = mean))

HTH,
Dennis


 Best regards,
 Marko

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Mean-and-Timeseries-modelling-tp3686326p3686326.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Indexing problem with matrix

2011-07-22 Thread Bogaso Christofer
Thanks Joshua and Berton for your pointers. Yes it was typo as I wanted to mean 
to select few columns.

-Original Message-
From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] 
Sent: 22 July 2011 22:02
To: Bogaso Christofer
Cc: r-help@r-project.org
Subject: Re: [R] Indexing problem with matrix

On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer
bogaso.christo...@gmail.com wrote:
 Dear all, assume I have a matrix with just 1 row. Now suppose I want to
 fetch 1st few rows from that matrix, however resulting object becomes

I'm assuming you mean the first few columns.  The place to look is
?[ where you would find the drop argument.

matrix(1:5, 1)[, -1, drop = FALSE]

Cheers,

Josh

 vector. Here is 1 such example:



 matrix(1:5, 1)

 [,1] [,2] [,3] [,4] [,5]

 [1,]12345



 matrix(1:5, 1)[,-1]

 [1] 2 3 4 5



 Can somebody point me how to keep resulting object as matrix with same row?
 Ofcourse I again make legitimate matrix with something like as.matrix()
 function. However I believe there must be some more directly way with
 indexing in some better way!



 Thanks,


[[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lattice: distance of Y-axis label from plot

2011-07-22 Thread Peter Ehlers

On 2011-07-22 07:33, marcel wrote:

Basic question: I looked around quite a bit, still having a little trouble
manipulating the distance between the Y-axis label and the plot. In this
case, I would like to move the Y axis title closer to the plot.


# Data
tC- textConnection(
Time Type1 Type2 Type3
1.3 .50 .10 .40
4.5 .45 .20 .35
5.2 .40 .30 .30
)

data1- read.table(header=TRUE, tC)
data2- data.frame(Time=rep(data1$Time, 3), stack(data1[,2:4]))
close.connection(tC)
rm(tC)

#PLOT 1 lattice bar plot
require(lattice)
plot1-xyplot(values ~ Time, ylab=list(label=Move this title closer to
plot, fontsize=9), scales=list(y=list(relation=free, rot=0, cex=0.7), x =
list(draw = FALSE)), group=ind, data=data2, stack=TRUE, horizontal=FALSE,
panel=panel.barchart, box.width=0.1, axes=FALSE, ylim=c(0.03,0.98),
xlim=c(-0.2, 6.25), main=, xlab=)

#position X1,Y1, X2,Y2
print(plot1, position=c(-0.018,0.221,0.741,0.466))


Lattice has many parameters that can be modified. Have a look at
help(trellis.par.get). For your purpose, look at either

 trellis.par.get()$layout.widths

or

 lattice.options()$layout.widths

You'll want to modify the ylab.axis.padding setting. The easiest
way is to add a par.settings argument to your plot definition:

 xyplot(...,
   par.settings = list(
 layout.widths = list(ylab.axis.padding = 0.5)))


Peter Ehlers




--
View this message in context: 
http://r.789695.n4.nabble.com/Lattice-distance-of-Y-axis-label-from-plot-tp3686855p3686855.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Seeking help on permutation

2011-07-22 Thread Megh Dal
Let say, I have a character vector of arbitrary length:

Vector - c(a, b, c)

Using that vector I would like to create a matrix (with number of columns as 2) 
with all pairwise combinations of those elements, like:

Vector - c(a, b, c)
Mat     - rbind(c(a, b), c(a, c), c(b, c)); Mat  # number of rows 
will obviously be n(n-1)/2
     [,1] [,2]
[1,] a  b 
[2,] a  c 
[3,] b  c 


Order must be kept same as c(c, a) or c(c, b) would not be allowed. 
Additionally, actually I have a very big initial character vector therefore I 
need to maintain speed as well.

I would be really grateful if somebody guide me how to do that

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread David Smith
Another option in this specific case is to use the new useRaster=TRUE
option, which makes the image function generate much more compact and
faster-rendering image plots. This code:

setEPS()
postscript (file=volc.eps,width=5,height=4)
image(volcano,useRaster=TRUE)
dev.off()

in R 2.13 generates a 37Kb file which renders very quickly (compared
to a 193Kb file without using the useRaster=TRUE option).

# David Smith

On Thu, Jul 21, 2011 at 12:23 AM, pilchat pilc...@gmail.com wrote:

 Dear R users,

 I have a desktop computer and a laptop, both of them with Ubuntu Lucid. The
 former has R2.10 installed from Ubuntu repositories (this is the most recent
 version in the repositories), while the latter has R2.13 from the CRAN
 repositories.

 I noticed that postscript files generated with R2.10 are better  than
 files generated with the latest release of R, in particular for plots with
 colored areas, such as the output of image or persp. The thing is that my ps
 viewer (e.g. gv or evince) is very slow in opening ps files from R2.13,
 while it smoothly displays ps files from R2.10, regardless of
 encapsulation.

 I think this is related to differences in the way the ps file is generated
 by the two versions of R, but I don't know how to go deeper in the matter.

 Is there anyone experiencing the same issue? Is there any solution?

 Thank you in advance

 Cheers

 Gaetano

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



--
David M Smith da...@revolutionanalytics.com
VP of Marketing, Revolution Analytics  http://blog.revolutionanalytics.com
Tel: +1 (650) 646-9523 (Palo Alto, CA, USA)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 versions and PostScript files

2011-07-22 Thread James Cloos
I suspect that a few s/def/bind def/ on that prologue might improve
things a bit.

The ps R creates freely switches between the sRGB ABC space and
setgray.  That is a good thing; it helps ensure that black will
be just black when sent to a CMYK device.  Without that you can
get CMY black from some devices.  But it does complicate things.

(CMYK devices often use CMY black rather than K black when the
source is RGB black because it is better when printing contone
images, such as photographs.  But it just wastes ink and toner
when printing charts and similar graphics.)

The best improvement would be to have R keep track of the last
colorspace and only run the srgb procedure when switching from
DeviceGray, rather than every time it changes the RGB colour.

The SetColor() function in R/src/library/grDevices/src/devPS.c
looks to be the place to do that.  The Invalidate() function
and the PostScriptDesc struct there also need to track any
such changes.

-JimC
-- 
James Cloos cl...@jhcloos.com OpenPGP: 1024D/ED7DAEA6

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Seeking help on permutation

2011-07-22 Thread Joshua Wiley
Hi,

Look at ?combn

t(combn(Vector, 2))

gives:

 [,1] [,2]
[1,] a  b
[2,] a  c
[3,] b  c

No idea how it is speed-wise.

HTH,

Josh

On Fri, Jul 22, 2011 at 10:09 AM, Megh Dal megh700...@yahoo.com wrote:
 Let say, I have a character vector of arbitrary length:

 Vector - c(a, b, c)

 Using that vector I would like to create a matrix (with number of columns as 
 2) with all pairwise combinations of those elements, like:

 Vector - c(a, b, c)
 Mat     - rbind(c(a, b), c(a, c), c(b, c)); Mat  # number of 
 rows will obviously be n(n-1)/2
      [,1] [,2]
 [1,] a  b
 [2,] a  c
 [3,] b  c


 Order must be kept same as c(c, a) or c(c, b) would not be allowed. 
 Additionally, actually I have a very big initial character vector therefore I 
 need to maintain speed as well.

 I would be really grateful if somebody guide me how to do that

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread pilchat
Thank you David, the useRaster=T does the trick! But, unfortunately, it
doesn't work for persp.

Is there any way to avoid the sRGB colors at the beginning of the R session?
I tried to edit my Rprofile:

 .First - function() {
a-system(ls /dati/software/R_lib/*.r,intern=T)
for (i in a) source(i) # my personal functions
library(MASS)  # attach a package
#library(RColorBrewer)
.ps.prolog - grDevices:::.ps.prolog
.ps.prolog[39] - /setrgb { setrgbcolor } def

}

.Last - function() {
graphics.off()# a small safety measure.
cat(paste(date(),\nAdios\n))# Is it time for lunch?
}

but it doesn't work either. If I type .ps.prolog at the prompt, I get

 .ps.prolog
Error: object '.ps.prolog' not found

It seems that the .ps.prolog array is not visible outside the .First()
function.

Moreover, if I comment out #library(RColorBrewer), the library is not
available in my R environment: I have to load it manually. The weirdest
thing is that, on the contrary, it works for the MASS package!

Is there something wrong with my Rprofile?

G

On Fri, Jul 22, 2011 at 7:12 PM, James Cloos cloos+r-h...@jhcloos.comwrote:

 I suspect that a few s/def/bind def/ on that prologue might improve
 things a bit.

 The ps R creates freely switches between the sRGB ABC space and
 setgray.  That is a good thing; it helps ensure that black will
 be just black when sent to a CMYK device.  Without that you can
 get CMY black from some devices.  But it does complicate things.

 (CMYK devices often use CMY black rather than K black when the
 source is RGB black because it is better when printing contone
 images, such as photographs.  But it just wastes ink and toner
 when printing charts and similar graphics.)

 The best improvement would be to have R keep track of the last
 colorspace and only run the srgb procedure when switching from
 DeviceGray, rather than every time it changes the RGB colour.

 The SetColor() function in R/src/library/grDevices/src/devPS.c
 looks to be the place to do that.  The Invalidate() function
 and the PostScriptDesc struct there also need to track any
 such changes.

 -JimC
 --
 James Cloos cl...@jhcloos.com OpenPGP: 1024D/ED7DAEA6

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R on Multicore for Linux

2011-07-22 Thread Madana_Babu
Hi,

Can you please explain me that how can i perform this on a multicore
processor? since i have a machine with 16-cores. I can do this much faster
if i use all cores.

Thanks in advance...

Regards,
Madana

--
View this message in context: 
http://r.789695.n4.nabble.com/R-on-Multicore-for-Linux-tp3682318p3687483.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R versions and PostScript files

2011-07-22 Thread James Cloos
I suspect that a few s/def/bind def/ on that prologue might improve
things a bit.

The ps R creates freely switches between the sRGB ABC space and
setgray.  That is a good thing; it helps ensure that black will
be just black when sent to a CMYK device.  Without that you can
get CMY black from some devices.  But it does complicate things.

(CMYK devices often use CMY black rather than K black when the
source is RGB black because it is better when printing contone
images, such as photographs.  But it just wastes ink and toner
when printing charts and similar graphics.)

The best improvement would be to have R keep track of the last
colorspace and only run the srgb procedure when switching from
DeviceGray, rather than every time it changes the RGB colour.

The SetColor() function in R/src/library/grDevices/src/devPS.c
looks to be the place to do that.  The Invalidate() function
and the PostScriptDesc struct there also need to track any
such changes.

-JimC
-- 
James Cloos cl...@jhcloos.com OpenPGP: 1024D/ED7DAEA6

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extracting components from a 'boot' class output in R

2011-07-22 Thread Sarath Gamini Banneheka
Dear R user,

I used the following to do a bootstrap.


bootObj-boot(data=DAT, statistic=Lp.est,
R=1000,x0=3)

I have the following output from the above bootstrap. How
can I extract  components of the output.
For example, how can I extract the std.error?


 bootObj
 
ORDINARY NONPARAMETRIC BOOTSTRAP
 
Call:
boot(data = DAT, statistic = Lp.est, R = 1000, x0 = 3)
 
Bootstrap Statistics :
  original    bias  std. error
t1*  794.9745 -0.341    4.042099

Any help is greatly appreciated.

Thank you 


Sarath Banneheka

[[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] pegas package: Problem using nuc.div and tajima d - error with dist.dna() - character variables must be duplicated in .C/.Fortran

2011-07-22 Thread Victor Garcia
Hi,

For the last few days I have tried utilise your package pegas in order 
to obtain some values for indices like the nuclear diversity and tajimas 
d value.

I have modified my dataset (a text file containing dna sequences) in 
order to be able to read it in with the tools provided by pegas. Here, I 
have oriented myself on the description provided by the help-page in 
read.loci(). A piece from the dataset is displayed further below. Here 
my code:

/Code/
library(ape)
library(adegenet)
library(pegas)
/
load with no problem.
/
/the command: /

  data.loci - read.loci(file 
=/Users/victor/Documents/SIV_Compartment/data/pegas_data_seq.txt,
 header = TRUE,
 col.loci = seq(1,200),
 col.pop = TRUE)

/seems to work./
/in fact:/

  data.loci
Allelic data frame: 68563 individuals
 200 loci
 5 additional variables

/but as soon as I try to calculate a certain index with the 
corresponding function out of pegas package, like nuc.div, tajima.test, 
or R2, I get the following error:
/
  nuc.div(data.loci[1:100,])
Error in dist.dna(x, raw, pairwise.deletion = pairwise.deletion) :
   character variables must be duplicated in .C/.Fortran

/Also:
/ nuc.div(data.loci[1:100, 1:200])
Error in dist.dna(x, raw, pairwise.deletion = pairwise.deletion) :
   character variables must be duplicated in .C/.Fortran
*
*/Nevertheless, the examples with the adegenet dataset woodmouse all 
work fine. I.e., using these functions on woodmouse does not lead to the 
errors. /
*

/What might be the problem causing the error message?/*/

Thank you very much.

if it is of any help: I use Mac OS X, Version 10.6.8. ; R version 2.11.1 
(2010-05-31)/



*This is an example of the header and the first two lines of the data 
file I am trying to use*:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
17 18 19 20 21 22 23 24 25 26 27 28 29 30 
31 32 33 34 35 36 37 38 39 40 41 42 43 44 
45 46 47 48 49 50 51 52 53 54 55 56 57 58 
59 60 61 62 63 64 65 66 67 68 69 70 71 72 
73 74 75 76 77 78 79 80 81 82 83 84 85 86 
87 88 89 90 91 92 93 94 95 96 97 98 99 100 
101 102 103 104 105 106 107 108 109 110 111 112 
113 114 115 116 117 118 119 120 121 122 123 124 
125 126 127 128 129 130 131 132 133 134 135 136 
137 138 139 140 141 142 143 144 145 146 147 148 
149 150 151 152 153 154 155 156 157 158 159 160 
161 162 163 164 165 166 167 168 169 170 171 172 
173 174 175 176 177 178 179 180 181 182 183 184 
185 186 187 188 189 190 191 192 193 194 195 196 
197 198 199 200 population animal tissue day frequency

1 C A C T T G G T A A T C A T A T C 
T A T A A T A G A C A T G G A G A C 
A C C C T T G A G G G A G C A G G A 
G A A C T C A T T A G A A T C C T C 
C A A C G A G C G C T C T T C A T G 
C A T T T C A G A G G C G G A T G C 
A T C C A C T C C A G A A T C G G C 
C A A C C T G G G G G A G G A A A T 
C C T C T C T C A G C T A T A C C G 
C C C T C T A G A A G C A T G C T A 
T A A C A C A T G C T A T T G T A A 
A A A 1 RDo8 LN 7 1

2 C A C T T G G T A A T C A T A T C 
T A T A A T A G A C A T G G A G A C 
A C C C T T G A G G G A G C A G G A 
G A A C T C A T T A G A A T C C T C 
C A A C G A G C G C T C T T C A T G 
C A T T T C A G A G G C G G A T G C 
A T C C A C T C C A G A A T C G G C 
C A A C C T G G G G G A G G A A A T 
C C T C T C T C A G C T A T A C C G 
C C C T C T A G A A G C A T G C T A 
T A A C A C A T G C T A T T G T A A 
A A A 2 RWi8 RB 7 1




[[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] matched pairs

2011-07-22 Thread Ellen S.
Hi all,

I am hoping to keep certain rows of my data set. These are rows whose value
in column X is equal to the value in column X for another row. For example:

1  1
2  1
3  2
4  3
5  4
6  4

From this I would want the following:

1  1
2  1
5  4
6  4

I am struggling with the for loop. Here is what I have currently:

## where to store values
  pairs.list - data.frame(NA, nrow(data), ncol(data))

  ## iterating through data
  for (i in 1:nn){

# check value with next value, store both
if(data$X[i]==data$X[i+1]){
  pairs.list[i] - data[i]
  pairs.list[1+1] - data[i+1]
}

# if values are different, discard the first, keep the second
else{
  data - data[which(!data[i]),]
}
  }
}


Any suggestions welcome. Thank you!

E

--
View this message in context: 
http://r.789695.n4.nabble.com/matched-pairs-tp3687257p3687257.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] Using matrix as a response variable

2011-07-22 Thread sovboss
Dear R users!

I have a problem using tune() from e1071 package. I need to to tune a neural
network where response variable is a vector. I've used this function as it
shown below and I got the error:

tune.netWhole - tune(nnet, x, y, ranges = list(...), tunecontrol = ...)
# weights:  28
initial  value 10824.223491 
iter  10 value 8687.908464
final  value 8685.151182 
converged
Error in crossprod(pred - true.y) : 
  dims [product 58] do not match the length of object [1218]

If someone has already handled with this problem, I'll be glad to read your
advices. Looking forward your answers.

--
View this message in context: 
http://r.789695.n4.nabble.com/Using-matrix-as-a-response-variable-tp3687296p3687296.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matched pairs

2011-07-22 Thread William Dunlap
Does the following do what you want?  The singletons()
function identifies the entries that appear only once
in a vector and we use its output to eliminate the singleton
entries.

   singletons - function(x) !(duplicated(x) | duplicated(x,fromLast=TRUE))
   d - data.frame(x=c(101, 102, 101, 105, 102, 101), y=1001:1006)
   d
  xy
  1 101 1001
  2 102 1002
  3 101 1003
  4 105 1004
  5 102 1005
  6 101 1006
   d[!singletons(d$x), , drop=FALSE]
  xy
  1 101 1001
  2 102 1002
  3 101 1003
  5 102 1005
  6 101 1006

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Ellen S.
 Sent: Friday, July 22, 2011 10:02 AM
 To: r-help@r-project.org
 Subject: [R] matched pairs
 
 Hi all,
 
 I am hoping to keep certain rows of my data set. These are rows whose value
 in column X is equal to the value in column X for another row. For example:
 
 1  1
 2  1
 3  2
 4  3
 5  4
 6  4
 
 From this I would want the following:
 
 1  1
 2  1
 5  4
 6  4
 
 I am struggling with the for loop. Here is what I have currently:
 
 ## where to store values
   pairs.list - data.frame(NA, nrow(data), ncol(data))
 
   ## iterating through data
   for (i in 1:nn){
 
 # check value with next value, store both
 if(data$X[i]==data$X[i+1]){
   pairs.list[i] - data[i]
   pairs.list[1+1] - data[i+1]
 }
 
 # if values are different, discard the first, keep the second
 else{
   data - data[which(!data[i]),]
 }
   }
 }
 
 
 Any suggestions welcome. Thank you!
 
 E
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/matched-pairs-tp3687257p3687257.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] User input(unknown name and number of files)

2011-07-22 Thread Bansal, Vikas
Dear all,

I need your help as I was not able to find out the solution.I sent this message 
before but did not get any help.Please help me.

The thing is-
I am having a code which is reading file with this code-

df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
 but as am making a tool so that user can use it and can do analysis on his 
file.But the name of the file will not be Case2.pileup and I want to use this 
code so that user can input as many files as he want.My code is like this-

df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
df$V9 -  apply(df, 1, function(x) gsub(\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10, 
,x[9]))
df$V10 - sapply(df$V10, function(a)  
 paste(as.integer(charToRaw(a)), collapse = ' '))
capture.output(print.data.frame(df,row.names=F), file = end.txt, append = 
FALSE)

I know it should do it with for loop and an array.I want that if user input 12 
files,the dataframe name df should be different for all the 12 files.

Can you please tell me how can I do this.


Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] User input(unknown name and number of files)

2011-07-22 Thread Joshua Wiley
On Fri, Jul 22, 2011 at 12:15 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear all,

 I need your help as I was not able to find out the solution.I sent this 
 message before but did not get any help.Please help me.

You only sent the message yesterday!!! (then again a few hours ago,
and *again* just now)

rather than hard code what you are doing, create a function that takes
a data file and outputs the type of data you want.  Then just:

lapply(c(file1, file2, etc.), yourfunction)

will create a list of all the output.

Josh


 The thing is-
 I am having a code which is reading file with this code-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
  but as am making a tool so that user can use it and can do analysis on his 
 file.But the name of the file will not be Case2.pileup and I want to use this 
 code so that user can input as many files as he want.My code is like this-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
 df$V9 -  apply(df, 1, function(x) 
 gsub(\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10, ,x[9]))
 df$V10 - sapply(df$V10, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))
 capture.output(print.data.frame(df,row.names=F), file = end.txt, append = 
 FALSE)

 I know it should do it with for loop and an array.I want that if user input 
 12 files,the dataframe name df should be different for all the 12 files.

 Can you please tell me how can I do this.


 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] User input(unknown name and number of files)

2011-07-22 Thread Bansal, Vikas
Thanks for your reply.That is why I wrote in the message that I have sent this 
message before but did not get any help (first line of my message).
can you please tell me that if user will input 50 files or 100 how my code will 
work.Do I need to write file1,file2 till file 100 in this code?

lapply(c(file1, file2, etc.), yourfunction)

From: Joshua Wiley [jwiley.ps...@gmail.com]
Sent: Friday, July 22, 2011 8:26 PM
To: Bansal, Vikas
Cc: r-help@r-project.org
Subject: Re: [R] User input(unknown name and number of files)

On Fri, Jul 22, 2011 at 12:15 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear all,

 I need your help as I was not able to find out the solution.I sent this 
 message before but did not get any help.Please help me.

You only sent the message yesterday!!! (then again a few hours ago,
and *again* just now)

rather than hard code what you are doing, create a function that takes
a data file and outputs the type of data you want.  Then just:

lapply(c(file1, file2, etc.), yourfunction)

will create a list of all the output.

Josh


 The thing is-
 I am having a code which is reading file with this code-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
  but as am making a tool so that user can use it and can do analysis on his 
 file.But the name of the file will not be Case2.pileup and I want to use this 
 code so that user can input as many files as he want.My code is like this-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
 df$V9 -  apply(df, 1, function(x) 
 gsub(\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10, ,x[9]))
 df$V10 - sapply(df$V10, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))
 capture.output(print.data.frame(df,row.names=F), file = end.txt, append = 
 FALSE)

 I know it should do it with for loop and an array.I want that if user input 
 12 files,the dataframe name df should be different for all the 12 files.

 Can you please tell me how can I do this.


 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting components from a 'boot' class output in R

2011-07-22 Thread Weidong Gu
Sarath,

Maybe someone can show a direct access to the statistic. One way to
get around is to access 't' component of the boot object which
contains individual estimates. so you can extract standard error by

sqrt(var(bootObj$t))

Weidong Gu

On Fri, Jul 22, 2011 at 11:36 AM, Sarath Gamini Banneheka
banneh...@yahoo.com wrote:
 Dear R user,

 I used the following to do a bootstrap.


bootObj-boot(data=DAT, statistic=Lp.est,
 R=1000,x0=3)

 I have the following output from the above bootstrap. How
 can I extract  components of the output.
 For example, how can I extract the std.error?


 bootObj

 ORDINARY NONPARAMETRIC BOOTSTRAP

 Call:
 boot(data = DAT, statistic = Lp.est, R = 1000, x0 = 3)

 Bootstrap Statistics :
   original    bias  std. error
 t1*  794.9745 -0.341    4.042099

 Any help is greatly appreciated.

 Thank you


 Sarath Banneheka

        [[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] applying a loop to multiple dataframes

2011-07-22 Thread Sean Bignami
Hello again R-folks,
I'm trying to apply a loop to multiple data frames and then organize the data 
in a manageable form. I have the code for my loop figured out (thanks to help 
from this list)...it runs up to 2000 iterations of a while loop until it 
finds a 40-row d2p column sum 5

n-nrow(dsub.f1)
test-0
for(k in 1:2001){
if(k2000){
break}  #stops after 2000 iterations
else{
while(test5){  #continues unti sum5, or 2000 iter.
i-sample(1:n-40,1)
x-dsub.f1[seq(from=i, to=i+40),]
test-sum(x[,d2p],na.rm=TRUE)}
}
}
 
My data frames are all named dsub.f1 through dsub.f360 (and are subsets of a 
laster data frame d) which I created using this code:

for(i in 1:360){
assign(paste(dsub.f,d[d$fish==i,1],sep=),subset(d[d$fish==i,]))}


I created a list of all my data frames using:

df.filter-function(x) inherits(get(x),'data.frame')
 #pulls all dataframes 
dfs-Filter(df.filter,ls());str(dfs) 
dsubs-dfs[3:360];head(dsubs) 
#removes d and data.csv dataframes that I don't want

But I can't figure out how to write a for loop that will apply the (top) code 
above to each data frame.

Also, once I'm able to apply the loop to each data frame, I would like to 
organize the data in a manageable form so I can reference it in other analyses.

I hope I explained what I'm trying to do well enough. Thanks!!!

sean







[[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] User input(unknown name and number of files)

2011-07-22 Thread Joshua Wiley
On Fri, Jul 22, 2011 at 12:30 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Thanks for your reply.That is why I wrote in the message that I have sent 
 this message before but did not get any help (first line of my message).
 can you please tell me that if user will input 50 files or 100 how my code 
 will work.Do I need to write file1,file2 till file 100 in this code?

No, the user will have to write out all 100 of their file names.


## Inner function
reader - function(x) {
  paste(letters[x], collapse = )
}

## Outer function
outerfoo - function(name) {
  int - lapply(name, function(n) {
grep(strsplit(tolower(n), )[[1]][1], letters)
  })

  stuff - lapply(int, function(i) {
lapply(list(c(35, 47), c(38, 37, 31, 36, 42), c(31, 41),
c(42, 30, 23, 42), c(32, 43, 41, 42), c(24, 27, 25, 23, 43, 41, 27),
c(47, 37, 43), c(42, 37, 34, 26), c(35, 27), c(47, 37, 43),
c(45, 27, 40, 27), c(41, 38, 23, 35, 35, 31, 36, 29), c(35, 47),
c(35, 23, 31, 34, 24, 37, 46), c(26, 37, 27, 41), c(36, 37, 42),
c(35, 23, 33, 27), c(31, 42), c(37, 33, 23, 47)), `-`, i)})

  output - lapply(stuff, function(x) {
paste(unlist(lapply(x, reader)), collapse =  )
  })
  return(output)
}

## Example (here is what the user will write)
## My example function is designed to work with names
outerfoo(c(Joshua, Wiley))


 lapply(c(file1, file2, etc.), yourfunction)
 
 From: Joshua Wiley [jwiley.ps...@gmail.com]
 Sent: Friday, July 22, 2011 8:26 PM
 To: Bansal, Vikas
 Cc: r-help@r-project.org
 Subject: Re: [R] User input(unknown name and number of files)

 On Fri, Jul 22, 2011 at 12:15 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk 
 wrote:
 Dear all,

 I need your help as I was not able to find out the solution.I sent this 
 message before but did not get any help.Please help me.

 You only sent the message yesterday!!! (then again a few hours ago,
 and *again* just now)

 rather than hard code what you are doing, create a function that takes
 a data file and outputs the type of data you want.  Then just:

 lapply(c(file1, file2, etc.), yourfunction)

 will create a list of all the output.

 Josh


 The thing is-
 I am having a code which is reading file with this code-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
  but as am making a tool so that user can use it and can do analysis on his 
 file.But the name of the file will not be Case2.pileup and I want to use 
 this code so that user can input as many files as he want.My code is like 
 this-

 df=read.table(Case2.pileup,fill=T,sep=\t,colClasses=character)
 df$V9 -  apply(df, 1, function(x) 
 gsub(\\:|\\$|\\^|!|\\-|1|2|3|4|5|6|7|8|10, ,x[9]))
 df$V10 - sapply(df$V10, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))
 capture.output(print.data.frame(df,row.names=F), file = end.txt, append = 
 FALSE)

 I know it should do it with for loop and an array.I want that if user input 
 12 files,the dataframe name df should be different for all the 12 files.

 Can you please tell me how can I do this.


 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 https://joshuawiley.com/




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R on Multicore for Linux

2011-07-22 Thread Changbin Du
library(multicore)
options(cores=10)
getOption(cores)




On Fri, Jul 22, 2011 at 11:35 AM, Madana_Babu madana_b...@infosys.comwrote:

 Hi,

 Can you please explain me that how can i perform this on a multicore
 processor? since i have a machine with 16-cores. I can do this much faster
 if i use all cores.

 Thanks in advance...

 Regards,
 Madana

 --
 View this message in context:
 http://r.789695.n4.nabble.com/R-on-Multicore-for-Linux-tp3682318p3687483.html
 Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Sincerely,
Changbin
--

Changbin Du
DOE Joint Genome Institute
Bldg 400 Rm 457
2800 Mitchell Dr
Walnut Creek, CA 94598
Phone: 925-927-2856

[[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] Using package amelia

2011-07-22 Thread Eduardo M. A. M.Mendes
Hello

 

I do not think I have fully grasped how to use Amelia to deal with missing
data.

 

For instance, suppose I have a data.frame variable with 4 columns (year,
mon, ssn, dev) = (year, month, measurements, standard deviation of the
measurement).  Of course, there are some  random missing values on columns 3
and 4.  The measurements are an almost periodic time-series contaminated by
noise.

 

I did some tests such as:

 

a.out - amelia(x, m = 5, ts = YEAR, p2s = 0, idvars=c(DEV));

 a.out - amelia(x, m = 5, ts = YEAR, p2s = 0, idvars=c(MON,DEV));

Error in matrix(1, AMn, 1) : non-numeric matrix extent

 

a.out - amelia(x, m = 5, ts = YEAR, p2s = 0);

 

a.out - amelia(x, m = 5, p2s = 0, idvars=c(MON,DEV));

 

If I got it right, idvars removes the columns from the imputation process.
Is that right?  

 

There is an option called cs (cross-section) but I have no idea what it
does. 

 

How can I use the information on column 4 to limit the values of the
estimates of the missing values?  Some of the results are extremely high.

 

Any pointers that help me to understand what is going on will be most
appreciated.

 

Many thanks

 

Ed

 


[[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] help on panel.superpose

2011-07-22 Thread Daniel Malter
For the first part, use the col and pch arguments:

id-rep(c(0,2),each=50)
e-rnorm(100)
x-rnorm(100)
y-id+x+e
xyplot(y~x,groups=id,col=c(3,4),pch=c(12,13))

For the second part, I do not know what exactly mean by superimpose the mean
level? Should the mean for each group be displayed as a horizontal line?

Best,
Daniel



Bharath Kumar wrote:
 
 Dear users,
 
 I am new to R and have couple of problems with xyplot.
 
 A) I am trying to use the xyplot to plot mean concentration vs time across
 5 dose groups.
 
 When i use the following script
 xyplot(mean~time,groups=dose,type=b,panel=panel.superpose). R generates
 the plot, but i have no control over pch or color for the line. It
 displays whatever color and pch it wants to generate. How do i fix this. 
 
 B) I am trying to use the same function to plot individual data across
 dose groups
 
 xyplot(conc~time|dose,groups=subject,type=l) works. But it would be
 great if anyone can shed light on how to superimpose the mean profile for
 each dose group within that panel
 
 Any help will be appreciated
 Thanks
 Kumar
 

--
View this message in context: 
http://r.789695.n4.nabble.com/help-on-panel-superpose-tp3687965p3688225.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Trouble getting plot to appear

2011-07-22 Thread Daniel Malter
Typically not, unless the device has not closed properly. Does the second
plot show up in the pdf?

Daniel


cherron wrote:
 
 Hello,
 
I am currently working on a script and I output plots to pdf using
  
 pdf(...)
 plot(...)
 dev.off()
 
then later I was trying to plot something and when I run just
 
 plot(...)
 
nothing appears. Is there something about using plot(..) after dev.off()
that does not allow the window to pop up? In other words I would like to be
able to see the plot display when just using the plot function. I am using R
in UNIX if this is at all relevant.
 
 Many thanks,
 
 Casey
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Trouble-getting-plot-to-appear-tp3688078p3688227.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] What are the good tools for professional R developers?

2011-07-22 Thread Mark Alen
I am trying to make this transition from a casual R programmer to a 
professional programmer (trying to make money with R)

What tools should a professional R developer have?

what are the good utilities that can help R developers to code and debug more 
efficiently? what type of tools are missing? For example, what are the good 
IDEs, unit testing and code coverage tools, debugging packages and maybe UML 
modeling tools for R?

What tools do you have in your R toolbox?

I am also interested in knowing the tools that exist for other languages but 
are missing for R development.

Thanks a lot
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Calculating the mean of values in tables using formulae

2011-07-22 Thread Mark Alen
I know commands like xtabs and table allow a user to do cross-tabulation
For example the following command generates a pivot table that shows the number 
of cars that have the same number of gears and cylinders.

xtabs(~cyl+gear,data =mtcars)
   gear
cyl  3 4 5
  4 1 8 2
  6 2 4 1
  812 0 2


We can extend the formula so it could show the sum of the horse power for the 
cars in each bin

xtabs(hp~cyl+gear,data =mtcars)
   gear
cyl    3   4   5
  4  97 608 204
  6 215 466 175
  82330   0 599


I am now wondering, is it possible to calculate the mean of horse powers for 
cars in each bin? for example something like this xtabs(mean(hp)~cyl+gear, data 
= mtcars)

Thank you 
Mark


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Calculating the mean of values in tables using formulae

2011-07-22 Thread Daniel Malter
Check the *apply() series of functions. tapply() will do what you want.

attach(mtcars)
tapply(hp,list(cyl,gear),mean)

HTH,
Daniel





Mark Alen wrote:
 
 I know commands like xtabs and table allow a user to do cross-tabulation
 For example the following command generates a pivot table that shows the
 number of cars that have the same number of gears and cylinders.
 
xtabs(~cyl+gear,data =mtcars)
    gear
 cyl  3 4 5
   4 1 8 2
   6 2 4 1
   812 0 2

 
 We can extend the formula so it could show the sum of the horse power for
 the cars in each bin
 
xtabs(hp~cyl+gear,data =mtcars)
    gear
 cyl    3   4   5
   4  97 608 204
   6 215 466 175
   82330   0 599

 
 I am now wondering, is it possible to calculate the mean of horse powers
 for cars in each bin? for example something like
 this xtabs(mean(hp)~cyl+gear, data = mtcars)
 
 Thank you 
 Mark
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Calculating-the-mean-of-values-in-tables-using-formulae-tp3688416p3688437.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] standard error of exp(coef) from coxph

2011-07-22 Thread Ehsan Karim

Dear List,
Must be a silly question, but I was wondering whether there is a direct way of 
calculating standard error of a HR or exp(coef) from coxph objects
x - coxph(Surv(time, status) ~ age + inst, lung) xcoef exp(coef) 
se(coef) zpage   0.0190  1.02  0.00925  2.06 0.04inst -0.0104  
0.99  0.01028 -1.01 0.31

cheers,
Ehsan 
[[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.