[R] Ignoring loadNamespace errors when loading a file

2011-08-22 Thread Allan Engelhardt
On a Unix machine I ran caret::rfe using the multicore package, and I 
saved the resulting object using save(lm2, file = lm2.RData).  
[Reproducible example below.]


When I try to load(lm2.RData) on my Windows laptop, I get

Error in loadNamespace(name) : there is no package called 'multicore'

I completely understand the error and I would like to ignore it and 
still load the saved object data.


I imagine that I can make myself an empty multicore package for Windows 
and load the data file successfully, but is there another way?


(I am not going to use any multicore functionality; I just want to 
inspect some of the data stored in the object and the reference in 
question is just an unfortunately stored link from the original call.)


(I did search for this question in the archives, but could only find it 
discussed in connection with starting R with a .RData file where the 
consensus seems to be to start R in vanilla mode and install the missing 
package.  This situation is different and installing a Unix-only package 
on Windows is obviously a non-starter, except as I proposed above.)


Obligatory reproducible example: On the Unix machine do

library(multicore)
a - list(data = 1:10, fun = mclapply)
save(a, file = a.RData)

and then try to load the a.RData file on Windows.  The question is if 
I can recover the data (1:10) on that platform.


Allan


 sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] compiler  stats graphics  grDevices utils datasets  methods
[8] base

other attached packages:
[1] caret_4.98  cluster_1.14.0  reshape_0.8.4   plyr_1.6
[5] lattice_0.19-31 boot_1.3-2  ctv_0.7-3

loaded via a namespace (and not attached):
[1] grid_2.13.1  tools_2.13.1

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


Re: [R] Changing data scales

2011-08-22 Thread Jim Lemon

On 08/22/2011 10:04 AM, Jim Silverton wrote:

I have data that ranges from 0.3 to 2 and I want to change the scale to be
from 0 to 1.
Can this be done in R?


Hi Jim,

library(prettyR)
rescale(x,c(0,1))

will linearly transform x into the specified range.

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] I have a problem with R!!

2011-08-22 Thread Petr PIKAL
Hi

Your code is rather baroque and it is difficult to see what is exactly 
going on without having appropriate data. I does not consider your process 
of reading data from Excel problematic.

Maybe the difference is in that

d- rnorm(whatever) 

produces vector while

d- read.delim(clipboard, header = T, dec = ,)

produces data frame

you can subset vector by

d[indices]

but doing the same with data.frame you try to subset columns which, in 
your case should not be what you want.

at least showing us 

str(data.readed.from.Excel)

can help us to help you.

Regards
Petr

 
 On 08/21/2011 05:29 AM, nferr...@fceia.unr.edu.ar wrote:
  Dear all
 
  i´m working with a program i´ve made in R (using functions that others
  created)
 
  to run my program i need a sample. if i generate the sample using  for
  example, rnorm(n, mu, sigma) i have no problem
 
  but if i obtain a sample from a column in excel and i copy it, the 
program
  says that there is a mistake: it says Error en `[.data.frame`(data,
  indices) : undefined columns selected
 
  my program is:
 
  d- read.delim(clipboard, header = T, dec = ,)
  #Para determinar los valores de las componentes del vector de 
capacidad es
  necesario definir primero las especificaciones y el valor objetivo, T, 
así
  como el máximo valor admitido para la proporción de producción no
  conforme, a cada lado de los límites de especificaciones#
  # Ingrese ahora el valor del límite inferior de especificaciones#
  LIE- 13
  # Ingrese ahora el valor del límite superior de especificaciones#
  LSE- 17
  # Ingrese ahora el valor objetivo#
  T- 14.5
  # Ingrese ahora el máximo valor admitido para la proporción de 
producción
  no conforme a cada lado de los límites de especificaciones#
  MA- 0.00135
  D- min ((LSE-T), (T-LIE))
  compo1- function(data, indices)
  {
  d- data[indices]
  n = length (d)
  desvio- sd(d)
  y- rep(1:n)
  y[x= mean(d)]- 1
  y[xmean(d)]- 0
  RI1- D/(3*desvio*2*mean(y))
  RI2- D/(3*desvio*2*(1-mean(y)))
  return (min (RI1, RI2))
  }
  compo2- function(data, indices)
  {
  d- data[indices]
  c2- (abs(mean(d) - T))/D
  return (1-c2)
  }
  compo3-function(data, indices)
  {
  d- data[indices]
  n- length (d)
  y- rep(1:n)
  y[d  LIE]- 1
  y[d= LIE]- 0
  INFE- mean (y);
  y- rep(1:n)
  y[d  LSE]- 1
  y[d= LSE]- 0
  SUPE- mean (y);
  PPI- (1 - INFE)/(1-MA)
  PPS- (1 - SUPE)/(1-MA)
  return (min (PPI, PPS))
  }
  save(file = compo1.RData)
  save(file = compo2.RData)
  save(file = compo3.RData)
  compos- function(data, indices)
  {
  d- data[indices]
  capacidad- c(compo1(d), compo2(d), compo3(d))
  return(capacidad)
  }
  save(file = compos.RData)
  require (boot)
  vectorcapacidad- boot (d, compos, R = 3000)
 
  ETC. ETC.
 
 
 
  WHEN I START MY PROGRAM WRITING:
  d- rnorm (n, mu, sigma)
 
  I HAVE NO PROBLEM. BUT WHEN I READ A VECTOR FROM EXCEL, R TELLS ME
  Error en `[.data.frame`(data, indices) : undefined columns selected
 
 
  CAN YOU HELP ME THANK YOU VERY MUCH!
 
  NOEMI FERRERI, ROSARIO, ARGENTINA
  SCHOOL OF INDUSTRIAL ENGINEERING
 
 Hi Noemi,
 Without some sample data, I can only guess, but I would first try saving 

 the Excel spreadsheet in CSV format and then reading the data in with 
 read.csv. This might solve your problem.
 
 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.

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

2011-08-22 Thread Uwe Ligges



On 22.08.2011 03:34, Brad Patrick Schneid wrote:

these guys wont help you with your homework.  But have you ever heard of
Google?... if so, R has plenty of online manuals and cheat sheets.



1. This went to R-help (and hence not necessarily to the original poster).
2. You forgot to cite the original question.

Uwe Ligges



--
View this message in context: 
http://r.789695.n4.nabble.com/Quadratic-equation-tp3758790p3759239.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] Wiki/revision control to management of CRAN package repository

2011-08-22 Thread Philippe Grosjean

Hello,

For the R Wiki, not very realistic to think about fusing it with the 
other tools, due to the nature of a wiki on one hand, and the necessity 
to share the CRAN site across different repositories on the other hand.


Also, I think that packages development is in the hand of their 
respective developers/maintainers. Except for making sure they pass R 
CMD check and respect a limited amount of requirements (license, size of 
enclosed documents, ...), it is probably not a good idea to FORCE people 
to collaborate, or share the same point of view for a given R extension. 
There are sometimes very different implementations of the same concept, 
e.g., object oriented approaches in S3/S4 (official), but see also R.oo 
or proto for alternative ideas. Another example: RUnit vs svUnit vs 
testthat. Would not be a good idea to force all these people to share 
the same implementation and fuse everything in a single package,... 
unless they decide by themselves, and completely freely, to do so.


This is an Open Source community, and it evolves a little bit like 
natural living ecosystems... with different ideas that could emerge and 
are ultimately selected by a kind of natural selection mechanism, 
related to (1) adoption of one or the other tool by the R community, and 
(2) the energy put in the project by their developers to maintain or 
make it better suitable to the community. That mechanism can only work 
if you are not too rigid in constraints for R packages.


The drawback is a little bit of confusion for the end-user that does not 
always easily know which of the different implementations he should adopt.


Best,

Philippe Grosjean


On 22/08/11 06:02, Etienne Low-Décarie wrote:

I propose the following humbly, with little know how as to how to implement, 
and realize it may have been proposed many times.  It is just something I had 
on my mind.

Would it be possible/desirable to have the whole CRAN package repository 
accessible through a public wiki, forge or version control interface (ideally a 
fusion of the wiki and forge approach)?


It appears it would be a first for a software repository.

CRAN package repository is becoming a jungle of R code and may do well with 
currating and editorial effort.  This can not/should not be the task of a 
single person or small group of people.  Using a crowd sourced method by 
implementing a wiki approach to the CRAN package repository would allow for the 
rapid editing, sorting and improvement of this impressive and precious 
resource, while also improving the accessibility, visibility and quality of 
individual packages.  It would also bind the

For example, such an interface would allow the cleaning up of the repository 
through the use of tagging of packages, using similar approaches to the 
wikipedia project 
(http://en.wikipedia.org/wiki/Wikipedia:Template_messages#Cleanup).

Such a tagging approach could be used within existing vcs, if the repository 
was migrated/mirrored within one of these systems.


Packages could be marked using tags for all following actions prior to 
implementing the action.  Actions could be undertaken directly by package users 
after a delay or discussion.

Packages management/editorial effort:
-Merging/
-Combining packages that have:
-Large overlap in functionality
-Are largely interdependant
-Are only minor extensions of another package
-…
-Split/fork
-Subdividing behemoth packages into smaller packages with more 
specific tasks
-Categorization
-Packages could be sorted by use, improvement of Task View
-Tags, keywords could be added to packages for searching
-Packages could be placed in a hierarchy, not only by true 
dependance and reverse dependance, but also by logical dependance/reverse 
dependance
-ie. which package should probably be used with which 
package, an improvement on the see also help section
-Deletion
-Marking/tagging
-a stub/prototype
-broken
Package improvements
-Improving help files
-Adding functions
-Adding examples
-Requiring, improving or adding references
-References to the theory or approach used...
-A section could include a list of articles making use of the 
package, with package users encourage to enter this information
-This would allow package author recognition and allow a 
package impact factor
-Adding key words for indexing and searching
-Function improvement
-Adding compatibility with other packages/formats (including 
when merging packages)
-Speed improvements
Discussion
-On package improvements, management steps directly attached to the 
package
-Help discussion



Re: [R] Ignoring loadNamespace errors when loading a file

2011-08-22 Thread Uwe Ligges



On 22.08.2011 08:52, Allan Engelhardt wrote:

On a Unix machine I ran caret::rfe using the multicore package, and I
saved the resulting object using save(lm2, file = lm2.RData).
[Reproducible example below.]

When I try to load(lm2.RData) on my Windows laptop, I get

Error in loadNamespace(name) : there is no package called 'multicore'

I completely understand the error and I would like to ignore it and
still load the saved object data.

I imagine that I can make myself an empty multicore package for Windows
and load the data file successfully, but is there another way?

(I am not going to use any multicore functionality; I just want to
inspect some of the data stored in the object and the reference in
question is just an unfortunately stored link from the original call.)

(I did search for this question in the archives, but could only find it
discussed in connection with starting R with a .RData file where the
consensus seems to be to start R in vanilla mode and install the missing
package. This situation is different and installing a Unix-only package
on Windows is obviously a non-starter, except as I proposed above.)

Obligatory reproducible example: On the Unix machine do

library(multicore)
a - list(data = 1:10, fun = mclapply)
save(a, file = a.RData)

and then try to load the a.RData file on Windows. The question is if I
can recover the data (1:10) on that platform.


Short answer: No.

The element fun within a relies on the Namespace being present. And 
then you want additionally just part of an object. If this is really 
relevant, you have to digg into ./src/main/saveload.R and serialize.R 
and try to write your own interface to extract parts of objects. So this 
is probably not worth the effort.


Uwe Ligges




Allan


sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] compiler stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] caret_4.98 cluster_1.14.0 reshape_0.8.4 plyr_1.6
[5] lattice_0.19-31 boot_1.3-2 ctv_0.7-3

loaded via a namespace (and not attached):
[1] grid_2.13.1 tools_2.13.1

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple R linear models into one Latex table

2011-08-22 Thread Rmh
please look at the latex() function in package Hmisc.

Sent from my iPhone

On Aug 22, 2011, at 0:55, Alex Ruiz Euler rruizeu...@ucsd.edu wrote:

 
 
 Dear community,
 
 I had been looking for an easy way to produce latex tables from R
 output. xtable() and the package apsrtable produce good outputs but they are 
 not
 exactly what I was looking for. 
 
 I wrote this code that generates regression tables from multiple R
 linear models. I want to share it because it might be
 useful for someone else, and because I would appreciate comments on how to
 optimize the code. I'm also open to suggestions about design or packages to 
 include. Or pointing out bugs. I hope this is the right list to post.
 
 Please consider it is still in a very primitive form, and the generated table 
 might look strange for some disciplines (I come from political science).
 
 Thanks,
 Alex
 
 
 
 ## Start script
 
 
 #
  R models to Latex table 
 #
 
 
 # nice() - Multiple R linear models into one Latex table.
 #
 #nice(list(fit1,fit2,...,fitn)) for generic table with n models
 #
 #or
 #
 #  for better tables, create objects 'model.names' and 'final.varnames', then
 #
 #nice(list(fit1,fit2,...,fitn), model.names, final.varnames)
 
 
 
 nice - function(modelos, model.names=NULL, final.varnames=NULL) {
 
  var.names-vector(mode=character)
  k-1
  for (i in 1:length(modelos)) {
l-length(names(coef(modelos[[i]])))
var.names[c(k:c(k+l-1))]-names(coef(modelos[[i]]))
k-k+l
  }
  var.names-unique(var.names)
 
  if(is.null(final.varnames)) {
  final.varnames-var.names
  }
 
  if(is.null(model.names)) {
  model.names-paste(Model,1:length(modelos))
  }
 
  mat.all-matrix(data=NA, nrow=length(var.names)*2, byrow=FALSE, 
 ncol=length(model.names), 
 dimnames=list(c(rep(c(coef,sd),length=length(var.names)*2)), 
 c(model.names)))
  dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], by=2))]-var.names; 
 dimnames(mat.all)[[1]][c(seq(2,dim(mat.all)[1], by=2))]-
 
  for (j in 1:length(modelos)) {

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])),j]-coef(modelos[[j]])

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])+1),j]-sqrt(diag(vcov(modelos[[j]])))
  }
 
  mat.all-signif(mat.all, digits=3); 
 dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], by=2))]-final.varnames
 
 
  cat(\\begin{table}[!hbt], \n,\\caption[Short for List of Tables]{Long 
 for this 
 title},\n,\\begin{center},\n,\\begin{tabular}{ll},\n)
  
 cat(,paste(model.names[1:length(model.names)-1],),model.names[length(model.names)],,\n,\\hline,\n)
  for(i in 1:dim(mat.all)[1]) {
if(i %in% c(seq(1,dim(mat.all)[1], by=2))) { # Odd rows (coefficients)
 
  cat(dimnames(mat.all)[[1]][i],)
  cat(
for (j in 1:(length(modelos)-1)) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
  } else cat(round(mat.all[i,j], digits=5),)
} else cat()
  })
 
  cat(
for (j in length(modelos) ) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
} else cat(round(mat.all[i,j], digits=5))
}
   })
  cat(, \n )
 
  } else {
  
 cat(,ifelse(!is.na(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)]),paste((\\emph{,round(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)],
  digits=5),}),sep=), paste()),
   
 ifelse(!is.na(mat.all[i,length(dimnames(mat.all)[[2]])]),paste((\\emph{,round(mat.all[i,length(dimnames(mat.all)[[2]])],
  digits=5),}),sep=),paste( )),
, sep=, fill=TRUE)}
}
 
  cat(\\hline,\n,\\emph{n},)
  cat(
  for(j in 1:(length(modelos)-1)) {
cat(length(modelos[[j]]$residuals),,sep=)
  },
  for(j in length(modelos)) {
cat(length(modelos[[j]]$residuals), , \n, sep=)
  }
  )
 
  cat(\\emph{Adj-R$^2$})
  cat(
for(j in 1:(length(modelos)-1)) {
if (class(modelos[[j]])[1]==lm) 
 {cat(round(summary(modelos[[j]])$adj.r.squared,digits=2),, sep=)} else {
cat() 
}
  },
  for(j in length(modelos)) {
if (class(modelos[[j]])[1]==lm) 
 {cat(round(summary(modelos[[j]])$adj.r.squared,digits=2),,\n)} else {
cat(,\n) 
}
  } 
)
 
  cat(\\emph{AIC})
  cat(
for(j in 1:(length(modelos)-1)) {
if (class(modelos[[j]])[1]==glm) {cat(round(summary(modelos[[j]])$aic, 
 digits=0),, sep=)} else {
cat()
  

Re: [R] questions about metafor package

2011-08-22 Thread Mike Cheung
Hi, Emilie.

For your second question. You may check Gleser and Olkin (2009). They gave
several formulas to estimate the sampling covariance for dependent effect
sizes. One of them can be applied in your case.

Gleser, L. J.,  Olkin, I. (2009). Stochastically dependent effect sizes. In
H. Cooper, L. V. Hedges,  J. C. Valentine (Eds.), The handbook of research
synthesis and meta-analysis. (2nd ed., pp. 357-376). New York: Russell Sage
Foundation.

Regards,
Mike
-- 
-
 Mike W.L. Cheung   Phone: (65) 6516-3702
 Department of Psychology   Fax:   (65) 6773-1843
 National University of Singapore
 http://courses.nus.edu.sg/course/psycwlm/internet/
-

On Sat, Aug 20, 2011 at 10:19 PM, Michael Dewey i...@aghmed.fsnet.co.ukwrote:

 At 16:21 17/08/2011, Emilie MAILLARD wrote:

 Hello,
 Â
 I would like to do a meta-analysis with the package « metafor ».
 Ideally I would like to use a mixed model because I’m interested to 
 see
 the effect of some moderators. But the data set I managed to collect from
 literature presents two limits.
 Â
 -Â Â Â Â Â Â Â Â  Firstly, for each observation, I have means for a
 treatment and for a control, but I don’t always have corresponding
 standard deviations (52 of a total of 93 observations don’t have 
 standard
 deviations). Nevertheless I have the sample sizes for all observations so I
 wonder if it was possible to weight observations by sample size in the
 package « metafor ».
 -Â Â Â Â Â Â Â Â  Secondly, some observations are probably not 
 independent
 as I have sometimes several relevant observations for a same design. More
 precisely, for these cases, the control mean is identical but treatment
 means varied. Ideally, I would not like to do a weighted average for these
 non-independent observations because these observations represent levels of
 a moderator. I know that the package « metafor » is not designed 
 for the
 analysis of correlated outcomes. What are the dangers of using the package
 even if observations are not really independent ? Â


 Emilie,
 I am not sure whether this is the answer to your problem of observations
 which are not independent but you might also look at the metaSEM package
 http://courses.nus.edu.sg/**course/psycwlm/internet/**metaSEM/http://courses.nus.edu.sg/course/psycwlm/internet/metaSEM/
 I am still trying to understand his paper on this (see link for reference)
 but he is trying to embed meta-analysis within the structural equation
 framework and it may be possible to cope with lack of independence in that
 way. But as I say I am still trying to come to grips with the paper.


  Â

 Thank you for your help,
 Â
 Émilie.
[[alternative HTML version deleted]]


 Michael Dewey
 i...@aghmed.fsnet.co.uk
 http://www.aghmed.fsnet.co.uk/**home.htmlhttp://www.aghmed.fsnet.co.uk/home.html


 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] Multiple R linear models into one Latex table

2011-08-22 Thread Matevž Pavlič
Hi, thanks for the help. 

Class says as follows :

 class(DF)
[1] SpatialPointsDataFrame
attr(,package)
[1] sp
 class(grd)
[1] SpatialPixels
attr(,package)
[1] sp

Anyway, the problem was, as Rmh suggested, with the zerodist().

Tnx, m

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Rmh
Sent: Monday, August 22, 2011 11:15 AM
To: Alex Ruiz Euler
Cc: r-help@r-project.org
Subject: Re: [R] Multiple R linear models into one Latex table

please look at the latex() function in package Hmisc.

Sent from my iPhone

On Aug 22, 2011, at 0:55, Alex Ruiz Euler rruizeu...@ucsd.edu wrote:

 
 
 Dear community,
 
 I had been looking for an easy way to produce latex tables from R 
 output. xtable() and the package apsrtable produce good outputs but 
 they are not exactly what I was looking for.
 
 I wrote this code that generates regression tables from multiple R 
 linear models. I want to share it because it might be useful for 
 someone else, and because I would appreciate comments on how to 
 optimize the code. I'm also open to suggestions about design or packages to 
 include. Or pointing out bugs. I hope this is the right list to post.
 
 Please consider it is still in a very primitive form, and the generated table 
 might look strange for some disciplines (I come from political science).
 
 Thanks,
 Alex
 
 
 
 ## Start script
 
 
 #
  R models to Latex table 
 #
 
 
 # nice() - Multiple R linear models into one Latex table.
 #
 #nice(list(fit1,fit2,...,fitn)) for generic table with n models
 #
 #or
 #
 #  for better tables, create objects 'model.names' and 
 'final.varnames', then #
 #nice(list(fit1,fit2,...,fitn), model.names, final.varnames)
 
 
 
 nice - function(modelos, model.names=NULL, final.varnames=NULL) {
 
  var.names-vector(mode=character)
  k-1
  for (i in 1:length(modelos)) {
l-length(names(coef(modelos[[i]])))
var.names[c(k:c(k+l-1))]-names(coef(modelos[[i]]))
k-k+l
  }
  var.names-unique(var.names)
 
  if(is.null(final.varnames)) {
  final.varnames-var.names
  }
 
  if(is.null(model.names)) {
  model.names-paste(Model,1:length(modelos))
  }
 
  mat.all-matrix(data=NA, nrow=length(var.names)*2, byrow=FALSE, 
 ncol=length(model.names), 
 dimnames=list(c(rep(c(coef,sd),length=length(var.names)*2)), 
 c(model.names)))  dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], 
 by=2))]-var.names; dimnames(mat.all)[[1]][c(seq(2,dim(mat.all)[1], 
 by=2))]-
 
  for (j in 1:length(modelos)) {

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])),j]-coef(modelos[[j]])

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])+1),j
 ]-sqrt(diag(vcov(modelos[[j]])))
  }
 
  mat.all-signif(mat.all, digits=3); 
 dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], 
 by=2))]-final.varnames
 
 
  cat(\\begin{table}[!hbt], \n,\\caption[Short for List of 
 Tables]{Long for this 
 title},\n,\\begin{center},\n,\\begin{tabular}{ll},\n
 )
  
 cat(,paste(model.names[1:length(model.names)-1],),model.names[le
 ngth(model.names)],,\n,\\hline,\n)
  for(i in 1:dim(mat.all)[1]) {
if(i %in% c(seq(1,dim(mat.all)[1], by=2))) { # Odd rows 
 (coefficients)
 
  cat(dimnames(mat.all)[[1]][i],)
  cat(
for (j in 1:(length(modelos)-1)) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
  } else cat(round(mat.all[i,j], digits=5),)
} else cat()
  })
 
  cat(
for (j in length(modelos) ) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
} else cat(round(mat.all[i,j], digits=5))
}
   })
  cat(, \n )
 
  } else {
  
 cat(,ifelse(!is.na(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)]),paste((\\emph{,round(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)],
  digits=5),}),sep=), paste()),
   
 ifelse(!is.na(mat.all[i,length(dimnames(mat.all)[[2]])]),paste((\\emph{,round(mat.all[i,length(dimnames(mat.all)[[2]])],
  digits=5),}),sep=),paste( )),
, sep=, fill=TRUE)}
}
 
  cat(\\hline,\n,\\emph{n},)
  cat(
  for(j in 1:(length(modelos)-1)) {
cat(length(modelos[[j]]$residuals),,sep=)
  },
  for(j in length(modelos)) {
cat(length(modelos[[j]]$residuals), , \n, sep=)
  }
  )
 
  cat(\\emph{Adj-R$^2$})
  cat(
for(j in 

Re: [R] Multiple R linear models into one Latex table

2011-08-22 Thread Matevž Pavlič
Sorry wrong thread ;)

m

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Matevž Pavlič
Sent: Monday, August 22, 2011 12:14 PM
To: Rmh; Alex Ruiz Euler
Cc: r-help@r-project.org
Subject: Re: [R] Multiple R linear models into one Latex table

Hi, thanks for the help. 

Class says as follows :

 class(DF)
[1] SpatialPointsDataFrame
attr(,package)
[1] sp
 class(grd)
[1] SpatialPixels
attr(,package)
[1] sp

Anyway, the problem was, as Rmh suggested, with the zerodist().

Tnx, m

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Rmh
Sent: Monday, August 22, 2011 11:15 AM
To: Alex Ruiz Euler
Cc: r-help@r-project.org
Subject: Re: [R] Multiple R linear models into one Latex table

please look at the latex() function in package Hmisc.

Sent from my iPhone

On Aug 22, 2011, at 0:55, Alex Ruiz Euler rruizeu...@ucsd.edu wrote:

 
 
 Dear community,
 
 I had been looking for an easy way to produce latex tables from R 
 output. xtable() and the package apsrtable produce good outputs but 
 they are not exactly what I was looking for.
 
 I wrote this code that generates regression tables from multiple R 
 linear models. I want to share it because it might be useful for 
 someone else, and because I would appreciate comments on how to 
 optimize the code. I'm also open to suggestions about design or packages to 
 include. Or pointing out bugs. I hope this is the right list to post.
 
 Please consider it is still in a very primitive form, and the generated table 
 might look strange for some disciplines (I come from political science).
 
 Thanks,
 Alex
 
 
 
 ## Start script
 
 
 #
  R models to Latex table 
 #
 
 
 # nice() - Multiple R linear models into one Latex table.
 #
 #nice(list(fit1,fit2,...,fitn)) for generic table with n models
 #
 #or
 #
 #  for better tables, create objects 'model.names' and 
 'final.varnames', then #
 #nice(list(fit1,fit2,...,fitn), model.names, final.varnames)
 
 
 
 nice - function(modelos, model.names=NULL, final.varnames=NULL) {
 
  var.names-vector(mode=character)
  k-1
  for (i in 1:length(modelos)) {
l-length(names(coef(modelos[[i]])))
var.names[c(k:c(k+l-1))]-names(coef(modelos[[i]]))
k-k+l
  }
  var.names-unique(var.names)
 
  if(is.null(final.varnames)) {
  final.varnames-var.names
  }
 
  if(is.null(model.names)) {
  model.names-paste(Model,1:length(modelos))
  }
 
  mat.all-matrix(data=NA, nrow=length(var.names)*2, byrow=FALSE, 
 ncol=length(model.names), 
 dimnames=list(c(rep(c(coef,sd),length=length(var.names)*2)), 
 c(model.names)))  dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], 
 by=2))]-var.names; dimnames(mat.all)[[1]][c(seq(2,dim(mat.all)[1], 
 by=2))]-
 
  for (j in 1:length(modelos)) {

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])),j]
 -coef(modelos[[j]])

 mat.all[c(match(names(coef(modelos[[j]])),dimnames(mat.all)[[1]])+1),j
 ]-sqrt(diag(vcov(modelos[[j]])))
  }
 
  mat.all-signif(mat.all, digits=3);
 dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1],
 by=2))]-final.varnames
 
 
  cat(\\begin{table}[!hbt], \n,\\caption[Short for List of 
 Tables]{Long for this 
 title},\n,\\begin{center},\n,\\begin{tabular}{ll},\n
 )
  
 cat(,paste(model.names[1:length(model.names)-1],),model.names[le
 ngth(model.names)],,\n,\\hline,\n)
  for(i in 1:dim(mat.all)[1]) {
if(i %in% c(seq(1,dim(mat.all)[1], by=2))) { # Odd rows
 (coefficients)
 
  cat(dimnames(mat.all)[[1]][i],)
  cat(
for (j in 1:(length(modelos)-1)) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
  } else cat(round(mat.all[i,j], digits=5),)
} else cat()
  })
 
  cat(
for (j in length(modelos) ) {
  if(!is.na(mat.all[i,j])) {
p.val-abs(mat.all[i,j]/mat.all[i+1,j])
if(p.val1.644) {
  if(1.645=p.val  p.val1.96) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),*}, sep=) else {
if(1.96p.val  p.val2.576) cat(\\textbf{,round(mat.all[i,j], 
 digits=5),**}, sep=) else {
  cat(\\textbf{,round(mat.all[i,j], digits=5),***}, sep=)
}
  }
} else cat(round(mat.all[i,j], digits=5))
}
   })
  cat(, \n )
 
  } else {
  
 cat(,ifelse(!is.na(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)]),paste((\\emph{,round(mat.all[i,1:(length(dimnames(mat.all)[[2]])-1)],
  digits=5),}),sep=), paste()),
   
 ifelse(!is.na(mat.all[i,length(dimnames(mat.all)[[2]])]),paste((\\emph{,round(mat.all[i,length(dimnames(mat.all)[[2]])],
  digits=5),}),sep=),paste( )),
, sep=, 

Re: [R] Sweave doesn't work

2011-08-22 Thread Eik Vettorazzi
Hi Daniele,
_ in dati_england is treated as a special character in LaTeX math
mode and causes your LaTeX-compiler trying to switch to math mode (you
might have noticed a warning abaout missing `$' inserted). To produce
a plain _ in TeX you have to mask it as \_. Package Hmisc has some
sanitization methods for that task, but you can do that easily by hand
using gsub.

Cheers.

Am 21.08.2011 18:18, schrieb danielepippo:
 Hi R users.
 
 I've got a problem in producing the pdf file from Latex with R code. When I
 run the code Sweave(example.Rtex) in R it seems working, but when I run
 the Latex file it doesn't. The code error shown to me is below:
  
 *Runaway argument?
 {echo=FALSE}
 data- read.csv(C:\\Users\\Daniele\\Desktop\\dati\\dati_england
 ! File ended while scanning use of \FV@BeginScanning.
 inserted text 
 \par 
 * ...le/Desktop/dati/LaTeX1.Rtex*
 
 The Sweave code in Latex is like this:
 
 *\begin{Scode}{echo=FALSE}
 data-
 read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
 \end{Scode}
 \begin{figure}[!h]
 \centering
 \begin{Scode}{fig=TRUE, width=6, height=9, echo=FALSE}
 data1=matrix(0,ncol=4,nrow=4)
 
 
 \end{Scode}
 \caption{Data}
 \end{figure}*
 
 I don't know how to fix this problem. Any advices?
 Thanks very much
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Sweave-doesn-t-work-tp3758658p3758658.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.

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Ignoring loadNamespace errors when loading a file

2011-08-22 Thread Martin Morgan

On 08/21/2011 11:52 PM, Allan Engelhardt wrote:

On a Unix machine I ran caret::rfe using the multicore package, and I
saved the resulting object using save(lm2, file = lm2.RData).
[Reproducible example below.]

When I try to load(lm2.RData) on my Windows laptop, I get

Error in loadNamespace(name) : there is no package called 'multicore'

I completely understand the error and I would like to ignore it and
still load the saved object data.

I imagine that I can make myself an empty multicore package for Windows
and load the data file successfully, but is there another way?

(I am not going to use any multicore functionality; I just want to
inspect some of the data stored in the object and the reference in
question is just an unfortunately stored link from the original call.)

(I did search for this question in the archives, but could only find it
discussed in connection with starting R with a .RData file where the
consensus seems to be to start R in vanilla mode and install the missing
package. This situation is different and installing a Unix-only package
on Windows is obviously a non-starter, except as I proposed above.)

Obligatory reproducible example: On the Unix machine do

library(multicore)
a - list(data = 1:10, fun = mclapply)
save(a, file = a.RData)

and then try to load the a.RData file on Windows. The question is if I
can recover the data (1:10) on that platform.


Is this a more realistic reproducible example (from ?rfe, modified to 
use computeFunction=mclapply)?


  data(BloodBrain)

  x - scale(bbbDescr[,-nearZeroVar(bbbDescr)])
  x - x[, -findCorrelation(cor(x), .8)]
  x - as.data.frame(x)

  set.seed(1)
  lmProfile - rfe(x, logBBB,
   sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
   rfeControl = rfeControl(functions = lmFuncs,
 number = 5,
 computeFunction=mclapply))

Maybe provide a computeFunction that only indirectly references mclapply

  computeFunction=function(...) {
  if (require(multicore)) mclapply(...)
  else lapply(...)
  }

or editing the result object to remove references to mclapply

  lmProfile$control$computeFunction - NULL

Martin




Allan


sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] compiler stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] caret_4.98 cluster_1.14.0 reshape_0.8.4 plyr_1.6
[5] lattice_0.19-31 boot_1.3-2 ctv_0.7-3

loaded via a namespace (and not attached):
[1] grid_2.13.1 tools_2.13.1

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



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

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

2011-08-22 Thread Jesse Brown

Hello,

I've been dealing with a set of values that contain time stamps and part 
of my summary needs to look at just weekend data. In trying to limit the 
data I've found a large difference in performance in the way I index a 
data frame. I've constructed a minimal example here to try to explain my 
observation.


   is.weekend - function(x) {
   tm - as.POSIXlt(x,origin=1970/01/01)
   format(tm,%a) %in% c(Sat,Sun)
   }

   use.lapply - function(data) {
   data[do.call(rbind,lapply(data$TIME,FUN=is.weekend)),]
   }

   use.sapply - function(data) {
   data[sapply(data$TIME,FUN=is.weekend),]
   }

   use.vapply - function(data) {
   data[vapply(data$TIME,FUN=is.weekend,FALSE),]
   }

   use.indexing - function(data) {
   data[is.weekend(data$TIME),]
   }

And the results of these methods:

 names(csv.data)
   [1] TIME FILE RADIAN   BITS DURATION

 length(csv.data$TIME)
   [1] 21471

 system.time(v1 - use.lapply(csv.data))
  user  system elapsed
19.562   6.402  25.967

 system.time(v2 - use.sapply(csv.data))
  user  system elapsed
19.456   6.492  25.951

 system.time(v3 - use.vapply(csv.data))
  user  system elapsed
19.334   6.468  25.808

 system.time(v4 - use.indexing(csv.data))
  user  system elapsed
 0.032   0.020   0.052

 all(identical(v1,v2),identical(v2,v3),identical(v3,v4))
   [1] TRUE



Forgive what is probably a trivial question, but why is there such a 
large difference in the *apply functions as opposed to the direct 
indexing method? On the surface it seems as though the use.indexing 
method uses the entire vector as an argument to the function while the 
others /might/ iterate over the values using one at a time as an 
argument to the function. In either case all elements must be part of 
the calculation...


Thanks for any insight.

Jesse

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting cases from matrices stored in lists

2011-08-22 Thread mdvaan
Hi,

I have two lists (c and h - see below) containing matrices with similar
cases but different values. I want to split these matrices into multiple
matrices based on the values in h. So, I did the following:

years-c(1997:1999) 
for (t in 1:length(years)) 
{ 
year=as.character(years[t]) 
h[[year]]-sapply(colnames(h[[year]]), function(var)
h[[year]][h[[year]][,var]0, h[[year]][var,]0]) 
} 

Now that I have created list h (with split matrices), I would like to use
these selections to make similar selections in list c. List c needs to get
the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) looks
like this: 

$`1997`$`8026` 
  B 
B  8025 8026 8029 
  8025   1.000 0.7739527 0.9656091 
  8026   0.7739527 1.000 0.7202771 
  8029   0.9656091 0.7202771 1.000 

Can anyone help me doing this? I have no idea how I can get it to work.
Thank you very much for your help! 


library(zoo) 
DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
8025  1995  0  4  1  2 
8025  1997  1  1  3  4 
8026  1995  0  7  0  0 
8026  1996  1  2  3  0 
8026  1997  1  2  3  1 
8026  1998  6  0  0  4 
8026  1999  3  7  0  3 
8027  1997  1  2  3  9 
8027  1998  1  2  3  1 
8027  1999  6  0  0  2 
8028  1999  3  7  0  0 
8029  1995  0  2  3  3 
8029  1998  1  2  3  2 
8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
  
a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA 
b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 
newDF - lapply(1:nrow(b), function(i) 
  prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, 
dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) 
names(newDF) - time(a) 
c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 

DF2 = data.frame(read.table(textConnection(  A  B  C 
80  8025  1995 
80  8026  1995 
80  8029  1995 
81  8026  1996 
82  8025  1997 
82  8026  1997 
83  8025  1997 
83  8027  1997 
90  8026  1998 
90  8027  1998 
90  8029  1998 
84  8026  1999 
84  8027  1999 
85  8028  1999 
85  8029  1999),head=TRUE,stringsAsFactors=FALSE)) 
  
e - function(y) crossprod(table(DF2[DF2$C %in% y, 1:2])) 
years - sort(unique(DF2$C)) 
f - as.data.frame(embed(years, 3)) 
g-lapply(split(f, f[, 1]), e) 
h-lapply(g, function (x) ifelse(x0,1,0)) 

--
View this message in context: 
http://r.789695.n4.nabble.com/Selecting-cases-from-matrices-stored-in-lists-tp3759597p3759597.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] Did I find a bug on TSERIES or URCA packages?

2011-08-22 Thread Dail
I'm tring the functions to check the cointegration of a matrix.

I'm using **Phillips  Ouliaris Cointegration Test**

The function in *tseries* package is **po.test** and **ca.po** in *urca* 

The results with **URCA** are:

 ca.po(prices, demean='none')

 
# Phillips and Ouliaris Unit Root Test # 
 

Test of type Pu 
detrending of series none 


Call:
lm(formula = z[, 1] ~ z[, -1] - 1)

Residuals:
Min  1Q  Median  3Q Max 
-7.4960 -0.2912  0.7116  1.4530  3.3962 

Coefficients:
Estimate Std. Error t value Pr(|t|)
z[, -1] 0.559705   0.004678   119.6   2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 1.73 on 749 degrees of freedom
Multiple R-squared: 0.9503, Adjusted R-squared: 0.9502 
F-statistic: 1.431e+04 on 1 and 749 DF,  p-value:  2.2e-16 


Value of test-statistic is: 12.9648 

Critical values of Pu are:
  10pct5pct1pct
critical values 20.3933 25.9711 38.3413


The result with TSERIES are:


 po.test(prices, demean=FALSE)

Phillips-Ouliaris Cointegration Test

data:  prices 
Phillips-Ouliaris standard = -25.6421, Truncation lag parameter = 7,
p-value = 0.01

Warning message:
In po.test(prices, demean = FALSE) : p-value smaller than printed
p-value


As you can see I'm testing the same matrix (prices).
How is it possible that URCA tells there is **NO** cointegration and TSERIES
**YES** ??

Prices max it's a simple matrix with two columns (stock1 - stock2), take a
look to an extract of that.

1  3.065448  5.244870
2  3.094924  5.806821
3  2.873858  5.647601
4  3.205457  6.190820
5  3.315990  6.453064
6  3.168612  6.865161
7  3.271777  7.230428

Thank you

--
View this message in context: 
http://r.789695.n4.nabble.com/Did-I-find-a-bug-on-TSERIES-or-URCA-packages-tp3759673p3759673.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] Histogram from frequency data in pre-made bins

2011-08-22 Thread RobinLovelace
Update: I have recreated an artificial distribution using uniform random
numbers

n - c(runif(Car[1],0,2), runif(Car[2],2,5),runif(Car[3],5,10),
runif(Car[4],10,20), 
runif(Car[5],20,30), runif(Car[6],30,40), runif(Car[7],40,60),
runif(Car[8],60,200) )

The resulting density distribution is very jumpy, but should, in theory
allow me to fit a distribution to it and then extract the bin means from a
random sample of the given distribution. Again, this is tedious and far from
ideal, but cannot see any way around it. Also the distributions I fit to
this artificial dataset shoot up to infinity as x = 0.

Any ideas anyone???

--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-from-frequency-data-in-pre-made-bins-tp3758198p3759645.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to generate piecewise cubic spline with many knots?

2011-08-22 Thread xuyongdeng
Any commons is great appreciated.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-generate-piecewise-cubic-spline-with-many-knots-tp3755419p3759893.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] Hat Matrix

2011-08-22 Thread hyak
Hi, I'm a new user of R - Is this how you construct a hat matrix?

H - x %*% solve(t(x) %*% x) %*% t(x)
H
colnames(H) = rep('', 11)
round(H,2)

If so can you make them for more than 2 matrices?  Why do you have to use
the 2nd piece of code to round and stuff? Shouldn't it be correct from the
start? 

Thanks for any feedback,

Hyak

--
View this message in context: 
http://r.789695.n4.nabble.com/Hat-Matrix-tp3759728p3759728.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] Increase the size of the boxes but not the text in a legend

2011-08-22 Thread Jean V Adams
 [R] Increase the size of the boxes but not the text in a legend
 Jürgen Biedermann 
 to:
 r-help
 08/21/2011 06:02 PM
 
 HI there,
 
 I want to add a legend to a plot using the density and angle argument, 
 so patterns with lines in different angles are used in the plot and 
 should be referred to.
 When I use default settings, the filled boxes are too small.
 With the cex argument I can enlarge the whole legend, but then the text 
 gets too big.
 
 How could I just increase the size of the single boxes and not the text.

There is no way to do this with the legend() function.  The cex= argument 
controls both the text and the box size.  You could either write your own 
code to place rectangles and text on your plot, or you could create a 
modified version of the legend() function to suit your needs.

Jean

 
 I tried:
 
 legend(topright, c(Trefferquote,Falschalarmquote), 
 density=c(20,16), angle=c(45,0),cex=1.5, y.intersp=0.8)
 
 The sizes of the boxes are good now, but the text is too large and so 
 also the whole legend box gets too big.
 
 Thank you very much for your help
 Jürgen
[[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] Selecting cases from matrices stored in lists

2011-08-22 Thread Jean V Adams
 [R] Selecting cases from matrices stored in lists
 mdvaan 
 to:
 r-help
 08/22/2011 07:24 AM
 
 Hi,
 
 I have two lists (c and h - see below) containing matrices with similar
 cases but different values. I want to split these matrices into multiple
 matrices based on the values in h. So, I did the following:
 
 years-c(1997:1999) 
 for (t in 1:length(years)) 
 { 
 year=as.character(years[t]) 
 h[[year]]-sapply(colnames(h[[year]]), function(var)
 h[[year]][h[[year]][,var]0, h[[year]][var,]0]) 
 } 
 
 Now that I have created list h (with split matrices), I would like to 
use
 these selections to make similar selections in list c. List c needs to 
get
 the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) looks
 like this: 
 
 $`1997`$`8026` 
   B 
 B  8025 8026 8029 
   8025   1.000 0.7739527 0.9656091 
   8026   0.7739527 1.000 0.7202771 
   8029   0.9656091 0.7202771 1.000 
 
 Can anyone help me doing this? I have no idea how I can get it to work.
 Thank you very much for your help! 
 

Try this:

c2 - h
years - names(h)
for (t in seq(years))
{ 
year - years[t]
c2[[year]] - sapply(colnames(h[[year]]), function(var) 
c[[t]][h[[year]][ ,var]  0, h[[year]][var, ]  0]) 
}

By the way, it's great that you included code in your question.
However, I encountered a couple of errors when running you code (see 
below).

Also, it would be better to use a different name for your list c, 
because c() is a function in R.

Jean

 
 library(zoo) 
 DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
 8025  1995  0  4  1  2 
 8025  1997  1  1  3  4 
 8026  1995  0  7  0  0 
 8026  1996  1  2  3  0 
 8026  1997  1  2  3  1 
 8026  1998  6  0  0  4 
 8026  1999  3  7  0  3 
 8027  1997  1  2  3  9 
 8027  1998  1  2  3  1 
 8027  1999  6  0  0  2 
 8028  1999  3  7  0  0 
 8029  1995  0  2  3  3 
 8029  1998  1  2  3  2 
 8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
 
 a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
 sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA 
 b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 

Error in FUN(cdata[st, i], ...) : unused argument(s) (partial = TRUE)

rollapply() has no argument partial.

 newDF - lapply(1:nrow(b), function(i) 
   prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, 
 dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) 

 names(newDF) - time(a) 

Error in names(newDF) - time(a) : 
  'names' attribute [5] must be the same length as the vector [3]

newDF has only 3 names, but time(a) is of length 5.

 c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 
 
 DF2 = data.frame(read.table(textConnection(  A  B  C 
 80  8025  1995 
 80  8026  1995 
 80  8029  1995 
 81  8026  1996 
 82  8025  1997 
 82  8026  1997 
 83  8025  1997 
 83  8027  1997 
 90  8026  1998 
 90  8027  1998 
 90  8029  1998 
 84  8026  1999 
 84  8027  1999 
 85  8028  1999 
 85  8029  1999),head=TRUE,stringsAsFactors=FALSE)) 
 
 e - function(y) crossprod(table(DF2[DF2$C %in% y, 1:2])) 
 years - sort(unique(DF2$C)) 
 f - as.data.frame(embed(years, 3)) 
 g-lapply(split(f, f[, 1]), e) 
 h-lapply(g, function (x) ifelse(x0,1,0)) 
[[alternative HTML version deleted]]

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


Re: [R] Data Frame Indexing

2011-08-22 Thread jim holtman
The problem is that the way you are using *apply, there are
individual calls to the function for each item.  In the direct
indexing, you are only making a single call with a vector of values;
Here is a illustration that shows the number of calls:

 # count the calls
 f.test - function(x) callCnt - callCnt + 1  # test function; just 
 increment counter

 # test vector
 x - 1:100
 callCnt - 0
 invisible(sapply(x, f.test))
 callCnt  # notice that there were 100 calls made
[1] 100

This again indicates that you need to think about how to vectorize
your operations.  Also if you have used Rprof, it may have shown where
you were spending time.


On Mon, Aug 22, 2011 at 8:13 AM, Jesse Brown jesse.r.br...@lmco.com wrote:
 Hello,

 I've been dealing with a set of values that contain time stamps and part of
 my summary needs to look at just weekend data. In trying to limit the data
 I've found a large difference in performance in the way I index a data
 frame. I've constructed a minimal example here to try to explain my
 observation.

   is.weekend - function(x) {
       tm - as.POSIXlt(x,origin=1970/01/01)
       format(tm,%a) %in% c(Sat,Sun)
   }

   use.lapply - function(data) {
       data[do.call(rbind,lapply(data$TIME,FUN=is.weekend)),]
   }

   use.sapply - function(data) {
       data[sapply(data$TIME,FUN=is.weekend),]
   }

   use.vapply - function(data) {
       data[vapply(data$TIME,FUN=is.weekend,FALSE),]
   }

   use.indexing - function(data) {
       data[is.weekend(data$TIME),]
   }

 And the results of these methods:

     names(csv.data)
   [1] TIME     FILE     RADIAN   BITS     DURATION

     length(csv.data$TIME)
   [1] 21471

     system.time(v1 - use.lapply(csv.data))
      user  system elapsed
    19.562   6.402  25.967

     system.time(v2 - use.sapply(csv.data))
      user  system elapsed
    19.456   6.492  25.951

     system.time(v3 - use.vapply(csv.data))
      user  system elapsed
    19.334   6.468  25.808

     system.time(v4 - use.indexing(csv.data))
      user  system elapsed
     0.032   0.020   0.052

     all(identical(v1,v2),identical(v2,v3),identical(v3,v4))
   [1] TRUE



 Forgive what is probably a trivial question, but why is there such a large
 difference in the *apply functions as opposed to the direct indexing method?
 On the surface it seems as though the use.indexing method uses the entire
 vector as an argument to the function while the others /might/ iterate over
 the values using one at a time as an argument to the function. In either
 case all elements must be part of the calculation...

 Thanks for any insight.

 Jesse

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

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


Re: [R] Groups and bwplot

2011-08-22 Thread Sébastien Bihorel
I got it to works. The problem was mainly how data were passed to my
panel and panel.groups function. For reference, here is what I ended
with:

require(lattice)

mybwplot - function(x,y,data,group){

  if (missing(group)||is.null(group)) {
group - 'NULL'
ngroups - 1
  } else {
data[[group]] - as.factor(data[[group]])
ngroups - nlevels(data[[group]])
  }

  mywidth - 1/(ngroups+1)

  mypanel - function(x,y,groups,...){
if (missing(groups) || is.null(groups) || ngroups==1) {
  panel.bwplot(x=x,y=y,...)
} else {
  panel.superpose(x=x,y=y,groups=groups,...)
}
  }

  mypanel.groups - function(x,y,ngroups,group.number,...){
if (ngroups==1) {
  NULL
} else {
  panel.bwplot(x+(group.number-0.5*(ngroups+1))/(ngroups+1),y, ...)
}
  }

  if (!is.null(group)) group - data[[group]]

  bwplot(formula(paste(y,x,sep='~')),
 data = data,
 ngroups = ngroups,
 groups = group,
 pch = |,
 box.width = mywidth,
 panel = mypanel,
 panel.groups = mypanel.groups)

}

myCO2 - CO2
myCO2$year - 2011

mybwplot('Type','uptake',myCO2) # works

mybwplot('Type','uptake',myCO2,'Treatment') # works

mybwplot('Type','uptake',myCO2,'year') # works



On Sat, Aug 20, 2011 at 1:35 PM, Sébastien Bihorel pomc...@free.fr wrote:
 Thanks for your input and this link. I realize that there was a typo
 in my example code that impacted the group argument... That's king of
 stupid.

 However, even with the implementation of Felix's syntax, the Error
 using packet 1, 'x' is missing error message is still displayed, even
 if the call appears correct. So I believe that group argument in not
 the issue but rather my panel functions. (Plus, Felix's notation
 creates side-issues such as the calculation of ngroups, which I have
 hard-coded in the following modified example).

 require(lattice)

 mybwplot - function(x,data,groups){

  if (missing(groups)) {
    ngroups - 1
  } else {
    ngroups - 2
  }

  mywidth - 1/(ngroups+1)

  mypanel - function(x,y,groups,...){
    if (missing(groups)||is.null(groups)) {
      panel.bwplot(x,y,...)
    } else {
      panel.superpose(x,y,...)
    }
  }

  mypanel.groups - function(x,y,groups,ngroups,group.number,...){
    if (missing(groups)||is.null(groups)){
      NULL
    } else {
      panel.bwplot(x+(group.number-0.5*(ngroups+1))/(ngroups+1),y, ...)
    }
  }

  ccall - quote(bwplot(x,
                        data = data,
                        ngroups=ngroups,
                        pch = |,
                        box.width = mywidth,
                        panel = mypanel,
                        panel.groups = mypanel.groups))
  ccall$groups - substitute(groups)
  str(ccall)
  eval(ccall)

 }

 myCO2 - CO2
 myCO2$year - 2011

 mybwplot(uptake~Type,myCO2) # works

 mybwplot(uptake~Type,myCO2,groups=Treatment) # Error using packet 1,
 'x' is missing

 #mybwplot(uptake~Type,myCO2,groups=year) # Error using packet 1, 'x' is 
 missing

 # Deepayan Sarkar suggested code (adapted to myC02)
 # bwplot(uptake ~ Type, data = myCO2, groups = Treatment,
 #        pch = |, box.width = 1/3,
 #        panel = panel.superpose,
 #        panel.groups = function(x, y, ..., group.number) {
 #            panel.bwplot(x + (group.number-1.5)/3, y, ...)
 #        })

 On Sat, Aug 20, 2011 at 11:38 AM, Weidong Gu anopheles...@gmail.com wrote:
 You may want to consult a recent post by Felix
 (https://stat.ethz.ch/pipermail/r-help/2011-August/286707.html) on how
 to pass group parameter.

 Weidong Gu

 On Sat, Aug 20, 2011 at 6:59 AM, Sébastien Bihorel pomc...@free.fr wrote:
 Dear R-users,

 A while ago, Deepayan Sarkar suggested some code that uses the group
 argument in bwplot to create some 'side-by-side' boxplots
 (https://stat.ethz.ch/pipermail/r-help/2010-February/230065.html). The
 example he gave was relatively specific and I wanted to generalize his
 approach into a function. Unfortunately, I seem to have some issues
 passing the correct arguments to the panel function, and would greatly
 appreciate any suggestions to solve these issues:

 require(lattice)

 mybwplot - function(x,y,data,groups){

  if (missing(groups)||is.null(groups)) {
    groups - NULL
    ngroups - 1
  } else {
    data[[groups]] - as.factor(data[[groups]])
    ngroups - nlevels(data[[groups]])
  }
  mywidth - 1/(ngroups+1)

  mypanel - function(x,y,groups,...){
    if (missing(groups)||is.null(groups)) {
      panel.bwplot(x,y,...)
    } else {
      panel.superpose(x,y,...)
    }
  }

  mypanel.groups - function(x,y,groups,ngroups,...){
    if (missing(groups)||is.null(groups)){
      NULL
    } else {
      function(x, y, ..., group.number) {
        panel.bwplot(x+(group.number-0.5*(ngroups+1))/(ngroups+1),y, ...)}
    }
  }

  bwplot(formula(paste(y,x,sep=' ~ ')),
       data = data,
       groups = 'Plant',
       ngroups=ngroups,
       pch = |,
       box.width = mywidth,
       panel = mypanel,
       panel.groups = mypanel.groups)

 }

 

Re: [R] Wiki/revision control to management of CRAN package repository

2011-08-22 Thread Ista Zahn
Hi,
Much of the tagging/sorting/commenting stuff is already implemented as
http://crantastic.org. Unfortunately few people have taken the time to
contribute reviews. I propose that those of us who would like to bring
more order to the R package universe should start by contributing
reviews, tags, etc. to crantastic.

Best,
Ista

2011/8/22 Etienne Low-Décarie etienne.low-deca...@mail.mcgill.ca:
 I propose the following humbly, with little know how as to how to implement, 
 and realize it may have been proposed many times.  It is just something I had 
 on my mind.

 Would it be possible/desirable to have the whole CRAN package repository 
 accessible through a public wiki, forge or version control interface (ideally 
 a fusion of the wiki and forge approach)?


 It appears it would be a first for a software repository.

 CRAN package repository is becoming a jungle of R code and may do well with 
 currating and editorial effort.  This can not/should not be the task of a 
 single person or small group of people.  Using a crowd sourced method by 
 implementing a wiki approach to the CRAN package repository would allow for 
 the rapid editing, sorting and improvement of this impressive and precious 
 resource, while also improving the accessibility, visibility and quality of 
 individual packages.  It would also bind the

 For example, such an interface would allow the cleaning up of the repository 
 through the use of tagging of packages, using similar approaches to the 
 wikipedia project 
 (http://en.wikipedia.org/wiki/Wikipedia:Template_messages#Cleanup).

 Such a tagging approach could be used within existing vcs, if the repository 
 was migrated/mirrored within one of these systems.


 Packages could be marked using tags for all following actions prior to 
 implementing the action.  Actions could be undertaken directly by package 
 users after a delay or discussion.

 Packages management/editorial effort:
        -Merging/
                -Combining packages that have:
                        -Large overlap in functionality
                        -Are largely interdependant
                        -Are only minor extensions of another package
                        -…
        -Split/fork
                -Subdividing behemoth packages into smaller packages with more 
 specific tasks
        -Categorization
                -Packages could be sorted by use, improvement of Task View
                -Tags, keywords could be added to packages for searching
                -Packages could be placed in a hierarchy, not only by true 
 dependance and reverse dependance, but also by logical dependance/reverse 
 dependance
                        -ie. which package should probably be used with which 
 package, an improvement on the see also help section
        -Deletion
        -Marking/tagging
                -a stub/prototype
                -broken
 Package improvements
        -Improving help files
        -Adding functions
        -Adding examples
        -Requiring, improving or adding references
                -References to the theory or approach used...
                -A section could include a list of articles making use of the 
 package, with package users encourage to enter this information
                -This would allow package author recognition and allow a 
 package impact factor
        -Adding key words for indexing and searching
        -Function improvement
                -Adding compatibility with other packages/formats (including 
 when merging packages)
                -Speed improvements
 Discussion
        -On package improvements, management steps directly attached to the 
 package
        -Help discussion




 These actions would be reversible, possibly with veto power from the author 
 of the package.

 Links:
 http://www.rforge.net/
 http://sourceforge.net/
 http://channel9.msdn.com/Forums/Coffeehouse/174561-Coding-Wiki
 http://code.google.com/p/mcover/
 http://www.tigris.org/

 This is just an idea I had on my mind.

 Thank you

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] Calculating p-value for 1-tailed test in a linear model

2011-08-22 Thread David Winsemius


On Aug 22, 2011, at 9:44 AM, Andrew Campomizzi wrote:


David,
It's fair to question my intentions.  I'm running power analyses using
simulations (based on Bolker's Ecological Models and Data in R) and  
need to
provide decision-makers with options.  So, I'm attempting to make it  
clear
that if the research hypothesis (e.g., response variable declines  
with an
increase in predictor variable) can be clearly answered with a 1- 
tailed
test, then one might need a sample size of n to get a particular  
power,

given variance and alpha.


So the possibility that the response variable will be increased by the  
predictor variable is known to be false? It would be unusual to have  
such prior knowledge but I suppose it is possible if the starting  
point is at the ceiling, but then typical regression methods may not  
be appropriate.



I think Mark's response answers my question.


Mark's response was not copied to the list.

--
David.

Thanks,
Andy

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: Saturday, August 20, 2011 6:02 PM
To: Andrew Campomizzi
Cc: r-help@r-project.org
Subject: Re: [R] Calculating p-value for 1-tailed test in a linear  
model



On Aug 19, 2011, at 6:20 PM, Andrew Campomizzi wrote:


Hello,

I'm having trouble figuring out how to calculate a p-value for a 1-
tailed
test of beta_1 in a linear model fit using command lm.  My model has
only 1
continuous, predictor variable.  I want to test the null hypothesis
beta_1
is = 0.  I can calculate the p-value for a 2-tailed test using the
code
2*pt(-abs(t-value), df=degrees.freedom), where t-value and
degrees.freedom
are values provided in the summary of the lm.  The resulting p-value
is the
same as provided by the summary of the lm for beta_1.  I'm unsure
how to
change my calculation of the p-value for a 1-tailed test.


You need to clearly state your hypothesis. Then using the output from
the regression function should be straightforward.

(Yes. this is a intentionally vague answer designed to elicit further
information about your understanding of the statistical issues and how
they relate to your domain knowledge. Many time peole already have the
data and because they didn't get the answer they wanted, they search
for other ways to game the system by ad-hoc changes in the
statistical rules of the road.)

--

David Winsemius, MD
West Hartford, CT




David Winsemius, MD
West Hartford, CT

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


Re: [R] Sweave doesn't work

2011-08-22 Thread Joshua Wiley
Hi Eik,

On Mon, Aug 22, 2011 at 4:14 AM, Eik Vettorazzi
e.vettora...@uke.uni-hamburg.de wrote:
 Hi Daniele,
 _ in dati_england is treated as a special character in LaTeX math
 mode and causes your LaTeX-compiler trying to switch to math mode (you
 might have noticed a warning abaout missing `$' inserted). To produce
 a plain _ in TeX you have to mask it as \_. Package Hmisc has some

This is true in the regular environment, but should not be true for
code.  Think about all the special characters encountered in R code---
$, quotes, _ ^.  The following minimal document compiles fine on my
system:

\documentclass{article}
\usepackage{Sweave}
\begin{document}
\section{Example showing underscores works fine inside an Schunk}
\begin{Schunk}
\begin{Sinput}
data-
read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
\end{Sinput}
\end{Schunk}
\end{document}

producing the attached PDF.

My system:

R Under development (unstable) (2011-08-13 r56733)
Platform: x86_64-pc-mingw32/x64 (64-bit)

Version 0.3 r.670 (MiKTeX 2.9)

Josh

 sanitization methods for that task, but you can do that easily by hand
 using gsub.

 Cheers.

 Am 21.08.2011 18:18, schrieb danielepippo:
 Hi R users.

 I've got a problem in producing the pdf file from Latex with R code. When I
 run the code Sweave(example.Rtex) in R it seems working, but when I run
 the Latex file it doesn't. The code error shown to me is below:

 *Runaway argument?
 {echo=FALSE}
 data- read.csv(C:\\Users\\Daniele\\Desktop\\dati\\dati_england
 ! File ended while scanning use of \FV@BeginScanning.
 inserted text
                 \par
 * ...le/Desktop/dati/LaTeX1.Rtex*

 The Sweave code in Latex is like this:

 *\begin{Scode}{echo=FALSE}
 data-
 read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
 \end{Scode}
 \begin{figure}[!h]
 \centering
 \begin{Scode}{fig=TRUE, width=6, height=9, echo=FALSE}
 data1=matrix(0,ncol=4,nrow=4)
 
 
 \end{Scode}
 \caption{Data}
 \end{figure}*

 I don't know how to fix this problem. Any advices?
 Thanks very much

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Sweave-doesn-t-work-tp3758658p3758658.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.

 --
 Eik Vettorazzi

 Department of Medical Biometry and Epidemiology
 University Medical Center Hamburg-Eppendorf

 Martinistr. 52
 20246 Hamburg

 T ++49/40/7410-58243
 F ++49/40/7410-57790

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/


example.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] neuralnet

2011-08-22 Thread azam jaafari
Hi
 
I used neuralnet for predciton new covarites. Ir give me the predictions as 
matrix 1*, . I want to convert the predictions to grid map. 
 
Please help me
 
Thank you so much
[[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] Calculating p-value for 1-tailed test in a linear model

2011-08-22 Thread Andrew Campomizzi
David,
It's fair to question my intentions.  I'm running power analyses using
simulations (based on Bolker's Ecological Models and Data in R) and need to
provide decision-makers with options.  So, I'm attempting to make it clear
that if the research hypothesis (e.g., response variable declines with an
increase in predictor variable) can be clearly answered with a 1-tailed
test, then one might need a sample size of n to get a particular power,
given variance and alpha.
I think Mark's response answers my question.
Thanks,
Andy

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Saturday, August 20, 2011 6:02 PM
To: Andrew Campomizzi
Cc: r-help@r-project.org
Subject: Re: [R] Calculating p-value for 1-tailed test in a linear model


On Aug 19, 2011, at 6:20 PM, Andrew Campomizzi wrote:

 Hello,

 I'm having trouble figuring out how to calculate a p-value for a 1- 
 tailed
 test of beta_1 in a linear model fit using command lm.  My model has  
 only 1
 continuous, predictor variable.  I want to test the null hypothesis  
 beta_1
 is = 0.  I can calculate the p-value for a 2-tailed test using the  
 code
 2*pt(-abs(t-value), df=degrees.freedom), where t-value and  
 degrees.freedom
 are values provided in the summary of the lm.  The resulting p-value  
 is the
 same as provided by the summary of the lm for beta_1.  I'm unsure  
 how to
 change my calculation of the p-value for a 1-tailed test.

You need to clearly state your hypothesis. Then using the output from  
the regression function should be straightforward.

(Yes. this is a intentionally vague answer designed to elicit further  
information about your understanding of the statistical issues and how  
they relate to your domain knowledge. Many time peole already have the  
data and because they didn't get the answer they wanted, they search  
for other ways to game the system by ad-hoc changes in the  
statistical rules of the road.)

--

David Winsemius, MD
West Hartford, CT

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


[R] d, p, q, r - What are the math relations with each other of this functions?

2011-08-22 Thread . .
Hi all,

Using the exponential distribution to exemplify: The dexp function is
the PDF (1) and pexp is the CDF (2), that is obtained integrating the
PDF. How can I get the qexp and the rexp? Considering that I have the
PDF, how this two are mathematically related to the PDF?

(1) ke^{-kx}
(2) 1-e^{kx}

Thanks in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to ggplot2 conversion help

2011-08-22 Thread ashz
Hi,

I am interested in ggplot2 and I found this lattice code very interesting
(http://addictedtor.free.fr/graphiques/graphcode.php?graph=48).

Code:
library(lattice) 
lattice.options(default.theme = canonical.theme(color = FALSE)) 


tmp -
expand.grid(geology = c(Sand,Clay,Silt,Rock), 
species = c(ArisDiff, BracSera, CynDact,
ElioMuti, EragCurS, EragPseu),
dist = seq(1,9,1) ) 

tmp$height - rnorm(216) 


sp - list(superpose.symbol = list(pch = 1:6, cex = 1.2), 
   superpose.line = list(col = grey, lty = 1)) 

# print is needed when you source() the file
print(xyplot(height ~ dist | geology, data = tmp, 
   groups = species,
   layout = c(2,2), 
   panel = function(x, y, type, ...) {
 panel.superpose(x, y, type=l, ...)
 lpoints(x, y, pch=16, col=white, cex=2) 
 panel.superpose(x, y, type=p,...)
   },
   par.settings = sp, 
   auto.key = list(columns = 2, lines = TRUE))) 



I will be very happy if someone can please explain me how to do it in
ggplot2 as it will be great help.

Cheers,
Ashz


--
View this message in context: 
http://r.789695.n4.nabble.com/lattice-to-ggplot2-conversion-help-tp3760001p3760001.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] Multiple forest plots with the same x-axis and colour coded estimates and lines

2011-08-22 Thread Laura Bonnett
Dear all,

I would like to draw three forest plots to represent results at years 1, 2
and 3.  I have the data as point estimates and 95% confidence intervals.
Using the following code I can get three basic forest plots - the first
which has the table of results.  I have to plot each separately as the usual
par(mfrow=c(3,1)) does not work with the function forestplot within rmeta.
I can easily put them next to one another within powerpoint or similar
though so that's not a problem.

#Read data in
dattabrem1 - read.table(risk factors rem1.txt,header=TRUE) # year 1
results
dattabrem2 - read.table(risk factors rem2.txt,header=TRUE) # year 2
results
dattabrem3 - read.table(risk factors rem3.txt,header=TRUE) # year 3
results

# Set up table of results for the three plots
plotextr -
rbind(c(Age,Gender,Seizures,Treatment),c(10,M,2,CBZ),c(10,F,2,CBZ),
c(10,M,2,LTG),c(10,F,2,LTG),c(10,M,10,CBZ),c(10,F,10,CBZ),
c(10,M,10,LTG),c(10,F,10,LTG),c(40,M,2,CBZ),c(40,F,2,CBZ),
c(40,M,2,LTG),c(40,F,2,LTG),c(40,M,10,CBZ),c(40,F,10,CBZ),
c(40,M,10,LTG),c(40,F,10,LTG),c(75,M,2,CBZ),c(75,F,2,CBZ),
c(75,M,2,LTG),c(75,F,2,LTG),c(75,M,10,CBZ),c(75,F,10,CBZ),
c(75,M,10,LTG),c(75,F,10,LTG))

# 1 year results
estimate1y - c(NA,dattabrem1$HR)
lowerd1y - c(NA,dattabrem1$CIlower)
upperd1y - c(NA,dattabrem1$CIupper)
# 2 year results
estimate2y - c(NA,dattabrem2$HR)
lowerd2y - c(NA,dattabrem2$CIlower)
upperd2y - c(NA,dattabrem2$CIupper)
# 3 year results
estimate3y - c(NA,dattabrem3$HR)
lowerd3y - c(NA,dattabrem3$CIlower)
upperd3y - c(NA,dattabrem3$CIupper)

# Draw forest plots
forestplot(plotextr,estimate1y,lowerd1y,upperd1y,is.summary=c(TRUE,rep(FALSE,24)),zero=,align=c,xlab=Remission
@ 1 year)
forestplot(plotext2r,estimate2y,lowerd2y,upperd2y,zero=,xlab=Remission @
2 years)
forestplot(plotext2r,estimate3y,lowerd3y,upperd3y,zero=,xlab=Remission @
3 years)

Having managed to obtain these basic plots I need the x-axes to be the
same.  Usually xlim would be sufficient to do this but this function is not
avaialble within forestplot so does anyone know how I can make the x-axes
the same over all the plots?

Additionally, within each plot, two treatments are compared (top two blocks
are treatment 1, 2nd 2 blocks are treatment 2, next 2 are treatment 1 etc.)
Is there any way I can colour code the boxes to show this?

Many thanks,
Laura
P.S. I'm using Windows, R 2.9.2

[[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 the ConText editor?

2011-08-22 Thread Robert Lundqvist
In my orgainzation, the people resonsible for the network are not that keen on 
setting up new software, so when I asked them to set up emacs or some other 
common R editor, I was told to have a look at ConText. This editor is avaliable 
in the network, and there is some R support. Special commands are highlighted 
and such, but the most important part, sending commands writtten in a ConText 
window into R is something I haven't been able to do. Anyone who has tried and 
made it work?

Robert
**
Robert Lundqvist
Norrbotten regional council
Sweden


[[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] Extracting columns with specific string in their names

2011-08-22 Thread Jay
Hi,

Let's say that I have a set of column names that begin with the string
Xyz. How do I extract these specific columns? I tried to do the
following:

dataframe1[,grep(Xyz,colnames(dataframe1))]

But it does not work. What is wrong with my expression?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting cases from matrices stored in lists

2011-08-22 Thread mdvaan

Jean V Adams wrote:
 
 [R] Selecting cases from matrices stored in lists
 mdvaan 
 to:
 r-help
 08/22/2011 07:24 AM
 
 Hi,
 
 I have two lists (c and h - see below) containing matrices with similar
 cases but different values. I want to split these matrices into multiple
 matrices based on the values in h. So, I did the following:
 
 years-c(1997:1999) 
 for (t in 1:length(years)) 
 { 
 year=as.character(years[t]) 
 h[[year]]-sapply(colnames(h[[year]]), function(var)
 h[[year]][h[[year]][,var]0, h[[year]][var,]0]) 
 } 
 
 Now that I have created list h (with split matrices), I would like to 
 use
 these selections to make similar selections in list c. List c needs to 
 get
 the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) looks
 like this: 
 
 $`1997`$`8026` 
   B 
 B  8025 8026 8029 
   8025   1.000 0.7739527 0.9656091 
   8026   0.7739527 1.000 0.7202771 
   8029   0.9656091 0.7202771 1.000 
 
 Can anyone help me doing this? I have no idea how I can get it to work.
 Thank you very much for your help! 
 
 
 Try this:
 
 c2 - h
 years - names(h)
 for (t in seq(years))
 { 
 year - years[t]
 c2[[year]] - sapply(colnames(h[[year]]), function(var) 
 c[[t]][h[[year]][ ,var]  0, h[[year]][var, ]  0]) 
 }
 
 By the way, it's great that you included code in your question.
 However, I encountered a couple of errors when running you code (see 
 below).
 
 Also, it would be better to use a different name for your list c, 
 because c() is a function in R.
 
 Jean
 
 
 library(zoo) 
 DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
 8025  1995  0  4  1  2 
 8025  1997  1  1  3  4 
 8026  1995  0  7  0  0 
 8026  1996  1  2  3  0 
 8026  1997  1  2  3  1 
 8026  1998  6  0  0  4 
 8026  1999  3  7  0  3 
 8027  1997  1  2  3  9 
 8027  1998  1  2  3  1 
 8027  1999  6  0  0  2 
 8028  1999  3  7  0  0 
 8029  1995  0  2  3  3 
 8029  1998  1  2  3  2 
 8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
 
 a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
 sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA 
 b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 
 
 Error in FUN(cdata[st, i], ...) : unused argument(s) (partial = TRUE)
 
 rollapply() has no argument partial.
 
 newDF - lapply(1:nrow(b), function(i) 
   prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, 
 dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 1)) 
 
 names(newDF) - time(a) 
 
 Error in names(newDF) - time(a) : 
   'names' attribute [5] must be the same length as the vector [3]
 
 newDF has only 3 names, but time(a) is of length 5.
 
 c-lapply(newDF, function(mat) tcrossprod(mat / sqrt(rowSums(mat^2 
 
 DF2 = data.frame(read.table(textConnection(  A  B  C 
 80  8025  1995 
 80  8026  1995 
 80  8029  1995 
 81  8026  1996 
 82  8025  1997 
 82  8026  1997 
 83  8025  1997 
 83  8027  1997 
 90  8026  1998 
 90  8027  1998 
 90  8029  1998 
 84  8026  1999 
 84  8027  1999 
 85  8028  1999 
 85  8029  1999),head=TRUE,stringsAsFactors=FALSE)) 
 
 e - function(y) crossprod(table(DF2[DF2$C %in% y, 1:2])) 
 years - sort(unique(DF2$C)) 
 f - as.data.frame(embed(years, 3)) 
 g-lapply(split(f, f[, 1]), e) 
 h-lapply(g, function (x) ifelse(x0,1,0)) 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

Sorry, I am using the devel version of zoo which allows you to use the
partial argument. The correct code is given below. 

I didn't get your suggestion to work. If I understand what you are trying to
do (multiplying c and h), this is likely to give the wrong results because h
contains values of 0. Since I am ultimately interested in the values of the
split matrices in c (based on the original matrices in c), this will
probable not work. Or am I just not understanding you? 

Thanks!  

# devel version of zoo
install.packages(zoo, repos = http://r-forge.r-project.org;)
library(zoo)
DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
8025  1995  0  4  1  2 
8025  1997  1  1  3  4 
8026  1995  0  7  0  0 
8026  1996  1  2  3  0 
8026  1997  1  2  3  1 
8026  1998  6  0  0  4 
8026  1999  3  7  0  3 
8027  1997  1  2  3  9 
8027  1998  1  2  3  1 
8027  1999  6  0  0  2 
8028  1999  3  7  0  0 
8029  1995  0  2  3  3 
8029  1998  1  2  3  2 
8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
  
a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA 
b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 
newDF - lapply(1:nrow(b), function(i) 
  

Re: [R] Calculating p-value for 1-tailed test in a linear model

2011-08-22 Thread Andrew Campomizzi
It's not that it's known to be false, rather it's not of interest in this
case.  If animal density (response) decreases with increasing year
(predictor), then a change in land management practices might be needed.
Whereas, if animal density is increasing, then the status quo should
suffice.  Decision makers might decide they only need to know if density is
decreasing so that management actions can be taken to mitigate the problem.

Mark's message:
Hi: jake the value of beta_ j hat ( whatever the coefficient is from the
output ) along with the standard deviation of that coefficient , sigma_ j
hat.

Then, if you want to test the alternative that beta is greater than zero,
then calculate

t* = (beta _j - 0)/sigma_j

and 1-pt(t*, df) will give you the p-value.

the only slightly tricky part tricky part is getting sigma_j hat. If you
take the summary of the lm and call it summlm. then take diag(summlm$cov)
and then the sigma_ j hat that you want is depends on which coefficient you
want to test. if you want the third coefficient, then take the third one
etc.

   mark

p.s: you could also divide the two tailed pvalue that have by 2 and that
will give you the right answer also but it doesn't show the understanding.

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Monday, August 22, 2011 9:12 AM
To: Andrew Campomizzi
Cc: r-help@r-project.org
Subject: Re: [R] Calculating p-value for 1-tailed test in a linear model


On Aug 22, 2011, at 9:44 AM, Andrew Campomizzi wrote:

 David,
 It's fair to question my intentions.  I'm running power analyses using
 simulations (based on Bolker's Ecological Models and Data in R) and  
 need to
 provide decision-makers with options.  So, I'm attempting to make it  
 clear
 that if the research hypothesis (e.g., response variable declines  
 with an
 increase in predictor variable) can be clearly answered with a 1- 
 tailed
 test, then one might need a sample size of n to get a particular  
 power,
 given variance and alpha.

So the possibility that the response variable will be increased by the  
predictor variable is known to be false? It would be unusual to have  
such prior knowledge but I suppose it is possible if the starting  
point is at the ceiling, but then typical regression methods may not  
be appropriate.

 I think Mark's response answers my question.

Mark's response was not copied to the list.

-- 
David.
 Thanks,
 Andy

 -Original Message-
 From: David Winsemius [mailto:dwinsem...@comcast.net]
 Sent: Saturday, August 20, 2011 6:02 PM
 To: Andrew Campomizzi
 Cc: r-help@r-project.org
 Subject: Re: [R] Calculating p-value for 1-tailed test in a linear  
 model


 On Aug 19, 2011, at 6:20 PM, Andrew Campomizzi wrote:

 Hello,

 I'm having trouble figuring out how to calculate a p-value for a 1-
 tailed
 test of beta_1 in a linear model fit using command lm.  My model has
 only 1
 continuous, predictor variable.  I want to test the null hypothesis
 beta_1
 is = 0.  I can calculate the p-value for a 2-tailed test using the
 code
 2*pt(-abs(t-value), df=degrees.freedom), where t-value and
 degrees.freedom
 are values provided in the summary of the lm.  The resulting p-value
 is the
 same as provided by the summary of the lm for beta_1.  I'm unsure
 how to
 change my calculation of the p-value for a 1-tailed test.

 You need to clearly state your hypothesis. Then using the output from
 the regression function should be straightforward.

 (Yes. this is a intentionally vague answer designed to elicit further
 information about your understanding of the statistical issues and how
 they relate to your domain knowledge. Many time peole already have the
 data and because they didn't get the answer they wanted, they search
 for other ways to game the system by ad-hoc changes in the
 statistical rules of the road.)

 --

 David Winsemius, MD
 West Hartford, CT



David Winsemius, MD
West Hartford, CT

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


Re: [R] Coding question for behavioral data analysis

2011-08-22 Thread jabroesch
Thank you both for the replies. While neither produced the exact desired
results, they spurred some new thinking about how to approach the problem. I
came up with a way to get the output desired, but it is probably pretty
clunky. I will post it here anyway, in case someone is interested in the
future. 

TimeG=mydata$Time[mydata$Behavior == g]

TimeA=mydata$Time[mydata$Behavior == a]
#next line prevents errors for when there are no instances of a given
behavior by creating a blank file
ifelse( (sum(mydata$Time[mydata$Behavior == a])==0), TimeA-0,
TimeA-TimeA)
outBehavA-data.frame(matrix(ncol =length(TimeA), nrow =length(TimeG)))

for (j in 1:length(TimeA)){
for (i in 1:length(TimeG)){
outBehavA[i,j]=TimeA[j]-TimeG[i] }}

rowmin=apply(outBehavA, 1, function(x) min(x[x=0]))
A-rowmin
t(A)

timedif-data.frame(A)


TimeG=mydata$Time[mydata$Behavior == g]

TimeZ=mydata$Time[mydata$Behavior == z]
ifelse( (sum(mydata$Time[mydata$Behavior == z])==0), TimeZ-0,
TimeZ-TimeZ)
outBehavZ-data.frame(matrix(ncol =length(TimeZ), nrow =length(TimeG)))

for (j in 1:length(TimeZ)){
for (i in 1:length(TimeG)){
outBehavZ[i,j]=TimeZ[j]-TimeG[i] }}

rowmin=apply(outBehavZ, 1, function(x) min(x[x=0]))
Z-rowmin
t(Z)


timedif-cbind(Z)

#removing all values over 1000miliseconds
timedif-as.data.frame(timedif)

timedif-apply(timedif, c(1,2), function(x) ifelse(x  1000,
x-NA, x-x))
timedif-as.data.frame(timedif)

#then retain only minimum(first behavior)
for (i in 1:nrow(timedif)){
t-which.min(timedif[i,])
timedif[i,t]-1
}
timedif-apply(timedif, c(1,2), function(x) ifelse(x ==1,
x-x, x-0))
timedif-as.data.frame(timedif)

#sumarizing for each subject

number_of_target_behaviors-nrow(timedif)

#number of times a behavior was responed to within 1000ms

rowsums1-rowSums (timedif, na.rm = TRUE, dims = 1)
number_of_contingent_responses_across_domains-sum(rowsums1)


#number_of_contingent_responses_in each domain

sumofcolumns-colSums (timedif, na.rm = TRUE, dims = 1)

--
View this message in context: 
http://r.789695.n4.nabble.com/Coding-question-for-behavioral-data-analysis-tp3753151p3760249.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] Sweave doesn't work

2011-08-22 Thread Eik Vettorazzi
Hi Josh,
you are absolutly right. Thanks for pointing that out. It is the
Scode- environment which causes the error in TeX.

@Daniele:
have a look at the Sweave user manual (page 7ff) and try

Sweave('example.Rtex',syntax=SweaveSyntaxLatex)

Your Scode block should not be asterisked. I don't know if this is the
case in your primary Sweave-file since you only provided the LaTeX output...

Cheers

Am 22.08.2011 16:14, schrieb Joshua Wiley:
 Hi Eik,
 
 On Mon, Aug 22, 2011 at 4:14 AM, Eik Vettorazzi
 e.vettora...@uke.uni-hamburg.de wrote:
 Hi Daniele,
 _ in dati_england is treated as a special character in LaTeX math
 mode and causes your LaTeX-compiler trying to switch to math mode (you
 might have noticed a warning abaout missing `$' inserted). To produce
 a plain _ in TeX you have to mask it as \_. Package Hmisc has some
 
 This is true in the regular environment, but should not be true for
 code.  Think about all the special characters encountered in R code---
 $, quotes, _ ^.  The following minimal document compiles fine on my
 system:
 
 \documentclass{article}
 \usepackage{Sweave}
 \begin{document}
 \section{Example showing underscores works fine inside an Schunk}
 \begin{Schunk}
 \begin{Sinput}
 data-
 read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
 \end{Sinput}
 \end{Schunk}
 \end{document}
 
 producing the attached PDF.
 
 My system:
 
 R Under development (unstable) (2011-08-13 r56733)
 Platform: x86_64-pc-mingw32/x64 (64-bit)
 
 Version 0.3 r.670 (MiKTeX 2.9)
 
 Josh
 
 sanitization methods for that task, but you can do that easily by hand
 using gsub.

 Cheers.

 Am 21.08.2011 18:18, schrieb danielepippo:
 Hi R users.

 I've got a problem in producing the pdf file from Latex with R code. When I
 run the code Sweave(example.Rtex) in R it seems working, but when I run
 the Latex file it doesn't. The code error shown to me is below:

 *Runaway argument?
 {echo=FALSE}
 data- read.csv(C:\\Users\\Daniele\\Desktop\\dati\\dati_england
 ! File ended while scanning use of \FV@BeginScanning.
 inserted text
 \par
 * ...le/Desktop/dati/LaTeX1.Rtex*

 The Sweave code in Latex is like this:

 *\begin{Scode}{echo=FALSE}
 data-
 read.csv(c:\\Users\\Daniele\\Desktop\\dati\\dati_england.csv,header=T,sep=,)
 \end{Scode}
 \begin{figure}[!h]
 \centering
 \begin{Scode}{fig=TRUE, width=6, height=9, echo=FALSE}
 data1=matrix(0,ncol=4,nrow=4)
 
 
 \end{Scode}
 \caption{Data}
 \end{figure}*

 I don't know how to fix this problem. Any advices?
 Thanks very much

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Sweave-doesn-t-work-tp3758658p3758658.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.

 --
 Eik Vettorazzi

 Department of Medical Biometry and Epidemiology
 University Medical Center Hamburg-Eppendorf

 Martinistr. 52
 20246 Hamburg

 T ++49/40/7410-58243
 F ++49/40/7410-57790

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

 
 
 

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] d, p, q, r - What are the math relations with each other of this functions?

2011-08-22 Thread R. Michael Weylandt
Read the documentation by typing ?qexp (or whatever other function) at the
command line.

But, since you asked and it won't take long to answer, the general pattern
is:

rDIST gives random numbers sampled from the distribution
dDIST gives the PDF
pDIST gives the CDF
qDIST gives the quantile function (which can be thought of as the inverse
CDF)

To see that last relationship, try

curve(qexp(pexp(x)) or curve(pexp(qexp(x))

Hope this helps, but really -- read the help first. I could get it if you
didn't get what qDIST was from the documentation, but you should have gotten
rDIST.

Happy R-ing,

Michael Weylandt

On Mon, Aug 22, 2011 at 8:55 AM, . . xkzi...@gmail.com wrote:

 Hi all,

 Using the exponential distribution to exemplify: The dexp function is
 the PDF (1) and pexp is the CDF (2), that is obtained integrating the
 PDF. How can I get the qexp and the rexp? Considering that I have the
 PDF, how this two are mathematically related to the PDF?

 (1) ke^{-kx}
 (2) 1-e^{kx}

 Thanks in advance.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Extracting columns with specific string in their names

2011-08-22 Thread R. Michael Weylandt
Can you say a little more about what you mean it does not work? I'd guess
you have a regular expression mistake and are probably getting more columns
than desired, but without an example, it's hard to be certain.

Use dput() and head() to give a small cut-and-paste-able example.

Michael

On Mon, Aug 22, 2011 at 10:33 AM, Jay josip.2...@gmail.com wrote:

 Hi,

 Let's say that I have a set of column names that begin with the string
 Xyz. How do I extract these specific columns? I tried to do the
 following:

 dataframe1[,grep(Xyz,colnames(dataframe1))]

 But it does not work. What is wrong with my expression?

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Selecting cases from matrices stored in lists

2011-08-22 Thread Gabor Grothendieck
On Mon, Aug 22, 2011 at 9:07 AM, Jean V Adams jvad...@usgs.gov wrote:
 [R] Selecting cases from matrices stored in lists
 mdvaan
 to:
 r-help
 08/22/2011 07:24 AM

 Hi,

 I have two lists (c and h - see below) containing matrices with similar
 cases but different values. I want to split these matrices into multiple
 matrices based on the values in h. So, I did the following:

 years-c(1997:1999)
 for (t in 1:length(years))
         {
         year=as.character(years[t])
         h[[year]]-sapply(colnames(h[[year]]), function(var)
 h[[year]][h[[year]][,var]0, h[[year]][var,]0])
         }

 Now that I have created list h (with split matrices), I would like to
 use
 these selections to make similar selections in list c. List c needs to
 get
 the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) looks
 like this:

 $`1997`$`8026`
       B
 B      8025 8026 8029
   8025   1.000 0.7739527 0.9656091
   8026   0.7739527 1.000 0.7202771
   8029   0.9656091 0.7202771 1.000

 Can anyone help me doing this? I have no idea how I can get it to work.
 Thank you very much for your help!


 Try this:

 c2 - h
 years - names(h)
 for (t in seq(years))
        {
        year - years[t]
        c2[[year]] - sapply(colnames(h[[year]]), function(var)
                c[[t]][h[[year]][ ,var]  0, h[[year]][var, ]  0])
        }

 By the way, it's great that you included code in your question.
 However, I encountered a couple of errors when running you code (see
 below).

 Also, it would be better to use a different name for your list c,
 because c() is a function in R.

 Jean


 library(zoo)
 DF1 = data.frame(read.table(textConnection(    B  C  D  E  F  G
 8025  1995  0  4  1  2
 8025  1997  1  1  3  4
 8026  1995  0  7  0  0
 8026  1996  1  2  3  0
 8026  1997  1  2  3  1
 8026  1998  6  0  0  4
 8026  1999  3  7  0  3
 8027  1997  1  2  3  9
 8027  1998  1  2  3  1
 8027  1999  6  0  0  2
 8028  1999  3  7  0  0
 8029  1995  0  2  3  3
 8029  1998  1  2  3  2
 8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE))

 a - read.zoo(DF1, split = 1, index = 2, FUN = identity)
 sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else NA
 b - rollapply(a, 3,  sum.na, align = right, partial = TRUE)

 Error in FUN(cdata[st, i], ...) : unused argument(s) (partial = TRUE)

 rollapply() has no argument partial.

rollapply was re-written for zoo 1.7.0 and the partial argument was
among the enhancements.


-- 
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] lattice to ggplot2 conversion help

2011-08-22 Thread Ista Zahn
Hi Ashz,

On Mon, Aug 22, 2011 at 8:42 AM, ashz a...@walla.co.il wrote:
 Hi,

 I am interested in ggplot2 and I found this lattice code very interesting
 (http://addictedtor.free.fr/graphiques/graphcode.php?graph=48).

 Code:
 library(lattice)
 lattice.options(default.theme = canonical.theme(color = FALSE))


 tmp -
    expand.grid(geology = c(Sand,Clay,Silt,Rock),
                species = c(ArisDiff, BracSera, CynDact,
                            ElioMuti, EragCurS, EragPseu),
                dist = seq(1,9,1) )

 tmp$height - rnorm(216)


 sp - list(superpose.symbol = list(pch = 1:6, cex = 1.2),
           superpose.line = list(col = grey, lty = 1))

 # print is needed when you source() the file
 print(xyplot(height ~ dist | geology, data = tmp,
       groups = species,
       layout = c(2,2),
       panel = function(x, y, type, ...) {
         panel.superpose(x, y, type=l, ...)
         lpoints(x, y, pch=16, col=white, cex=2)
         panel.superpose(x, y, type=p,...)
       },
       par.settings = sp,
       auto.key = list(columns = 2, lines = TRUE)))



 I will be very happy if someone can please explain me how to do it in
 ggplot2 as it will be great help.

The basic plot can be created with

ggplot(tmp, aes(x = dist, y = height)) +
  geom_point(aes(shape = species)) +
  geom_line(aes(group = species)) +
  facet_wrap(~geology)

and some of the formatting can be reproduced with

ggplot(tmp, aes(x = dist, y = height)) +
  geom_point(aes(shape = species), size = 4) +
  geom_line(aes(group = species), color = gray60) +
  facet_wrap(~geology) +
  theme_bw() +
  opts(legend.position = top, legend.direction = horizontal)

I do have to say that I think this graph is  a mess though. Too many
jumbled points and lines to easily make sense of it. I would go with
small multiples all the way:

ggplot(tmp, aes(x = dist, y = height)) +
  geom_point() +
  geom_line() +
  facet_grid(species~geology) +
  theme_bw() +
  opts(legend.position = top, legend.direction = horizontal)

as this seems like a much clearer presentation of the data.

Best,
Ista

 Cheers,
 Ashz


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/lattice-to-ggplot2-conversion-help-tp3760001p3760001.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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] How to add horizontal lines above bar graph to display p-values?

2011-08-22 Thread Sébastien Vigneau
Thanks!

Sebastien


2011/8/20 Uwe Ligges lig...@statistik.tu-dortmund.de



 On 19.08.2011 22:27, Sébastien Vigneau wrote:

 Hi,

 I would like to draw horizontal lines above a bar graph, in order to
 display
 the p-values of a Fisher test. Here is an
 examplehttp://thejns.org/**action/showPopup?citid=**
 citart1id=f3-1060501doi=10.**3171%2Fped.2007.106.6.501http://thejns.org/action/showPopup?citid=citart1id=f3-1060501doi=10.3171%2Fped.2007.106.6.501
 of

 the type of display I would like to have. Is there a way to draw the
 horizontal lines


 See ?abline, ?lines, ?segments, 



  and write their associated p-values in R?


 See ?text

 Uwe Ligges



 Thanks for you help!

 Sebastien Vigneau

[[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] pooled hazard model with aftreg and time-dependent variables

2011-08-22 Thread JPF
In STATA,
 
multiple observations correspond to the same individual, the cluster( )
option can be employed to 
request that the analysis be clustered by individual. 

Any suggestion with aftreg?

Thanks,

J

--
View this message in context: 
http://r.789695.n4.nabble.com/pooled-hazard-model-with-aftreg-and-time-dependent-variables-tp3758805p3760440.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] Selecting cases from matrices stored in lists

2011-08-22 Thread Jean V Adams
 Re: [R] Selecting cases from matrices stored in lists
 mdvaan 
 to:
 r-help
 08/22/2011 09:46 AM
 
 Jean V Adams wrote:
  
  [R] Selecting cases from matrices stored in lists
  mdvaan 
  to:
  r-help
  08/22/2011 07:24 AM
  
  Hi,
  
  I have two lists (c and h - see below) containing matrices with 
similar
  cases but different values. I want to split these matrices into 
multiple
  matrices based on the values in h. So, I did the following:
  
  years-c(1997:1999) 
  for (t in 1:length(years)) 
  { 
  year=as.character(years[t]) 
  h[[year]]-sapply(colnames(h[[year]]), function(var)
  h[[year]][h[[year]][,var]0, h[[year]][var,]0]) 
  } 
  
  Now that I have created list h (with split matrices), I would like to 

  use
  these selections to make similar selections in list c. List c needs 
to 
  get
  the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) 
looks
  like this: 
  
  $`1997`$`8026` 
B 
  B  8025 8026 8029 
8025   1.000 0.7739527 0.9656091 
8026   0.7739527 1.000 0.7202771 
8029   0.9656091 0.7202771 1.000 
  
  Can anyone help me doing this? I have no idea how I can get it to 
work.
  Thank you very much for your help! 
  
  
  Try this:
  
  c2 - h
  years - names(h)
  for (t in seq(years))
  { 
  year - years[t]
  c2[[year]] - sapply(colnames(h[[year]]), function(var) 
  c[[t]][h[[year]][ ,var]  0, h[[year]][var, ]  0]) 
  }
  
  By the way, it's great that you included code in your question.
  However, I encountered a couple of errors when running you code (see 
  below).
  
  Also, it would be better to use a different name for your list c, 
  because c() is a function in R.
  
  Jean
  
  
  library(zoo) 
  DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
  8025  1995  0  4  1  2 
  8025  1997  1  1  3  4 
  8026  1995  0  7  0  0 
  8026  1996  1  2  3  0 
  8026  1997  1  2  3  1 
  8026  1998  6  0  0  4 
  8026  1999  3  7  0  3 
  8027  1997  1  2  3  9 
  8027  1998  1  2  3  1 
  8027  1999  6  0  0  2 
  8028  1999  3  7  0  0 
  8029  1995  0  2  3  3 
  8029  1998  1  2  3  2 
  8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
  
  a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
  sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else 
NA 
  b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 
  
  Error in FUN(cdata[st, i], ...) : unused argument(s) (partial = TRUE)
  
  rollapply() has no argument partial.
  
  newDF - lapply(1:nrow(b), function(i) 
prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, 
  dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 
1)) 
  
  names(newDF) - time(a) 
  
  Error in names(newDF) - time(a) : 
'names' attribute [5] must be the same length as the vector [3]
  
  newDF has only 3 names, but time(a) is of length 5.
  
  c-lapply(newDF, function(mat) tcrossprod(mat / 
sqrt(rowSums(mat^2 
  
  DF2 = data.frame(read.table(textConnection(  A  B  C 
  80  8025  1995 
  80  8026  1995 
  80  8029  1995 
  81  8026  1996 
  82  8025  1997 
  82  8026  1997 
  83  8025  1997 
  83  8027  1997 
  90  8026  1998 
  90  8027  1998 
  90  8029  1998 
  84  8026  1999 
  84  8027  1999 
  85  8028  1999 
  85  8029  1999),head=TRUE,stringsAsFactors=FALSE)) 
  
  e - function(y) crossprod(table(DF2[DF2$C %in% y, 1:2])) 
  years - sort(unique(DF2$C)) 
  f - as.data.frame(embed(years, 3)) 
  g-lapply(split(f, f[, 1]), e) 
  h-lapply(g, function (x) ifelse(x0,1,0)) 
 [[alternative HTML version deleted]]
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
 
 Sorry, I am using the devel version of zoo which allows you to use the
 partial argument. The correct code is given below. 

My error.  I didn't have the latest version installed.

 
 I didn't get your suggestion to work. If I understand what you are 
trying to
 do (multiplying c and h), this is likely to give the wrong results 
because h
 contains values of 0. Since I am ultimately interested in the values of 
the
 split matrices in c (based on the original matrices in c), this will
 probable not work. Or am I just not understanding you? 

I'm not doing any multiplication.  I just applied your extraction
[h[[year]][ ,var]  0, h[[year]][var, ]  0]
to the c list rather than the h list.

You say you didn't get it to work.  Did you get an error message?  Or did 
it run, but not give you the values you wanted?  Or ... ?

Jean

 
 Thanks! 
 
 # devel version of zoo
 install.packages(zoo, repos = http://r-forge.r-project.org;)
 library(zoo)
 DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
 8025  1995  0  4  1  2 
 8025  1997  1  

[R] Edit 2

2011-08-22 Thread RobinLovelace
Sorry to anyone who tried but failed to download the data - seems not to be
there.

Here's a new link to it please take a look.

http://ubuntuone.com/p/1C6U/

--
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-from-frequency-data-in-pre-made-bins-tp3758198p3760458.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] Multiple regression in R - unstandardised coefficients are a different sign to standardised coefficients, is this correct?

2011-08-22 Thread JC Matthews


Hello,

I have a statistical problem that I am using R for, but I am not making 
sense of the results. I am trying to use multiple regression to explore 
which variables (weather conditions) have the greater effect on a local 
atmospheric variable. The data is taken from a database that has 20391 data 
points (Z1).


A simplified version of the data I'm looking at is given below, but I have 
a problem in that there is a disagreement in sign between the regression 
coefficients and the standardised regression coefficients. Intuitively I 
would expect both to be the same sign, but in many of the parameters, they 
are not.


I am aware that there is a strong opinion that using standardised 
correlation coefficients is highly discouraged by some people, but I would 
nevertheless like to see the results. Not least because it has made me 
doubt the non-standardised values of B that R has given me.


The code I have used, and some of the data, is as follows (once the 
database has been imported from SQL, and outliers removed).




Z1sub  - Z1[, c(2, 5, 7,11, 12, 13, 15, 16)]
colnames(Z1sub) - c(temp, hum, wind, press, rain, s.rad, 
mean1, sd1 )


attach(Z1sub)
names(Z1sub)


Model1d - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) + I(rain^2) )

summary(Model1d)

Call:
lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
   I(rain^2))

Residuals:
Min   1Q   Median   3Q  Max
-1230.64   -63.1718.5197.85  1275.73

Coefficients:
   Estimate Std. Error t value Pr(|t|)
(Intercept)   -9.243e+02  5.689e+01 -16.246   2e-16 ***
hum2.835e+01  1.468e+00  19.312   2e-16 ***
wind   1.236e+02  4.832e+00  25.587   2e-16 ***
rain  -3.144e+03  7.635e+02  -4.118 3.84e-05 ***
I(hum^2)  -1.953e-01  9.393e-03 -20.793   2e-16 ***
I(wind^2)  6.914e-01  2.174e-01   3.181  0.00147 **
I(rain^2)  2.730e+02  3.265e+01   8.362   2e-16 ***
hum:wind  -1.782e+00  5.448e-02 -32.706   2e-16 ***
hum:rain   2.798e+01  8.410e+00   3.327  0.00088 ***
wind:rain  6.018e+02  2.146e+02   2.805  0.00504 **
hum:wind:rain -6.606e+00  2.401e+00  -2.751  0.00594 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 180.5 on 20337 degrees of freedom
Multiple R-squared: 0.2394, Adjusted R-squared: 0.239
F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16





To calculate the standardised coefficients, I used the following:

Z1sub.scaled - data.frame(scale( Z1sub[,c('temp', 'hum', 'wind', 'press', 
'rain', 's.rad', 'mean1', 'sd1' ) ] ) )


attach(Z1sub.scaled)
names(Z1sub.scaled)


Model1d.sc - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) + I(rain^2) )

summary(Model1d.scaled)

Call:
lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
   I(rain^2))

Residuals:
Min   1Q   Median   3Q  Max
-5.94713 -0.30527  0.08946  0.47287  6.16503

Coefficients:
   Estimate Std. Error t value Pr(|t|)
(Intercept)0.0806858  0.0096614   8.351   2e-16 ***
hum   -0.4581509  0.0073456 -62.371   2e-16 ***
wind  -0.1995316  0.0073767 -27.049   2e-16 ***
rain  -0.1806894  0.0158037 -11.433   2e-16 ***
I(hum^2)  -0.1120435  0.0053885 -20.793   2e-16 ***
I(wind^2)  0.0172870  0.0054346   3.181  0.00147 **
I(rain^2)  0.0040575  0.0004853   8.362   2e-16 ***
hum:wind  -0.2188729  0.0066659 -32.835   2e-16 ***
hum:rain   0.0267420  0.0146201   1.829  0.06740 .
wind:rain  0.0365615  0.0122335   2.989  0.00281 **
hum:wind:rain -0.0438790  0.0159479  -2.751  0.00594 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.8723 on 20337 degrees of freedom
Multiple R-squared: 0.2394, Adjusted R-squared: 0.239
F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16



So having, for instance for humidity (hum), B = 28.35 +/-  1.468, while 
Beta = -0.4581509 +/- 0.0073456 is concerning. Is this normal, or is there 
an error in my code that has caused this contradiction?


Many thanks,

James.


--
JC Matthews
School of Chemistry
Bristol University

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


[R] test if vector contains elements of another vector (disregarding the position)

2011-08-22 Thread Martin Batholdy
Hi,


I have the following problem:


I have two vectors:

i - c('a','c','g','h','b','d','f','k','l','e','i')

j - c('a', 'b', 'c')



now I would like to generate a vector with the length of i that 
has zeros where i[x] != any element of j 
and 1 where i[x] == any element of j.

So for the example above the vector would look like this:

c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0)



can someone help me on this?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] test if vector contains elements of another vector (disregarding the position)

2011-08-22 Thread R. Michael Weylandt
%in%

Here,

i %in% j

Hope this helps,

Michael

On Mon, Aug 22, 2011 at 11:51 AM, Martin Batholdy
batho...@googlemail.comwrote:

 Hi,


 I have the following problem:


 I have two vectors:

 i - c('a','c','g','h','b','d','f','k','l','e','i')

 j - c('a', 'b', 'c')



 now I would like to generate a vector with the length of i that
 has zeros where i[x] != any element of j
 and 1 where i[x] == any element of j.

 So for the example above the vector would look like this:

 c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0)



 can someone help me on this?

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Ignoring loadNamespace errors when loading a file

2011-08-22 Thread Allan Engelhardt



On 22/08/11 12:26, Martin Morgan wrote:

On 08/21/2011 11:52 PM, Allan Engelhardt wrote:

[...]
Obligatory reproducible example: On the Unix machine do

library(multicore)
a - list(data = 1:10, fun = mclapply)
save(a, file = a.RData)

and then try to load the a.RData file on Windows. The question is if I
can recover the data (1:10) on that platform.


Is this a more realistic reproducible example (from ?rfe, modified to 
use computeFunction=mclapply)?


  data(BloodBrain)

  x - scale(bbbDescr[,-nearZeroVar(bbbDescr)])
  x - x[, -findCorrelation(cor(x), .8)]
  x - as.data.frame(x)

  set.seed(1)
  lmProfile - rfe(x, logBBB,
   sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
   rfeControl = rfeControl(functions = lmFuncs,
 number = 5,
 computeFunction=mclapply))

Maybe provide a computeFunction that only indirectly references mclapply

  computeFunction=function(...) {
  if (require(multicore)) mclapply(...)
  else lapply(...)
  }

[...]


Yes, that workaround works for my usage.  Thanks!

Allan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple regression in R - unstandardised coefficients are a different sign to standardised coefficients, is this correct?

2011-08-22 Thread Ista Zahn
Hi JC,

You have interactions in your model, which means that your models
specifies that the coefficients for hum, wind, and rain should vary
depending on the value of the other two (and depending on their own
value actually, since you also have quadratic effects for each of
these variables in your model). Since these coefficients are varying
according to the model, it is impossible to specify their value
unconditionally. The values you are seeing are therefore conditional
estimates that at particular values on the variables with which each
predictor interacts. Since you've changed the distribution of those
variables by standardizing them, you get different conditional
estimates.

All this will be covered in most regression textbooks.

Best,
Ista

On Mon, Aug 22, 2011 at 11:37 AM, JC Matthews
j.c.matth...@bristol.ac.uk wrote:

 Hello,

 I have a statistical problem that I am using R for, but I am not making
 sense of the results. I am trying to use multiple regression to explore
 which variables (weather conditions) have the greater effect on a local
 atmospheric variable. The data is taken from a database that has 20391 data
 points (Z1).

 A simplified version of the data I'm looking at is given below, but I have a
 problem in that there is a disagreement in sign between the regression
 coefficients and the standardised regression coefficients. Intuitively I
 would expect both to be the same sign, but in many of the parameters, they
 are not.

 I am aware that there is a strong opinion that using standardised
 correlation coefficients is highly discouraged by some people, but I would
 nevertheless like to see the results. Not least because it has made me doubt
 the non-standardised values of B that R has given me.

 The code I have used, and some of the data, is as follows (once the database
 has been imported from SQL, and outliers removed).



 Z1sub  - Z1[, c(2, 5, 7,11, 12, 13, 15, 16)]
 colnames(Z1sub) - c(temp, hum, wind, press, rain, s.rad,
 mean1, sd1 )

 attach(Z1sub)
 names(Z1sub)


 Model1d - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) + I(rain^2) )

 summary(Model1d)

 Call:
 lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
   I(rain^2))

 Residuals:
    Min       1Q   Median       3Q      Max
 -1230.64   -63.17    18.51    97.85  1275.73

 Coefficients:
               Estimate Std. Error t value Pr(|t|)
 (Intercept)   -9.243e+02  5.689e+01 -16.246   2e-16 ***
 hum            2.835e+01  1.468e+00  19.312   2e-16 ***
 wind           1.236e+02  4.832e+00  25.587   2e-16 ***
 rain          -3.144e+03  7.635e+02  -4.118 3.84e-05 ***
 I(hum^2)      -1.953e-01  9.393e-03 -20.793   2e-16 ***
 I(wind^2)      6.914e-01  2.174e-01   3.181  0.00147 **
 I(rain^2)      2.730e+02  3.265e+01   8.362   2e-16 ***
 hum:wind      -1.782e+00  5.448e-02 -32.706   2e-16 ***
 hum:rain       2.798e+01  8.410e+00   3.327  0.00088 ***
 wind:rain      6.018e+02  2.146e+02   2.805  0.00504 **
 hum:wind:rain -6.606e+00  2.401e+00  -2.751  0.00594 **
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 180.5 on 20337 degrees of freedom
 Multiple R-squared: 0.2394,     Adjusted R-squared: 0.239
 F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16





 To calculate the standardised coefficients, I used the following:

 Z1sub.scaled - data.frame(scale( Z1sub[,c('temp', 'hum', 'wind', 'press',
 'rain', 's.rad', 'mean1', 'sd1' ) ] ) )

 attach(Z1sub.scaled)
 names(Z1sub.scaled)


 Model1d.sc - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) + I(rain^2) )

 summary(Model1d.scaled)

 Call:
 lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
   I(rain^2))

 Residuals:
    Min       1Q   Median       3Q      Max
 -5.94713 -0.30527  0.08946  0.47287  6.16503

 Coefficients:
               Estimate Std. Error t value Pr(|t|)
 (Intercept)    0.0806858  0.0096614   8.351   2e-16 ***
 hum           -0.4581509  0.0073456 -62.371   2e-16 ***
 wind          -0.1995316  0.0073767 -27.049   2e-16 ***
 rain          -0.1806894  0.0158037 -11.433   2e-16 ***
 I(hum^2)      -0.1120435  0.0053885 -20.793   2e-16 ***
 I(wind^2)      0.0172870  0.0054346   3.181  0.00147 **
 I(rain^2)      0.0040575  0.0004853   8.362   2e-16 ***
 hum:wind      -0.2188729  0.0066659 -32.835   2e-16 ***
 hum:rain       0.0267420  0.0146201   1.829  0.06740 .
 wind:rain      0.0365615  0.0122335   2.989  0.00281 **
 hum:wind:rain -0.0438790  0.0159479  -2.751  0.00594 **
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 0.8723 on 20337 degrees of freedom
 Multiple R-squared: 0.2394,     Adjusted R-squared: 0.239
 F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16



 So having, for instance for humidity (hum), B = 28.35 +/-  1.468, while Beta
 = -0.4581509 +/- 0.0073456 is concerning. Is this normal, or is there an
 error in my code that has caused this contradiction?

 Many thanks,

 James.


 --
 JC Matthews

[R] automatic file input

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

I have 100 files which are used as input.and I have to input the name of  my 
files again and again.the name of the files are 1.out, 2.out..100.out.
I want to know if there is anything like perl so that i can use something like 
this-


for($f = 1; $f = 100; $f++) {
  $file = $f..out;


I have tried this thing in R but it does not work.Can somebody please help me.



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] Extracting columns with specific string in their names

2011-08-22 Thread Jay
Sorry, my mistake. The thing is that the command return no results at
all. However, when I just tried a simpler version of this (I had no
capital letters or no spaces in the string), it worked fine. I cant
figure it out, I think it all boils down to the fact that I'm no
expert at regexp's...




On Aug 22, 5:53 pm, R. Michael Weylandt michael.weyla...@gmail.com
wrote:
 Can you say a little more about what you mean it does not work? I'd guess
 you have a regular expression mistake and are probably getting more columns
 than desired, but without an example, it's hard to be certain.

 Use dput() and head() to give a small cut-and-paste-able example.

 Michael









 On Mon, Aug 22, 2011 at 10:33 AM, Jay josip.2...@gmail.com wrote:
  Hi,

  Let's say that I have a set of column names that begin with the string
  Xyz. How do I extract these specific columns? I tried to do the
  following:

  dataframe1[,grep(Xyz,colnames(dataframe1))]

  But it does not work. What is wrong with my expression?

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

         [[alternative HTML version deleted]]

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://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] automatic file input

2011-08-22 Thread Ista Zahn
Hi Vikas,
please do make an effort to search for the answer before posting. A
google search for R read multiple files will give you everything you
need.

Best,
Ista

On Mon, Aug 22, 2011 at 12:08 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear all,

 I have 100 files which are used as input.and I have to input the name of  my 
 files again and again.the name of the files are 1.out, 2.out..100.out.
 I want to know if there is anything like perl so that i can use something 
 like this-


 for($f = 1; $f = 100; $f++) {
  $file = $f..out;


 I have tried this thing in R but it does not work.Can somebody please help me.



 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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] Multiple regression in R - unstandardised coefficients a

2011-08-22 Thread Ted Harding
On 22-Aug-11 15:37:40, JC Matthews wrote:
 Hello,
 
 I have a statistical problem that I am using R for, but I am
 not making sense of the results. I am trying to use multiple
 regression to explore which variables (weather conditions)
 have the greater effect on a local atmospheric variable.
 The data is taken from a database that has 20391 data points (Z1).
 
 A simplified version of the data I'm looking at is given below,
 but I have a problem in that there is a disagreement in sign
 between the regression coefficients and the standardised regression
 coefficients. Intuitively I would expect both to be the same sign,
 but in many of the parameters, they are not.
 
 I am aware that there is a strong opinion that using standardised 
 correlation coefficients is highly discouraged by some people,
 but I would nevertheless like to see the results. Not least
 because it has made me doubt the non-standardised values of B
 that R has given me.
 
 The code I have used, and some of the data, is as follows (once
 the database has been imported from SQL, and outliers removed).
 
 Z1sub  - Z1[, c(2, 5, 7,11, 12, 13, 15, 16)]
 colnames(Z1sub) - c(temp, hum, wind, press, rain, s.rad, 
 mean1, sd1 )
 
 attach(Z1sub)
 names(Z1sub)
 
 
 Model1d - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) + I(rain^2)
 )
 
 summary(Model1d)
 
 Call:
 lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
 I(rain^2))
 
 Residuals:
  Min   1Q   Median   3Q  Max
 -1230.64   -63.1718.5197.85  1275.73
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)   -9.243e+02  5.689e+01 -16.246   2e-16 ***
 hum2.835e+01  1.468e+00  19.312   2e-16 ***
 wind   1.236e+02  4.832e+00  25.587   2e-16 ***
 rain  -3.144e+03  7.635e+02  -4.118 3.84e-05 ***
 I(hum^2)  -1.953e-01  9.393e-03 -20.793   2e-16 ***
 I(wind^2)  6.914e-01  2.174e-01   3.181  0.00147 **
 I(rain^2)  2.730e+02  3.265e+01   8.362   2e-16 ***
 hum:wind  -1.782e+00  5.448e-02 -32.706   2e-16 ***
 hum:rain   2.798e+01  8.410e+00   3.327  0.00088 ***
 wind:rain  6.018e+02  2.146e+02   2.805  0.00504 **
 hum:wind:rain -6.606e+00  2.401e+00  -2.751  0.00594 **
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 180.5 on 20337 degrees of freedom
 Multiple R-squared: 0.2394, Adjusted R-squared: 0.239
 F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16
 
 
 
 
 
 To calculate the standardised coefficients, I used the following:
 
 Z1sub.scaled - data.frame(scale( Z1sub[,c('temp', 'hum', 'wind',
 'press', 
 'rain', 's.rad', 'mean1', 'sd1' ) ] ) )
 
 attach(Z1sub.scaled)
 names(Z1sub.scaled)
 
 
 Model1d.sc - lm(mean1 ~ hum*wind*rain +  I(hum^2) + I(wind^2) +
 I(rain^2) )
 
 summary(Model1d.scaled)
 
 Call:
 lm(formula = mean1 ~ hum * wind * rain + I(hum^2) + I(wind^2) +
 I(rain^2))
 
 Residuals:
  Min   1Q   Median   3Q  Max
 -5.94713 -0.30527  0.08946  0.47287  6.16503
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)0.0806858  0.0096614   8.351   2e-16 ***
 hum   -0.4581509  0.0073456 -62.371   2e-16 ***
 wind  -0.1995316  0.0073767 -27.049   2e-16 ***
 rain  -0.1806894  0.0158037 -11.433   2e-16 ***
 I(hum^2)  -0.1120435  0.0053885 -20.793   2e-16 ***
 I(wind^2)  0.0172870  0.0054346   3.181  0.00147 **
 I(rain^2)  0.0040575  0.0004853   8.362   2e-16 ***
 hum:wind  -0.2188729  0.0066659 -32.835   2e-16 ***
 hum:rain   0.0267420  0.0146201   1.829  0.06740 .
 wind:rain  0.0365615  0.0122335   2.989  0.00281 **
 hum:wind:rain -0.0438790  0.0159479  -2.751  0.00594 **
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 0.8723 on 20337 degrees of freedom
 Multiple R-squared: 0.2394, Adjusted R-squared: 0.239
 F-statistic: 640.2 on 10 and 20337 DF,  p-value:  2.2e-16
 
 
 
 So having, for instance for humidity (hum), B = 28.35 +/-  1.468, while
 Beta = -0.4581509 +/- 0.0073456 is concerning. Is this normal, or is
 there 
 an error in my code that has caused this contradiction?
 
 Many thanks,
 
 James.
 --
 JC Matthews
 School of Chemistry
 Bristol University

Hi,
without having your data, so unable to check, I would not be
surprised if the changes of sign were the outcome of your model
formula, in particular the 3-variable (2nd-order) interaction,
i.e. you are using a model which is non-linear in the variables
themselves. Let's just take that part of the model:

  lm(formula = mean1 ~ hum * wind * rain

This, in its quantitative expression, expands to:

  mean1 = C0 + C11*hum + C12*wind + C13*rain
 + C21*hum*wind + C22*hum*rain + C23*wind*rain
 + C31*hum*wind*rain

Suppose that is for the unstandardised variables. Now express
it in terms of standardised variables (initial capital letters):

  mean1 = C0 + C11*sd(hum)*(Hum + 

[R] select columns array2 not equal to 10

2011-08-22 Thread Changbin Du
Dear R community,

I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
array7
1C-3 10  16566949 10 10 10 10 10 10
10
2C-3AAAB 17  33478940 10 10 10 10 10 10
10
3C-3AAAC  3 187369224 10 10 2 10 10 1 10
4C-3AAAD  8  28375041 10 10 10 10 10 10
10
5C-3AAAG 13  99134921 10 10 10 10 10 10
10
6C-3AAAH 16  31565412 10 10 10 10 10 10
10
  array8 array9 array10 array11 array12 array13 array14 array15
1 10 10  10  10  10  10  10  10
2 10 10  10  10  10  10  10  10
3 10 10  10  10  10  10  10  10
4 10 10  10  10  10  10  10  10
5 10 10  10  10  10  1  10  10
6 10 10  10  0  10  10  10  10

I want to select the array columns that are not equal to 10.

I tried the following codes:

head(reduce.final-final[which(final$array*!=10), ]) # it does not wok,
do any one have a smart to do this?

Thanks so much!


-- 
Sincerely,
Changbin
--

[[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] test if vector contains elements of another vector (disregarding the position)

2011-08-22 Thread Henrique Dallazuanna
Try this:

i %in% j * 1

On Mon, Aug 22, 2011 at 12:51 PM, Martin Batholdy
batho...@googlemail.com wrote:
 Hi,


 I have the following problem:


 I have two vectors:

 i - c('a','c','g','h','b','d','f','k','l','e','i')

 j - c('a', 'b', 'c')



 now I would like to generate a vector with the length of i that
 has zeros where i[x] != any element of j
 and 1 where i[x] == any element of j.

 So for the example above the vector would look like this:

 c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0)



 can someone help me on this?

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

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

2011-08-22 Thread Bansal, Vikas
Dear Ista

I have searched about the problem and came to know that we can make a list of 
our file names.But the thing is I am using this code-


define- function() 
 { repeat{
 hojy=readline(Enter the name of your file: )
 if(file.exists(hojy)==T)
{return(hojy)
break}
else
print(File does not exist.Please enter again)}
 }


for(i in 1:100){

df=read.table(define(),fill=T,colClasses = character)
df$V6 - sapply(df$V6, function(a)  
 paste(as.integer(charToRaw(a)), collapse = ' '))}

so here i am using a function which is asking user to input the file name.But I 
was thinking that if I will delete this function and will use the read.table 
like this-

for(i in 1:100){

df=read.table($i.out,fill=T,colClasses = character)
df$V6 - sapply(df$V6, function(a)  
 paste(as.integer(charToRaw(a)), collapse = ' '))}

if you will check this line-
df=read.table($i.out,fill=T,colClasses = character)

I have used $i.out here and every time in for loop i will be 1 then 2 then 3 
till 100.So it will become very easy.But this $ sign is not working in the 
R.Can I do this thing in R.


  

Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London

From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
[iz...@psych.rochester.edu]
Sent: Monday, August 22, 2011 5:16 PM
To: Bansal, Vikas
Cc: r-help@r-project.org
Subject: Re: [R] automatic file input

Hi Vikas,
please do make an effort to search for the answer before posting. A
google search for R read multiple files will give you everything you
need.

Best,
Ista

On Mon, Aug 22, 2011 at 12:08 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear all,

 I have 100 files which are used as input.and I have to input the name of  my 
 files again and again.the name of the files are 1.out, 2.out..100.out.
 I want to know if there is anything like perl so that i can use something 
 like this-


 for($f = 1; $f = 100; $f++) {
  $file = $f..out;


 I have tried this thing in R but it does not work.Can somebody please help me.



 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.




--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


[R] Reading DESCRIPTION files to create dependency diagram

2011-08-22 Thread Rainer M Krug
Hi

I want to create a dependence diagram of a subset of the packages on CRAN
and would therefore like to read the DEACRIPTION files into a list. The list
should be as follow for each package:

- package name: list
  - Package: character
  - Version: character
  - Date: character
  - ...
  - Depends: character vector
  - Suggests: character vector
  - ...

I downloaded all packages and extracted all DESCRIPTION, but I am struggling
with the creation of the list (I tried using scan(what=list(),
multi.line=TRUE) with different things in list()). Before I spend to much
time on it, is there a function which could help me or has somebody done
something similar (I assume the DESCRIPTION file ust be somewhere be read
dueing install.packages()?

Cheers,

Rainer


-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax (F):   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug

[[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] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
I want to select the array columns that are not equal to 10. is ambiguous
to me.

Just to clarify, do you want to simply drop the column named array10 or do
you want to check each column for having one/all 10's as values and drop
based on that test?

Michael

On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.com wrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
 10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

[[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] email with authentication

2011-08-22 Thread Ben qant
Hello,

I'd like to send an email from R using Windows Outlook.
The sendmailR package doesn't allow for authentication (usernames and
passwords).

Is there any other way to do this? From the Windows command line?

Right now I am using a .bat file to send an email via a program called Blat.
I'd like to reduce our dependencies and run everything in R.

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] select columns array2 not equal to 10

2011-08-22 Thread Changbin Du
HI, Michael,

What I want to do is remove all the rows, for which array1, array2,
..array15 are all equal to 10.

I want to keep all the rows at least one of the array variables are not
equal to 10.

sorry for the confusion.




On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is ambiguous
 to me.

 Just to clarify, do you want to simply drop the column named array10 or do
 you want to check each column for having one/all 10's as values and drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.com wrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
 10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

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

[[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] Convert week value to date

2011-08-22 Thread Folkes, Michael
Here is my solution to produce a date value if your data set only has week 
values associated with data (ie no date).
It gives the first monday of the week.
Michael Folkes


s - seq(as.Date(2010-01-01), as.Date(2010-12-31), by = day) #produce all 
days of the year
series.mon-data.frame(day.monday=s[format(s, %w) == 
1],week.val=as.integer(format(s[format(s, %w) == 1],%W))) #calc week 
value for every day

my.data.weeks-sort(sample(1:52, size = 10, replace = FALSE))  #fictitious 
weekly data (assuming I don't have the associated date)
data.frame(my.data.weeks, first.weekday=series.mon[ series.mon$week.val %in%  
my.data.weeks,1]) #combine


[[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] Reading DESCRIPTION files to create dependency diagram

2011-08-22 Thread Uwe Ligges



On 22.08.2011 18:43, Rainer M Krug wrote:

Hi

I want to create a dependence diagram of a subset of the packages on CRAN
and would therefore like to read the DEACRIPTION files into a list. The list
should be as follow for each package:

- package name: list
   - Package: character
   - Version: character
   - Date: character
   - ...
   - Depends: character vector
   - Suggests: character vector
   - ...


Some of these informations are collected in the CRAN repository's 
PACKAGES file. If those are not sufficient, you can also read separate 
DESCRIPTIONS files, of course.


There is packageDescription() in utils for accessing installed packages' 
DESCRIPTION information or just use read.dcf() to read the DESCRIPTION 
files directly.


Example:
as.list(read.dcf(system.file(DESCRIPTION, package=tools))[1,])


For the dependency diagram, see
dependsOnPkgs() and .package_dependencies() (the latter internal) in 
package tools, as well as what these guys wrote:
Theußl, S., Ligges, U. and Hornik, K. (2011): Prospects and Challenges 
in R Package Development. Computational Statistics 26 (3), 395-404.


Uwe Ligges








I downloaded all packages and extracted all DESCRIPTION, but I am struggling
with the creation of the list (I tried using scan(what=list(),
multi.line=TRUE) with different things in list()). Before I spend to much
time on it, is there a function which could help me or has somebody done
something similar (I assume the DESCRIPTION file ust be somewhere be read
dueing install.packages()?

Cheers,

Rainer




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

2011-08-22 Thread Ista Zahn
Why don't you just use list.files() and iterate over the result in
your for loop?

fileNames - list.files(pattern = \\.out)
myFiles - list()
for(i in fileNames) {
myFiles[[i]] - read.table(i, fill=T,colClasses = character)
}

?

Best,
Ista


On Mon, Aug 22, 2011 at 12:34 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear Ista

 I have searched about the problem and came to know that we can make a list of 
 our file names.But the thing is I am using this code-


 define- function()
  { repeat{
  hojy=readline(Enter the name of your file: )
  if(file.exists(hojy)==T)
 {return(hojy)
 break}
 else
 print(File does not exist.Please enter again)}
  }


 for(i in 1:100){

 df=read.table(define(),fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 so here i am using a function which is asking user to input the file name.But 
 I was thinking that if I will delete this function and will use the 
 read.table like this-

 for(i in 1:100){

 df=read.table($i.out,fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 if you will check this line-
 df=read.table($i.out,fill=T,colClasses = character)

 I have used $i.out here and every time in for loop i will be 1 then 2 then 3 
 till 100.So it will become very easy.But this $ sign is not working in the 
 R.Can I do this thing in R.




 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 
 From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
 [iz...@psych.rochester.edu]
 Sent: Monday, August 22, 2011 5:16 PM
 To: Bansal, Vikas
 Cc: r-help@r-project.org
 Subject: Re: [R] automatic file input

 Hi Vikas,
 please do make an effort to search for the answer before posting. A
 google search for R read multiple files will give you everything you
 need.

 Best,
 Ista

 On Mon, Aug 22, 2011 at 12:08 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk 
 wrote:
 Dear all,

 I have 100 files which are used as input.and I have to input the name of  my 
 files again and again.the name of the files are 1.out, 2.out..100.out.
 I want to know if there is anything like perl so that i can use something 
 like this-


 for($f = 1; $f = 100; $f++) {
  $file = $f..out;


 I have tried this thing in R but it does not work.Can somebody please help 
 me.



 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.




 --
 Ista Zahn
 Graduate student
 University of Rochester
 Department of Clinical and Social Psychology
 http://yourpsyche.org




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
This isn't the most beautiful code, but I think it should work for you:

# Some sample data
M =
cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3))
colnames(M) = c(Thing1,Thing2,paste(array,1:3,sep=))

colsToCheck = grepl(array,colnames(M)) # Isolate the array columns
rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)})
# apply the test function row-wise to get a logical vector of which rows to
keep

Answer = M[rowsToKeep,] # keep only those rows

Hope this helps,

Michael

On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du changb...@gmail.com wrote:

 HI, Michael,

 What I want to do is remove all the rows, for which array1, array2,
 ..array15 are all equal to 10.

 I want to keep all the rows at least one of the array variables are not
 equal to 10.

 sorry for the confusion.





 On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is
 ambiguous to me.

 Just to clarify, do you want to simply drop the column named array10 or do
 you want to check each column for having one/all 10's as values and drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.comwrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
   10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

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



[[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] email with authentication

2011-08-22 Thread Ben Bolker
Ben qant ccquant at gmail.com writes:

 
 Hello,
 
 I'd like to send an email from R using Windows Outlook.
 The sendmailR package doesn't allow for authentication (usernames and
 passwords).

  I don't know about Outlook, but you can try

install.packages(Rmail,repos=http://www.math.mcmaster.ca/bolker/R;)

It allows for direct connection to an SMTP server with basic name/password
authentication.

 It hasn't been widely tested.

  Ben Bolker

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


Re: [R] Calculating p-value for 1-tailed test in a linear model

2011-08-22 Thread Ben Bolker
Campomizzi, Andrew J acampomizzi at neo.tamu.edu writes:

 On 20/08/11 10:20, Andrew Campomizzi wrote:
  Hello,
 
  I'm having trouble figuring out how to calculate a p-value for a 1-tailed
  test of beta_1 in a linear model fit using command lm.  My model has only 1
  continuous, predictor variable.  I want to test the null hypothesis beta_1
  is= 0.  I can calculate the p-value for a 2-tailed test using the code
  2*pt(-abs(t-value), df=degrees.freedom), where t-value and degrees.freedom
  are values provided in the summary of the lm.  The resulting p-value is the
  same as provided by the summary of the lm for beta_1.  I'm unsure how to
  change my calculation of the p-value for a 1-tailed test.
 

  Isn't it just 

pt(tvalue,df=degrees.freedom,lower.tail=FALSE)

if the value is positive (and expected to be positive) or

pt(tvalue,df=degrees.freedom)

if the value is negative (and expected to be negative)?

  In fact, if the value is in the expected direction, I think you
can just leave out the multiplication by 2 and get the right answer ...

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

2011-08-22 Thread Bansal, Vikas
Because i have to use the value of i in for loop also.example-

 for(i in 1:100){

 df=read.table($i.out,fill=T,colClasses = character)
if(i=50){
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
else{
 df$V5 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
}
 so what I was thinking that if i will use paste, then it is working


 for(i in 1:100){

 df=read.table(paste(i),fill=T,colClasses = character)
if(i=50){
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
else{
 df$V5 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
}

This works perfect for me.But I have to change my file names from 1.out to 1 
and 2.out to 2 etc.because when i used -

 df=read.table(paste(i.out),fill=T,colClasses = character)
then it is not working.


Thanking you,
Warm Regards
Vikas Bansal
Msc Bioinformatics
Kings College London

From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
[iz...@psych.rochester.edu]
Sent: Monday, August 22, 2011 6:14 PM
To: Bansal, Vikas
Cc: r-help@r-project.org
Subject: Re: [R] automatic file input

Why don't you just use list.files() and iterate over the result in
your for loop?

fileNames - list.files(pattern = \\.out)
myFiles - list()
for(i in fileNames) {
myFiles[[i]] - read.table(i, fill=T,colClasses = character)
}

?

Best,
Ista


On Mon, Aug 22, 2011 at 12:34 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Dear Ista

 I have searched about the problem and came to know that we can make a list of 
 our file names.But the thing is I am using this code-


 define- function()
  { repeat{
  hojy=readline(Enter the name of your file: )
  if(file.exists(hojy)==T)
 {return(hojy)
 break}
 else
 print(File does not exist.Please enter again)}
  }


 for(i in 1:100){

 df=read.table(define(),fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 so here i am using a function which is asking user to input the file name.But 
 I was thinking that if I will delete this function and will use the 
 read.table like this-

 for(i in 1:100){

 df=read.table($i.out,fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 if you will check this line-
 df=read.table($i.out,fill=T,colClasses = character)

 I have used $i.out here and every time in for loop i will be 1 then 2 then 3 
 till 100.So it will become very easy.But this $ sign is not working in the 
 R.Can I do this thing in R.




 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 
 From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
 [iz...@psych.rochester.edu]
 Sent: Monday, August 22, 2011 5:16 PM
 To: Bansal, Vikas
 Cc: r-help@r-project.org
 Subject: Re: [R] automatic file input

 Hi Vikas,
 please do make an effort to search for the answer before posting. A
 google search for R read multiple files will give you everything you
 need.

 Best,
 Ista

 On Mon, Aug 22, 2011 at 12:08 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk 
 wrote:
 Dear all,

 I have 100 files which are used as input.and I have to input the name of  my 
 files again and again.the name of the files are 1.out, 2.out..100.out.
 I want to know if there is anything like perl so that i can use something 
 like this-


 for($f = 1; $f = 100; $f++) {
  $file = $f..out;


 I have tried this thing in R but it does not work.Can somebody please help 
 me.



 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.




 --
 Ista Zahn
 Graduate student
 University of Rochester
 Department of Clinical and Social Psychology
 http://yourpsyche.org




--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] select columns array2 not equal to 10

2011-08-22 Thread Changbin Du
THANKS SO MUCH, Michael!

Appreciated!



On Mon, Aug 22, 2011 at 10:16 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 This isn't the most beautiful code, but I think it should work for you:

 # Some sample data
 M =
 cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3))
 colnames(M) = c(Thing1,Thing2,paste(array,1:3,sep=))

 colsToCheck = grepl(array,colnames(M)) # Isolate the array columns
 rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)})
 # apply the test function row-wise to get a logical vector of which rows to
 keep

 Answer = M[rowsToKeep,] # keep only those rows

 Hope this helps,

 Michael


 On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du changb...@gmail.com wrote:

 HI, Michael,

 What I want to do is remove all the rows, for which array1, array2,
 ..array15 are all equal to 10.

 I want to keep all the rows at least one of the array variables are not
 equal to 10.

 sorry for the confusion.





 On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is
 ambiguous to me.

 Just to clarify, do you want to simply drop the column named array10 or
 do you want to check each column for having one/all 10's as values and drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.comwrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
   10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

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





-- 
Sincerely,
Changbin
--

Changbin Du
Data Analysis Group, Affymetrix Inc
6550 Emeryville, CA, 94608

[[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] automatic file input

2011-08-22 Thread Ista Zahn
On Mon, Aug 22, 2011 at 1:25 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk wrote:
 Because i have to use the value of i in for loop also.example-

  for(i in 1:100){

  df=read.table($i.out,fill=T,colClasses = character)
 if(i=50){
  df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
 else{
  df$V5 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
 }
  so what I was thinking that if i will use paste, then it is working


  for(i in 1:100){

  df=read.table(paste(i),fill=T,colClasses = character)
 if(i=50){
  df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
 else{
  df$V5 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}
 }

 This works perfect for me.But I have to change my file names from 1.out to 1 
 and 2.out to 2 etc.because when i used -

  df=read.table(paste(i.out),fill=T,colClasses = character)
 then it is not working.

use paste(i, .out, sep = )

Best,
Ista


 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 
 From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
 [iz...@psych.rochester.edu]
 Sent: Monday, August 22, 2011 6:14 PM
 To: Bansal, Vikas
 Cc: r-help@r-project.org
 Subject: Re: [R] automatic file input

 Why don't you just use list.files() and iterate over the result in
 your for loop?

 fileNames - list.files(pattern = \\.out)
 myFiles - list()
 for(i in fileNames) {
 myFiles[[i]] - read.table(i, fill=T,colClasses = character)
 }

 ?

 Best,
 Ista


 On Mon, Aug 22, 2011 at 12:34 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk 
 wrote:
 Dear Ista

 I have searched about the problem and came to know that we can make a list 
 of our file names.But the thing is I am using this code-


 define- function()
  { repeat{
  hojy=readline(Enter the name of your file: )
  if(file.exists(hojy)==T)
 {return(hojy)
 break}
 else
 print(File does not exist.Please enter again)}
  }


 for(i in 1:100){

 df=read.table(define(),fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 so here i am using a function which is asking user to input the file 
 name.But I was thinking that if I will delete this function and will use the 
 read.table like this-

 for(i in 1:100){

 df=read.table($i.out,fill=T,colClasses = character)
 df$V6 - sapply(df$V6, function(a)
  paste(as.integer(charToRaw(a)), collapse = ' '))}

 if you will check this line-
 df=read.table($i.out,fill=T,colClasses = character)

 I have used $i.out here and every time in for loop i will be 1 then 2 then 3 
 till 100.So it will become very easy.But this $ sign is not working in the 
 R.Can I do this thing in R.




 Thanking you,
 Warm Regards
 Vikas Bansal
 Msc Bioinformatics
 Kings College London
 
 From: istaz...@gmail.com [istaz...@gmail.com] On Behalf Of Ista Zahn 
 [iz...@psych.rochester.edu]
 Sent: Monday, August 22, 2011 5:16 PM
 To: Bansal, Vikas
 Cc: r-help@r-project.org
 Subject: Re: [R] automatic file input

 Hi Vikas,
 please do make an effort to search for the answer before posting. A
 google search for R read multiple files will give you everything you
 need.

 Best,
 Ista

 On Mon, Aug 22, 2011 at 12:08 PM, Bansal, Vikas vikas.ban...@kcl.ac.uk 
 wrote:
 Dear all,

 I have 100 files which are used as input.and I have to input the name of  
 my files again and again.the name of the files are 1.out, 
 2.out..100.out.
 I want to know if there is anything like perl so that i can use something 
 like this-


 for($f = 1; $f = 100; $f++) {
  $file = $f..out;


 I have tried this thing in R but it does not work.Can somebody please help 
 me.



 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.




 --
 Ista Zahn
 Graduate student
 University of Rochester
 Department of Clinical and Social Psychology
 http://yourpsyche.org




 --
 Ista Zahn
 Graduate student
 University of Rochester
 Department of Clinical and Social Psychology
 http://yourpsyche.org




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

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


Re: [R] Calculating p-value for 1-tailed test in a linear model

2011-08-22 Thread Albyn Jones
For H_0: beta = 0, then the correct p-value is

 pt(tvalue,df)

regardless of the sign of tvalue.  Negative tvalues of large magnitude
will yield small p-values.

albyn

On Mon, Aug 22, 2011 at 05:22:06PM +, Ben Bolker wrote:
 Campomizzi, Andrew J acampomizzi at neo.tamu.edu writes:
 
  On 20/08/11 10:20, Andrew Campomizzi wrote:
   Hello,
  
   I'm having trouble figuring out how to calculate a p-value for a 1-tailed
   test of beta_1 in a linear model fit using command lm.  My model has only 
   1
   continuous, predictor variable.  I want to test the null hypothesis beta_1
   is= 0.  I can calculate the p-value for a 2-tailed test using the code
   2*pt(-abs(t-value), df=degrees.freedom), where t-value and 
   degrees.freedom
   are values provided in the summary of the lm.  The resulting p-value is 
   the
   same as provided by the summary of the lm for beta_1.  I'm unsure how to
   change my calculation of the p-value for a 1-tailed test.
  
 
   Isn't it just 
 
 pt(tvalue,df=degrees.freedom,lower.tail=FALSE)
 
 if the value is positive (and expected to be positive) or
 
 pt(tvalue,df=degrees.freedom)
 
 if the value is negative (and expected to be negative)?
 
   In fact, if the value is in the expected direction, I think you
 can just leave out the multiplication by 2 and get the right answer ...
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
Albyn Jones
Reed College
jo...@reed.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] select columns array2 not equal to 10

2011-08-22 Thread Changbin Du
HI, Michael,

Sorry for my numb, I have one more question.

When you use function(x){any (x != 10), here x is a vector, x!=10 will give
a vector of logical value, right?

If it is, how can vector be compared to a scale, 10 in this case?

Thanks!




On Mon, Aug 22, 2011 at 10:16 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 This isn't the most beautiful code, but I think it should work for you:

 # Some sample data
 M =
 cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3))
 colnames(M) = c(Thing1,Thing2,paste(array,1:3,sep=))

 colsToCheck = grepl(array,colnames(M)) # Isolate the array columns
 rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)})
 # apply the test function row-wise to get a logical vector of which rows to
 keep

 Answer = M[rowsToKeep,] # keep only those rows

 Hope this helps,

 Michael


 On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du changb...@gmail.com wrote:

 HI, Michael,

 What I want to do is remove all the rows, for which array1, array2,
 ..array15 are all equal to 10.

 I want to keep all the rows at least one of the array variables are not
 equal to 10.

 sorry for the confusion.





 On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is
 ambiguous to me.

 Just to clarify, do you want to simply drop the column named array10 or
 do you want to check each column for having one/all 10's as values and drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.comwrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
   10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

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





-- 
Sincerely,
Changbin
--

[[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] Extracting columns with specific string in their names

2011-08-22 Thread Dennis Murphy
Hi:

You need a leading ^ in your grep string. Here's a reproducible
example to illustrate:

df - data.frame(Xyz1 = rnorm(5), Xyz2 = rnorm(5), Xyz3 = rnorm(5),
  Abc1 = rnorm(5), Abc2 = rnorm(5))
df[, grep('^Xyz', names(df))]
df[, grep('^Abc', names(df))]

HTH,
Dennis

On Mon, Aug 22, 2011 at 7:33 AM, Jay josip.2...@gmail.com wrote:
 Hi,

 Let's say that I have a set of column names that begin with the string
 Xyz. How do I extract these specific columns? I tried to do the
 following:

 dataframe1[,grep(Xyz,colnames(dataframe1))]

 But it does not work. What is wrong with my expression?

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
The different lengths work because R recycles values whenever you try to do
a binary operation on things of different lengths: in essence, R copies 10
however many times needed to make something that has the right length for an
elementwise comparison with x.**

If you did something like

x != c(1,10)

R would make a recycled-copy that looks like 1,10,1,10,1,10, etc. and
compare that to x, in essence, checking half the values against 1 and half
against 10.

Similarly, you can use vectors of totally different lengths and R will
simply repeat the shorter one to the right length:

e.g.,

(1:10)  (1:3)

this plays out as

c(1,2,3,4,5,6,7,8,9,10)  c(1,2,3,1,2,3,1,2,3)

but gives you a warning message that the two vectors don't fit correctly.
This message never comes up when one side is only a scalar because it can
always fit exactly.

You can see a surprising example of this at work with

(-5:5)  (-2 : 7)

which returns all FALSE values except for the last term, when 5 gets
compared to a recycled -2

When R makes this comparison, it creates a vector of logicals (TRUE and
FALSE values) and then the any() command tells us if there is at least 1
TRUE, which signals to us to keep the row.

Michael

** I'm not actually sure if that's how the code is implemented for the
scalar case, but it's probably easiest to think of it this way to get the
intuition for larger cases.

PS -- Is your data guaranteed to be an integer? If you have floating point
data, it's good practice to use something more like

abs(x - 10)  1e-8

rather than x != 0 in your code. If you need to use this formulation, just
put it inside the any() statement.

On Mon, Aug 22, 2011 at 1:43 PM, Changbin Du changb...@gmail.com wrote:

 HI, Michael,

 Sorry for my numb, I have one more question.

 When you use function(x){any (x != 10), here x is a vector, x!=10 will give
 a vector of logical value, right?

 If it is, how can vector be compared to a scale, 10 in this case?

 Thanks!





 On Mon, Aug 22, 2011 at 10:16 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 This isn't the most beautiful code, but I think it should work for you:

 # Some sample data
 M =
 cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3))
 colnames(M) = c(Thing1,Thing2,paste(array,1:3,sep=))

 colsToCheck = grepl(array,colnames(M)) # Isolate the array columns
 rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)})
 # apply the test function row-wise to get a logical vector of which rows
 to keep

 Answer = M[rowsToKeep,] # keep only those rows

 Hope this helps,

 Michael


 On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du changb...@gmail.comwrote:

 HI, Michael,

 What I want to do is remove all the rows, for which array1, array2,
 ..array15 are all equal to 10.

 I want to keep all the rows at least one of the array variables are not
 equal to 10.

 sorry for the confusion.





 On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is
 ambiguous to me.

 Just to clarify, do you want to simply drop the column named array10 or
 do you want to check each column for having one/all 10's as values and drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.comwrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
 10
 4C-3AAAD  8  28375041 10 10 10 10 10 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

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

[R] Two-levels labels on x-axis?

2011-08-22 Thread Sébastien Vigneau
Hi,

I would like to draw a stacked bar chart with four bars (say a, b, c,
d) . Two bars belong to group A and the two others to group B. Therefore,
I would like to have, on the x-axis, a label for each bar and an additional
label for each group, positioned underneath. To give an idea, the x-axis
labels should look like this:
|a|b|c|d|
| A | B |

Do you know how I can generate such two-levels labels in R?

Thank you for your help!

Sebastien

[[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] select columns array2 not equal to 10

2011-08-22 Thread Changbin Du
Thanks, Michael!

You have an heart of gold! Appreciated!


On Mon, Aug 22, 2011 at 10:53 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 The different lengths work because R recycles values whenever you try to do
 a binary operation on things of different lengths: in essence, R copies 10
 however many times needed to make something that has the right length for an
 elementwise comparison with x.**

 If you did something like

 x != c(1,10)

 R would make a recycled-copy that looks like 1,10,1,10,1,10, etc. and
 compare that to x, in essence, checking half the values against 1 and half
 against 10.

 Similarly, you can use vectors of totally different lengths and R will
 simply repeat the shorter one to the right length:

 e.g.,

 (1:10)  (1:3)

 this plays out as

 c(1,2,3,4,5,6,7,8,9,10)  c(1,2,3,1,2,3,1,2,3)

 but gives you a warning message that the two vectors don't fit correctly.
 This message never comes up when one side is only a scalar because it can
 always fit exactly.

 You can see a surprising example of this at work with

 (-5:5)  (-2 : 7)

 which returns all FALSE values except for the last term, when 5 gets
 compared to a recycled -2

 When R makes this comparison, it creates a vector of logicals (TRUE and
 FALSE values) and then the any() command tells us if there is at least 1
 TRUE, which signals to us to keep the row.

 Michael

 ** I'm not actually sure if that's how the code is implemented for the
 scalar case, but it's probably easiest to think of it this way to get the
 intuition for larger cases.

 PS -- Is your data guaranteed to be an integer? If you have floating point
 data, it's good practice to use something more like

 abs(x - 10)  1e-8

 rather than x != 0 in your code. If you need to use this formulation, just
 put it inside the any() statement.

 On Mon, Aug 22, 2011 at 1:43 PM, Changbin Du changb...@gmail.com wrote:

 HI, Michael,

 Sorry for my numb, I have one more question.

 When you use function(x){any (x != 10), here x is a vector, x!=10 will
 give a vector of logical value, right?

 If it is, how can vector be compared to a scale, 10 in this case?

 Thanks!





 On Mon, Aug 22, 2011 at 10:16 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 This isn't the most beautiful code, but I think it should work for you:

 # Some sample data
 M =
 cbind(matrix(rnorm(10),ncol=2),matrix(sample(c(10,1),15,replace=T),ncol=3))
 colnames(M) = c(Thing1,Thing2,paste(array,1:3,sep=))

 colsToCheck = grepl(array,colnames(M)) # Isolate the array columns
 rowsToKeep = apply(M[,colsToCheck],1,function(x){any (x != 10)})
 # apply the test function row-wise to get a logical vector of which rows
 to keep

 Answer = M[rowsToKeep,] # keep only those rows

 Hope this helps,

 Michael


 On Mon, Aug 22, 2011 at 12:56 PM, Changbin Du changb...@gmail.comwrote:

 HI, Michael,

 What I want to do is remove all the rows, for which array1, array2,
 ..array15 are all equal to 10.

 I want to keep all the rows at least one of the array variables are not
 equal to 10.

 sorry for the confusion.





 On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 I want to select the array columns that are not equal to 10. is
 ambiguous to me.

 Just to clarify, do you want to simply drop the column named array10 or
 do you want to check each column for having one/all 10's as values and 
 drop
 based on that test?

 Michael

 On Mon, Aug 22, 2011 at 12:35 PM, Changbin Du changb...@gmail.comwrote:

 Dear R community,

 I have a data set like the following:

  probe_name chr_id  position array1 array2 array3 array4 array5 array6
 array7
 1C-3 10  16566949 10 10 10 10 10
 10
 10
 2C-3AAAB 17  33478940 10 10 10 10 10
 10
 10
 3C-3AAAC  3 187369224 10 10 2 10 10 1
 10
 4C-3AAAD  8  28375041 10 10 10 10 10
 10
 10
 5C-3AAAG 13  99134921 10 10 10 10 10
 10
 10
 6C-3AAAH 16  31565412 10 10 10 10 10
 10
 10
  array8 array9 array10 array11 array12 array13 array14 array15
 1 10 10  10  10  10  10  10  10
 2 10 10  10  10  10  10  10  10
 3 10 10  10  10  10  10  10  10
 4 10 10  10  10  10  10  10  10
 5 10 10  10  10  10  1  10  10
 6 10 10  10  0  10  10  10  10

 I want to select the array columns that are not equal to 10.

 I tried the following codes:

 head(reduce.final-final[which(final$array*!=10), ]) # it does not
 wok,
 do any one have a smart to do this?

 Thanks so much!


 --
 Sincerely,
 Changbin
 --

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 

Re: [R] Two-levels labels on x-axis?

2011-08-22 Thread Joshua Wiley
Hi Sébastien,

Not sure about an elegant, general way but here is something quick and dirty:

p - barplot(matrix(1:8, 2))
axis(1, at = p, labels = letters[1:4])
axis(1, at = c(mean(p[1:2]), mean(p[3:4])), labels = paste(\n,
LETTERS[1:2]), padj = 1)

Cheers,

Josh



On Mon, Aug 22, 2011 at 10:14 AM, Sébastien Vigneau
sebastien.vign...@gmail.com wrote:
 Hi,

 I would like to draw a stacked bar chart with four bars (say a, b, c,
 d) . Two bars belong to group A and the two others to group B. Therefore,
 I would like to have, on the x-axis, a label for each bar and an additional
 label for each group, positioned underneath. To give an idea, the x-axis
 labels should look like this:
 |a|b|c|d|
 | A | B |

 Do you know how I can generate such two-levels labels in R?

 Thank you for your help!

 Sebastien

        [[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
Programmer Analyst II, ATS Statistical Consulting Group
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 columns with specific string in their names

2011-08-22 Thread David Winsemius


On Aug 22, 2011, at 1:45 PM, Dennis Murphy wrote:


Hi:

You need a leading ^ in your grep string. Here's a reproducible
example to illustrate:

df - data.frame(Xyz1 = rnorm(5), Xyz2 = rnorm(5), Xyz3 = rnorm(5),
 Abc1 = rnorm(5), Abc2 = rnorm(5))
df[, grep('^Xyz', names(df))]
df[, grep('^Abc', names(df))]


The leading ^ should not be necessary to solve the problem of no  
matches at all reported in the followup message, since it narrows the  
search rather than expanding it. It would only be necessary if there  
were column names that you wanted to exlcude where Xyz was not at  
the beginning of the string. My guess is that th eOP does not realize  
the importantce of capitaliszation and that all these are different so  
would NOT be matched by grep(Xyz ,...):xyz, xYz, xyZ.




HTH,
Dennis

On Mon, Aug 22, 2011 at 7:33 AM, Jay josip.2...@gmail.com wrote:

Hi,

Let's say that I have a set of column names that begin with the  
string

Xyz. How do I extract these specific columns? I tried to do the
following:

dataframe1[,grep(Xyz,colnames(dataframe1))]

But it does not work. What is wrong with my expression?



--
David Winsemius, MD
West Hartford, CT

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


Re: [R] Two-levels labels on x-axis?

2011-08-22 Thread Marc Schwartz
On Aug 22, 2011, at 12:14 PM, Sébastien Vigneau wrote:

 Hi,
 
 I would like to draw a stacked bar chart with four bars (say a, b, c,
 d) . Two bars belong to group A and the two others to group B. Therefore,
 I would like to have, on the x-axis, a label for each bar and an additional
 label for each group, positioned underneath. To give an idea, the x-axis
 labels should look like this:
 |a|b|c|d|
 | A | B |
 
 Do you know how I can generate such two-levels labels in R?
 
 Thank you for your help!
 
 Sebastien


See ?barplot and note in the Value section:

  If beside is true, use colMeans(mp) for the midpoints of each group of bars, 
see example.


Here is another example:

mat - matrix(1:4, ncol = 2)

mp - barplot(mat, beside = TRUE)

Groups - c(A, B)
Sub.Groups - c(a, b, c, d)

mtext(side = 1, line = 1, at = mp, text = Sub.Groups)
mtext(side = 1, line = 3, at = colMeans(mp), text = Groups)


HTH,

Marc Schwartz

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

2011-08-22 Thread Jim Silverton
Hello all,

I have two columns of numbers. I would like to do the following:
(1) Plot both cdfs, F1 and F2 on the same graph.
(2) Find smoothed approximations of F1 and F2 lets call them F1hat and F2hat
(3) Find values for F1hat when we substitue a value of x in it.
(4) Find the corresponding densities of the cdfs.
Any ideas?

-- 
Thanks,
Jim.

[[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] CDFs

2011-08-22 Thread R. Michael Weylandt
Number 1 can be done as follows:

x = rnorm(50); y = rnorm(50)
xCDF = ecdf(x); yCDF = ecdf(y)

plot(xCDF)
lines(yCDF,col=2)

For the other ones, you are going to have to be a little more specific as to
how you want to do the approximation...but ?density might be a place to
start for #4, assuming you meant density of the PDF. If you meant CDF, it I
think that's implicit in number 2.

Michael Weylandt

On Mon, Aug 22, 2011 at 2:15 PM, Jim Silverton jim.silver...@gmail.comwrote:

 Hello all,

 I have two columns of numbers. I would like to do the following:
 (1) Plot both cdfs, F1 and F2 on the same graph.
 (2) Find smoothed approximations of F1 and F2 lets call them F1hat and
 F2hat
 (3) Find values for F1hat when we substitue a value of x in it.
 (4) Find the corresponding densities of the cdfs.
 Any ideas?

 --
 Thanks,
 Jim.

[[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] Problem with xtable

2011-08-22 Thread ea819
Dear all,

I am having trouble creating LaTex tables using the xtable command. I am
using the bayesm package to analyse data. However, I am unable to generate
LaTex tables converting the output from summary(out$deltadraws.) I have made
several attempts using xtable but have been unsuccessful and receive the
below error message. Does anyone have any ideas on how I can solve this
problem or an alternative way to create Tex tables? 

print(xtable(mat), type=latex, file=PosterSumm_Delta_MnlNmixMarg.tex)
Error in UseMethod(xtable) : 
  no applicable method for 'xtable' applied to an object of class NULL

Many thanks in advance.
Elcin 


--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-xtable-tp3760991p3760991.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] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
R -

I have 3 variables with data below.  Variable Rev is a vector that changes
from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with 1's
and 0's.  Variable bin is a different binary variable with 1's and 0's.

I want to calculate the number of elements:

1.  Starting with the first element where Rev switches (i.e. 1 to 2)

2.  The number of elements between the transition and the first 0 in the
FF vector; *when bin is also a 0.*
*
*
3.  I want to do this for each transition in Rev, but ignore all elements
after calculating #2 until another transition has occurred.


structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
), row.names = c(NA, -40L), class = data.frame)


-- 
Edward H. Patzelt
Research Assistant – TRiCAM Lab
University of Minnesota – Psychology/Psychiatry
VA Medical Center
Office: S355 Elliot Hall - Twin Cities Campus
Phone: 612-626-0072  Email: patze...@umn.edu

Please consider the environment before printing this email
www.psych.umn.edu/research/tricam

[[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] Problem with xtable

2011-08-22 Thread David Winsemius


On Aug 22, 2011, at 3:18 PM, ea819 wrote:


Dear all,

I am having trouble creating LaTex tables using the xtable command.  
I am
using the bayesm package to analyse data. However, I am unable to  
generate
LaTex tables converting the output from summary(out$deltadraws.) I  
have made
several attempts using xtable but have been unsuccessful and receive  
the
below error message. Does anyone have any ideas on how I can solve  
this

problem or an alternative way to create Tex tables?

print(xtable(mat), type=latex,  
file=PosterSumm_Delta_MnlNmixMarg.tex)

Error in UseMethod(xtable) :
 no applicable method for 'xtable' applied to an object of class  
NULL




It is going to be difficult to answer this since your installation of  
R thinks that 'mat' does not exist.


--
David.


Many thanks in advance.
Elcin
--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-xtable-tp3760991p3760991.html




David Winsemius, MD
West Hartford, CT

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


[R] Threads in R

2011-08-22 Thread Immanuel

Hello all,

I posted a questions on how to terminate a function call that does not
return after a certain time ( I can not modify the function code) some
time ago.
Since I didn't find a solution I just came up with the idea to run the
functions call in a separate thread who I could terminate a will.

Would this be possible? Any pointers in the right direction? A looked
briefly a snow and Rmpi but they seem to serve other needs.

best regards,
Immanuel

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

2011-08-22 Thread David L Carlson
When you read Excel data from the Windows clipboard, the delimiter is a tab,
not a comma. 

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Petr PIKAL
Sent: Monday, August 22, 2011 3:18 AM
To: nferr...@fceia.unr.edu.ar
Cc: r-help@r-project.org
Subject: Re: [R] I have a problem with R!!

Hi

Your code is rather baroque and it is difficult to see what is exactly 
going on without having appropriate data. I does not consider your process 
of reading data from Excel problematic.

Maybe the difference is in that

d- rnorm(whatever) 

produces vector while

d- read.delim(clipboard, header = T, dec = ,)

produces data frame

you can subset vector by

d[indices]

but doing the same with data.frame you try to subset columns which, in 
your case should not be what you want.

at least showing us 

str(data.readed.from.Excel)

can help us to help you.

Regards
Petr

 
 On 08/21/2011 05:29 AM, nferr...@fceia.unr.edu.ar wrote:
  Dear all
 
  i´m working with a program i´ve made in R (using functions that others
  created)
 
  to run my program i need a sample. if i generate the sample using  for
  example, rnorm(n, mu, sigma) i have no problem
 
  but if i obtain a sample from a column in excel and i copy it, the 
program
  says that there is a mistake: it says Error en `[.data.frame`(data,
  indices) : undefined columns selected
 
  my program is:
 
  d- read.delim(clipboard, header = T, dec = ,)
  #Para determinar los valores de las componentes del vector de 
capacidad es
  necesario definir primero las especificaciones y el valor objetivo, T, 
así
  como el máximo valor admitido para la proporción de producción no
  conforme, a cada lado de los límites de especificaciones#
  # Ingrese ahora el valor del límite inferior de especificaciones#
  LIE- 13
  # Ingrese ahora el valor del límite superior de especificaciones#
  LSE- 17
  # Ingrese ahora el valor objetivo#
  T- 14.5
  # Ingrese ahora el máximo valor admitido para la proporción de 
producción
  no conforme a cada lado de los límites de especificaciones#
  MA- 0.00135
  D- min ((LSE-T), (T-LIE))
  compo1- function(data, indices)
  {
  d- data[indices]
  n = length (d)
  desvio- sd(d)
  y- rep(1:n)
  y[x= mean(d)]- 1
  y[xmean(d)]- 0
  RI1- D/(3*desvio*2*mean(y))
  RI2- D/(3*desvio*2*(1-mean(y)))
  return (min (RI1, RI2))
  }
  compo2- function(data, indices)
  {
  d- data[indices]
  c2- (abs(mean(d) - T))/D
  return (1-c2)
  }
  compo3-function(data, indices)
  {
  d- data[indices]
  n- length (d)
  y- rep(1:n)
  y[d  LIE]- 1
  y[d= LIE]- 0
  INFE- mean (y);
  y- rep(1:n)
  y[d  LSE]- 1
  y[d= LSE]- 0
  SUPE- mean (y);
  PPI- (1 - INFE)/(1-MA)
  PPS- (1 - SUPE)/(1-MA)
  return (min (PPI, PPS))
  }
  save(file = compo1.RData)
  save(file = compo2.RData)
  save(file = compo3.RData)
  compos- function(data, indices)
  {
  d- data[indices]
  capacidad- c(compo1(d), compo2(d), compo3(d))
  return(capacidad)
  }
  save(file = compos.RData)
  require (boot)
  vectorcapacidad- boot (d, compos, R = 3000)
 
  ETC. ETC.
 
 
 
  WHEN I START MY PROGRAM WRITING:
  d- rnorm (n, mu, sigma)
 
  I HAVE NO PROBLEM. BUT WHEN I READ A VECTOR FROM EXCEL, R TELLS ME
  Error en `[.data.frame`(data, indices) : undefined columns selected
 
 
  CAN YOU HELP ME THANK YOU VERY MUCH!
 
  NOEMI FERRERI, ROSARIO, ARGENTINA
  SCHOOL OF INDUSTRIAL ENGINEERING
 
 Hi Noemi,
 Without some sample data, I can only guess, but I would first try saving 

 the Excel spreadsheet in CSV format and then reading the data in with 
 read.csv. This might solve your problem.
 
 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.

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

2011-08-22 Thread R. Michael Weylandt
Yes. The xCDF/yCDF objects that are returned by the ecdf function can be
called like functions.

For example:

x = rnrom(50); xCDF = ecdf(x); xCDF(0.3)
# This value tells you what fraction of x is less than 0.3

You can also assign this behavior to a function:

F - function(z) { xCDF(z) }

F does not inherit xCDF directly though and looses the step-function-ness of
the xCDF object. (Compare plots of F and xCDF to see one consequence)

So yes, you can do subtraction on this basis

x = rnrom(50); xCDF = ecdf(x); Fx - function(z) { xCDF(z) }
y = rnrom(50); yCDF = ecdf(x); Fy - function(z) { yCDF(z) }

F - function(z) {Fx(z) - Fy(z)}
# F - function(z) {xCDF(z)-yCDF(z)} # Another way to do the same thing

Hope this helps,

Michael


On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton jim.silver...@gmail.comwrote:

 WHat about if you have two cdfs and you want to subtract them? Like G(x) -
 H(x)? Can ecdf do this?


 On Mon, Aug 22, 2011 at 2:24 PM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

 Number 1 can be done as follows:

 x = rnorm(50); y = rnorm(50)
 xCDF = ecdf(x); yCDF = ecdf(y)

 plot(xCDF)
 lines(yCDF,col=2)

 For the other ones, you are going to have to be a little more specific as
 to how you want to do the approximation...but ?density might be a place to
 start for #4, assuming you meant density of the PDF. If you meant CDF, it I
 think that's implicit in number 2.

 Michael Weylandt

 On Mon, Aug 22, 2011 at 2:15 PM, Jim Silverton 
 jim.silver...@gmail.comwrote:

 Hello all,

 I have two columns of numbers. I would like to do the following:
 (1) Plot both cdfs, F1 and F2 on the same graph.
 (2) Find smoothed approximations of F1 and F2 lets call them F1hat and
 F2hat
 (3) Find values for F1hat when we substitue a value of x in it.
 (4) Find the corresponding densities of the cdfs.
 Any ideas?

 --
 Thanks,
 Jim.

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





 --
 Thanks,
 Jim.



[[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] Two-levels labels on x-axis?

2011-08-22 Thread Sébastien Vigneau
Thanks!

Sebastien

On Mon, Aug 22, 2011 at 2:11 PM, Marc Schwartz marc_schwa...@me.com wrote:

 On Aug 22, 2011, at 12:14 PM, Sébastien Vigneau wrote:

  Hi,
 
  I would like to draw a stacked bar chart with four bars (say a, b,
 c,
  d) . Two bars belong to group A and the two others to group B.
 Therefore,
  I would like to have, on the x-axis, a label for each bar and an
 additional
  label for each group, positioned underneath. To give an idea, the x-axis
  labels should look like this:
  |a|b|c|d|
  | A | B |
 
  Do you know how I can generate such two-levels labels in R?
 
  Thank you for your help!
 
  Sebastien


 See ?barplot and note in the Value section:

  If beside is true, use colMeans(mp) for the midpoints of each group of
 bars, see example.


 Here is another example:

 mat - matrix(1:4, ncol = 2)

 mp - barplot(mat, beside = TRUE)

 Groups - c(A, B)
 Sub.Groups - c(a, b, c, d)

 mtext(side = 1, line = 1, at = mp, text = Sub.Groups)
 mtext(side = 1, line = 3, at = colMeans(mp), text = Groups)


 HTH,

 Marc Schwartz



[[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] Threads in R

2011-08-22 Thread Peter Langfelder
On Mon, Aug 22, 2011 at 12:39 PM, Immanuel mane.d...@googlemail.com wrote:
 Hello all,

 I posted a questions on how to terminate a function call that does not
 return after a certain time ( I can not modify the function code) some
 time ago.
 Since I didn't find a solution I just came up with the idea to run the
 functions call in a separate thread who I could terminate a will.

 Would this be possible? Any pointers in the right direction?

Try package multicore. You can run child processes using parallel()
and kill() the child process when it runs out of time. Not sure how
easy or hard it is because I have never kill'ed a process using that
function, but it should work.

HTH,

Peter

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


Re: [R] CDFs

2011-08-22 Thread David Winsemius


On Aug 22, 2011, at 3:50 PM, R. Michael Weylandt wrote:

Yes. The xCDF/yCDF objects that are returned by the ecdf function  
can be

called like functions.


Because they _are_ functions.

 function %in% class(xCDF)
[1] TRUE
 is.function(xCDF)
[1] TRUE



For example:

x = rnrom(50); xCDF = ecdf(x); xCDF(0.3)
# This value tells you what fraction of x is less than 0.3

You can also assign this behavior to a function:

F - function(z) { xCDF(z) }

F does not inherit xCDF directly though and looses the step-function- 
ness of

the xCDF object. (Compare plots of F and xCDF to see one consequence)


Not correct. Steps are still there in the same locations.



So yes, you can do subtraction on this basis

x = rnrom(50); Fx = ecdf(x); Fx - function(z) { xCDF(z) }


You are adding an unnecessary function layer. Try (after correcting  
the misspelling):


xCDF(seq(-2,2,by=0.02)) == Fx(seq(-2,2,by=0.02)) # = creating Fx is  
superfluous


x - function(x){function(x) x}  == x - function(x){ x}

Turtles all the way down.



y = rnrom(50); yCDF = ecdf(x); Fy - function(z) { yCDF(z) }

F - function(z) {Fx(z) - Fy(z)}
# F - function(z) {xCDF(z)-yCDF(z)} # Another way to do the same  
thing


As this would have this:

 F = function(z) xCDF(z)-yCDF(z)
 plot(seq(-2,2,by=0.02), F(seq(-2,2,by=0.02)) ,type=l)

Interesting plot by the way. Unit steps at Gaussian random intervals.  
I'm not sure my intuition would have gotten there all on its own. I  
guess that arises from the discreteness of the sampling. I wasn't  
think that ecdf was the inverse function but seem to remember someone  
(some bloke named Weylandt, now that I check)  saying as much earlier  
in the day.


--
David.


Hope this helps,

Michael


On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton jim.silver...@gmail.com 
wrote:


WHat about if you have two cdfs and you want to subtract them? Like  
G(x) -

H(x)? Can ecdf do this?


On Mon, Aug 22, 2011 at 2:24 PM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:


Number 1 can be done as follows:

x = rnorm(50); y = rnorm(50)
xCDF = ecdf(x); yCDF = ecdf(y)

plot(xCDF)
lines(yCDF,col=2)

For the other ones, you are going to have to be a little more  
specific as
to how you want to do the approximation...but ?density might be a  
place to
start for #4, assuming you meant density of the PDF. If you meant  
CDF, it I

think that's implicit in number 2.

Michael Weylandt

On Mon, Aug 22, 2011 at 2:15 PM, Jim Silverton jim.silver...@gmail.com 
wrote:



Hello all,

I have two columns of numbers. I would like to do the following:
(1) Plot both cdfs, F1 and F2 on the same graph.
(2) Find smoothed approximations of F1 and F2 lets call them  
F1hat and

F2hat
(3) Find values for F1hat when we substitue a value of x in it.
(4) Find the corresponding densities of the cdfs.
Any ideas?

--
Thanks,
Jim.

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







--
Thanks,
Jim.




[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


[R] looping with paste

2011-08-22 Thread Juta Kawalerowicz
Dear list, 

I have a spacialPolygonDataFrame where variables were unnecessarily imported as 
factors. So I am trying to unfactor variables from spatialPolygonDataFrame@data 
with a loop

 
for (i in (1:length(names( spatialPolygonDataFrame{


command-paste(spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[,i,])-as.character(
 spatialPolygonDataFrame$names( spatialPolygonDataFrame@data[,i,]))
command-noquote(command)
command

}


But I keep getting just a printout

spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 1 
])-as.character(spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 1 
])
spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 2 
])-as.character(spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 2 
])
spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 3 
])-as.character(spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[ 3 
])

and so on

Could somebody suggest why it's not working?
Thanks, 
Juta
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting cases from matrices stored in lists

2011-08-22 Thread mdvaan
Thanks Jean, changing c[[t]] to c[[year]] solved the issue.

Math


Jean V Adams wrote:
 
 Re: [R] Selecting cases from matrices stored in lists
 mdvaan 
 to:
 r-help
 08/22/2011 09:46 AM
 
 Jean V Adams wrote:
  
  [R] Selecting cases from matrices stored in lists
  mdvaan 
  to:
  r-help
  08/22/2011 07:24 AM
  
  Hi,
  
  I have two lists (c and h - see below) containing matrices with 
 similar
  cases but different values. I want to split these matrices into 
 multiple
  matrices based on the values in h. So, I did the following:
  
  years-c(1997:1999) 
  for (t in 1:length(years)) 
  { 
  year=as.character(years[t]) 
  h[[year]]-sapply(colnames(h[[year]]), function(var)
  h[[year]][h[[year]][,var]0, h[[year]][var,]0]) 
  } 
  
  Now that I have created list h (with split matrices), I would like to 
 
  use
  these selections to make similar selections in list c. List c needs 
 to 
  get
  the exact same shape as h, so that `8026`in 1997 (c$`1997`$`8026`) 
 looks
  like this: 
  
  $`1997`$`8026` 
B 
  B  8025 8026 8029 
8025   1.000 0.7739527 0.9656091 
8026   0.7739527 1.000 0.7202771 
8029   0.9656091 0.7202771 1.000 
  
  Can anyone help me doing this? I have no idea how I can get it to 
 work.
  Thank you very much for your help! 
  
  
  Try this:
  
  c2 - h
  years - names(h)
  for (t in seq(years))
  { 
  year - years[t]
  c2[[year]] - sapply(colnames(h[[year]]), function(var) 
  c[[t]][h[[year]][ ,var]  0, h[[year]][var, ]  0]) 
  }
  
  By the way, it's great that you included code in your question.
  However, I encountered a couple of errors when running you code (see 
  below).
  
  Also, it would be better to use a different name for your list c, 
  because c() is a function in R.
  
  Jean
  
  
  library(zoo) 
  DF1 = data.frame(read.table(textConnection(B  C  D  E  F  G 
  8025  1995  0  4  1  2 
  8025  1997  1  1  3  4 
  8026  1995  0  7  0  0 
  8026  1996  1  2  3  0 
  8026  1997  1  2  3  1 
  8026  1998  6  0  0  4 
  8026  1999  3  7  0  3 
  8027  1997  1  2  3  9 
  8027  1998  1  2  3  1 
  8027  1999  6  0  0  2 
  8028  1999  3  7  0  0 
  8029  1995  0  2  3  3 
  8029  1998  1  2  3  2 
  8029  1999  6  0  0  1),head=TRUE,stringsAsFactors=FALSE)) 
  
  a - read.zoo(DF1, split = 1, index = 2, FUN = identity) 
  sum.na - function(x) if (any(!is.na(x))) sum(x, na.rm = TRUE) else 
 NA 
  b - rollapply(a, 3,  sum.na, align = right, partial = TRUE) 
  
  Error in FUN(cdata[st, i], ...) : unused argument(s) (partial = TRUE)
  
  rollapply() has no argument partial.
  
  newDF - lapply(1:nrow(b), function(i) 
prop.table(na.omit(matrix(b[i,], nc = 4, byrow = TRUE, 
  dimnames = list(unique(DF1$B), names(DF1)[-1:-2]))), 
 1)) 
  
  names(newDF) - time(a) 
  
  Error in names(newDF) - time(a) : 
'names' attribute [5] must be the same length as the vector [3]
  
  newDF has only 3 names, but time(a) is of length 5.
  
  c-lapply(newDF, function(mat) tcrossprod(mat / 
 sqrt(rowSums(mat^2 
  
  DF2 = data.frame(read.table(textConnection(  A  B  C 
  80  8025  1995 
  80  8026  1995 
  80  8029  1995 
  81  8026  1996 
  82  8025  1997 
  82  8026  1997 
  83  8025  1997 
  83  8027  1997 
  90  8026  1998 
  90  8027  1998 
  90  8029  1998 
  84  8026  1999 
  84  8027  1999 
  85  8028  1999 
  85  8029  1999),head=TRUE,stringsAsFactors=FALSE)) 
  
  e - function(y) crossprod(table(DF2[DF2$C %in% y, 1:2])) 
  years - sort(unique(DF2$C)) 
  f - as.data.frame(embed(years, 3)) 
  g-lapply(split(f, f[, 1]), e) 
  h-lapply(g, function (x) ifelse(x0,1,0)) 
 [[alternative HTML version deleted]]
  
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
 
 Sorry, I am using the devel version of zoo which allows you to use the
 partial argument. The correct code is given below. 
 
 My error.  I didn't have the latest version installed.
 
 
 I didn't get your suggestion to work. If I understand what you are 
 trying to
 do (multiplying c and h), this is likely to give the wrong results 
 because h
 contains values of 0. Since I am ultimately interested in the values of 
 the
 split matrices in c (based on the original matrices in c), this will
 probable not work. Or am I just not understanding you? 
 
 I'm not doing any multiplication.  I just applied your extraction
 [h[[year]][ ,var]  0, h[[year]][var, ]  0]
 to the c list rather than the h list.
 
 You say you didn't get it to work.  Did you get an error message?  Or did 
 it run, but not give you the values you wanted?  Or ... ?
 
 Jean
 
 
 Thanks! 
 
 # devel version of zoo
 install.packages(zoo, repos = http://r-forge.r-project.org;)
 

Re: [R] looping with paste

2011-08-22 Thread Sarah Goslee
Juta,

On Mon, Aug 22, 2011 at 4:29 PM, Juta Kawalerowicz
juta.kawalerow...@stx.ox.ac.uk wrote:
 Dear list,

 I have a spacialPolygonDataFrame where variables were unnecessarily imported 
 as factors. So I am trying to unfactor variables from 
 spatialPolygonDataFrame@data with a loop


 for (i in (1:length(names( spatialPolygonDataFrame{


 command-paste(spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[,i,])-as.character(
  spatialPolygonDataFrame$names( spatialPolygonDataFrame@data[,i,]))
 command-noquote(command)
 command

 }


 But I keep getting just a printout

Yeah, you're putting together a string, not actually running any commands.

Does this not work:

for (i in (1:length(names( spatialPolygonDataFrame{

spatialPolygonDataFrame$names(spatialPolygonDataFrame@data[i]) -
as.character( spatialPolygonDataFrame$names(
spatialPolygonDataFrame@data[i]))

}

Subsetting on a variable should work just fine. I don't see any need for
paste().

Sarah
-- 
Sarah Goslee


http://www.functionaldiversity.org

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


Re: [R] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
 [R] Counting Elements Conditionally
 Edward Patzelt 
 to:
 r-help
 08/22/2011 02:33 PM
 
 R -
 
 I have 3 variables with data below.  Variable Rev is a vector that 
changes
 from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with 
1's
 and 0's.  Variable bin is a different binary variable with 1's and 
0's.
 
 I want to calculate the number of elements:
 
 1.  Starting with the first element where Rev switches (i.e. 1 to 2)
 
 2.  The number of elements between the transition and the first 0 in the
 FF vector; *when bin is also a 0.*
 *
 *
 3.  I want to do this for each transition in Rev, but ignore all 
elements
 after calculating #2 until another transition has occurred.
 
 
 structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
 1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
 ), row.names = c(NA, -40L), class = data.frame)
 
 
 -- 
 Edward H. Patzelt
 Research Assistant ? TRiCAM Lab
 University of Minnesota ? Psychology/Psychiatry
 VA Medical Center
 Office: S355 Elliot Hall - Twin Cities Campus
 Phone: 612-626-0072  Email: patze...@umn.edu
 

Try this (I'm assuming your data.frame is called df:


uR - unique(df$Rev)
uR0 - uR*10L

first.Rev - match(uR, df$Rev)
first.Rev0 - match(uR0, df$Rev * 10L + df$FF)

no.elements - first.Rev0 - first.Rev + 1


This starts with Rev=1 (rather than Rev=2), but you can get rid of that by 
dropping the first result ...


no.elements[-1]


Jean

[[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] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
 Re: [R] Counting Elements Conditionally
 Jean V Adams 
 to:
 Edward Patzelt
 08/22/2011 03:53 PM
 
  [R] Counting Elements Conditionally
  Edward Patzelt 
  to:
  r-help
  08/22/2011 02:33 PM
  
  R -
  
  I have 3 variables with data below.  Variable Rev is a vector that 
 changes
  from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with 
 1's
  and 0's.  Variable bin is a different binary variable with 1's and 
 0's.
  
  I want to calculate the number of elements:
  
  1.  Starting with the first element where Rev switches (i.e. 1 to 2)
  
  2.  The number of elements between the transition and the first 0 in 
the
  FF vector; *when bin is also a 0.*
  *
  *
  3.  I want to do this for each transition in Rev, but ignore all 
 elements
  after calculating #2 until another transition has occurred.
  
  
  structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
  1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
  1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
  1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
  1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
  0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
  ), row.names = c(NA, -40L), class = data.frame)
  
  
  -- 
  Edward H. Patzelt
  Research Assistant ? TRiCAM Lab
  University of Minnesota ? Psychology/Psychiatry
  VA Medical Center
  Office: S355 Elliot Hall - Twin Cities Campus
  Phone: 612-626-0072  Email: patze...@umn.edu
  
 
 Try this (I'm assuming your data.frame is called df:
 
 
 uR - unique(df$Rev)
 uR0 - uR*10L
 
 first.Rev - match(uR, df$Rev)
 first.Rev0 - match(uR0, df$Rev * 10L + df$FF)
 
 no.elements - first.Rev0 - first.Rev + 1
 
 
 This starts with Rev=1 (rather than Rev=2), but you can get rid of that 
by 
 dropping the first result ...
 
 
 no.elements[-1]
 
 
 Jean
 

Ooops.  Too hasty in my reply.  I missed the part about bin also being 
zero.  Try this instead.


uR - unique(df$Rev)
uR00 - uR*100L

first.Rev - match(uR, df$Rev)
first.Rev00 - match(uR00, df$Rev * 100L + df$FF * 10L + df$bin)

no.elements - first.Rev00 - first.Rev + 1


Jean
[[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] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
Awesome, this is close, couple changes.  Below is full data set for 1
person.  I want the code to look at the first time it sees a 0 in FF after
the transition in Rev.  I then want it to test whether bin is also a 0.  If
and only if this is the first 0 in FF after the transition, and bin = 0,
then count the number of elements between the transition in Rev and the 0 in
FF.

structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L), FF = c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L,
1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1)), .Names = c(Rev, FF, bin), row.names = c(NA,
-125L), class = data.frame)


On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote:


  Re: [R] Counting Elements Conditionally
  Jean V Adams
  to:
  Edward Patzelt
  08/22/2011 03:53 PM
 
   [R] Counting Elements Conditionally
   Edward Patzelt
   to:
   r-help
   08/22/2011 02:33 PM
  
   R -
  
   I have 3 variables with data below.  Variable Rev is a vector that
  changes
   from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with
  1's
   and 0's.  Variable bin is a different binary variable with 1's and
  0's.
  
   I want to calculate the number of elements:
  
   1.  Starting with the first element where Rev switches (i.e. 1 to 2)
  
   2.  The number of elements between the transition and the first 0 in
 the
   FF vector; *when bin is also a 0.*
   *
   *
   3.  I want to do this for each transition in Rev, but ignore all
  elements
   after calculating #2 until another transition has occurred.
  
  
   structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
   1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
   2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
   1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
   1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
   1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
   0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
   ), row.names = c(NA, -40L), class = data.frame)
  
  
   --
   Edward H. Patzelt
   Research Assistant ? TRiCAM Lab
   University of Minnesota ? Psychology/Psychiatry
   VA Medical Center
   Office: S355 Elliot Hall - Twin Cities Campus
   Phone: 612-626-0072  Email: patze...@umn.edu
  
 
  Try this (I'm assuming your data.frame is called df:
 
 
  uR - unique(df$Rev)
  uR0 - uR*10L
 
  first.Rev - match(uR, df$Rev)
  first.Rev0 - match(uR0, df$Rev * 10L + df$FF)
 
  no.elements - first.Rev0 - first.Rev + 1
 
 
  This starts with Rev=1 (rather than Rev=2), but you can get rid of that
 by
  dropping the first result ...
 
 
  no.elements[-1]
 
 
  Jean
 

 Ooops.  Too hasty in my reply.  I missed the part about bin also being
 zero.  Try this instead.


 uR - unique(df$Rev)
 uR00 - uR*100L

 first.Rev - match(uR, df$Rev)
 first.Rev00 - match(uR00, df$Rev * 100L + df$FF * 10L + df$bin)

 no.elements - first.Rev00 - first.Rev + 1


 Jean




-- 
Edward H. Patzelt
Research Assistant – TRiCAM Lab
University of Minnesota – Psychology/Psychiatry
VA Medical Center
Office: S355 Elliot Hall - Twin Cities Campus
Phone: 612-626-0072  Email: patze...@umn.edu

Please consider the environment before printing this email
www.psych.umn.edu/research/tricam

[[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] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
after it sees the first occurrence of 0 in FF following a transition, I want
it to ignore all further elements until the next transition.

On Mon, Aug 22, 2011 at 3:58 PM, Edward Patzelt patze...@umn.edu wrote:

 Awesome, this is close, couple changes.  Below is full data set for 1
 person.  I want the code to look at the first time it sees a 0 in FF after
 the transition in Rev.  I then want it to test whether bin is also a 0.  If
 and only if this is the first 0 in FF after the transition, and bin = 0,
 then count the number of elements between the transition in Rev and the 0 in
 FF.

 structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
 3L, 3L, 3L), FF = c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L,
 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L,
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L,
 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L,
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L,
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0,
 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1,
 1, 1, 1, 1, 1)), .Names = c(Rev, FF, bin), row.names = c(NA,
 -125L), class = data.frame)


 On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote:


  Re: [R] Counting Elements Conditionally
  Jean V Adams
  to:
  Edward Patzelt
  08/22/2011 03:53 PM
 
   [R] Counting Elements Conditionally
   Edward Patzelt
   to:
   r-help
   08/22/2011 02:33 PM
  
   R -
  
   I have 3 variables with data below.  Variable Rev is a vector that
  changes
   from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with
  1's
   and 0's.  Variable bin is a different binary variable with 1's and
  0's.
  
   I want to calculate the number of elements:
  
   1.  Starting with the first element where Rev switches (i.e. 1 to 2)
  
   2.  The number of elements between the transition and the first 0 in
 the
   FF vector; *when bin is also a 0.*
   *
   *
   3.  I want to do this for each transition in Rev, but ignore all
  elements
   after calculating #2 until another transition has occurred.
  
  
   structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
   1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
   2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
   1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
   1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
   1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
   0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
   ), row.names = c(NA, -40L), class = data.frame)
  
  
   --
   Edward H. Patzelt
   Research Assistant ? TRiCAM Lab
   University of Minnesota ? Psychology/Psychiatry
   VA Medical Center
   Office: S355 Elliot Hall - Twin Cities Campus
   Phone: 612-626-0072  Email: patze...@umn.edu
  
 
  Try this (I'm assuming your data.frame is called df:
 
 
  uR - unique(df$Rev)
  uR0 - uR*10L
 
  first.Rev - match(uR, df$Rev)
  first.Rev0 - match(uR0, df$Rev * 10L + df$FF)
 
  no.elements - first.Rev0 - first.Rev + 1
 
 
  This starts with Rev=1 (rather than Rev=2), but you can get rid of that
 by
  dropping the first result ...
 
 
  no.elements[-1]
 
 
  Jean
 

 Ooops.  Too hasty in my reply.  I missed the part about bin also being
 zero.  Try this instead.


 uR - unique(df$Rev)
 uR00 - uR*100L

 first.Rev - match(uR, df$Rev)
 first.Rev00 - match(uR00, df$Rev * 100L + df$FF * 10L + df$bin)

 no.elements - first.Rev00 - first.Rev + 1


 Jean




 --
 Edward H. Patzelt
 Research Assistant – TRiCAM Lab
 University of Minnesota – Psychology/Psychiatry
 VA Medical Center
 Office: S355 Elliot Hall - Twin Cities Campus
 Phone: 612-626-0072  Email: patze...@umn.edu

 Please consider the environment before printing this email
 www.psych.umn.edu/research/tricam




-- 
Edward H. Patzelt
Research Assistant – TRiCAM Lab
University of Minnesota – Psychology/Psychiatry
VA Medical Center
Office: S355 Elliot Hall - Twin Cities 

Re: [R] CDFs

2011-08-22 Thread David Winsemius


On Aug 22, 2011, at 4:34 PM, David Winsemius wrote:



On Aug 22, 2011, at 3:50 PM, R. Michael Weylandt wrote:

Yes. The xCDF/yCDF objects that are returned by the ecdf function  
can be

called like functions.


Because they _are_ functions.

 function %in% class(xCDF)
[1] TRUE
 is.function(xCDF)
[1] TRUE



For example:

x = rnrom(50); xCDF = ecdf(x); xCDF(0.3)
# This value tells you what fraction of x is less than 0.3

You can also assign this behavior to a function:

F - function(z) { xCDF(z) }

F does not inherit xCDF directly though and looses the step- 
function-ness of

the xCDF object. (Compare plots of F and xCDF to see one consequence)


Not correct. Steps are still there in the same locations.



So yes, you can do subtraction on this basis

x = rnrom(50); Fx = ecdf(x); Fx - function(z) { xCDF(z) }


You are adding an unnecessary function layer. Try (after  
correcting the misspelling):


xCDF(seq(-2,2,by=0.02)) == Fx(seq(-2,2,by=0.02)) # = creating Fx is  
superfluous


x - function(x){function(x) x}  == x - function(x){ x}

Turtles all the way down.



y = rnrom(50); yCDF = ecdf(x); Fy - function(z) { yCDF(z) }

F - function(z) {Fx(z) - Fy(z)}
# F - function(z) {xCDF(z)-yCDF(z)} # Another way to do the same  
thing


As this would have this:

F = function(z) xCDF(z)-yCDF(z)
plot(seq(-2,2,by=0.02), F(seq(-2,2,by=0.02)) ,type=l)

Interesting plot by the way. Unit steps at Gaussian random  
intervals. I'm not sure my intuition would have gotten there all on  
its own. I guess that arises from the discreteness of the sampling.  
I wasn't think that ecdf was the inverse function but seem to  
remember someone (some bloke named Weylandt, now that I check)   
saying as much earlier in the day.




I take it back. Not necessarily unit jumps, Quantized, yes, but the  
sample I'm looking at has jumps of 0,1,2, and 3  * 0.02 units.   
Poisson?  (Probably a homework problem in Feller.)



--
David.


Hope this helps,

Michael


On Mon, Aug 22, 2011 at 3:30 PM, Jim Silverton jim.silver...@gmail.com 
wrote:


WHat about if you have two cdfs and you want to subtract them?  
Like G(x) -

H(x)? Can ecdf do this?


On Mon, Aug 22, 2011 at 2:24 PM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:


Number 1 can be done as follows:

x = rnorm(50); y = rnorm(50)
xCDF = ecdf(x); yCDF = ecdf(y)

plot(xCDF)
lines(yCDF,col=2)

For the other ones, you are going to have to be a little more  
specific as
to how you want to do the approximation...but ?density might be a  
place to
start for #4, assuming you meant density of the PDF. If you meant  
CDF, it I

think that's implicit in number 2.

Michael Weylandt

On Mon, Aug 22, 2011 at 2:15 PM, Jim Silverton jim.silver...@gmail.com 
wrote:



Hello all,

I have two columns of numbers. I would like to do the following:
(1) Plot both cdfs, F1 and F2 on the same graph.
(2) Find smoothed approximations of F1 and F2 lets call them  
F1hat and

F2hat
(3) Find values for F1hat when we substitue a value of x in it.
(4) Find the corresponding densities of the cdfs.
Any ideas?

--
Thanks,
Jim.

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







--
Thanks,
Jim.




[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
So, using the full data set, what should the result look like?

c(NA, NA, NA, 3, NA,NA, NA, 2) ?

Jean

Edward Patzelt patze...@umn.edu wrote on 08/22/2011 03:58:38 PM:

 [image removed] 
 
 Re: [R] Counting Elements Conditionally
 
 Edward Patzelt 
 
 to:
 
 Jean V Adams
 
 08/22/2011 03:58 PM
 
 Cc:
 
 r-help
 
 Awesome, this is close, couple changes.  Below is full data set for 
 1 person.  I want the code to look at the first time it sees a 0 in 
 FF after the transition in Rev.  I then want it to test whether bin 
 is also a 0.  If and only if this is the first 0 in FF after the 
 transition, and bin = 0, then count the number of elements between 
 the transition in Rev and the 0 in FF.
 
 
 structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
 3L, 3L, 3L), FF = c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 
 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 
 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 
 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 
 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 
 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 
 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 
 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 
 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 
 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 
 1, 1, 1, 1, 1)), .Names = c(Rev, FF, bin), row.names = c(NA, 
 -125L), class = data.frame)
 
 On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote:
 
  Re: [R] Counting Elements Conditionally 
  Jean V Adams 
  to: 
  Edward Patzelt 
  08/22/2011 03:53 PM 
  
   [R] Counting Elements Conditionally
   Edward Patzelt 
   to:
   r-help
   08/22/2011 02:33 PM
   
   R -
   
   I have 3 variables with data below.  Variable Rev is a vector that 

  changes
   from 1 to 2, 2 to 3, etc  Variable FF is a binary variable 
with 
  1's
   and 0's.  Variable bin is a different binary variable with 1's and 

  0's.
   
   I want to calculate the number of elements:
   
   1.  Starting with the first element where Rev switches (i.e. 1 to 2)
   
   2.  The number of elements between the transition and the first 0 in 
the
   FF vector; *when bin is also a 0.*
   *
   *
   3.  I want to do this for each transition in Rev, but ignore all 
  elements
   after calculating #2 until another transition has occurred.
   
   
   structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
   1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
   2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
   1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
   1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
   1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
   0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
   ), row.names = c(NA, -40L), class = data.frame)
   
   
   -- 
   Edward H. Patzelt
   Research Assistant ? TRiCAM Lab
   University of Minnesota ? Psychology/Psychiatry
   VA Medical Center
   Office: S355 Elliot Hall - Twin Cities Campus
   Phone: 612-626-0072  Email: patze...@umn.edu
   
  
  Try this (I'm assuming your data.frame is called df:
  
  
  uR - unique(df$Rev)
  uR0 - uR*10L
  
  first.Rev - match(uR, df$Rev)
  first.Rev0 - match(uR0, df$Rev * 10L + df$FF)
  
  no.elements - first.Rev0 - first.Rev + 1
  
  
  This starts with Rev=1 (rather than Rev=2), but you can get rid of 
that by 
  dropping the first result ...
  
  
  no.elements[-1]
  
  
  Jean
  

 Ooops.  Too hasty in my reply.  I missed the part about bin also 
 being zero.  Try this instead. 
 
 
 uR - unique(df$Rev) 
 uR00 - uR*100L 
 
 first.Rev - match(uR, df$Rev) 
 first.Rev00 - match(uR00, df$Rev * 100L + df$FF * 10L + df$bin) 
 
 no.elements - first.Rev00 - first.Rev + 1 
 
 
 Jean
 

 
 -- 
 Edward H. Patzelt
 Research Assistant ? TRiCAM Lab
 University of Minnesota ? Psychology/Psychiatry
 VA Medical Center
 Office: S355 Elliot Hall - Twin Cities Campus
 Phone: 612-626-0072  Email: patze...@umn.edu
 
 Please consider the environment before printing this email
 

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
that is exactly correct, assuming we did not start at the beginning, but
started at the first transition (this is the correct way to think about it)

On Mon, Aug 22, 2011 at 4:08 PM, Jean V Adams jvad...@usgs.gov wrote:


 So, using the full data set, what should the result look like?

 c(NA, NA, NA, 3, NA,NA, NA, 2) ?

 Jean

 Edward Patzelt patze...@umn.edu wrote on 08/22/2011 03:58:38 PM:

  [image removed]
 
  Re: [R] Counting Elements Conditionally
 
  Edward Patzelt
 
  to:
 
  Jean V Adams
 
  08/22/2011 03:58 PM
 
  Cc:
 
  r-help
 
  Awesome, this is close, couple changes.  Below is full data set for
  1 person.  I want the code to look at the first time it sees a 0 in
  FF after the transition in Rev.  I then want it to test whether bin
  is also a 0.  If and only if this is the first 0 in FF after the
  transition, and bin = 0, then count the number of elements between
  the transition in Rev and the 0 in FF.
 
 
  structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
  3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
  2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
  3L, 3L, 3L), FF = c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L,
  1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L,
  1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L,
  1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L,
  1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,
  0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L,
  1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L,
  1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0,
  1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1)), .Names = c(Rev, FF, bin), row.names = c(NA,
  -125L), class = data.frame)
 
  On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote:
 
   Re: [R] Counting Elements Conditionally
   Jean V Adams
   to:
   Edward Patzelt
   08/22/2011 03:53 PM
  
[R] Counting Elements Conditionally
Edward Patzelt
to:
r-help
08/22/2011 02:33 PM
   
R -
   
I have 3 variables with data below.  Variable Rev is a vector that
   changes
from 1 to 2, 2 to 3, etc  Variable FF is a binary variable with

   1's
and 0's.  Variable bin is a different binary variable with 1's and
   0's.
   
I want to calculate the number of elements:
   
1.  Starting with the first element where Rev switches (i.e. 1 to 2)
   
2.  The number of elements between the transition and the first 0 in
 the
FF vector; *when bin is also a 0.*
*
*
3.  I want to do this for each transition in Rev, but ignore all
   elements
after calculating #2 until another transition has occurred.
   
   
structure(list(Rev = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), FF = c(0L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L), bin = c(NA, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1)), .Names = c(Rev, FF, bin
), row.names = c(NA, -40L), class = data.frame)
   
   
--
Edward H. Patzelt
Research Assistant ? TRiCAM Lab
University of Minnesota ? Psychology/Psychiatry
VA Medical Center
Office: S355 Elliot Hall - Twin Cities Campus
Phone: 612-626-0072  Email: patze...@umn.edu
   
  
   Try this (I'm assuming your data.frame is called df:
  
  
   uR - unique(df$Rev)
   uR0 - uR*10L
  
   first.Rev - match(uR, df$Rev)
   first.Rev0 - match(uR0, df$Rev * 10L + df$FF)
  
   no.elements - first.Rev0 - first.Rev + 1
  
  
   This starts with Rev=1 (rather than Rev=2), but you can get rid of that
 by
   dropping the first result ...
  
  
   no.elements[-1]
  
  
   Jean
  

  Ooops.  Too hasty in my reply.  I missed the part about bin also
  being zero.  Try this instead.
 
 
  uR - unique(df$Rev)
  uR00 - uR*100L
 
  first.Rev - match(uR, df$Rev)
  first.Rev00 - match(uR00, df$Rev * 100L + df$FF * 10L + df$bin)
 
  no.elements - first.Rev00 - first.Rev + 1
 
 
  Jean
 

 
  --
  

Re: [R] Threads in R

2011-08-22 Thread Immanuel

Hello,

thanks for the input. Below is a small example, simpler then expected :)
 I'm just curious why I can't see any output from print(i).

--
library(multicore)

f_long - function() {
for (i in 1:1){ a=i}
print(i)
return(finished)
}

p_long - parallel(f_long() ,silent =FALSE)
collect(p_long, wait=FALSE, 10)
# stops the execution since its not finished after 10sec
# on my machine anyway ;)


f_short - function() {
for (i in 1:1){ a=i}
print(i)
return(finished)
}


p_short - parallel(f_short() ,silent =FALSE)
collect(p_short, wait=FALSE, 10)
# will retrieve the result (since it's fast)

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


  1   2   >