[R] lattice: ticks at the joining sides of panels?

2013-02-26 Thread Martin Ivanov
 Dear R users,

I would like to produce a lattice graph that keeps the ticks at the joining 
sides of the panels.
For example:

library(lattice)
library(datasets)
xyplot(lat ~ long | cut(depth, 2), data = quakes, between=list(x=1))

You can see that ticks are plotted at the sides 1 (bottom), 2 (right) and 3 
(top) of panel 1
and 1 (bottom), 3 (top) and 4 (right) of panel 2. Is it possible to plot ticks 
at side
4 (right) of panel 1 and side 2 (left) of panel 2?

Thank You very much for Your attention.

Best regards,

Martin

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


Re: [R] Issue attaching a dataset

2013-02-26 Thread Milan Bouchet-Valat
Le lundi 25 février 2013 à 20:26 -0300, Pablo Menese a écrit :
 I use to work whit stata dataframe, so, when I use R I type read.dta
 Until today I do that without any problem, after type:
 
 mydata-read.dta(C:/dropbox/dataframe.dta)
 attach(mydata)
 
 Everything works great... but today, when I typed:
 
 mydata-read.dta(C:/dropbox/dataframe.dta)
 attach(mydata)
 
 Appeared:
 
 Error in substr(these, 1L, 6L) : invalid multibyte string at 'f1'
 
 I searched in google and nothing. Can anyone help me?
To be clear: the error appears when running read.dta(), not when calling
attach(), right? And the C:/dropbox/dataframe.dta that fails today is
different from the one that worked yesterday? Are you able to read it in
Stata?

Also, please provide the output of sessionInfo().


Regards

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

2013-02-26 Thread Prof Brian Ripley

On 26/02/2013 09:55, Milan Bouchet-Valat wrote:

Le lundi 25 février 2013 à 20:26 -0300, Pablo Menese a écrit :

I use to work whit stata dataframe, so, when I use R I type read.dta
Until today I do that without any problem, after type:

mydata-read.dta(C:/dropbox/dataframe.dta)
attach(mydata)

Everything works great... but today, when I typed:

mydata-read.dta(C:/dropbox/dataframe.dta)
attach(mydata)

Appeared:

Error in substr(these, 1L, 6L) : invalid multibyte string at 'f1'

I searched in google and nothing. Can anyone help me?

To be clear: the error appears when running read.dta(), not when calling
attach(), right? And the C:/dropbox/dataframe.dta that fails today is
different from the one that worked yesterday? Are you able to read it in
Stata?

Also, please provide the output of sessionInfo().


Note that Stata say

 4. Strings use ASCII encoding.

(in the URL linked from ?read.dta).  We have seen exceptions in the 
past, but as the format has no way to record the encoding (it is ASCII, 
right?), read.dta can only read files in the native encoding.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[R] Help with graphs in A4 size

2013-02-26 Thread Eva Prieto Castro

Hi, 

I need to generate complex graphics which have to be shown in the plot window 
but also in pdf file, and they must have A4 size. This is the reason why I use 
width=8.27 and heigth=11.69.

The problem is that I don't make it runs when I put something (text, lines, and 
so on) outside the plot region. 

I mean if I run the following code, it works perfectly, because the text My 
title appears in pdf:

library(plotrix)
graphics.off()
windows(width=8.27, height=11.69)

plot(3:10, main=My title)
###text(4, 11,My title)
axis.break()
axis.break(2,2.9,style=zigzag)
mtext(Texto adicional, side=1, line=2)
text(4, 9,Texto)

dev.copy2pdf(file=Graph.pdf,height=11.69, width=8.27)
shell.exec(file.path(getwd(), Graph.pdf))

However, if I use text() to put My title (outside the plot region) it seems 
that dev.copy2pdf 
does not make the pdf correctly (it expands the plot and the text My title 
does not appear).
I indicate the code I refer to:

library(plotrix)
graphics.off()
windows(width=8.27, height=11.69)

plot(3:10)
#plot(3:10, main=My title)
par(xpd=TRUE)
text(4, 11,My title)
axis.break()
axis.break(2,2.9,style=zigzag)
mtext(Texto adicional, side=1, line=2)
text(4, 9,Texto)

dev.copy2pdf(file=Graph.pdf,height=11.69, width=8.27)
shell.exec(file.path(getwd(), Graph.pdf))

I have tested using layout with different zones and the results were wrong. 

Some idea about how can I solve it?.

I indicate some important notes:

1) I need to use plotrix package, because of axis.break and addtable2plot 
functions.
2) I can not use ggplot2 packahe, because of incompatibility with other 
functions I have to choose.
3) I would not like to use pdf() and dev.off() as method for the pdf creation. 
I would like to use dev.copy2pdf.

Thank you in advance.


Eva

[[alternative HTML version deleted]]

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


Re: [R] Help with graphs in A4 size

2013-02-26 Thread Duncan Mackay

Hi Eva

Apparently no problem for me with Win 7 as far as I can see. Perhaps 
returning to the command window may be a problem?


R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] 
LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252 
LC_MONETARY=English_Australia.1252 
LC_NUMERIC=C   LC_TIME=English_Australia.1252


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


other attached packages:
[1] 
plotrix_3.4-5   R.oo_1.10.1 R.methodsS3_1.4.2 
foreign_0.8-51  chron_2.3-43MASS_7.3-22 
latticeExtra_0.6-24 RColorBrewer_1.0-5

[9] lattice_0.20-10

Now to bed

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



At 21:45 26/02/2013, you wrote:


Hi,

I need to generate complex graphics which have to be shown in the 
plot window but also in pdf file, and they must have A4 size. This 
is the reason why I use width=8.27 and heigth=11.69.


The problem is that I don't make it runs when I put something (text, 
lines, and so on) outside the plot region.


I mean if I run the following code, it works perfectly, because the 
text My title appears in pdf:


library(plotrix)
graphics.off()
windows(width=8.27, height=11.69)

plot(3:10, main=My title)
###text(4, 11,My title)
axis.break()
axis.break(2,2.9,style=zigzag)
mtext(Texto adicional, side=1, line=2)
text(4, 9,Texto)

dev.copy2pdf(file=Graph.pdf,height=11.69, width=8.27)
shell.exec(file.path(getwd(), Graph.pdf))

However, if I use text() to put My title (outside the plot region) 
it seems that dev.copy2pdf
does not make the pdf correctly (it expands the plot and the text 
My title does not appear).

I indicate the code I refer to:

library(plotrix)
graphics.off()
windows(width=8.27, height=11.69)

plot(3:10)
#plot(3:10, main=My title)
par(xpd=TRUE)
text(4, 11,My title)
axis.break()
axis.break(2,2.9,style=zigzag)
mtext(Texto adicional, side=1, line=2)
text(4, 9,Texto)

dev.copy2pdf(file=Graph.pdf,height=11.69, width=8.27)
shell.exec(file.path(getwd(), Graph.pdf))

I have tested using layout with different zones and the results were wrong.

Some idea about how can I solve it?.

I indicate some important notes:

1) I need to use plotrix package, because of axis.break and 
addtable2plot functions.
2) I can not use ggplot2 packahe, because of incompatibility with 
other functions I have to choose.
3) I would not like to use pdf() and dev.off() as method for the pdf 
creation. I would like to use dev.copy2pdf.


Thank you in advance.


Eva

[[alternative HTML version deleted]]

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


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


[R] parallel execution in R

2013-02-26 Thread Alaios
Dear all,
I have a piece of code that  I want to run in parallel (I am working in system 
of 16 cores)


foreach (i=(seq(-93,-73,length.out=21))) %dopar% 
 {
  threshold-i
 
 print(i)
 do_analysis1(i,path)
 do_analysis2(i,path)
           do_something_else_analysis1(i,path)
           something_else_now(i,path)
 }


as you can see I have already tried to make this run in parallel, meaning for 
every  i   value each of the 16 processor shoule take a block of the body such 
as:

    threshold-i
 
 print(i)
 do_analysis1(i,path)
 do_analysis2(i,path)
           do_something_else_analysis1(i,path)
           something_else_now(i,,path)
 



and execute it . Unfortunately this does not work and oonly one processor looks 
utilized.

Alternatively, mclapply have worked well in the past, but in this case I am not 
sure how to convert the serial execution of the body of the loop to a list that 
would be compatible with the mclapply. 

I would like to thank you in advance for your help

Regards
Alex

[[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] frequency table-visualization for complex categorical variables

2013-02-26 Thread Niklas Fischer
Hi again,



Thanks for Anthony about the links on reproducible codes.



Thanks for Rui about ordering when rows are intact.



One more question





Here is your code.



x -
cbind(
sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
sample( LETTERS[1:6] , 100 , replace = TRUE )
)

y - as.matrix( x )

w2 - apply( y , 1 , paste0 , collapse =  )
table(w2)







Do you know any trick to organize merge certain elements together?

For example, if the final table includes

BCC, CCB, CBC how should I sum frequency of one element like BCC? I have a
very long table it would be indeed very useful!





Niklas.

2013/2/25 Rui Barradas ruipbarra...@sapo.pt

 Hello,

 I disagree with the way you've sorted the matrix, like this all A's become
 first, then B's, etc, irrespective of the respondents. Each row is a
 respondent, and the rows should be kept intact, but with a different
 ordering. To this effect, use order():

 z - y[order(y[,1], y[,2], y[,3]), ]


 Then use the rest of your code.

 Or, which would save us the sorting, paste the rows elements together
 directly from matrix 'y' and use the fact that table() sorts its output.

 w2 - apply( y , 1 , paste0 , collapse =  )
 table(w2)


 Hope this helps,

 Rui Barradas

 Em 25-02-2013 18:32, Anthony Damico escreveu:

  in the future, please provide R code to re-create some example data :)
 read
 http://stackoverflow.com/**questions/5963269/how-to-make-**
 a-great-r-reproducible-**exampleforhttp://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-examplefor
 more detail..



 # create a data table with three unique columns' values..
 # treat these values just like letters
 x -
  cbind(
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE )
  )

 # look at x.. this is good data i hope?
 x

 # convert this to a matrix
 y - as.matrix( x )

 # i don't think you care about ordering, so sort left-to-rightwards
 z - apply( y , 2 , sort )

 # look at your results
 z

 # paste these results together across the matrix
 w - apply( z , 1 , paste0 , collapse =  )

 # count the final distinct results
 table( w )




 On Mon, Feb 25, 2013 at 1:04 PM, Niklas Fischer
 niklasfischer...@gmail.com**wrote:

  Dear R users,

 I have three questions measuring close relationships.
 The questions are same and the respondents put the answer in order.

 I'd like to examine the pattern of answers and visualize it.

 For example q1 (A,B,C,D,E) and q2 and q3 are the same. If the respondents
 selects A B C (so BCA or BAC or CBA or CAB), I'd like to construct
 frequency table for ABC and other combinations for example DEF.


 Unfortunately, there are many answers, and three-way contingency table
 includes lots of cells which make it diffucult to interpret and requires
 lots of extra work to organize data.

 What is the best way to construct fruequency table of these kind of
 variables and to visulize the results with the most simple form


 All the bests,
 Niklas

  [[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.htmlhttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-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] lattice: ticks at the joining sides of panels?

2013-02-26 Thread Bert Gunter
Have you tried using an at list in the x and y components of the
scales list argument to xyplot?

The docs say that that list should be as long as the number of panels,
indicating that you get tic marks drawn for all panels. And I assume
you can specify no tics drawn for some.  Presumably this list is used
in whatever panel order you have specified. As I have never done this,
I do not know whether this works or gives you what you want. You just
will need to try and see.

-- Bert

On Tue, Feb 26, 2013 at 12:27 AM, Martin Ivanov tra...@abv.bg wrote:
  Dear R users,

 I would like to produce a lattice graph that keeps the ticks at the joining 
 sides of the panels.
 For example:

 library(lattice)
 library(datasets)
 xyplot(lat ~ long | cut(depth, 2), data = quakes, between=list(x=1))

 You can see that ticks are plotted at the sides 1 (bottom), 2 (right) and 3 
 (top) of panel 1
 and 1 (bottom), 3 (top) and 4 (right) of panel 2. Is it possible to plot 
 ticks at side
 4 (right) of panel 1 and side 2 (left) of panel 2?

 Thank You very much for Your attention.

 Best regards,

 Martin

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] Light Libraries

2013-02-26 Thread Uwe Ligges
Perhaps you want to tell people where the advantage is comparing it with 
the very well established R package system.


Best,
Uwe Ligges



On 26.02.2013 02:43, ivo welch wrote:

Dear R-Help group:

I have been tinkering with how I want my personal standard library
functions to look like.  They are not designed to be professional and
heavyweight, but lightweight.  There are probably dozens of little bugs,
because I don't know or have not properly taken care of a variety of
internal R code issues.  still, I like how this ended up, and there is no
learning curve, so I thought I would share it.

I have put all my functions into a directory ~/src/iaw/R/ .  In my standard
.Rprofile, I thus first added a list of my libraries (well, I have just
one) and invoke it:

options(strict=very)
Libdirs - c(~/src/iaw/R/)
for (libdir in Libdirs) {
source( Sys.glob(paste0(libdir, Rprofile))) )
}


(I prefer mnemonics to numbers. it is 2013.  why is it text(..., pos=1),
when it should be text(...,pos=east)?  East, E should be
abbreviations for it.  Then we could also use NNW...but I am getting
distracted...)

in each of my light libraries, I now have an Rprofile file that looks
like this


library(compiler)

cached - paste0(libdir, /library.Rdata)

if (file.exists(cached)  all( file.info(cached)$mtime 
file.info(Sys.glob(paste0(libdir,/*.R)))$mtime
) ) {
   load(cached)
   cat(Loaded, cached, \n)
} else {

   Rprofile - Sys.glob(paste0(libdir, *.R))
   for (n in Rprofile) {
 source(n)
   }

   ## libraries that I need to have in order to be able to compile
   library(utils)
   library(parallel)
   library(stats)
   library(graphics)
   library(grDevices)

   for (n in ls()) {
 (is.function(.GlobalEnv[[n]]))%or% next
 ##if ((n %in% c(n, Rprofile, cached))) next
 cat([', n, ']\n, sep=)
 .GlobalEnv[[n]] - cmpfun(.GlobalEnv[[n]])
   }

   save.image(file=cached)
   cat(Saved, cached, \n)
}


the basic organizational idea now is to stick each R function into its own
.R file.  the Rprofile code makes sure that whenever I change a function in
the ~src/iaw/*.R directory, the library is rebuilt (all functions are
recompiled and then saved into an .Rdata file).  this is very fast in my
case; if it were not, I could add some intelligence.  all of this
could/should be stuck into a universal function
(library.light(directoryname)), but because I only have one library for
now, it can just live in the Rprofile.

with this organization, it is now also easy to keep vignettes, latex text,
other code, etc., in the same directory.  they will just be ignored because
they do not end with .R.


the actual functions follow a format that is different from existing
documentation systems, incl Hadley's oxygen, but designed to plug in
(eventually) into the standard R manual and help system.

PREAMBLE - c(
doc = '

@TITLE lagseries

@AUTHOR ivo.we...@gmail.com

@DATE Feb 25, 2013

@DESCRIPTION

lagseries takes a vector and shift its contents numlags items to the
left, filling in appropriate missing values to retain the length of the
vector.  If panelid is named, then lagged value from another panelid will
not be assigned to be the lag.  (Usually, the panelid will be the firm id,
and the panel must be sorted by firmid. Naturally, it makes little sense to
use this unless the observations are also sorted by the time of the
observation.  This is, after all, a lagseries function.)

@USAGE  lagseries( seriesin, numlags =1, panelid=NULL)

@ARGUMENTS

seriesin: a numeric vector

numlags: an integer, can be negative

panelid: an optional panel id

@DETAILS

None

@SEEALSO

leadseries, chgseries, pchgseries, compoundseries

@EXAMPLES

x - rnorm(10)
xlag - lagseries(x,2)
lm( x ~ xlag )

d - data.frame( x - c( rnorm(20), runif(30), rcauchy(40) ),
  who= c( rep(firm1,20), rep(firm2, 30),
rep(firm3,40)),
  year= c( 1961:1980, 1971:2000, 1971:2010 ) )

lagd - data.frame( x=lagseries(d$x, panelid=who), who=d$who,
year=lagseries(d$x, panelid=who) )

',
test = '

   all( lagseries( 1:6, 2, c(1,1,2,2,2,2) ) == c(NA,NA,NA,NA,3,4),
na.rm=TRUE )

')


lagseries - function (seriesin, numlags = 1, panelid = NULL) {

   if (!is.null(getOption(strict))) {
 (is.null(seriesin)) %and% Looks like you are trying to calc a
lagseries from a NULL or non-existing series
 (is.vector(seriesin, mode=any)) %or% Your series is not a vector,
but a {{class(seriesin)}}.
 (length(seriesin)  1) %or% Need more observations than
{{length(seriesin)}}

 (is.vector(numlags, mode=numeric, length=1)) %or% numlags must be a
simple integer, not {{numlags}}.

 (is.null(panelid) | (is.vector(seriesin, mode=any,
length=length(seriesin %or%
   panel id must be NULL or a vector of same length as seriesin.  right
now it is {{class(panelid)}}
   }

   (numlags == 0) %and% return(seriesin)

   if (numlags  

Re: [R] parallel execution in R

2013-02-26 Thread Uwe Ligges



On 26.02.2013 14:00, Alaios wrote:

Dear all,
I have a piece of code that  I want to run in parallel (I am working in system 
of 16 cores)


foreach (i=(seq(-93,-73,length.out=21))) %dopar%
  {
   threshold-i

  print(i)
  do_analysis1(i,path)
  do_analysis2(i,path)
do_something_else_analysis1(i,path)
something_else_now(i,path)
  }



We do not know how your cluster was set up, hence cannot respond.


I'd just use the parallel (an R base package) and do:

library(parallel)
cl - makeCluster(.)
result - parSapply(cl, seq(-93,-73,length.out=21), function(i){
   threshold-i
   print(i)
   do_analysis1(i,path)
   do_analysis2(i,path)
   do_something_else_analysis1(i,path)
   something_else_now(i,path)
})
stopCluster(cl)

(untested, of course)

Uwe Ligges






as you can see I have already tried to make this run in parallel, meaning for 
every  i   value each of the 16 processor shoule take a block of the body such 
as:

 threshold-i

  print(i)
  do_analysis1(i,path)
  do_analysis2(i,path)
do_something_else_analysis1(i,path)
something_else_now(i,,path)




and execute it . Unfortunately this does not work and oonly one processor looks 
utilized.

Alternatively, mclapply have worked well in the past, but in this case I am not 
sure how to convert the serial execution of the body of the loop to a list that 
would be compatible with the mclapply.

I would like to thank you in advance for your help

Regards
Alex

[[alternative HTML version deleted]]



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



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


[R] What happened to financial package?

2013-02-26 Thread Keith Weintraub
Folks,
  I have been using the cf function from the financial package for a few 
years now.

Upon updating my version of R to ... I found that the package no longer exists 
in the main collection of R packages.

Has this package been renamed or merged with another package?

If the functionality is no longer available what is the best way to integrate 
the archived version of the package into my current setup?

Thanks for your time,
KW


--


[[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] What happened to financial package?

2013-02-26 Thread Prof Brian Ripley

On 26/02/2013 14:45, Keith Weintraub wrote:

Folks,
   I have been using the cf function from the financial package for a few 
years now.


I believe it was never converted for 2.14.0 (it was last touched in 
2006, and did not have a NAMESPACE file until CRAN auto-generated one), 
and the maintainer address is invalid.



Upon updating my version of R to ... I found that the package no longer exists 
in the main collection of R packages.

Has this package been renamed or merged with another package?


If so, the CRAN package page would say so.


If the functionality is no longer available what is the best way to integrate 
the archived version of the package into my current setup?


Get the package from the archive, extract the file cf.R and source it.


Thanks for your time,
KW


--


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


That does mean you: no HTML.

--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [R] Light Libraries

2013-02-26 Thread ivo welch
there may be no advantage at all.  I don't even know a full set of the
choices here.  if someone does know all the choices, it would be good to
point out to readers why my design choices are worse and/or what the
alternatives are.  some of it is, of course, simply taste.

I like the simplicity and minimum learning curve for novices for what I put
down.  I also like that this system is structured enough to be mapped into
the standard R packaging system without much trouble.  the original R
packaging system is more complex, doesn't keep the docs with the code, and
has a higher learning curve.  it is more flexible, though.

for the R code itself, relative to oxygen, I like avoiding the #'  on
each line and the simple grouping of tests and docs in the same file.   I
also like the way the entry contract tests are done and the perl-like
conditionals [with recognition and use of estrings],  I think this will
encourage their use and make error messages more informative.  if I had any
influence on the R core team, I think it should adopt these perl-like
conditionals with estrings, as well as introduce a strict option.

I may be a weird bird here: I know enough R to do damage, but not enough to
know what I am doing.  put differently, R is a programming language for me,
but I don't have the time to learn its finer details.  I am a simple R
user, not an R developer.  my guess is that there are many of my types, but
I do not know this.  in any case, I am greatly indebted to you, Uwe, and a
couple of others to have helped me out many times to solve problems I have
run into.  without r-help, I would have given up on it.

regards,

/iaw


Ivo Welch (ivo.we...@gmail.com)
http://www.ivo-welch.info/



On Tue, Feb 26, 2013 at 6:35 AM, Uwe Ligges lig...@statistik.tu-dortmund.de
 wrote:

 Perhaps you want to tell people where the advantage is comparing it with
 the very well established R package system.

 Best,
 Uwe Ligges




 On 26.02.2013 02:43, ivo welch wrote:

 Dear R-Help group:

 I have been tinkering with how I want my personal standard library
 functions to look like.  They are not designed to be professional and
 heavyweight, but lightweight.  There are probably dozens of little bugs,
 because I don't know or have not properly taken care of a variety of
 internal R code issues.  still, I like how this ended up, and there is no
 learning curve, so I thought I would share it.

 I have put all my functions into a directory ~/src/iaw/R/ .  In my
 standard
 .Rprofile, I thus first added a list of my libraries (well, I have just
 one) and invoke it:

 options(strict=very)
 Libdirs - c(~/src/iaw/R/)
 for (libdir in Libdirs) {
 source( Sys.glob(paste0(libdir, Rprofile))) )
 }


 (I prefer mnemonics to numbers. it is 2013.  why is it text(..., pos=1),
 when it should be text(...,pos=east)?  East, E should be
 abbreviations for it.  Then we could also use NNW...but I am getting
 distracted...)

 in each of my light libraries, I now have an Rprofile file that looks
 like this


 library(compiler)

 cached - paste0(libdir, /library.Rdata)

 if (file.exists(cached)  all( file.info(cached)$mtime 
 file.info(Sys.glob(paste0(**libdir,/*.R)))$mtime
 ) ) {
load(cached)
cat(Loaded, cached, \n)
 } else {

Rprofile - Sys.glob(paste0(libdir, *.R))
for (n in Rprofile) {
  source(n)
}

## libraries that I need to have in order to be able to compile
library(utils)
library(parallel)
library(stats)
library(graphics)
library(grDevices)

for (n in ls()) {
  (is.function(.GlobalEnv[[n]]))**%or% next
  ##if ((n %in% c(n, Rprofile, cached))) next
  cat([', n, ']\n, sep=)
  .GlobalEnv[[n]] - cmpfun(.GlobalEnv[[n]])
}

save.image(file=cached)
cat(Saved, cached, \n)
 }


 the basic organizational idea now is to stick each R function into its own
 .R file.  the Rprofile code makes sure that whenever I change a function
 in
 the ~src/iaw/*.R directory, the library is rebuilt (all functions are
 recompiled and then saved into an .Rdata file).  this is very fast in my
 case; if it were not, I could add some intelligence.  all of this
 could/should be stuck into a universal function
 (library.light(directoryname)**), but because I only have one library
 for
 now, it can just live in the Rprofile.

 with this organization, it is now also easy to keep vignettes, latex text,
 other code, etc., in the same directory.  they will just be ignored
 because
 they do not end with .R.


 the actual functions follow a format that is different from existing
 documentation systems, incl Hadley's oxygen, but designed to plug in
 (eventually) into the standard R manual and help system.

 PREAMBLE - c(
 doc = '

 @TITLE lagseries

 @AUTHOR ivo.we...@gmail.com

 @DATE Feb 25, 2013

 @DESCRIPTION

 lagseries takes a vector and shift its contents numlags items to the
 left, filling in appropriate missing values to retain the length of the
 vector.  If panelid is named, then lagged value 

[R] combining 2 dataframes into a 3rd df, with 1 row for each row in df1 df2

2013-02-26 Thread Anika Masters
# 'I need help combining 2 dataframes (df1  df2) into a 3rd (mydf).
I want the 3rd dataframe to contain 1 row for each row in df1  df2,
and all the columns in both df1  df2. # Advice is appreciated. Thank
you.

df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )

df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )

mydf - matrix(data = c(7, 99, 'na', 12, 'na', 'na', 'na',
'34','56','88','12','44') , nrow=2 ,  byrow = T, dimnames = list( NULL
,  c('a' , 'b' , 'c' ,  'd', 'x' , 'y' ) ) )

df1
df2
mydf


 df1
  a  b  d
1 7 99 12

 df2
   d  b  x  y  c
1 88 34 12 44 56

 mydf
 abcdxy
[1,] 7  99 na 12 na na
[2,] na 34 56 88 12 44

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] combining 2 dataframes into a 3rd df, with 1 row for each row in df1 df2

2013-02-26 Thread Anika Masters
df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )

df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1
,dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )

I figured it out.
mydf - merge(df2,df1,all.y=T, all.x=T)
mydf2 - mydf[,sort(names(mydf))]

On Tue, Feb 26, 2013 at 8:34 AM, Anika Masters anika.mast...@gmail.com wrote:
 # 'I need help combining 2 dataframes (df1  df2) into a 3rd (mydf).
 I want the 3rd dataframe to contain 1 row for each row in df1  df2,
 and all the columns in both df1  df2. # Advice is appreciated. Thank
 you.

 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )

 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )

 mydf - matrix(data = c(7, 99, 'na', 12, 'na', 'na', 'na',
 '34','56','88','12','44') , nrow=2 ,  byrow = T, dimnames = list( NULL
 ,  c('a' , 'b' , 'c' ,  'd', 'x' , 'y' ) ) )

 df1
 df2
 mydf


 df1
   a  b  d
 1 7 99 12

 df2
d  b  x  y  c
 1 88 34 12 44 56

 mydf
  abcdxy
 [1,] 7  99 na 12 na na
 [2,] na 34 56 88 12 44

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] frequency table-visualization for complex categorical variables

2013-02-26 Thread Rui Barradas

Hello,

I'm not sure I understand, do you want to treat BCC, CBC and CCB as the 
same? If so try


w2 - apply( y , 1 , function(x) paste0(sort(x) , collapse =  ))
table(w2)


Hope this helps,

Rui Barradas

Em 26-02-2013 13:58, Niklas Fischer escreveu:

Hi again,



Thanks for Anthony about the links on reproducible codes.



Thanks for Rui about ordering when rows are intact.



One more question





Here is your code.



x -
 cbind(
 sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
 sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
 sample( LETTERS[1:6] , 100 , replace = TRUE )
 )

y - as.matrix( x )

w2 - apply( y , 1 , paste0 , collapse =  )
table(w2)







Do you know any trick to organize merge certain elements together?

For example, if the final table includes

BCC, CCB, CBC how should I sum frequency of one element like BCC? I have a
very long table it would be indeed very useful!





Niklas.

2013/2/25 Rui Barradas ruipbarra...@sapo.pt


Hello,

I disagree with the way you've sorted the matrix, like this all A's become
first, then B's, etc, irrespective of the respondents. Each row is a
respondent, and the rows should be kept intact, but with a different
ordering. To this effect, use order():

z - y[order(y[,1], y[,2], y[,3]), ]


Then use the rest of your code.

Or, which would save us the sorting, paste the rows elements together
directly from matrix 'y' and use the fact that table() sorts its output.

w2 - apply( y , 1 , paste0 , collapse =  )
table(w2)


Hope this helps,

Rui Barradas

Em 25-02-2013 18:32, Anthony Damico escreveu:

  in the future, please provide R code to re-create some example data :)

read
http://stackoverflow.com/**questions/5963269/how-to-make-**
a-great-r-reproducible-**exampleforhttp://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-examplefor
more detail..



# create a data table with three unique columns' values..
# treat these values just like letters
x -
  cbind(
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE )
  )

# look at x.. this is good data i hope?
x

# convert this to a matrix
y - as.matrix( x )

# i don't think you care about ordering, so sort left-to-rightwards
z - apply( y , 2 , sort )

# look at your results
z

# paste these results together across the matrix
w - apply( z , 1 , paste0 , collapse =  )

# count the final distinct results
table( w )




On Mon, Feb 25, 2013 at 1:04 PM, Niklas Fischer
niklasfischer...@gmail.com**wrote:

  Dear R users,


I have three questions measuring close relationships.
The questions are same and the respondents put the answer in order.

I'd like to examine the pattern of answers and visualize it.

For example q1 (A,B,C,D,E) and q2 and q3 are the same. If the respondents
selects A B C (so BCA or BAC or CBA or CAB), I'd like to construct
frequency table for ABC and other combinations for example DEF.


Unfortunately, there are many answers, and three-way contingency table
includes lots of cells which make it diffucult to interpret and requires
lots of extra work to organize data.

What is the best way to construct fruequency table of these kind of
variables and to visulize the results with the most simple form


All the bests,
Niklas

  [[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.htmlhttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



 [[alternative HTML version deleted]]

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






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cut a vector in equal parts

2013-02-26 Thread Martin Batholdy
Hi,

I would like to cut a vector of values in parts.
Each part should have an equal number of elements.

for example:

x - (rnorm(500)^2)

now I want 5 vectors each with 100 elements.
The first vector should include the 100 lowest values of x and so on
(so that the fifth vector contains the 100 highest values of x).


thanks for any help!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Merging value labels into indicator variable.

2013-02-26 Thread Tasnuva Tabassum
I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I want to
make an indicator variable that will take value 1 if NAM=7 or NAM=8 or
NAM=9. How can I do that?
I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case.

[[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] ggplot2 Increase font size

2013-02-26 Thread Alaios
Hi,
I am not quite sure what you meanΙ. I give again reproducible code:



require(ggplot2)
require(reshape)

DataToPlot-matrix(data=rnorm(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
tdm-melt(DataToPlot)
p- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
                  labs(x = MHz, y = Threshold, fill = 
Duty Cycle) +
                  geom_raster(alpha=1) +
                  
scale_fill_discrete(h.start=1,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1))
 +
                  scale_x_continuous(expand = c(0, 0)) +
                  scale_y_continuous(expand = c(0, 0))







DataToPlot in my case contains something like that:

DataToPlot
           4          5          6
1 -0.4135124  0.4643110 -0.7530622
2  0.8827643 -0.1702428  0.4607671
3  0.7942167 -1.2450487 -0.9380290


what I would like to have is to have one specific color for each of the 
following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)

so for example the -0.4 would be categorized under the 0 category 

the 0.46 would be categorized under the 0.5 category
the -0.75 would be categorized under the 0 category
the 0.88 would be categorized under the 0.9 category


right now the code I gave prints no color bar. If I change it like that.
p- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
                  labs(x = MHz, y = Threshold, fill = 
Duty Cycle) +
                  geom_raster(alpha=1) +
                 
 
scale_fill_discrete(h.start=1)
 +
                  scale_x_continuous(expand = c(0, 0)) +
                  scale_y_continuous(expand = c(0, 0))


colorbar comes back but as you will see the defined values is not how I want to 
categorize my data.

Could you please help me find what I do not understand here?

I would like to thank you in advance for your reply

Regards
Alex




 From: Ista Zahn istaz...@gmail.com

Cc: R help R-help@r-project.org 
Sent: Monday, February 25, 2013 3:54 PM
Subject: Re: [R] ggplot2 Increase font size

Hi Alex,

See ?theme

Best,
Ista



 Dear all,
 I am using the code as below
   tdm - melt(matrixToPlot)
    p- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
                   labs(x = Mz, y = T, fill = D) +
                   geom_raster(alpha=1) +
                   scale_fill_discrete(h.start=1) +
                   scale_x_continuous(expand = c(0, 0)) +
                   scale_y_continuous(expand = c(0, 0))

 to plot an two dimensional image .

 I would like to ask your help to replace the gray border with white color
 and increase the font size of x and y axis as wells as the legend of the
 color bar. Could you please give me the function names to use?

 Regards
 Alex
         [[alternative HTML version deleted]]


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

[[alternative HTML version deleted]]

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


Re: [R] Merging value labels into indicator variable.

2013-02-26 Thread Pete Brecknock
tasnuvat wrote
 I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I want to
 make an indicator variable that will take value 1 if NAM=7 or NAM=8 or
 NAM=9. How can I do that?
 I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case.
 
   [[alternative HTML version deleted]]
 
 __

 R-help@

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

How about something like ...
NAM = c(1,2,3,4,5,6,7,8,9)

ifelse(NAM=7,1,0)
 # or
ifelse(NAM %in% c(7,8,9),1,0)

HTH

Pete




--
View this message in context: 
http://r.789695.n4.nabble.com/Merging-value-labels-into-indicator-variable-tp4659703p4659705.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] Merging value labels into indicator variable.

2013-02-26 Thread Berend Hasselman

On 26-02-2013, at 18:45, Tasnuva Tabassum t.tasn...@gmail.com wrote:

 I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I want to
 make an indicator variable that will take value 1 if NAM=7 or NAM=8 or
 NAM=9. How can I do that?
 I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case.


How about 

Var001- ifelse(NAM=7   NAM=9,1,0)


Berend

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


Re: [R] cut a vector in equal parts

2013-02-26 Thread jim holtman
?sort
?cut

On Tue, Feb 26, 2013 at 12:39 PM, Martin Batholdy
batho...@googlemail.com wrote:
 Hi,

 I would like to cut a vector of values in parts.
 Each part should have an equal number of elements.

 for example:

 x - (rnorm(500)^2)

 now I want 5 vectors each with 100 elements.
 The first vector should include the 100 lowest values of x and so on
 (so that the fifth vector contains the 100 highest values of x).


 thanks for any help!

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Merging value labels into indicator variable.

2013-02-26 Thread Tasnuva Tabassum
Thanx all, I found my answer. I prefer Peter's second solution.


On Tue, Feb 26, 2013 at 11:59 PM, Berend Hasselman b...@xs4all.nl wrote:


 On 26-02-2013, at 18:45, Tasnuva Tabassum t.tasn...@gmail.com wrote:

  I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I want to
  make an indicator variable that will take value 1 if NAM=7 or NAM=8 or
  NAM=9. How can I do that?
  I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case.


 How about

 Var001- ifelse(NAM=7   NAM=9,1,0)


 Berend


[[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] legend issues.

2013-02-26 Thread Greg Snow
Nicole,

Since you seem more interested in accusing David of being rude than
recognizing your own rudeness and taking steps to overcome that and
increase your chance of getting useful responses I will quote a few lines
from the posting guide for you (the entire posting guide is available from
the link at the bottom of this and every R-help post):

 Like many responses posted on the list, it is written in a concise
manner. This is not intended to be unfriendly - it is more a consequence of
allocating the limited available time and space to technical issues rather
than to social niceties.

Remember that customs differ. Some people are very direct. Others surround
everything they say with hedges and apologies. Be tolerant. Rudeness is
never warranted, but sometimes `read the manual' *is* the appropriate
response.

No HTML posting (harder to detect spam) (note that this is the default in
some mail clients - you may have to turn it off).

at a minimum, copy and paste the output from sessionInfo() into your
message


I see attempts to help you in David's posts, I see very little in your
responses that would help him (or any of the rest of us) help you.


On Mon, Feb 25, 2013 at 3:57 PM, Nicole Ford nicolefor...@gmail.com wrote:

 by the time your rude reply came ( you are often rude to people so i
 shouldn't have been surprised but somehow was) , i had already found my
 answer, by doing it MYSELF on her computer and found had not followed some
 simple instructions.

 be well.
 ~Nicole Ford
 Ph.D. student
 Graduate Assistant/ Instructor
 University of South Florida
 Government and International Affairs
 office: SOC 012M
 e: nmhi...@mail.usf.edu
 http://gia.usf.edu/student/nford/






 On Feb 25, 2013, at 4:18 PM, David Winsemius wrote:

  My point is that you _still_ have not adhered to the Posting Guide
 request for sessionInfo() ... I say again. Please read the Posting Guide
 ... AND PLEASE STOP posting formatted email.
 
  --
  David.
 
  On Feb 25, 2013, at 10:20 AM, Nicole Ford wrote:
 
  I did look at ??pie  ??graphics, as per my reply.  which netted nothing
 of value.
 
  thanks.
  ~Nicole Ford
  Ph.D. student
  Graduate Assistant/ Instructor
  University of South Florida
  Government and International Affairs
  office: SOC 012M
  e: nmhi...@mail.usf.edu
  http://gia.usf.edu/student/nford/
 
 
 
 
 
 
  On Feb 25, 2013, at 12:38 PM, David Winsemius wrote:
 
 
  On Feb 25, 2013, at 7:37 AM, Nicole Ford wrote:
 
  hello, all.
 
  one of my students is having an issue with the pie  legend function.
 
  this is her code.  (below)
 
  it works just fine for me.
 
  her error is plot.new has not been called yet.  i know this means
 her pie chart is coming up blank so the legend will not work.
 
  So at that point, why not issue the command:
 
  plot.new()# ?
 
  Graphics problems can be very system specific. Follow-up should
 include a proper adherence to the Posting Guide advice about the necessary
 problem description. You should assist R help by first educating yourself
 and then giving your students proper training in how to construct questions
 for R-help.
 
 
  according to ?graphics  this package *is* supposed to handle these
 functionalities.  however, when i tried to install it i get the following
 error:
 
  Warning message:
  package Œgraphics‚ is not available (for R version 2.15.2)
 
  The graphics package is part of the base installation. As far as I
 know you cannot reinstall it. You would instead need to reinstall R if you
 thought her installation if R was corrupt.
 
  --
  David.
 
 
  however, the ?graphics page shows it is indeed available for this
 version of R.
 
 
  Package:   graphics
  Version:   2.15.2
  Priority:  base
  Title: The R Graphics Package
  Author:R Core Team and contributors worldwide
  Maintainer:R Core Team r-c...@r-project.org
  Description:   R functions for base graphics
  Imports:   grDevices
  License:   Part of R 2.15.2
  Built: R 2.15.2; ; 2012-10-26 16:14:39 UTC; unix
 
  thoughts are greatly appreciated.
 
 
 
  strength - factor(c(rep(8.0-9.9, 2), rep(7.0-7.9, 12),
 rep(6.0-6.9, 108)))
  plot(strength, xlab=Earthquake Strength, ylab=Frequency)
  histogram(strength, xlab=Earthquake Strength, ylab=Relative
 Frequency by Percentage)
  pie(table(strength))
  legend(topright, title=Earthquake Strength, cex=0.6, pch=16,
 col=c(white, blue, red), legend=c(6.0 to 6.9, 7.0 to 7.9, 8.0 to
 8.9), ncol=3)
 
 
  David Winsemius
  Alameda, CA, USA
 
 
 
  David Winsemius
  Alameda, CA, USA
 


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




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]


Re: [R] ggplot2 Increase font size

2013-02-26 Thread Ista Zahn
Are you sure you didn't get you threads mixed up? Your original
question was about changing font size and background colors...

See inline for answers to this new question.

On Tue, Feb 26, 2013 at 12:45 PM, Alaios ala...@yahoo.com wrote:
 Hi,
 I am not quite sure what you meanΙ. I give again reproducible code:


 require(ggplot2)
 require(reshape)
 DataToPlot-matrix(data=rnorm(9),nrow=3,dimnames=list(seq(1,3),seq(4,6)))
 tdm-melt(DataToPlot)
 p- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
   labs(x = MHz, y = Threshold, fill = Duty Cycle) +
   geom_raster(alpha=1) +

 scale_fill_discrete(h.start=1,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1))
 +

   scale_x_continuous(expand = c(0, 0)) +
   scale_y_continuous(expand = c(0, 0))






 DataToPlot in my case contains something like that:

 DataToPlot
4  5  6
 1 -0.4135124  0.4643110 -0.7530622
 2  0.8827643 -0.1702428  0.4607671
 3  0.7942167 -1.2450487 -0.9380290



Translating from English:

 what I would like to have is to have one specific color for each of the
 following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)

 so for example the -0.4 would be categorized under the 0 category
 the 0.46 would be categorized under the 0.5 category
 the -0.75 would be categorized under the 0 category
 the 0.88 would be categorized under the 0.9 category

to R:

tdm - within(tdm,{
  value - ifelse(value  0, 0, value)
  value - ifelse(value  1, 1, value)
  value -factor(round(value, digits=1), levels=seq(0, 1, by=.1))
})

ggplot(tdm, aes(x = Var2, y = Var1, fill = value)) +
  labs(x = MHz, y = Threshold, fill = Duty Cycle) +
  geom_raster(alpha=1) +
  scale_fill_discrete(h.start=1, drop=FALSE) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0))
tdm - within(tdm,{
  value - ifelse(value  0, 0, value)
  value - ifelse(value  1, 1, value)
  value -factor(round(value, digits=1))
})




 right now the code I gave prints no color bar.

because the breaks on your discrete scale don't match the actual
levels of your data...

If I change it like that.
 p- ggplot(tdm, aes(x = X2, y = X1, fill = factor(value))) +
   labs(x = MHz, y = Threshold, fill = Duty Cycle) +

   geom_raster(alpha=1) +
   scale_fill_discrete(h.start=1) +
   scale_x_continuous(expand = c(0, 0)) +
   scale_y_continuous(expand = c(0, 0))


 colorbar comes back but as you will see the defined values is not how I want
 to categorize my data.

So categorize your data properly.

 what I would like to have is to have one specific color for each of the
 following cases c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)

 so for example the -0.4 would be categorized under the 0 category
 the 0.46 would be categorized under the 0.5 category
 the -0.75 would be categorized under the 0 category
 the 0.88 would be categorized under the 0.9 category

 Could you please help me find what I do not understand here?

Not sure, but what I don't understand is why you're following up to a
question about font sizes and background colors with a question about
factor levels.

Best,
Ista


 I would like to thank you in advance for your reply

 Regards
 Alex


 
 From: Ista Zahn istaz...@gmail.com
 To: Alaios ala...@yahoo.com
 Cc: R help R-help@r-project.org
 Sent: Monday, February 25, 2013 3:54 PM
 Subject: Re: [R] ggplot2 Increase font size

 Hi Alex,

 See ?theme

 Best,
 Ista

 On Mon, Feb 25, 2013 at 9:44 AM, Alaios ala...@yahoo.com wrote:

 Dear all,
 I am using the code as below
  tdm - melt(matrixToPlot)
p- ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value))) +
  labs(x = Mz, y = T, fill = D) +
  geom_raster(alpha=1) +
  scale_fill_discrete(h.start=1) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0))

 to plot an two dimensional image .

 I would like to ask your help to replace the gray border with white color
 and increase the font size of x and y axis as wells as the legend of the
 color bar. Could you please give me the function names to use?

 Regards
 Alex
[[alternative HTML version deleted]]


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




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


[R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread Anika Masters
#I want to merge or join 2 dataframes (df1  df2) into a 3rd
(mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
 df2, and all the columns in both df1  df2. The solution should
work even if the 2 dataframes are identical, and even if the 2
dataframes do not have the same column names.  The rbind.fill function
seems to work.  For learning purposes, are there other good ways to
solve this problem, using merge or other functions other than
rbind.fill?

#e.g. These 3 examples all seem to work correctly and as I hoped:

df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )
df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
mydf - merge(df2, df1, all.y=T, all.x=T)
mydf

#e.g. this works:
library(reshape)
mydf - rbind.fill(df1, df2)
mydf

#This works:
library(reshape)
mydf - rbind.fill(df1, df2)
mydf

#But this does not (the 2 dataframes are identical)
df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )
df2 - df1
mydf - merge(df2, df1, all.y=T, all.x=T)
mydf

#Any way to get mere to work for this final example? Any other good solutions?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread arun
Hi,

You could also try:
library(gtools)
smartbind(df2,df1)
#  a  b  d
#1 7 99 12
#2 7 99 12


When df1!=df2
smartbind(df1,df2)
#   a  b  d  x  y  c
#1  7 99 12 NA NA NA
#2 NA 34 88 12 44 56
A.K.




- Original Message -
From: Anika Masters anika.mast...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Tuesday, February 26, 2013 1:55 PM
Subject: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

#I want to merge or join 2 dataframes (df1  df2) into a 3rd
(mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
 df2, and all the columns in both df1  df2. The solution should
work even if the 2 dataframes are identical, and even if the 2
dataframes do not have the same column names.  The rbind.fill function
seems to work.  For learning purposes, are there other good ways to
solve this problem, using merge or other functions other than
rbind.fill?

#e.g. These 3 examples all seem to work correctly and as I hoped:

df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )
df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
mydf - merge(df2, df1, all.y=T, all.x=T)
mydf

#e.g. this works:
library(reshape)
mydf - rbind.fill(df1, df2)
mydf

#This works:
library(reshape)
mydf - rbind.fill(df1, df2)
mydf

#But this does not (the 2 dataframes are identical)
df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
list( NULL ,  c('a' , 'b' , 'd') ) ) )
df2 - df1
mydf - merge(df2, df1, all.y=T, all.x=T)
mydf

#Any way to get mere to work for this final example? Any other good solutions?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Anika Masters
 Sent: Tuesday, February 26, 2013 10:56 AM
 To: r-help@r-project.org
 Subject: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?
 
 #I want to merge or join 2 dataframes (df1  df2) into a 3rd
 (mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
  df2, and all the columns in both df1  df2. The solution should
 work even if the 2 dataframes are identical, and even if the 2
 dataframes do not have the same column names.  The rbind.fill function
 seems to work.  For learning purposes, are there other good ways to
 solve this problem, using merge or other functions other than
 rbind.fill?
 
 #e.g. These 3 examples all seem to work correctly and as I hoped:
 
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf
 
 #e.g. this works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf
 
 #This works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf
 
 #But this does not (the 2 dataframes are identical)
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - df1
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf
 
 #Any way to get mere to work for this final example? Any other good
 solutions?

If rbind.fill(df1,df2) works, why do you need to use merge?

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


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


Re: [R] cut a vector in equal parts

2013-02-26 Thread Rui Barradas

Hello,

Try the following.

x - rnorm(500)^2
split(x, cut(x, quantile(x, probs = seq(0, 1, by = 0.2


Hope this helps,

Rui Barradas

Em 26-02-2013 17:39, Martin Batholdy escreveu:

Hi,

I would like to cut a vector of values in parts.
Each part should have an equal number of elements.

for example:

x - (rnorm(500)^2)

now I want 5 vectors each with 100 elements.
The first vector should include the 100 lowest values of x and so on
(so that the fifth vector contains the 100 highest values of x).


thanks for any help!

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



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


[R] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread Debs Majumdar
Hi All,

I have a data set of around 17,000 gene names and their lengths. E.g.

  gene  kblength    
 A3GALT2   14.333    
AADACL3   12.609    
AADACL4   22.532    
     ABCA4 128.312    
    ABCB10  42.114    
  ABCD3    100.287

.

and I was able to draw a reverse cumulative frequency plot using the following 
code:
d - read.table(gene_length_data.txt, header=T)
attach(d)
kblength.ecdf -ecdf(kblength)
r -range(kblength)
curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
detach(d)

Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810

I want to put markers and the corresponding gene names in the graph for a small 
list of 6 genes. i.e. say a hollow circle on the curve followed by the 
corresponding gene name.

I am fighting with this but wasn't able to get a solution.

Any help is appreciated.

Thanks,
 Debs

[[alternative HTML version deleted]]

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


[R] Help on a code

2013-02-26 Thread Andras Farkas
Dear List,
 
I have the following code:
 
x -c(0, 13.8, 38.16667, 62.16667, 
85.91667, 108.9167)
y -c(1.77, 2.39, 3, 2.65, 2.62, 1.8)
Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
plot(Interpolated)
 
in this code x is time in hours (cumulative), and y is a biological variable. I 
am using linear interpolation assuming getting from y(i) to y(i+1) is a linear 
path. I would like to calculate the time in this case that it takes to surpass 
the y value of 2 for the first time. If you look at the plot, you will see that 
the y value of 2 is crossed on 2 occasions: between the first and second value 
of y (ie:1.77 to 2.39) and the fifth and sixth value of y (ie2.62 and 1.8). In 
my case I really only care about the first section (ie: how long it takes to 
get from 1.77 to 2.0). Any thoughts on how I could calculate that chunk of the 
time would be greatly appreciated.
 
let me present it in a simpler idea wher I can actually tell you what the 
answer should be without having the code:
 
x -c(0, 12, 24, 36, 48, 60)
y -c(1.5, 2, 3, 2.65, 2.62, 1.8)
Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
plot(Interpolated)
 
the answer in this case is 12 hours, which is the time spent in getting from 
1.5 to 2...
 
hope I explained clearly what I am trying to do
 
appreciate the help,
 
Andras
 
[[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] cut a vector in equal parts

2013-02-26 Thread David L Carlson
Insert include.lowest=TRUE or the lowest value will get dropped (assigned
NA):

split(x, cut(x, quantile(x, probs = seq(0, 1, by = 0.2)),
include.lowest=TRUE))

--
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-bounces@r-
 project.org] On Behalf Of Rui Barradas
 Sent: Tuesday, February 26, 2013 1:59 PM
 To: Martin Batholdy
 Cc: r-help@r-project.org
 Subject: Re: [R] cut a vector in equal parts
 
 Hello,
 
 Try the following.
 
 x - rnorm(500)^2
 split(x, cut(x, quantile(x, probs = seq(0, 1, by = 0.2
 
 
 Hope this helps,
 
 Rui Barradas
 
 Em 26-02-2013 17:39, Martin Batholdy escreveu:
  Hi,
 
  I would like to cut a vector of values in parts.
  Each part should have an equal number of elements.
 
  for example:
 
  x - (rnorm(500)^2)
 
  now I want 5 vectors each with 100 elements.
  The first vector should include the 100 lowest values of x and so on
  (so that the fifth vector contains the 100 highest values of x).
 
 
  thanks for any help!
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] Help on a code

2013-02-26 Thread Ista Zahn
Hi Andras,

This may be too simplistic, but how about

with(Interpolated, x[y==2][1])

?


On Tue, Feb 26, 2013 at 4:21 PM, Andras Farkas motyoc...@yahoo.com wrote:
 Dear List,

 I have the following code:

 x -c(0, 13.8, 38.16667, 62.16667, 
 85.91667, 108.9167)
 y -c(1.77, 2.39, 3, 2.65, 2.62, 1.8)
 Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
 plot(Interpolated)

 in this code x is time in hours (cumulative), and y is a biological variable. 
 I am using linear interpolation assuming getting from y(i) to y(i+1) is a 
 linear path. I would like to calculate the time in this case that it takes to 
 surpass the y value of 2 for the first time. If you look at the plot, you 
 will see that the y value of 2 is crossed on 2 occasions: between the first 
 and second value of y (ie:1.77 to 2.39) and the fifth and sixth value of y 
 (ie2.62 and 1.8). In my case I really only care about the first section 
 (ie: how long it takes to get from 1.77 to 2.0). Any thoughts on how I could 
 calculate that chunk of the time would be greatly appreciated.

 let me present it in a simpler idea wher I can actually tell you what the 
 answer should be without having the code:

 x -c(0, 12, 24, 36, 48, 60)
 y -c(1.5, 2, 3, 2.65, 2.62, 1.8)
 Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
 plot(Interpolated)

 the answer in this case is 12 hours, which is the time spent in getting from 
 1.5 to 2...

 hope I explained clearly what I am trying to do

 appreciate the help,

 Andras

 [[alternative HTML version deleted]]


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


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


Re: [R] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread Greg Snow
What have you tried so far?

The points function will add points to an existing graph (base) and the
text function will add text to an existing graph.

If those don't do what you need then give us some more details.


On Tue, Feb 26, 2013 at 2:04 PM, Debs Majumdar debs_st...@yahoo.com wrote:

 Hi All,

 I have a data set of around 17,000 gene names and their lengths. E.g.

   gene  kblength
  A3GALT2   14.333
 AADACL3   12.609
 AADACL4   22.532
  ABCA4 128.312
 ABCB10  42.114
   ABCD3100.287
 
 .

 and I was able to draw a reverse cumulative frequency plot using the
 following code:
 d - read.table(gene_length_data.txt, header=T)
 attach(d)
 kblength.ecdf -ecdf(kblength)
 r -range(kblength)
 curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
 detach(d)

 Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810

 I want to put markers and the corresponding gene names in the graph for a
 small list of 6 genes. i.e. say a hollow circle on the curve followed by
 the corresponding gene name.

 I am fighting with this but wasn't able to get a solution.

 Any help is appreciated.

 Thanks,
  Debs

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




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


[R] problem with nested loops

2013-02-26 Thread Richard Saba
Each of the data sets contains monthly observations on price indices for 7 
countries. I use the fitted values from reg1 in the reg2 model. The interior 
loop executes without error as long as I explicitly specify the data set, i.e. 
data=dat70. However the code fails to execute if I specify the model in the 
form of the commented line, i. e   reg1 -dynlm(form1,data=Dnames[j])
I get the following error message:


Error in merge.zoo(USA, lag(USA, k = -1), lag(USA, k = -2), lag(Canada,  :

  object 'USA' not found


Apparently the Dnames[j] does not evaluate to the dataset name. Does anyone 
have a solution to my problem?

The values in Names are:

  [1] Canada  France  Germany Italy   Japan   UK  USA



And in Dnames are :

 [1] dat70   dat80   dat90   dat2000


library(dynlm)
kimdat-ts(read.csv(data.csv, header = TRUE),start=1970,frequency=12)
dat70 - window(kimdat,start =c(1970,1), end=c(1979,12))
dat80 - window(kimdat,start =c(1980,1), end=c(1989,12))
dat90 - window(kimdat,start =c(1990,1), end=c(1999,12))
dat2000 - window(kimdat,start =c(2000,1), end=c(2009,12))
Names-colnames(kimdat)

Dnames - c(dat70,dat80,dat90,dat2000)
for (j in 1:4) {
 for( i in 7:2) {
   form1-as.formula(paste(Names[i],~,lag(,Names[i],,k=-1) + 
lag(,Names[i],,k=-2)+ lag(,Names[1],,k=-1) +lag(,Names[1],,k=-2)))
   form2-as.formula(paste(Names[1],~fitted(reg1)))

   #  reg1 -dynlm(form1,data=Dnames[j])
 #  reg2 -dynlm(form2,data=Dnames[j])

  reg1 -dynlm(form1,data=dat80)
  reg2 -dynlm(form2,data=dat80)
 print(summary(reg1))
  print(summary(reg2))
  }
}

Thanks,
Richard Saba

[[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] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread David Winsemius

On Feb 26, 2013, at 1:04 PM, Debs Majumdar wrote:

 Hi All,
 
 I have a data set of around 17,000 gene names and their lengths. E.g.
 
   gene  kblength
  A3GALT2   14.333
 AADACL3   12.609
 AADACL4   22.532
  ABCA4 128.312
 ABCB10  42.114
   ABCD3100.287
 
 .
 
 and I was able to draw a reverse cumulative frequency plot using the 
 following code:
 d - read.table(gene_length_data.txt, header=T)
 attach(d)

Using 'attach' is a bad idea. In particular we have trouble keeping straight 
what is a column name or a first class object in your workspace.

 kblength.ecdf -ecdf(kblength)
 r -range(kblength)
 curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
 detach(d)

 Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810
 
 I want to put markers

Use points()

 and the corresponding gene names in the graph for a small list of 6 genes. 
 i.e. say a hollow circle on the curve followed by the corresponding gene name.


text(x= d[ which( d[['gene']]==AADACL4), 2], 
 y= kblength.ecdf( d[ which( dat[['gene']]==AADACL4), 2]), 
AADACL4)
 
 I am fighting with this but wasn't able to get a solution.

 
 Any help is appreciated.
 
 Thanks,
  Debs
 
   [[alternative HTML version deleted]]

Please learn to post in plain text. And please, please do read the fine Posting 
Guide.

-- 
David Winsemius
Alameda, CA, USA

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


Re: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread David L Carlson
Clumsy but it doesn't require any packages:

merge2 - function(x, y) {
if(all(union(names(x), names(y)) == intersect(names(x), names(y{
rbind(x, y)
} else merge(x, y, all=TRUE)
}
merge2(df1, df2)
df3 - df1
merge2(df1, df3)

--
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-bounces@r-
 project.org] On Behalf Of arun
 Sent: Tuesday, February 26, 2013 1:14 PM
 To: Anika Masters
 Cc: R help
 Subject: Re: [R] merging or joining 2 dataframes: merge, rbind.fill,
 etc.?
 
 Hi,
 
 You could also try:
 library(gtools)
 smartbind(df2,df1)
 #  a  b  d
 #1 7 99 12
 #2 7 99 12
 
 
 When df1!=df2
 smartbind(df1,df2)
 #   a  b  d  x  y  c
 #1  7 99 12 NA NA NA
 #2 NA 34 88 12 44 56
 A.K.
 
 
 
 
 - Original Message -
 From: Anika Masters anika.mast...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Tuesday, February 26, 2013 1:55 PM
 Subject: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?
 
 #I want to merge or join 2 dataframes (df1  df2) into a 3rd
 (mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
  df2, and all the columns in both df1  df2. The solution should
 work even if the 2 dataframes are identical, and even if the 2
 dataframes do not have the same column names.  The rbind.fill function
 seems to work.  For learning purposes, are there other good ways to
 solve this problem, using merge or other functions other than
 rbind.fill?
 
 #e.g. These 3 examples all seem to work correctly and as I hoped:
 
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf
 
 #e.g. this works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf
 
 #This works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf
 
 #But this does not (the 2 dataframes are identical)
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - df1
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf
 
 #Any way to get mere to work for this final example? Any other good
 solutions?
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Help on a code

2013-02-26 Thread William Dunlap
f - function(x, y, criticalY) {
   # return x value of first upcrossing of y past criticalY
   stopifnot(length(x) == length(y), length(x)1, length(criticalY)==1)
   i - seq_along(x)[-1]
   w - which(y[i] = criticalY  y[i-1] = criticalY)[1] # pos of first 
upcrossing
   if (is.na(w)) { # no upcrossing
   NA
   } else {
   denom - y[w+1] - y[w]
   if (denom == 0) { # take left side of flat spot
   x[w]
} else { # the nice case
   x[w] + (x[w+1] - x[w]) / denom * (criticalY - y[w])
}
}
}

 f(x=c(1,2,3,4,5), y=c(0, 1.5, 3, 1, 4), criticalY=2)
[1] 2.33
 f(x=c(1,2,3,4,5), y=c(0, 1.5, 3, 1, 4), criticalY=100)
[1] NA

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Andras Farkas
 Sent: Tuesday, February 26, 2013 1:21 PM
 To: r-help@r-project.org
 Subject: [R] Help on a code
 
 Dear List,
 
 I have the following code:
 
 x -c(0, 13.8, 38.16667, 62.16667, 
 85.91667,
 108.9167)
 y -c(1.77, 2.39, 3, 2.65, 2.62, 1.8)
 Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
 plot(Interpolated)
 
 in this code x is time in hours (cumulative), and y is a biological variable. 
 I am using linear
 interpolation assuming getting from y(i) to y(i+1) is a linear path. I would 
 like to calculate
 the time in this case that it takes to surpass the y value of 2 for the first 
 time. If you look
 at the plot, you will see that the y value of 2 is crossed on 2 occasions: 
 between the first
 and second value of y (ie:1.77 to 2.39) and the fifth and sixth value of y 
 (ie2.62 and 1.8).
 In my case I really only care about the first section (ie: how long it 
 takes to get from
 1.77 to 2.0). Any thoughts on how I could calculate that chunk of the time 
 would be
 greatly appreciated.
 
 let me present it in a simpler idea wher I can actually tell you what the 
 answer should be
 without having the code:
 
 x -c(0, 12, 24, 36, 48, 60)
 y -c(1.5, 2, 3, 2.65, 2.62, 1.8)
 Interpolated - approx(x, y,xout=0:tail(x, n=1),method=linear)
 plot(Interpolated)
 
 the answer in this case is 12 hours, which is the time spent in getting from 
 1.5 to 2...
 
 hope I explained clearly what I am trying to do
 
 appreciate the help,
 
 Andras
 
   [[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] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread Jim Lemon

On 02/27/2013 08:04 AM, Debs Majumdar wrote:

Hi All,

I have a data set of around 17,000 gene names and their lengths. E.g.

   gene  kblength
  A3GALT2   14.333
AADACL3   12.609
AADACL4   22.532
  ABCA4 128.312
 ABCB10  42.114
   ABCD3100.287

.

and I was able to draw a reverse cumulative frequency plot using the following 
code:
d- read.table(gene_length_data.txt, header=T)
attach(d)
kblength.ecdf-ecdf(kblength)
r-range(kblength)
curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
detach(d)

Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810

I want to put markers and the corresponding gene names in the graph for a small 
list of 6 genes. i.e. say a hollow circle on the curve followed by the 
corresponding gene name.

I am fighting with this but wasn't able to get a solution.


Hi Debs,
I think you can get what you want with this:

kborder-order(kblength)
example_pos-c(25,50,75,100,125)
text(example_pos,kblength[kborder][example_pos],
 paste(gene[kborder][example_pos],kblength[kborder][example_pos],
 sep=\n))

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] problem with nested loops

2013-02-26 Thread David Winsemius

On Feb 26, 2013, at 1:53 PM, Richard Saba wrote:

 Each of the data sets contains monthly observations on price indices for 7 
 countries. I use the fitted values from reg1 in the reg2 model. The interior 
 loop executes without error as long as I explicitly specify the data set, 
 i.e. data=dat70. However the code fails to execute if I specify the model in 
 the form of the commented line, i. e   reg1 -dynlm(form1,data=Dnames[j])
 I get the following error message:
 
 
 Error in merge.zoo(USA, lag(USA, k = -1), lag(USA, k = -2), lag(Canada,  :
 
  object 'USA' not found


 
 
 Apparently the Dnames[j] does not evaluate to the dataset name. Does anyone 
 have a solution to my problem?
 
 The values in Names are:
 
  [1] Canada  France  Germany Italy   Japan   UK  USA
 
 
 
 And in Dnames are :
 
 [1] dat70   dat80   dat90   dat2000
 
 
 library(dynlm)
 kimdat-ts(read.csv(data.csv, header = TRUE),start=1970,frequency=12)
 dat70 - window(kimdat,start =c(1970,1), end=c(1979,12))
 dat80 - window(kimdat,start =c(1980,1), end=c(1989,12))
 dat90 - window(kimdat,start =c(1990,1), end=c(1999,12))
 dat2000 - window(kimdat,start =c(2000,1), end=c(2009,12))
 Names-colnames(kimdat)
 
 Dnames - c(dat70,dat80,dat90,dat2000)

Convert to a list:

Dnames - c(dat70, dat80, dat90, dat2000)

 for (j in 1:4) {
 for( i in 7:2) {
   form1-as.formula(paste(Names[i],~,lag(,Names[i],,k=-1) + 
 lag(,Names[i],,k=-2)+ lag(,Names[1],,k=-1) +lag(,Names[1],,k=-2)))
   form2-as.formula(paste(Names[1],~fitted(reg1)))
 
# And then use [[ to get the values rather than a sublist:

reg1 -dynlm(form1,data=Dnames[[j]])
 reg2 -dynlm(form2,data=Dnames[[j]])

 # reg1 -dynlm(form1,data=dat80)
#  reg2 -dynlm(form2,data=dat80)
 print(summary(reg1))
  print(summary(reg2))
  }
 }
 
 Thanks,
 Richard Saba
 
   [[alternative HTML version deleted]]

And please learn to post in plain text and please do read the rest of the 
Posting Guide that I did not just repeat for you.

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread Debs Majumdar
Hi David, 

Thanks for your suggestions.


I am not sure how to plot the points by using gene names, but I will give it a 
try.

Thanks,

Debs




 From: David Winsemius dwinsem...@comcast.net

Cc: r-help@r-project.org r-help@r-project.org 
Sent: Tuesday, February 26, 2013 1:54 PM
Subject: Re: [R] Adding markers and text for some data points after drawing a 
plot


On Feb 26, 2013, at 1:04 PM, Debs Majumdar wrote:

 Hi All,
 
 I have a data set of around 17,000 gene names and their lengths. E.g.
 
           gene      kblength    
  A3GALT2       14.333    
 AADACL3       12.609    
 AADACL4       22.532    
      ABCA4     128.312    
     ABCB10      42.114    
       ABCD3    100.287    
 
 .
 
 and I was able to draw a reverse cumulative frequency plot using the 
 following code:
 d - read.table(gene_length_data.txt, header=T)
 attach(d)

Using 'attach' is a bad idea. In particular we have trouble keeping straight 
what is a column name or a first class object in your workspace.

 kblength.ecdf -ecdf(kblength)
 r -range(kblength)
 curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
 detach(d)

 Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810
 
 I want to put markers

Use points()

 and the corresponding gene names in the graph for a small list of 6 genes. 
 i.e. say a hollow circle on the curve followed by the corresponding gene name.


text(x= d[ which( d[['gene']]==AADACL4), 2], 
     y= kblength.ecdf( d[ which( dat[['gene']]==AADACL4), 2]),
    AADACL4)
 
 I am fighting with this but wasn't able to get a solution.

 
 Any help is appreciated.
 
 Thanks,
  Debs
 
     [[alternative HTML version deleted]]

Please learn to post in plain text. And please, please do read the fine Posting 
Guide.

-- 
David Winsemius
Alameda, CA, USA
[[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] Adding markers and text for some data points after drawing a plot

2013-02-26 Thread David Winsemius

On Feb 26, 2013, at 2:28 PM, Debs Majumdar wrote:

 Hi David, 
 
 Thanks for your suggestions.
 
 I am not sure how to plot the points by using gene names, but I will give it 
 a try.

The x and y arguments would be the same as were used in the text() call.

(You are _still_ sending formatted text.)
http://help.yahoo.com/kb/index?locale=en_USy=PROD_ACCTpage=contentid=SLN3514


-- 
David.
 
 Thanks,
 
 Debs
 
 From: David Winsemius dwinsem...@comcast.net
 To: Debs Majumdar debs_st...@yahoo.com 
 Cc: r-help@r-project.org r-help@r-project.org 
 Sent: Tuesday, February 26, 2013 1:54 PM
 Subject: Re: [R] Adding markers and text for some data points after drawing a 
 plot
 
 
 On Feb 26, 2013, at 1:04 PM, Debs Majumdar wrote:
 
  Hi All,
  
  I have a data set of around 17,000 gene names and their lengths. E.g.
  
   gene  kblength
   A3GALT2  14.333
  AADACL3  12.609
  AADACL4  22.532
   ABCA4128.312
 ABCB10  42.114
   ABCD3100.287
  
  .
  
  and I was able to draw a reverse cumulative frequency plot using the 
  following code:
  d - read.table(gene_length_data.txt, header=T)
  attach(d)
 
 Using 'attach' is a bad idea. In particular we have trouble keeping straight 
 what is a column name or a first class object in your workspace.
 
  kblength.ecdf -ecdf(kblength)
  r -range(kblength)
  curve(1-kblength.ecdf(x), from=r[1], to=r[2], col=red, xlim=r)
  detach(d)
 
  Here's the link to the output: http://www.tiikoni.com/tis/view/?id=5c41810
  
  I want to put markers
 
 Use points()
 
  and the corresponding gene names in the graph for a small list of 6 genes. 
  i.e. say a hollow circle on the curve followed by the corresponding gene 
  name.
 
 
 text(x= d[ which( d[['gene']]==AADACL4), 2], 
 y= kblength.ecdf( d[ which( dat[['gene']]==AADACL4), 2]), 
 AADACL4)
  
  I am fighting with this but wasn't able to get a solution.
 
  
  Any help is appreciated.
  
  Thanks,
   Debs
  
  [[alternative HTML version deleted]]
 
 Please learn to post in plain text. And please, please do read the fine 
 Posting Guide.
 
 -- 
 David Winsemius
 Alameda, CA, USA
 
 
 

David Winsemius
Alameda, CA, USA

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


[R] Could R help with locating coordinates in a serial manner?

2013-02-26 Thread Onur Uncu
Dear R community,

My question is not a quick fix one but it would be helpful if you have any
advice for me.

I have a large data set of many locations in the US and all of these
locations are expressed in coordinates (longitudes and latitudes). I need a
tool which returns the state that each location is situated in. So the
program should return me a vector of state names (eg. NY,CA,OH, etc). Could
R help with this? Any ideas on other technologies that can be used for
this? Sorry for the open ended question. Thank you.

[[alternative HTML version deleted]]

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


Re: [R] Could R help with locating coordinates in a serial manner?

2013-02-26 Thread Ista Zahn
Hi,

See 
http://stackoverflow.com/questions/8751497/latitude-longitude-coordinates-to-state-code-in-r

Best,
Ista

On Tue, Feb 26, 2013 at 5:35 PM, Onur Uncu onuru...@gmail.com wrote:
 Dear R community,

 My question is not a quick fix one but it would be helpful if you have any
 advice for me.

 I have a large data set of many locations in the US and all of these
 locations are expressed in coordinates (longitudes and latitudes). I need a
 tool which returns the state that each location is situated in. So the
 program should return me a vector of state names (eg. NY,CA,OH, etc). Could
 R help with this? Any ideas on other technologies that can be used for
 this? Sorry for the open ended question. Thank you.

 [[alternative HTML version deleted]]

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] understanding cex (R plots)

2013-02-26 Thread Martin Batholdy
Hi,

I try to make multiple plots look as similar as possible.


I create each plot with pdf(), using the same height but different width in 
inch.
For some plots I use the layout() function to draw multiple subplots side by 
side in one pdf.

For each plot I use the same cex values for the different plotting functions
(cex.axis, cex.lab, cex.points etc.)

Still, when I compare the pdf's the axis labels, titles etc. have different 
size factors!

Is that expected?

I thought by fixing the height parameter and using the same character expansion 
values I would end up with similar plots
(and especially same font size across pdfs).

How can I make sure that across multiple plot calls the character expansion 
level (font size) is the same?



thanks!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Where is JGR's Java source code?

2013-02-26 Thread mlell08
Hello List,

I'm trying to get behind the secrets of rJava, especially how to run an
R session within a java Programm **and especially how wo inspect objects
of an R workspace from within a java program**

But as I can't find any documentation on the Java side of rJava, I tried
to learn somethin from the existing project JGR.

But I can't find any java code associated with this project! All I found
is one R/JGR.R file and some starter stuff downloadable by svn checkout
from the JGR homepage?!

So, please, dear list, tell me: where can I find the whole (Java!)
source code of JGR??

Best Regards,
Moritz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multistate occupancy models using Jags

2013-02-26 Thread Francisco Carvalho Diniz
Hi everyone,

I am trying to run the example of  multistate occupancy model from the book
Bayesian Population Analysis using WinBUGS (Marc Kéry and Michael Schaub):
This example is available on
http://www.vogelwarte.ch/code-for-running-bpa-using-jags.html

When I try to run the first line of this section of the model :

# Initial values
 zst - apply(y, 1, max, na.rm = TRUE)
 zst[zst == -Inf] - 1
  inits - function(){list(z = zst)}

I receive this warning message from R:

1: In FUN(newX[, i], ...) :
  no non-missing argument to max; returning -Inf

(Original message in Portuguese: Mensagens de aviso perdidas:
1: In FUN(newX[, i], ...) :
  nenhum argumento não faltante para max; retornando -Inf
)

Does someone know what is happening? I couldn't find anything related to
this model and error.
Thanks

Francisco

[[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] R documentation, how to set a character in bold font within math mode, within eqn or deqn?

2013-02-26 Thread Ehsan Masoudi
Hello all, 

I want to set (x_1, x_2, \dots, x_n) in a bold font within R documentation. I 
wrote 
\deqn(\bold{x}_1, \bold{x}_2, \ldots, \bold{x}_n),
but when Rstudio shows HTML preview of the documentation,  x is not 
bold and \bold{x} is illustrated instead. The other latex math bold producer 
such as \boldsymbol, \mathbf, \boldmath were also unsuccessful.
However, for PDF version of documentation it works.


So, What is the right command for setting a character in a bold within math for 
HTML version of documentation?

Thank you,

P.S.I achieved the same result with \mathbf and \boldsymbol


Ehsan MasoudiMaster graduated in Mathematical Statistics,
Ferdowsi university of Mashhad 
[[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] sys.frame() and variables from parent frame

2013-02-26 Thread José Miguel Delgado

Dear R-help,

I wrote the following lines in order to use a variable from a parent 
frame in my callM() function. I would like to solve this by only editing 
the callM(function). When I run this code I obtain a empty list, meaning 
that eval(ls(),sys.frame(-1)) could not access the variables in the 
parent function. Any suggestions? Thanks in advance!


metaCall - function()
  {
NN - 99
callM()
}

callM - function()
  {
Ls - eval(ls(),sys.frame(-1))
print(Ls)
### use Ls to call a certain model named M
}

metaCall()




--
  Zé Miguel
  ___

  JM Delgado
  Reichenberger Str. 52
  10999 Berlim
  Alemanha

  t(d):+49 30 841 18 127
  m(d):+49 176 9633 92 56
  m(p):+351 91 671 07 08

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


[R] R documentation, how to force Rcmd Rd2pdf to automatically break an overfull line in examples R-like section?

2013-02-26 Thread Ehsan Masoudi
Hi all,


My package passed Rcmd check successfully. but 
in constructed PDF format of R documentation, within the examples 
section, half of the line (R code) is out of the paper. I also found 
another CRAN submitted package, ftsa , that suffer from overfulling in a line 
too, see ftsa Reference manual.
I guess this 
problem roots in the behavior of the verbatim environment in Latex. However 
there are some Latex packages to deal with this, 
http://tex.stackexchange.com/questions/14342/verbatim-environment-that-can-break-too-long-lines,
 but I do not know how to use them with Rcmd.
1. In dealing with these cases, why Rcmd check does not show any error, 
warnings ornote as Latex does to point out to maintainer?
2. How can I force line breaking in examples section?
Thank you

Ehsan MasoudiMaster graduated in Mathematical Statistics,
Ferdowsi university of Mashhad
[[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] cutreeDynamic error

2013-02-26 Thread Joanna Papakonstantinou
I am having difficulty getting the dynamic tree cut package to work.

Given the data table myddtable
LengthPlaceColorAge5HRed224ABlue205WGreen243GRed222GBlue236WGreen255ARed194H
Blue23
I created a similarity matrix using DAISY and Gower metric and specified
Place and Color columns as characters (since they are categorical variables)

 dd.daisy-daisy(myddtable, metric = gower, stand = FALSE, type =
list(character=c(Place,Color)))

Then I clustered using DIANA
dd.diana-diana(dd.daisy)
I am trying to cutreeDynamic {dynamicTreeCut} as follows

cutreeDynamic(dd.diana, cutHeight = 2, minClusterSize = 1, method =
hybrid,+ distM = dd.daisy,+ deepSplit =
(ifelse(method==hybrid, 1, FALSE)),+ maxCoreScatter =
NULL, minGap = NULL,+ maxAbsCoreScatter = NULL,
minAbsGap = NULL,+ maxDistToLabel = cutHeight,+
respectSmallClusters = TRUE, + verbose = 2, indent
= 0)

But get the following error:

Warning in if (class(dendro) != hclust) stop(Argument dendro must
have class hclust.) :
the condition has length  1 and only the first element will be
usedError in cutreeDynamic(dd.diana, cutHeight = 2, minClusterSize =
1, method = hybrid, :
Argument dendro must have class hclust.

Is this trying to tell me I cannot use this with DIANA but only with hclust
because I thought it could be used with any of the hierarchical methods?

I hope someone can please tell me what I am doing wrong.

Thank you.


-- 
**


*Joanna Papakonstantinou, Ph.D.*

[[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] upgrading r-base

2013-02-26 Thread Dave Mitchell
I'm trying to install R 2.15 on an Ubuntu server.  I'm getting the depends
 but it's not going to be installed error messages I've seen people
write about, but never solve.  I've attached a screen shot, if that helps.
Has anyone seen (and solved) these updating issues?  I find it hard to
believe that everyone using Ubuntu server is an R version behind.  Thanks
for your time.

Dave Mitchell
attachment: r-base_error.PNG__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] legend issues.

2013-02-26 Thread Nicole Ford
I thought my reply went to the group last night.  i had already resolved it.

in short, before his first reply it was resolved... which is why i didn't offer 
additional information.  i was honestly taken aback by his response to me.  i 
don't respond well to vitriol wrapped in attempts to help.  i am adult, not a 5 
year old.

i have offered help to others here before, not often, but i have. i watch this 
list daily, multiple times a day.  i know the rules.

i had a moment of panic and i forgot to add that in my initial email.  

i panicked becuase:  i went through all of the typical stuff one would with 
such an error with that student.  is the car package installed'; have you 
restarted R; have you cleared out the workspace and reinstalled everything?  
etc.  this is my first time teaching this course.  i am also the ONLY one here 
in my department that uses R.  and i am proficent through multinom/ logit/ 
probit, etc. (though still have a lot to learn, of course).  i am no dummy. but 
i was stuck.  i had no one else to turn to, and i was worried i would not  be 
able to help her on my own.  i forgot to add her session info in a lapse.  
that's all.  sorry i wasn't expecting the level of response i got.

by the time i realized it, i had alreayd resovled it.  i had come back to say 
that when i saw this reply,  and just ended up mentioning i had done many of 
the things he suggested.  and failed to mention it was resolved because -at 
that point- 1) i didn't need the help  2) since i didn't provide the info, i 
wasn't going to have anyone else attempt to help me so i didn't see that as a 
big deal.

i had no intent on being rude.  i simply forgot.  are we not allowed to make 
mistakes without being attacked?  no one is perfect all of the time.  

anyway.  that is is rhetorical question.

i don't wish to engage in a online 'argument' or defense of my honest mistake.  
so i will bow out of this thread at this time out of repect for everyone else.

~Nicole Ford
Ph.D. student
Graduate Assistant/ Instructor
University of South Florida
Government and International Affairs
office: SOC 012M
e: nmhi...@mail.usf.edu
http://gia.usf.edu/student/nford/






On Feb 26, 2013, at 1:07 PM, Greg Snow wrote:

 Nicole,
 
 Since you seem more interested in accusing David of being rude than 
 recognizing your own rudeness and taking steps to overcome that and increase 
 your chance of getting useful responses I will quote a few lines from the 
 posting guide for you (the entire posting guide is available from the link at 
 the bottom of this and every R-help post):
 
  Like many responses posted on the list, it is written in a concise manner. 
 This is not intended to be unfriendly - it is more a consequence of 
 allocating the limited available time and space to technical issues rather 
 than to social niceties.
 
 Remember that customs differ. Some people are very direct. Others surround 
 everything they say with hedges and apologies. Be tolerant. Rudeness is never 
 warranted, but sometimes `read the manual' is the appropriate response.
 
 No HTML posting (harder to detect spam) (note that this is the default in 
 some mail clients - you may have to turn it off).
 
 at a minimum, copy and paste the output from sessionInfo() into your message
 
 
 I see attempts to help you in David's posts, I see very little in your 
 responses that would help him (or any of the rest of us) help you.
 
 
 On Mon, Feb 25, 2013 at 3:57 PM, Nicole Ford nicolefor...@gmail.com wrote:
 by the time your rude reply came ( you are often rude to people so i 
 shouldn't have been surprised but somehow was) , i had already found my 
 answer, by doing it MYSELF on her computer and found had not followed some 
 simple instructions.
 
 be well.
 ~Nicole Ford
 Ph.D. student
 Graduate Assistant/ Instructor
 University of South Florida
 Government and International Affairs
 office: SOC 012M
 e: nmhi...@mail.usf.edu
 http://gia.usf.edu/student/nford/
 
 
 
 
 
 
 On Feb 25, 2013, at 4:18 PM, David Winsemius wrote:
 
  My point is that you _still_ have not adhered to the Posting Guide request 
  for sessionInfo() ... I say again. Please read the Posting Guide ... AND 
  PLEASE STOP posting formatted email.
 
  --
  David.
 
  On Feb 25, 2013, at 10:20 AM, Nicole Ford wrote:
 
  I did look at ??pie  ??graphics, as per my reply.  which netted nothing of 
  value.
 
  thanks.
  ~Nicole Ford
  Ph.D. student
  Graduate Assistant/ Instructor
  University of South Florida
  Government and International Affairs
  office: SOC 012M
  e: nmhi...@mail.usf.edu
  http://gia.usf.edu/student/nford/
 
 
 
 
 
 
  On Feb 25, 2013, at 12:38 PM, David Winsemius wrote:
 
 
  On Feb 25, 2013, at 7:37 AM, Nicole Ford wrote:
 
  hello, all.
 
  one of my students is having an issue with the pie  legend function.
 
  this is her code.  (below)
 
  it works just fine for me.
 
  her error is plot.new has not been called yet.  i know this means her 
  pie chart is coming up blank so 

[R] cutreeDynamic error

2013-02-26 Thread Joanna Papakonstantinou
So I realized I had to convert my dd.daisy to a matrix and used:
ddmatrix.daisy-as.matrix(dd.daisy)
and then I passed that in as the distM:
 cutreeDynamic(as.hclust(dd.diana), cutHeight = NULL, minClusterSize = 2,
method = hybrid, distM = ddmatrix.daisy,deepSplit =
(ifelse(method==hybrid, 1, FALSE)),maxCoreScatter = NULL, minGap = NULL,
maxAbsCoreScatter = NULL, minAbsGap = NULL,useMedoids = FALSE,
maxDistToLabel = cutHeight,respectSmallClusters = TRUE, verbose = 2, indent
= 0)

However, now I am getting a different error:

 Detecting clusters...
..cutHeight not given, setting it to 0.847  ===  99% of the (truncated)
height range in dendro.
Error in ifelse(method == hybrid, 1, FALSE) : object 'method' not found

Anny suggestions on how to fix this?

Joanna

[[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] Count function calls

2013-02-26 Thread Simon Zehnder
Dear R-users,

I have the following problem: I am running the function 'pvcm' from the 'plm' 
Panel Data package. Inside this function 'solve' is called and gives for a 
certain individual data series an exception because of singularity. I would 
like to know which individual data series causes this error. I tried to debug 
it, but this is truly painful, as solve is called inside of 'lapply' and there 
are over 5,000 individual data series in the panel. 

Now, what I would like to do is to count the calls to 'solve' inside the 
function, so I can see, where the function throws the exception. I tried to use 
'trace' with a count variable, but I have no clue how to define a global 
variable to be used by trace and updated at every call.is there another 
approach? 


Best

Simon

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Getting the correct factor level as Dunnett control in glht()

2013-02-26 Thread Andrew Koeser
Hello all,

I would like to do a Dunnett test in glht(). However, the factor level I 
want to use as the control is not the first.

dunn1-glht(model3, linfct = mcp(Container = Dunnett), alternative = 
less)

The factor container has 8 levels, so it would be nice not to manually 
enter in all of the contrasts. I originally discovered glht() when 
working with a glm model and like the versatility it offers.  I there a 
place to enter a base level? I have not had any luck with this question 
looking at online documentation. Is the book for multcomp a good reference?

Thanks to Dalgaard's book, I was able stumble through reordering the data.

levels(petunia$Container)
  [1] bioplastic coir   cowfertil netpeat   
plasticrice   soilwrap
[10] straw
petunia$Container - 
factor(petunia$Container,levels(petunia$Container)[c(7,1:6,8:10)])
petunia2-order(petunia$Container)
petunia.sorted-petunia[petunia2,]
petunia.sorted
  ID  Container TotalWater LeafArea Distance   Fresh   Dry  Bag Biomass
121  15plastic1961.00332.0   109.10  42.700 11.00 7.903.10
122  38plastic2153.00552.087.90  56.700 12.00 7.804.20
123  46plastic1880.00394.081.10  48.100 11.60 7.903.70
124  66plastic2267.00214.062.50  35.800 11.50 8.003.50
125  84plastic2150.50362.046.50  40.400 10.60 7.802.80
126  86plastic2034.00494.047.60  53.700 11.90 7.804.10
127  87plastic2342.00383.547.05  44.700 12.80 7.904.90
128  96plastic1952.00273.046.50  35.700 10.50 7.902.60
129  98plastic2411.00532.037.10  58.400 12.20 7.904.30

130 106plastic2162.00314.031.20  41.200 10.90 7.903.00
131 116plastic2531.00389.019.40  51.000 12.10 7.904.20
132 119plastic2129.00346.025.80  41.600 11.20 7.903.30
133 122plastic2429.00464.021.30  51.600 11.90 7.904.00
134 123plastic2342.00303.016.20  43.200 11.30 7.803.50
135 148plastic1709.00331.0   135.30  40.800 10.80 7.803.00
136 152plastic2143.00332.0   120.70  41.300 12.50 7.904.60
137 165plastic2213.50440.5   122.80  51.300 12.80 7.904.90
138 178plastic2284.00549.0   124.90  61.300 12.90 7.905.00
139 195plastic1994.00314.0   111.10  39.300 10.80 7.902.90
140 199plastic2191.00363.090.70  44.900 11.70 7.803.90
114 bioplastic2120.00433.0   108.20  48.800 11.60 7.903.70
220 bioplastic1643.00375.0   101.00  39.300 10.00 7.902.10
327 bioplastic1735.00432.094.70  43.500 10.70 7.902.80


After that, I reran the model and all worked out

model3b-aov(TotalWater~Container, data=petunia.sorted)
dunn2-glht(model3b, linfct = mcp(Container = Dunnett),alternative = 
greater)
summary(dunn2)

  Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Dunnett Contrasts


Fit: aov(formula = TotalWater ~ Container, data = petunia.sorted)

Linear Hypotheses:
   Estimate Std. Error t value Pr(t)
bioplastic - plastic = 0  -147.55  79.15  -1.864  1.000
coir - plastic = 0 824.35  79.15  10.414 1e-04 ***
cow - plastic = 0 1380.28  79.15  17.438 1e-04 ***
fertil - plastic = 0  1572.60  79.15  19.868 1e-04 ***
net - plastic = 0  845.20  79.15  10.678 1e-04 ***
peat - plastic = 0 786.20  79.15   9.933 1e-04 ***
rice - plastic = 0 -36.62  79.15  -0.463  0.968
soilwrap - plastic = 0 375.75  79.15   4.747 1e-04 ***
straw - plastic = 0   1358.20  79.15  17.159 1e-04 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Adjusted p values reported -- single-step method)


Is there a better/easier way of doing this? I am showing my labmates R 
as part of our weekly meetings (we are a SAS department). I think this 
may scare them.

Thanks,

Andrew

-- 
Research and Teaching Assistant
Department of Crop Sciences
University of Illinois at Champaign-Urbana


[[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] cumulative sum by group and under some criteria

2013-02-26 Thread Zjoanna
Hi Arun

I noticed that the values of Fmm, Fnn, and other corresponding variables
are not correct, for example,  for the 4th obs after you run this code, the
Fmm is 0.40,  but if you use the x, m, y, n in the 4th row to calculate
them, the results are not consistent, same for the 5th obs.

#check
#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
Pn2-rbeta(1000, 0.2, 0.8+4)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(0)
Fmm2  #0.582
Fnn2   #0


Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs5
Pn2-rbeta(1000, 0.2+1, 0.8+3)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(1/4)
Fmm2 #0.404
Fnn2  #0.416



On Sat, Feb 23, 2013 at 10:53 PM, arun kirshna [via R] 
ml-node+s789695n4659514...@n4.nabble.com wrote:

 Hi,
 d3-structure(list(m1 = c(2, 3, 2), n1 = c(2, 2, 3), cterm1_P0L =
 c(0.9025,
 0.857375, 0.9025), cterm1_P1L = c(0.64, 0.512, 0.64), cterm1_P0H =
 c(0.9025,
 0.9025, 0.857375), cterm1_P1H = c(0.64, 0.64, 0.512)), .Names = c(m1,
 n1, cterm1_P0L, cterm1_P1L, cterm1_P0H, cterm1_P1H), row.names =
 c(NA,
 3L), class = data.frame)
 d2- data.frame()
 for (m1 in 2:3) {
 for (n1 in 2:3) {
 for (x1 in 0:(m1-1)) {
 for (y1 in 0:(n1-1)) {
 for (m in (m1+2): (7-n1)){
for (n in (n1+2):(9-m)){
for (x in x1:(x1+m-m1)){
  for(y in y1:(y1+n-n1)){
  d2- rbind(d2,c(m1,n1,x1,y1,m,n,x,y))
  
 colnames(d2)-c(m1,n1,x1,y1,m,n,x,y)
  #or

 res1-do.call(rbind,lapply(unique(d3$m1),function(m1)
  do.call(rbind,lapply(unique(d3$n1),function(n1)
  do.call(rbind,lapply(0:(m1-1),function(x1)
  do.call(rbind,lapply(0:(n1-1),function(y1)
  do.call(rbind,lapply((m1+2):(7-n1),function(m)
  do.call(rbind,lapply((n1+2):(9-m),function(n)
  do.call(rbind,lapply(x1:(x1+m-m1), function(x)
  do.call(rbind,lapply(y1:(y1+n-n1), function(y)
  expand.grid(m1,n1,x1,y1,m,n,x,y)) )))
  names(res1)- c(m1,n1,x1,y1,m,n,x,y)
  attr(res1,out.attrs)-NULL
 res1[]- sapply(res1,as.integer)

 library(plyr)
 res2- join(res1,d3,by=c(m1,n1),type=inner)

 #Assuming that these are the values you used:

 p0L-0.05
 p0H-0.05
 p1L-0.20
 p1H-0.20
 res2- within(res2,{p1- x/m; p2- y/n;term2_p0-dbinom(x1,m1, p0L,
 log=FALSE)* dbinom(y1,n1,p0H, log=FALSE)*dbinom(x-x1,m-m1, p0L, log=FALSE)*
 dbinom(y-y1,n-n1,p0H, log=FALSE);term2_p1- dbinom(x1,m1, p1L, log=FALSE)*
 dbinom(y1,n1,p1H, log=FALSE)*dbinom(x-x1,m-m1, p1L, log=FALSE)*
 dbinom(y-y1,n-n1,p1H, log=FALSE);Pm2-rbeta(240, 0.2+x,
 0.8+m-x);Pn2-rbeta(240, 0.2+y, 0.8+n-y)})
 Fm2- ecdf(res2$Pm2)
 Fn2- ecdf(res2$Pn2)

 res3- within(res2,{Fmm2-Fm2(p1);Fnn2- Fn2(p2);R2- (Fmm2+Fnn2)/2}) #not
 sure about this step especially the Fm2() or Fn2()
 res3$Fmm_f2-apply(res3[,c(R2,Fmm2)],1,min)
  res3$Fnn_f2-apply(res3[,c(R2,Fnn2)],1,max)
 res3- within(res3,{Qm2- 1-Fmm_f2;Qn2- 1-Fnn_f2})
 head(res3)
 #  m1 n1 x1 y1 m n x y cterm1_P0L cterm1_P1L cterm1_P0H cterm1_P1H
 Pn2
 #1  2  2  0  0 4 4 0 0 0.9025   0.64 0.9025   0.64
 0.001084648
 #2  2  2  0  0 4 4 0 1 0.9025   0.64 0.9025   0.64
 0.504593909
 #3  2  2  0  0 4 4 0 2 0.9025   0.64 0.9025   0.64
 0.541379357
 #4  2  2  0  0 4 4 1 0 0.9025   0.64 0.9025   0.64
 0.138947785
 #5  2  2  0  0 4 4 1 1 0.9025   0.64 0.9025   0.64
 0.272364957
 #6  2  2  0  0 4 4 1 2 0.9025   0.64 0.9025   0.64
 0.761635059
 #   Pm2   term2_p1 term2_p0   p2   p1R2  Fnn2 Fmm2
 #1 1.212348e-05 0.16777216 0.6634204313 0.00 0.00 0.000 0.000  0.0
 #2 1.007697e-03 0.08388608 0.0698337296 0.25 0.00 0.1791667 0.358  0.0
 #3 1.106946e-05 0.01048576 0.0018377297 0.50 0.00 0.3479167 0.6958333  0.0
 # 2.086758e-01 0.08388608 0.0698337296 0.00 0.25 0.200 0.000  0.4
 #5 2.382179e-01 0.04194304 0.0073509189 0.25 0.25 0.3791667 0.358  0.4
 #6 4.494673e-01 0.00524288 0.0001934452 0.50 0.25 0.5479167 0.6958333  0.4
 # Fmm_f2Fnn_f2   Qn2   Qm2
 #1 0.000 0.000 1.000 1.000
 #2 0.000 0.358 0.6416667 1.000
 #3 0.000 0.6958333 0.3041667 1.000
 #4 0.200 0.200 0.800 0.800
 #5 0.3791667 0.3791667 0.6208333 0.6208333
 #6 0.400 0.6958333 0.3041667 0.600


 A.K.







 
 From: Joanna Zhang [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4659514i=0

 To: arun [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4659514i=1

 Sent: Friday, February 22, 2013 11:02 AM
 Subject: Re: [R] cumulative sum by group and under some criteria


 Thanks!  Then I need to create new variables based on the res2.  I can't
 find Fmm_f1, Fnn_f2, R2, Qm2, Qn2 until  running the code several times and
 the values of Fnn_f2, Fmm_f2 are correct.

 attach(res2)
 res2$p1-x/m
 res2$p2-y/n
 res2$term2_p0 - dbinom(x1,m1, p0L, log=FALSE)* dbinom(y1,n1,p0H,
 log=FALSE)*dbinom(x-x1,m-m1, p0L, log=FALSE)* dbinom(y-y1,n-n1,p0H,
 log=FALSE)
 res2$term2_p1 - dbinom(x1,m1, p1L, log=FALSE)* dbinom(y1,n1,p1H,
 

Re: [R] understanding cex (R plots)

2013-02-26 Thread Greg Snow
Have you queried the value of 'cex' and related parameters at the different
time points?

The help page for par says that when you set mfcol or mfrow that cex is
changed, but I don't know if the layout function also changes those or not.
 I would start by peppering your code with calls to par('cex') to see what
R thinks the parameter is at the time of the different plots.  That may
answer your question, or if not at least give up more information to work
with.


On Tue, Feb 26, 2013 at 3:46 PM, Martin Batholdy batho...@googlemail.comwrote:

 Hi,

 I try to make multiple plots look as similar as possible.


 I create each plot with pdf(), using the same height but different width
 in inch.
 For some plots I use the layout() function to draw multiple subplots side
 by side in one pdf.

 For each plot I use the same cex values for the different plotting
 functions
 (cex.axis, cex.lab, cex.points etc.)

 Still, when I compare the pdf's the axis labels, titles etc. have
 different size factors!

 Is that expected?

 I thought by fixing the height parameter and using the same character
 expansion values I would end up with similar plots
 (and especially same font size across pdfs).

 How can I make sure that across multiple plot calls the character
 expansion level (font size) is the same?



 thanks!

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




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] understanding cex (R plots)

2013-02-26 Thread Martin Batholdy
thank you!

It seems like the problem was the layout-function automatically changing the 
cex parameter for the subplots.

adding par(cex =1) after the layout() call solved it.
Now, character expansion levels seem equal across plots.


On Feb 27, 2013, at 00:57 , Greg Snow 538...@gmail.com wrote:

 Have you queried the value of 'cex' and related parameters at the different 
 time points?  
 
 The help page for par says that when you set mfcol or mfrow that cex is 
 changed, but I don't know if the layout function also changes those or not.  
 I would start by peppering your code with calls to par('cex') to see what R 
 thinks the parameter is at the time of the different plots.  That may answer 
 your question, or if not at least give up more information to work with.
 
 
 On Tue, Feb 26, 2013 at 3:46 PM, Martin Batholdy batho...@googlemail.com 
 wrote:
 Hi,
 
 I try to make multiple plots look as similar as possible.
 
 
 I create each plot with pdf(), using the same height but different width in 
 inch.
 For some plots I use the layout() function to draw multiple subplots side by 
 side in one pdf.
 
 For each plot I use the same cex values for the different plotting functions
 (cex.axis, cex.lab, cex.points etc.)
 
 Still, when I compare the pdf's the axis labels, titles etc. have different 
 size factors!
 
 Is that expected?
 
 I thought by fixing the height parameter and using the same character 
 expansion values I would end up with similar plots
 (and especially same font size across pdfs).
 
 How can I make sure that across multiple plot calls the character expansion 
 level (font size) is the same?
 
 
 
 thanks!
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 -- 
 Gregory (Greg) L. Snow Ph.D.
 538...@gmail.com


[[alternative HTML version deleted]]

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


Re: [R] R documentation, how to force Rcmd Rd2pdf to automatically break an overfull line in examples R-like section?

2013-02-26 Thread Duncan Murdoch

On 13-02-26 3:32 AM, Ehsan Masoudi wrote:

Hi all,


My package passed Rcmd check successfully. but
in constructed PDF format of R documentation, within the examples
section, half of the line (R code) is out of the paper. I also found
another CRAN submitted package, ftsa , that suffer from overfulling in a line 
too, see ftsa Reference manual.
I guess this
problem roots in the behavior of the verbatim environment in Latex. However 
there are some Latex packages to deal with this, 
http://tex.stackexchange.com/questions/14342/verbatim-environment-that-can-break-too-long-lines,
 but I do not know how to use them with Rcmd.
1. In dealing with these cases, why Rcmd check does not show any error, 
warnings ornote as Latex does to point out to maintainer?


Because there is no test for that.  It might be useful to write one, but 
nobody has done so.



2. How can I force line breaking in examples section?


Just put a line break in your code.

Duncan Murdoch


Thank you

Ehsan MasoudiMaster graduated in Mathematical Statistics,
Ferdowsi university of Mashhad
[[alternative HTML version deleted]]

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



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


Re: [R] sys.frame() and variables from parent frame

2013-02-26 Thread David Winsemius

On Feb 26, 2013, at 2:40 AM, José Miguel Delgado wrote:

 Dear R-help,
 
 I wrote the following lines in order to use a variable from a parent frame in 
 my callM() function. I would like to solve this by only editing the 
 callM(function). When I run this code I obtain a empty list, meaning that 
 eval(ls(),sys.frame(-1)) could not access the variables in the parent 
 function. Any suggestions? Thanks in advance!
 
 metaCall - function()
  {
NN - 99
callM()
}
 
 callM - function()
  {
Ls - eval(ls(),sys.frame(-1))
print(Ls)
### use Ls to call a certain model named M

That doesn't make much sense.

}
 
 metaCall()
 

I don't think you need the eval() call:

 metaCall - function()
 {
   NN - 99
   callM()
   }

callM - function()
 {
   Ls - ls(env=sys.frame(-1))
   cat(Ls)
   }

metaCall()
NN

You should be aware that metaCall will not return anything since the last value 
is from the cat()-call or the print()-call and they each return NULL. If you 
wanted to go on from there and do something with 'NN, which is no longer a 
number but rather a character vector, you could, however.

Oh, I think I finally see  the eval() was an attempt to retrieve  the 
object named NN in the parent.frame? That means you need :

?get

metaCall - function()
 {
   NN - 99
   callM()
   }

callM - function()
 {
   Ls - ls(env=sys.frame(-1))
   str(get(Ls, env=sys.frame(-1)))
   }

metaCall()
# num 99

-- 
David Winsemius
Alameda, CA, USA

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


[R] temp seems ineffective in SANN (optim)

2013-02-26 Thread Ross Boylan
I am trying to control the behavior of the SANN method in optim (R
2.14.1) via control$temp.  In my toy tests it works; in my real use, it
doesn't.

As far as I can tell my code with different temp values is loaded; I
even traced into the function that calls optim and verified temp had the
value I had set.

Could the fact that I have NaN's coming back from the objective function
be a factor?  Here are the results I've gotten from 20 iterations with
temp varying from 2 to 9.  The first column is the value of the
objective function, and the rest are the parameter values (the objective
function is augmented to leave a trace).  The rows represent SANN's
different guesses, in sequence.
 history9
   [,1]  [,2][,3][,4]  [,5][,6]
 [1,] -3507.346 -4.50  1.  1. 1.000  0.69314718
 [2,] -3828.071 -3.942424  0.03090623  0.30739233 1.7062554 -0.01814918
 [3,] -4007.624 -3.126794  1.79592189  1.41855332 1.2060574  1.54479512
 [4,]   NaN -4.064653 -0.25017279  1.30476170 0.2559306 -0.31140650
 [5,] -4222.272 -3.058714 -0.93063613 -0.54296159 0.8287307  1.92103676
 [6,]   NaN -3.833080  1.00721123  1.66564249 0.7923725 -0.04967723
 [7,]   NaN -5.050322 -0.45545409  0.83209653 1.4976764 -0.47211795
 [8,]   NaN -3.717588  0.62400594  0.73424007 0.1359730  1.62073131
 [9,]   NaN -6.078701  0.1219  0.36961894 0.2633589  0.67651053
[10,]   NaN -3.404865  2.92992664  1.45204623 0.2020535  1.49936000
[11,]   NaN -3.387337  2.17682158  0.06994319 1.1717615  0.68526889
[12,]   NaN -4.534316  0.88676089  1.34499190 0.9148238  0.98417597
[13,]   NaN -4.445174  1.06230896  1.51960345 0.4651780  1.14127715
[14,] -3784.848 -4.007890  0.77866330  1.01243770 1.1957120  1.33305656
[15,]   NaN -3.707500  1.30038651  1.30480610 0.6210218  0.81355299
[16,] -3730.219 -4.155193  0.76779830  1.06686987 1.0546294  1.45601474
[17,] -3524.462 -5.074722  1.21296408  0.59787431 0.9228195  1.07755859
[18,] -3588.086 -5.146427  1.28721218  0.74634447 1.1107613  0.63009540
[19,] -3715.411 -4.501889  0.72491408  0.75046935 0.8476556  1.64229603
[20,] -3711.158 -4.813507  0.88125227  1.10291836 0.1452430  0.07181056
 [,7]   [,8]  [,9][,10]
 [1,]  0.  0.5493061 -4.50 4.00
 [2,] -1.33969887  2.6881171 -5.797714 4.712738
 [3,]  1.10373337  1.5164159 -4.666298 4.551507
 [4,]  0.36425367  0.5755519 -3.558595 3.84
 [5,] -0.77555882  0.4863321 -5.060481 4.987640
 [6,] -1.14686363  0.5164433 -4.759286 3.650409
 [7,] -0.43179263  1.1326352 -4.611431 3.920483
 [8,]  1.67696259  0.8754158 -4.352415 3.095768
 [9,]  1.10927659  0.5779504 -4.952128 4.649442
[10,] -0.67478207  2.8174240 -4.704395 2.986569
[11,]  0.45878472  0.6479467 -4.122482 2.934156
[12,] -0.04871212  0.9457826 -4.617438 4.377056
[13,] -0.01321339  0.3833625 -4.591240 4.729049
[14,] -0.49075803  0.3322742 -3.971298 4.357731
[15,]  0.16922427  0.4820518 -4.683029 3.875409
[16,] -0.18047923 -0.4957090 -4.492014 4.317694
[17,] -0.28481705  0.1923373 -4.288773 3.956130
[18,]  0.12102775 -0.2332984 -4.981987 4.301450
[19,]  0.15961575  1.1644561 -4.459003 3.777286
[20,] -0.24130528  0.6126422 -4.075133 3.628426
 sum(is.nan(history9[,1]))
[1] 10
 max(abs(history9-history5), na.rm=TRUE)
[1] 9.094947e-13
# historyN has a temp of N

BTW the values of the objective function have their sign reversed to
make it a maximization problem.

Ross Boylan

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

2013-02-26 Thread William Dunlap
This is where - is helpful:
N - 0 ; trace(solve, quote(N - N + 1), print=FALSE)
   Tracing function solve in package base
   [1] solve
lapply(3:0, function(i)solve(diag(i,3), 1:3))
   Error in solve.default(diag(i, 3), 1:3) : 
 Lapack routine dgesv: system is exactly singular: U[1,1] = 0
N
   [1] 4

You can also set
   options(error=recover)
to look at the state of things when the error occurs.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Simon Zehnder
 Sent: Tuesday, February 26, 2013 2:53 AM
 To: r-help@r-project.org help
 Subject: [R] Count function calls
 
 Dear R-users,
 
 I have the following problem: I am running the function 'pvcm' from the 'plm' 
 Panel Data
 package. Inside this function 'solve' is called and gives for a certain 
 individual data series
 an exception because of singularity. I would like to know which individual 
 data series
 causes this error. I tried to debug it, but this is truly painful, as solve 
 is called inside of
 'lapply' and there are over 5,000 individual data series in the panel.
 
 Now, what I would like to do is to count the calls to 'solve' inside the 
 function, so I can
 see, where the function throws the exception. I tried to use 'trace' with a 
 count variable,
 but I have no clue how to define a global variable to be used by trace and 
 updated at
 every call.is there another approach?
 
 
 Best
 
 Simon
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] upgrading r-base

2013-02-26 Thread Rolf Turner



Have you looked at the instructions at the URL which Sarah Goslee
drew to the attention of the list on 19 July 2012?

There's a special README for Ubuntu to help you get the current version.
http://cran.r-project.org/bin/linux/ubuntu/README

You probably need to modify your /etc/apt/sources.list file in the
manner suggested in those instructions.

cheers,

Rolf Turner



On 02/27/2013 10:16 AM, Dave Mitchell wrote:

I'm trying to install R 2.15 on an Ubuntu server.  I'm getting the depends
 but it's not going to be installed error messages I've seen people
write about, but never solve.  I've attached a screen shot, if that helps.
Has anyone seen (and solved) these updating issues?  I find it hard to
believe that everyone using Ubuntu server is an R version behind.  Thanks
for your time.


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


Re: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread Anika Masters
Thanks Arun and David.  Another issue I am running into are memory
issues when one of the data frames I'm trying to rbind to or merge
with are very large.  (This is a repetitive  problem, as I am trying
to merge/rbind thousands of small dataframes into a single very
large dataframe.)



I'm thinking of creating a function that creates an empty dataframe to
which I can add data, but will need to first determine and ensure that
each dataframe has the exact same columns, in the exact same
location.



Before I write any new code, is there any pre-existing functions or
code that might solve this problem of merging small or medium sized
dataframes with a very large dataframe.)

On Tue, Feb 26, 2013 at 2:00 PM, David L Carlson dcarl...@tamu.edu wrote:
 Clumsy but it doesn't require any packages:

 merge2 - function(x, y) {
 if(all(union(names(x), names(y)) == intersect(names(x), names(y{
 rbind(x, y)
 } else merge(x, y, all=TRUE)
 }
 merge2(df1, df2)
 df3 - df1
 merge2(df1, df3)

 --
 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-bounces@r-
 project.org] On Behalf Of arun
 Sent: Tuesday, February 26, 2013 1:14 PM
 To: Anika Masters
 Cc: R help
 Subject: Re: [R] merging or joining 2 dataframes: merge, rbind.fill,
 etc.?

 Hi,

 You could also try:
 library(gtools)
 smartbind(df2,df1)
 #  a  b  d
 #1 7 99 12
 #2 7 99 12


 When df1!=df2
 smartbind(df1,df2)
 #   a  b  d  x  y  c
 #1  7 99 12 NA NA NA
 #2 NA 34 88 12 44 56
 A.K.




 - Original Message -
 From: Anika Masters anika.mast...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Tuesday, February 26, 2013 1:55 PM
 Subject: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

 #I want to merge or join 2 dataframes (df1  df2) into a 3rd
 (mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
  df2, and all the columns in both df1  df2. The solution should
 work even if the 2 dataframes are identical, and even if the 2
 dataframes do not have the same column names.  The rbind.fill function
 seems to work.  For learning purposes, are there other good ways to
 solve this problem, using merge or other functions other than
 rbind.fill?

 #e.g. These 3 examples all seem to work correctly and as I hoped:

 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #e.g. this works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #This works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #But this does not (the 2 dataframes are identical)
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - df1
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #Any way to get mere to work for this final example? Any other good
 solutions?

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


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


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


[R] Parallelizing Other Apply Functions, e.g. by, the Easy (Wrong?) Way

2013-02-26 Thread ivo welch
Dear R Users---this is more curiosity than a real problem.  I am wondering
how to add mc* functions for all of R's *apply functions.   stackoverflow
3505701 has a nice overview of these functions.  roughly,

apply ( function to rows and columns of matrix )
lapply ( function to each element of list, get back list )
sapply ( function to each element of list, get back vector )
vapply ( like sapply, but tells R about return values of function for speed
)
mapply ( function to first element of multiple lists, then second element
of multiple lists, etc )
rapply ( uncommon recursive use )

tapply ( function to one vector based on groups of another vector )
by ( function to apply to data frame or list, based on one vector in the
list; relies on tapply )
aggregate ( seems to be sort of like by )

ave ( merges by results back into a vector of same length )


many of the functions use lapply internally.  by uses tapply internally.
which uses lapply.  these functions should ideally have had a parameter
that is the lapply function that they use, so that mc.by - function(...)
by(..., lapply=mclapply ).  unfortunately, they do not.  so, I am now
wondering what the preferred way is to patch them.

one way to do this would be:

  mc.by - function( ... ) {
  oc.lapply - lapply
  lapply - mclapply
  result - by( ... )
  lapply - oc.lapply
  return(result)
  }


the disadvantage is that if the function to mc.by itself relies on, say,
sapply somewhere, both would use the multicore mclapply function.  I don't
think it is possible to spoof the GlobalEnv for only one function, but not
its own lower-tier functions.  another big problem here is that I probably
have to trap this function appropriately, so that this restores on abort
the original lapply function.  not pretty.  the advantage of doing it is
that future changes by the R core team to by() will not create any changes.

the alternative is to copy the definitions from by.data.frame and
by.default, and replace them with my own, which has only one change---the
optional argument.  this is not hard to do, but I now run the risk that the
R team could change by().  I wish I could at least test whether the by()
function changes from release to release to alert me, but functions are not
atomic and therefore cannot be compared.


what is the recommended way to do this?

/iaw


Ivo Welch (ivo.we...@gmail.com)
http://www.ivo-welch.info/

[[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] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread Jeff Newmiller
merge and rbind have very different memory usage profiles. There are some 
optimizations you can take advantage of if you store all of your small data 
frames in a list first, and then feed it through sapply (base) or ldply (plyr) 
to form the large data frame all at once, which can avoid the memory 
fragmentation associated with incrementally appending the data.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Anika Masters anika.mast...@gmail.com wrote:

Thanks Arun and David.  Another issue I am running into are memory
issues when one of the data frames I'm trying to rbind to or merge
with are very large.  (This is a repetitive  problem, as I am trying
to merge/rbind thousands of small dataframes into a single very
large dataframe.)



I'm thinking of creating a function that creates an empty dataframe to
which I can add data, but will need to first determine and ensure that
each dataframe has the exact same columns, in the exact same
location.



Before I write any new code, is there any pre-existing functions or
code that might solve this problem of merging small or medium sized
dataframes with a very large dataframe.)

On Tue, Feb 26, 2013 at 2:00 PM, David L Carlson dcarl...@tamu.edu
wrote:
 Clumsy but it doesn't require any packages:

 merge2 - function(x, y) {
 if(all(union(names(x), names(y)) == intersect(names(x), names(y{
 rbind(x, y)
 } else merge(x, y, all=TRUE)
 }
 merge2(df1, df2)
 df3 - df1
 merge2(df1, df3)

 --
 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-bounces@r-
 project.org] On Behalf Of arun
 Sent: Tuesday, February 26, 2013 1:14 PM
 To: Anika Masters
 Cc: R help
 Subject: Re: [R] merging or joining 2 dataframes: merge, rbind.fill,
 etc.?

 Hi,

 You could also try:
 library(gtools)
 smartbind(df2,df1)
 #  a  b  d
 #1 7 99 12
 #2 7 99 12


 When df1!=df2
 smartbind(df1,df2)
 #   a  b  d  x  y  c
 #1  7 99 12 NA NA NA
 #2 NA 34 88 12 44 56
 A.K.




 - Original Message -
 From: Anika Masters anika.mast...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Tuesday, February 26, 2013 1:55 PM
 Subject: [R] merging or joining 2 dataframes: merge, rbind.fill,
etc.?

 #I want to merge or join 2 dataframes (df1  df2) into a 3rd
 (mydf).  I want the 3rd dataframe to contain 1 row for each row in
df1
  df2, and all the columns in both df1  df2. The solution should
 work even if the 2 dataframes are identical, and even if the 2
 dataframes do not have the same column names.  The rbind.fill
function
 seems to work.  For learning purposes, are there other good ways
to
 solve this problem, using merge or other functions other than
 rbind.fill?

 #e.g. These 3 examples all seem to work correctly and as I hoped:

 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #e.g. this works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #This works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #But this does not (the 2 dataframes are identical)
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - df1
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #Any way to get mere to work for this final example? Any other
good
 solutions?

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] cumulative sum by group and under some criteria

2013-02-26 Thread arun
HI,
#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
 length(Pm2)
#[1] 1000


Pn2-rbeta(1000, 0.2, 0.8+4)
 length(Pn2)
#[1] 1000
Here, you are creating Pm2 or Pn2 from a single observation.

In the code, it is creating 1000 values in total from the combination of values 
from x, m, 
 Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
 length(Pm2)
#[1] 1000

A.K.



- Original Message -
From: Zjoanna zjoanna2...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Tuesday, February 26, 2013 3:13 PM
Subject: Re: [R] cumulative sum by group and under some criteria

Hi Arun

I noticed that the values of Fmm, Fnn, and other corresponding variables
are not correct, for example,  for the 4th obs after you run this code, the
Fmm is 0.40,  but if you use the x, m, y, n in the 4th row to calculate
them, the results are not consistent, same for the 5th obs.

#check
#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
Pn2-rbeta(1000, 0.2, 0.8+4)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(0)
Fmm2  #0.582
Fnn2   #0


Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs5
Pn2-rbeta(1000, 0.2+1, 0.8+3)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(1/4)
Fmm2 #0.404
Fnn2  #0.416



On Sat, Feb 23, 2013 at 10:53 PM, arun kirshna [via R] 
ml-node+s789695n4659514...@n4.nabble.com wrote:

 Hi,
 d3-structure(list(m1 = c(2, 3, 2), n1 = c(2, 2, 3), cterm1_P0L =
 c(0.9025,
 0.857375, 0.9025), cterm1_P1L = c(0.64, 0.512, 0.64), cterm1_P0H =
 c(0.9025,
 0.9025, 0.857375), cterm1_P1H = c(0.64, 0.64, 0.512)), .Names = c(m1,
 n1, cterm1_P0L, cterm1_P1L, cterm1_P0H, cterm1_P1H), row.names =
 c(NA,
 3L), class = data.frame)
 d2- data.frame()
 for (m1 in 2:3) {
     for (n1 in 2:3) {
         for (x1 in 0:(m1-1)) {
             for (y1 in 0:(n1-1)) {
         for (m in (m1+2): (7-n1)){
                for (n in (n1+2):(9-m)){
                for (x in x1:(x1+m-m1)){
              for(y in y1:(y1+n-n1)){
  d2- rbind(d2,c(m1,n1,x1,y1,m,n,x,y))
  
 colnames(d2)-c(m1,n1,x1,y1,m,n,x,y)
  #or

 res1-do.call(rbind,lapply(unique(d3$m1),function(m1)
  do.call(rbind,lapply(unique(d3$n1),function(n1)
  do.call(rbind,lapply(0:(m1-1),function(x1)
  do.call(rbind,lapply(0:(n1-1),function(y1)
  do.call(rbind,lapply((m1+2):(7-n1),function(m)
  do.call(rbind,lapply((n1+2):(9-m),function(n)
  do.call(rbind,lapply(x1:(x1+m-m1), function(x)
  do.call(rbind,lapply(y1:(y1+n-n1), function(y)
  expand.grid(m1,n1,x1,y1,m,n,x,y)) )))
  names(res1)- c(m1,n1,x1,y1,m,n,x,y)
  attr(res1,out.attrs)-NULL
 res1[]- sapply(res1,as.integer)

 library(plyr)
 res2- join(res1,d3,by=c(m1,n1),type=inner)

 #Assuming that these are the values you used:

 p0L-0.05
 p0H-0.05
 p1L-0.20
 p1H-0.20
 res2- within(res2,{p1- x/m; p2- y/n;term2_p0-dbinom(x1,m1, p0L,
 log=FALSE)* dbinom(y1,n1,p0H, log=FALSE)*dbinom(x-x1,m-m1, p0L, log=FALSE)*
 dbinom(y-y1,n-n1,p0H, log=FALSE);term2_p1- dbinom(x1,m1, p1L, log=FALSE)*
 dbinom(y1,n1,p1H, log=FALSE)*dbinom(x-x1,m-m1, p1L, log=FALSE)*
 dbinom(y-y1,n-n1,p1H, log=FALSE);Pm2-rbeta(240, 0.2+x,
 0.8+m-x);Pn2-rbeta(240, 0.2+y, 0.8+n-y)})
 Fm2- ecdf(res2$Pm2)
 Fn2- ecdf(res2$Pn2)

 res3- within(res2,{Fmm2-Fm2(p1);Fnn2- Fn2(p2);R2- (Fmm2+Fnn2)/2}) #not
 sure about this step especially the Fm2() or Fn2()
 res3$Fmm_f2-apply(res3[,c(R2,Fmm2)],1,min)
  res3$Fnn_f2-apply(res3[,c(R2,Fnn2)],1,max)
 res3- within(res3,{Qm2- 1-Fmm_f2;Qn2- 1-Fnn_f2})
 head(res3)
 #  m1 n1 x1 y1 m n x y cterm1_P0L cterm1_P1L cterm1_P0H cterm1_P1H
 Pn2
 #1  2  2  0  0 4 4 0 0     0.9025       0.64     0.9025       0.64
 0.001084648
 #2  2  2  0  0 4 4 0 1     0.9025       0.64     0.9025       0.64
 0.504593909
 #3  2  2  0  0 4 4 0 2     0.9025       0.64     0.9025       0.64
 0.541379357
 #4  2  2  0  0 4 4 1 0     0.9025       0.64     0.9025       0.64
 0.138947785
 #5  2  2  0  0 4 4 1 1     0.9025       0.64     0.9025       0.64
 0.272364957
 #6  2  2  0  0 4 4 1 2     0.9025       0.64     0.9025       0.64
 0.761635059
 #           Pm2   term2_p1     term2_p0   p2   p1        R2      Fnn2 Fmm2
 #1 1.212348e-05 0.16777216 0.6634204313 0.00 0.00 0.000 0.000  0.0
 #2 1.007697e-03 0.08388608 0.0698337296 0.25 0.00 0.1791667 0.358  0.0
 #3 1.106946e-05 0.01048576 0.0018377297 0.50 0.00 0.3479167 0.6958333  0.0
 # 2.086758e-01 0.08388608 0.0698337296 0.00 0.25 0.200 0.000  0.4
 #5 2.382179e-01 0.04194304 0.0073509189 0.25 0.25 0.3791667 0.358  0.4
 #6 4.494673e-01 0.00524288 0.0001934452 0.50 0.25 0.5479167 0.6958333  0.4
 #     Fmm_f2    Fnn_f2       Qn2       Qm2
 #1 0.000 0.000 1.000 1.000
 #2 0.000 0.358 0.6416667 1.000
 #3 0.000 0.6958333 0.3041667 1.000
 #4 0.200 0.200 0.800 0.800
 #5 0.3791667 0.3791667 0.6208333 0.6208333
 #6 0.400 0.6958333 0.3041667 0.600


 A.K.







 
 From: Joanna Zhang [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4659514i=0

 To: arun [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4659514i=1

 Sent: Friday, February 22, 

Re: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

2013-02-26 Thread David Kulp
On Feb 26, 2013, at 9:33 PM, Anika Masters anika.mast...@gmail.com wrote:

 Thanks Arun and David.  Another issue I am running into are memory
 issues when one of the data frames I'm trying to rbind to or merge
 with are very large.  (This is a repetitive  problem, as I am trying
 to merge/rbind thousands of small dataframes into a single very
 large dataframe.)



 I'm thinking of creating a function that creates an empty dataframe to
 which I can add data, but will need to first determine and ensure that
 each dataframe has the exact same columns, in the exact same
 location.



 Before I write any new code, is there any pre-existing functions or
 code that might solve this problem of merging small or medium sized
 dataframes with a very large dataframe.)

Consider plyr. Memory issues can be a problem, but it's a piece of
cake to write a one liner that iterates over a list of data frames and
returns them all rbind'd together.  Or just: do.call(rbind,
list.of.data.frames).

If memory is a serious problem then I think it's best to write your
own code that appends each row by index - which avoids copying entire
data frames in memory.


 On Tue, Feb 26, 2013 at 2:00 PM, David L Carlson dcarl...@tamu.edu wrote:
 Clumsy but it doesn't require any packages:

 merge2 - function(x, y) {
 if(all(union(names(x), names(y)) == intersect(names(x), names(y{
rbind(x, y)
} else merge(x, y, all=TRUE)
 }
 merge2(df1, df2)
 df3 - df1
 merge2(df1, df3)

 --
 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-bounces@r-
 project.org] On Behalf Of arun
 Sent: Tuesday, February 26, 2013 1:14 PM
 To: Anika Masters
 Cc: R help
 Subject: Re: [R] merging or joining 2 dataframes: merge, rbind.fill,
 etc.?

 Hi,

 You could also try:
 library(gtools)
 smartbind(df2,df1)
 #  a  b  d
 #1 7 99 12
 #2 7 99 12


 When df1!=df2
 smartbind(df1,df2)
 #   a  b  d  x  y  c
 #1  7 99 12 NA NA NA
 #2 NA 34 88 12 44 56
 A.K.




 - Original Message -
 From: Anika Masters anika.mast...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Tuesday, February 26, 2013 1:55 PM
 Subject: [R] merging or joining 2 dataframes: merge, rbind.fill, etc.?

 #I want to merge or join 2 dataframes (df1  df2) into a 3rd
 (mydf).  I want the 3rd dataframe to contain 1 row for each row in df1
  df2, and all the columns in both df1  df2. The solution should
 work even if the 2 dataframes are identical, and even if the 2
 dataframes do not have the same column names.  The rbind.fill function
 seems to work.  For learning purposes, are there other good ways to
 solve this problem, using merge or other functions other than
 rbind.fill?

 #e.g. These 3 examples all seem to work correctly and as I hoped:

 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - data.frame(matrix(data=c(88, 34, 12, 44, 56) ,  nrow=1 ,
 dimnames = list( NULL ,  c('d' , 'b' , 'x' ,  'y', 'c') ) ) )
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #e.g. this works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #This works:
 library(reshape)
 mydf - rbind.fill(df1, df2)
 mydf

 #But this does not (the 2 dataframes are identical)
 df1 - data.frame(matrix(data=c(7, 99, 12) ,  nrow=1 ,  dimnames =
 list( NULL ,  c('a' , 'b' , 'd') ) ) )
 df2 - df1
 mydf - merge(df2, df1, all.y=T, all.x=T)
 mydf

 #Any way to get mere to work for this final example? Any other good
 solutions?

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


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


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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative sum by group and under some criteria

2013-02-26 Thread Zjoanna
 HI,
 #
 Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
  length(Pm2)
 #[1] 1000


 Pn2-rbeta(1000, 0.2, 0.8+4)
  length(Pn2)
 #[1] 1000
 Here, you are creating Pm2 or Pn2 from a single observation.

 In the code, it is creating 1000 values in total from the combination of
 values from x, m,
  Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
  length(Pm2)
 #[1] 1000
 I dont' get it. I thought it should create 1000 randome samples from the
 beta distribution for each combination of values of x and m and this is
 what I wanted. So for the 4th observation x=1, m=4, y=0, n =4 the Fmm2,
 Fnn2 should be consistent with the values of Fmm2, Fnn2 from the following
 code.


Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
Pn2-rbeta(1000, 0.2, 0.8+4)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(0)
Fmm2  #0.582
Fnn2   #0



 A.K.



 - Original Message -
 From: Zjoanna [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=4659769i=0

 To: [hidden email] http://user/SendEmail.jtp?type=nodenode=4659769i=1
 Cc:
 Sent: Tuesday, February 26, 2013 3:13 PM
 Subject: Re: [R] cumulative sum by group and under some criteria

  Hi Arun

 I noticed that the values of Fmm, Fnn, and other corresponding variables
 are not correct, for example,  for the 4th obs after you run this code,
 the
 Fmm is 0.40,  but if you use the x, m, y, n in the 4th row to calculate
 them, the results are not consistent, same for the 5th obs.

 #check
 #
 Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
 Pn2-rbeta(1000, 0.2, 0.8+4)
 Fm2- ecdf(Pm2)
 Fn2- ecdf(Pn2)
 Fmm2-Fm2(1/4)
 Fnn2-Fn2(0)
 Fmm2  #0.582
 Fnn2   #0


 Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs5
 Pn2-rbeta(1000, 0.2+1, 0.8+3)
 Fm2- ecdf(Pm2)
 Fn2- ecdf(Pn2)
 Fmm2-Fm2(1/4)
 Fnn2-Fn2(1/4)
 Fmm2 #0.404
 Fnn2  #0.416



 On Sat, Feb 23, 2013 at 10:53 PM, arun kirshna [via R] 
 [hidden email] http://user/SendEmail.jtp?type=nodenode=4659769i=2
 wrote:

  Hi,
  d3-structure(list(m1 = c(2, 3, 2), n1 = c(2, 2, 3), cterm1_P0L =
  c(0.9025,
  0.857375, 0.9025), cterm1_P1L = c(0.64, 0.512, 0.64), cterm1_P0H =
  c(0.9025,
  0.9025, 0.857375), cterm1_P1H = c(0.64, 0.64, 0.512)), .Names = c(m1,
  n1, cterm1_P0L, cterm1_P1L, cterm1_P0H, cterm1_P1H), row.names
 =
  c(NA,
  3L), class = data.frame)
  d2- data.frame()
  for (m1 in 2:3) {
  for (n1 in 2:3) {
  for (x1 in 0:(m1-1)) {
  for (y1 in 0:(n1-1)) {
  for (m in (m1+2): (7-n1)){
 for (n in (n1+2):(9-m)){
 for (x in x1:(x1+m-m1)){
   for(y in y1:(y1+n-n1)){
   d2- rbind(d2,c(m1,n1,x1,y1,m,n,x,y))
   
  colnames(d2)-c(m1,n1,x1,y1,m,n,x,y)
   #or
 
  res1-do.call(rbind,lapply(unique(d3$m1),function(m1)
   do.call(rbind,lapply(unique(d3$n1),function(n1)
   do.call(rbind,lapply(0:(m1-1),function(x1)
   do.call(rbind,lapply(0:(n1-1),function(y1)
   do.call(rbind,lapply((m1+2):(7-n1),function(m)
   do.call(rbind,lapply((n1+2):(9-m),function(n)
   do.call(rbind,lapply(x1:(x1+m-m1), function(x)
   do.call(rbind,lapply(y1:(y1+n-n1), function(y)
   expand.grid(m1,n1,x1,y1,m,n,x,y)) )))
   names(res1)- c(m1,n1,x1,y1,m,n,x,y)
   attr(res1,out.attrs)-NULL
  res1[]- sapply(res1,as.integer)
 
  library(plyr)
  res2- join(res1,d3,by=c(m1,n1),type=inner)
 
  #Assuming that these are the values you used:
 
  p0L-0.05
  p0H-0.05
  p1L-0.20
  p1H-0.20
  res2- within(res2,{p1- x/m; p2- y/n;term2_p0-dbinom(x1,m1, p0L,
  log=FALSE)* dbinom(y1,n1,p0H, log=FALSE)*dbinom(x-x1,m-m1, p0L,
 log=FALSE)*
  dbinom(y-y1,n-n1,p0H, log=FALSE);term2_p1- dbinom(x1,m1, p1L,
 log=FALSE)*
  dbinom(y1,n1,p1H, log=FALSE)*dbinom(x-x1,m-m1, p1L, log=FALSE)*
  dbinom(y-y1,n-n1,p1H, log=FALSE);Pm2-rbeta(240, 0.2+x,
  0.8+m-x);Pn2-rbeta(240, 0.2+y, 0.8+n-y)})
  Fm2- ecdf(res2$Pm2)
  Fn2- ecdf(res2$Pn2)
 
  res3- within(res2,{Fmm2-Fm2(p1);Fnn2- Fn2(p2);R2- (Fmm2+Fnn2)/2})
 #not
  sure about this step especially the Fm2() or Fn2()
  res3$Fmm_f2-apply(res3[,c(R2,Fmm2)],1,min)
   res3$Fnn_f2-apply(res3[,c(R2,Fnn2)],1,max)
  res3- within(res3,{Qm2- 1-Fmm_f2;Qn2- 1-Fnn_f2})
  head(res3)
  #  m1 n1 x1 y1 m n x y cterm1_P0L cterm1_P1L cterm1_P0H cterm1_P1H
  Pn2
  #1  2  2  0  0 4 4 0 0 0.9025   0.64 0.9025   0.64
  0.001084648
  #2  2  2  0  0 4 4 0 1 0.9025   0.64 0.9025   0.64
  0.504593909
  #3  2  2  0  0 4 4 0 2 0.9025   0.64 0.9025   0.64
  0.541379357
  #4  2  2  0  0 4 4 1 0 0.9025   0.64 0.9025   0.64
  0.138947785
  #5  2  2  0  0 4 4 1 1 0.9025   0.64 0.9025   0.64
  0.272364957
  #6  2  2  0  0 4 4 1 2 0.9025   0.64 0.9025   0.64
  0.761635059
  #   Pm2   term2_p1 term2_p0   p2   p1R2  Fnn2
 Fmm2
  #1 1.212348e-05 0.16777216 0.6634204313 0.00 0.00 0.000 0.000
 0.0
  #2 1.007697e-03 0.08388608 0.0698337296 0.25 0.00 0.1791667 0.358
 0.0
  #3 1.106946e-05 0.01048576 0.0018377297 0.50 0.00 0.3479167 0.6958333
 0.0
  # 2.086758e-01 0.08388608 0.0698337296 0.00 0.25 0.200 0.000
 0.4
  #5 

Re: [R] cumulative sum by group and under some criteria

2013-02-26 Thread arun
The values of 'x' an 'm' from res2.  For more information, you can check ?rbeta.
I also don't get what you are up to.
If you want to create 1000 random samples for each combinations of x, m
 
lapply(lapply(unique(apply(cbind(res2$x,res2$m),1,paste,collapse=)),function(i)
 as.numeric(unlist(strsplit(i,,function(x) 
rbeta(1000,0.2+x[1],0.8+x[2]-x[1]))

A.K.







From: Joanna Zhang zjoanna2...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Tuesday, February 26, 2013 10:37 PM
Subject: Re: [R] cumulative sum by group and under some criteria


I don't get it  What values of x and m are used here? I thought it should 
create 1000 random samples from the beta distribution for each combination of 
x,m in the data and this is what I wanted. 


In the code, it is creating 1000 values in total from the combination of values 
from x, m,
 Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
 length(Pm2)
#[1] 1000

On Tue, Feb 26, 2013 at 8:56 PM, arun smartpink...@yahoo.com wrote:

?? 




 From: Joanna Zhang zjoanna2...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Tuesday, February 26, 2013 9:51 PM

Subject: Re: [R] cumulative sum by group and under some criteria



Hi,

#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4  
this is for x=1, m=2

 length(Pm2)
#[1] 1000


Pn2-rbeta(1000, 0.2, 0.8+4)
 length(Pn2)
#[1] 1000
Here, you are creating Pm2 or Pn2 from a single observation.

In the code, it is creating 1000 values in total from the combination of 
values from x, m,
 Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
 length(Pm2)
#[1] 1000

I don't get it here. What values of x and m are used here? I thought it 
should create 1000 observations for each combination of x,m in the data and 
this is what I want.

 
A.K.



- Original Message -

From: Zjoanna zjoanna2...@gmail.com
To: r-help@r-project.org
Cc:

Sent: Tuesday, February 26, 2013 3:13 PM
Subject: Re: [R] cumulative sum by group and under some criteria


Hi Arun

I noticed that the values of Fmm, Fnn, and other corresponding variables
are not correct, for example,  for the 4th obs after you run this code, the
Fmm is 0.40,  but if you use the x, m, y, n in the 4th row to calculate
them, the results are not consistent, same for the 5th obs.

#check
#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4
Pn2-rbeta(1000, 0.2, 0.8+4)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(0)
Fmm2  #0.582
Fnn2   #0


Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs5
Pn2-rbeta(1000, 0.2+1, 0.8+3)
Fm2- ecdf(Pm2)
Fn2- ecdf(Pn2)
Fmm2-Fm2(1/4)
Fnn2-Fn2(1/4)
Fmm2 #0.404
Fnn2  #0.416



On Sat, Feb 23, 2013 at 10:53 PM, arun kirshna [via R] 
ml-node+s789695n4659514...@n4.nabble.com wrote:

 Hi,
 d3-structure(list(m1 = c(2, 3, 2), n1 = c(2, 2, 3), cterm1_P0L =
 c(0.9025,
 0.857375, 0.9025), cterm1_P1L = c(0.64, 0.512, 0.64), cterm1_P0H =
 c(0.9025,
 0.9025, 0.857375), cterm1_P1H = c(0.64, 0.64, 0.512)), .Names = c(m1,
 n1, cterm1_P0L, cterm1_P1L, cterm1_P0H, cterm1_P1H), row.names =
 c(NA,
 3L), class = data.frame)
 d2- data.frame()
 for (m1 in 2:3) {
     for (n1 in 2:3) {
         for (x1 in 0:(m1-1)) {
             for (y1 in 0:(n1-1)) {
         for (m in (m1+2): (7-n1)){
                for (n in (n1+2):(9-m)){
                for (x in x1:(x1+m-m1)){
              for(y in y1:(y1+n-n1)){
  d2- rbind(d2,c(m1,n1,x1,y1,m,n,x,y))
  
 colnames(d2)-c(m1,n1,x1,y1,m,n,x,y)
  #or

 res1-do.call(rbind,lapply(unique(d3$m1),function(m1)
  do.call(rbind,lapply(unique(d3$n1),function(n1)
  do.call(rbind,lapply(0:(m1-1),function(x1)
  do.call(rbind,lapply(0:(n1-1),function(y1)
  do.call(rbind,lapply((m1+2):(7-n1),function(m)
  do.call(rbind,lapply((n1+2):(9-m),function(n)
  do.call(rbind,lapply(x1:(x1+m-m1), function(x)
  do.call(rbind,lapply(y1:(y1+n-n1), function(y)
  expand.grid(m1,n1,x1,y1,m,n,x,y)) )))
  names(res1)- c(m1,n1,x1,y1,m,n,x,y)
  attr(res1,out.attrs)-NULL
 res1[]- sapply(res1,as.integer)

 library(plyr)
 res2- join(res1,d3,by=c(m1,n1),type=inner)

 #Assuming that these are the values you used:

 p0L-0.05
 p0H-0.05
 p1L-0.20
 p1H-0.20
 res2- within(res2,{p1- x/m; p2- y/n;term2_p0-dbinom(x1,m1, p0L,
 log=FALSE)* dbinom(y1,n1,p0H, log=FALSE)*dbinom(x-x1,m-m1, p0L, log=FALSE)*
 dbinom(y-y1,n-n1,p0H, log=FALSE);term2_p1- dbinom(x1,m1, p1L, log=FALSE)*
 dbinom(y1,n1,p1H, log=FALSE)*dbinom(x-x1,m-m1, p1L, log=FALSE)*
 dbinom(y-y1,n-n1,p1H, log=FALSE);Pm2-rbeta(240, 0.2+x,
 0.8+m-x);Pn2-rbeta(240, 0.2+y, 0.8+n-y)})
 Fm2- ecdf(res2$Pm2)
 Fn2- ecdf(res2$Pn2)

 res3- within(res2,{Fmm2-Fm2(p1);Fnn2- Fn2(p2);R2- (Fmm2+Fnn2)/2}) #not
 sure about this step especially the Fm2() or Fn2()
 res3$Fmm_f2-apply(res3[,c(R2,Fmm2)],1,min)
  res3$Fnn_f2-apply(res3[,c(R2,Fnn2)],1,max)
 res3- within(res3,{Qm2- 1-Fmm_f2;Qn2- 1-Fnn_f2})
 head(res3)
 #  m1 n1 x1 y1 m n x y cterm1_P0L cterm1_P1L cterm1_P0H cterm1_P1H
 Pn2
 #1  2  2  0  0 4 4 0 0     0.9025       0.64     0.9025       0.64
 0.001084648
 #2  2  2  0  0 4 4 0 1     0.9025       0.64    

[R] Bigalgebra and irlba error

2013-02-26 Thread Gavan McGrath
When running irlba on a big.matrix as in the example from the vignette (on 
Windows R 2.15.2 64 bit)  it returns with an error (see below). irlba works 
fine on a regular R matrix

 library(bigalgebra)
 library(irlba)
Loading required package: Matrix
Loading required package: lattice
  matmul - function(A, x, transpose=FALSE)
+   {
+   if(transpose) {return(t( t(x) %*% A))}# i.e., t(A) %*% x
+   return (A %*% x)
+   }
  set.seed(1)
  A - matrix(rnorm(100),10)
  a - as.big.matrix(A)
  La - irlba(a, nu=2, nv=2, matmul=matmul)
Error in W[, j] - matmul(A, V[, j, drop = FALSE]) :
  number of items to replace is not a multiple of replacement length
  LA - irlba(A, nu=2, nv=2, matmul=matmul)
  LA$d
[1] 5.154081 4.816501
Any clues or is this a bug with the package integration?

Cheers,
Gavan

[[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] frequency table-visualization for complex categorical variables

2013-02-26 Thread Niklas Fischer
Thanks Rui,
It is very useful indeed.
Bests,
Niklas

2013/2/26 Rui Barradas ruipbarra...@sapo.pt

 Hello,

 I'm not sure I understand, do you want to treat BCC, CBC and CCB as the
 same? If so try

 w2 - apply( y , 1 , function(x) paste0(sort(x) , collapse =  ))

 table(w2)


 Hope this helps,

 Rui Barradas

 Em 26-02-2013 13:58, Niklas Fischer escreveu:

 Hi again,



 Thanks for Anthony about the links on reproducible codes.



 Thanks for Rui about ordering when rows are intact.



 One more question





 Here is your code.



 x -
  cbind(
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
  sample( LETTERS[1:6] , 100 , replace = TRUE )
  )

 y - as.matrix( x )

 w2 - apply( y , 1 , paste0 , collapse =  )
 table(w2)







 Do you know any trick to organize merge certain elements together?

 For example, if the final table includes

 BCC, CCB, CBC how should I sum frequency of one element like BCC? I have a
 very long table it would be indeed very useful!





 Niklas.

 2013/2/25 Rui Barradas ruipbarra...@sapo.pt

  Hello,

 I disagree with the way you've sorted the matrix, like this all A's
 become
 first, then B's, etc, irrespective of the respondents. Each row is a
 respondent, and the rows should be kept intact, but with a different
 ordering. To this effect, use order():

 z - y[order(y[,1], y[,2], y[,3]), ]


 Then use the rest of your code.

 Or, which would save us the sorting, paste the rows elements together
 directly from matrix 'y' and use the fact that table() sorts its output.

 w2 - apply( y , 1 , paste0 , collapse =  )
 table(w2)


 Hope this helps,

 Rui Barradas

 Em 25-02-2013 18:32, Anthony Damico escreveu:

   in the future, please provide R code to re-create some example data :)

 read
 http://stackoverflow.com/questions/5963269/how-to-make-http://stackoverflow.com/**questions/5963269/how-to-make-**
 a-great-r-reproducible-exampleforhttp://**
 stackoverflow.com/questions/**5963269/how-to-make-a-great-r-**
 reproducible-exampleforhttp://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-examplefor
 

 more detail..



 # create a data table with three unique columns' values..
 # treat these values just like letters
 x -
   cbind(
   sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
   sample( LETTERS[1:6] , 100 , replace = TRUE ) ,
   sample( LETTERS[1:6] , 100 , replace = TRUE )
   )

 # look at x.. this is good data i hope?
 x

 # convert this to a matrix
 y - as.matrix( x )

 # i don't think you care about ordering, so sort left-to-rightwards
 z - apply( y , 2 , sort )

 # look at your results
 z

 # paste these results together across the matrix
 w - apply( z , 1 , paste0 , collapse =  )

 # count the final distinct results
 table( w )




 On Mon, Feb 25, 2013 at 1:04 PM, Niklas Fischer
 niklasfischer...@gmail.comwrote:

   Dear R users,


 I have three questions measuring close relationships.
 The questions are same and the respondents put the answer in order.

 I'd like to examine the pattern of answers and visualize it.

 For example q1 (A,B,C,D,E) and q2 and q3 are the same. If the
 respondents
 selects A B C (so BCA or BAC or CBA or CAB), I'd like to construct
 frequency table for ABC and other combinations for example DEF.


 Unfortunately, there are many answers, and three-way contingency table
 includes lots of cells which make it diffucult to interpret and
 requires
 lots of extra work to organize data.

 What is the best way to construct fruequency table of these kind of
 variables and to visulize the results with the most simple form


 All the bests,
 Niklas

   [[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
 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.htmlhttp://www.R-project.org/**posting-guide.html
 http://www.**R-project.org/posting-guide.**htmlhttp://www.R-project.org/posting-guide.html
 

 and provide commented, minimal, self-contained, reproducible code.


   [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
 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.htmlhttp://www.R-project.org/posting-guide.html
 

 and provide commented, minimal, self-contained, reproducible code.





[[alternative HTML version deleted]]


Re: [R] Merging value labels into indicator variable.

2013-02-26 Thread PIKAL Petr
Hi

can not resist

Var001 - (NAM=7  NAM=9)*1

Regards
Petr

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Tasnuva Tabassum
 Sent: Tuesday, February 26, 2013 7:03 PM
 To: Berend Hasselman
 Cc: R help
 Subject: Re: [R] Merging value labels into indicator variable.
 
 Thanx all, I found my answer. I prefer Peter's second solution.
 
 
 On Tue, Feb 26, 2013 at 11:59 PM, Berend Hasselman b...@xs4all.nl
 wrote:
 
 
  On 26-02-2013, at 18:45, Tasnuva Tabassum t.tasn...@gmail.com
 wrote:
 
   I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9.  I
 want
   to make an indicator variable that will take value 1 if NAM=7 or
   NAM=8 or NAM=9. How can I do that?
   I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case.
 
 
  How about
 
  Var001- ifelse(NAM=7   NAM=9,1,0)
 
 
  Berend
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] cutreeDynamic error

2013-02-26 Thread Peter Langfelder
On Tue, Feb 26, 2013 at 8:34 AM, Joanna Papakonstantinou
joanna.p...@gmail.com wrote:
 So I realized I had to convert my dd.daisy to a matrix and used:
 ddmatrix.daisy-as.matrix(dd.daisy)
 and then I passed that in as the distM:
 cutreeDynamic(as.hclust(dd.diana), cutHeight = NULL, minClusterSize = 2,
 method = hybrid, distM = ddmatrix.daisy,deepSplit =
 (ifelse(method==hybrid, 1, FALSE)),maxCoreScatter = NULL, minGap = NULL,
 maxAbsCoreScatter = NULL, minAbsGap = NULL,useMedoids = FALSE,
 maxDistToLabel = cutHeight,respectSmallClusters = TRUE, verbose = 2, indent
 = 0)

 However, now I am getting a different error:

  Detecting clusters...
 ..cutHeight not given, setting it to 0.847  ===  99% of the (truncated)
 height range in dendro.
 Error in ifelse(method == hybrid, 1, FALSE) : object 'method' not found

 Anny suggestions on how to fix this?

Yes, leave out the 'deepSplit = (ifelse(method==hybrid, 1, FALSE))'
from the call. This is not really a cutreeDynamic problem, it is a
perhaps somewhat confusing aspect of R language. If you don't specify
deepSplit, its default value will be evaluated within the function
'interior' where the variable 'method' is defined. If you do specify
deepSplit, the expression that you specify is evaluated from 'outside'
the function where the variable 'method' is undefined. Thus, the
seemingly same expression can lead to two different results.

In fact, you may want to leave out all arguments for which you are
using a default value, it will make your call shorter and less prone
to the type of error you just experienced.

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.


[R] metafor - interpretion of QM in mixed-effects model with factor moderator

2013-02-26 Thread Rachel Slatyer
Hi,

I'm using metafor to perform a mixed-effects meta-analysis. I'd like to
test whether the effect is different for animals and plants/whether group
(animal/plant) influences the effect size, but am having trouble
interpreting the results I get. I've read previous posts about QM in
metafor, but I'm still a bit confused. I've dummy-coded the factors:

MData$k.animal-ifelse(MData$Type==Animal,1,0)MData$k.plant-ifelse(MData$Type==Plant,
1,0)


I've then run the model with the following script:

MixModel-rma(z, v.z., mods=cbind(k.animal, k.plant), intercept=FALSE,
data=MData, subset=(Response==Tolerance))MixModel


I receive the output:

Test of Moderators (coefficient(s) 1,2):
QM(df = 2) = 8.5758, p-val = 0.0137

Model Results:

  estimate  sezvalpvalci.lb   ci.ub
k.animal0.4877  0.2703  1.8042  0.0712  -0.0421  1.0175  .
k.plant 0.5095  0.2209  2.3066  0.0211   0.0766  0.9424  *

Does this mean that, overall, there is a significant effect of group on
the overall effect size (based on the QM test)? If I want to test whether
the effect size for plants is different to that for animals, can I use:

MixModel2-rma(z, v.z., mods=cbind(k.plant), data=MData,
subset=(Response==Tolerance)) ?


Here I get:

Test of Moderators (coefficient(s) 2):
QM(df = 1) = 0.0039, p-val = 0.9502

Model Results:

 estimate  sezvalpvalci.lb   ci.ub
intrcpt0.4877  0.2703  1.8042  0.0712  -0.0421  1.0175  .
k.plant0.0218  0.3491  0.0624  0.9502  -0.6624  0.7060


Does this mean that there is no significant difference in effect size
between plants and animals (now the intercept?) ? Or is this something
completely different?

I'd really appreciate any input,

Rachel Slatyer

[[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] cumulative sum by group and under some criteria

2013-02-26 Thread arun
res2- join(res1,d3,by=c(m1,n1),type=inner)
p0L-0.05 
p0H-0.05 
p1L-0.20 
p1H-0.20 
  
res2- within(res2,{p1- x/m; p2- y/n;term2_p0-dbinom(x1,m1, p0L, log=FALSE)* 
dbinom(y1,n1,p0H, log=FALSE)*dbinom(x-x1,m-m1, p0L, log=FALSE)* 
dbinom(y-y1,n-n1,p0H, log=FALSE);term2_p1- dbinom(x1,m1, p1L, log=FALSE)* 
dbinom(y1,n1,p1H, log=FALSE)*dbinom(x-x1,m-m1, p1L, log=FALSE)* 
dbinom(y-y1,n-n1,p1H, log=FALSE)}) 

res4-do.call(rbind,lapply(seq_len(nrow(res2)),function(i) 
{Pm2-rbeta(1000,0.2+res2[i,x],0.8+res2[i,m]-res2[i,x]);Pn2- 
rbeta(1000,0.2+res2[i,y],0.8+res2[i,n]-res2[i,y]); Fm2- ecdf(Pm2); Fn2- 
ecdf(Pn2); Fmm2- Fm2(res2[i,p1]); Fnn2- Fn2(res2[i,p2]);R2- 
(Fmm2+Fnn2)/2; Fmm_f2- min(R2, Fmm2); Fnn_f2- max(R2, Fnn2); Qm2- 1-Fmm_f2; 
Qn2- 1-Fnn_f2;data.frame(Fmm2,Fnn2,R2,Fmm_f2,Fnn_f2,Qm2,Qn2)}))

res5-cbind(res2,res4)
 head(res5,5)
#  m1 n1 x1 y1 m n x y cterm1_P0L cterm1_P1L cterm1_P0H cterm1_P1H   term2_p1
#1  2  2  0  0 4 4 0 0 0.9025   0.64 0.9025   0.64 0.16777216
#2  2  2  0  0 4 4 0 1 0.9025   0.64 0.9025   0.64 0.08388608
#3  2  2  0  0 4 4 0 2 0.9025   0.64 0.9025   0.64 0.01048576
#4  2  2  0  0 4 4 1 0 0.9025   0.64 0.9025   0.64 0.08388608
#5  2  2  0  0 4 4 1 1 0.9025   0.64 0.9025   0.64 0.04194304
# term2_p0   p2   p1 Fmm2  Fnn2 R2 Fmm_f2 Fnn_f2   Qm2   Qn2
#1 0.663420431 0.00 0.00 0.00 0.000 0.  0.000  0.000 1.000 1.000
#2 0.069833730 0.25 0.00 0.00 0.601 0.3005  0.000  0.601 1.000 0.399
#3 0.001837730 0.50 0.00 0.00 0.612 0.3060  0.000  0.612 1.000 0.388
#4 0.069833730 0.00 0.25 0.59 0.000 0.2950  0.295  0.295 0.705 0.705
#5 0.007350919 0.25 0.25 0.60 0.566 0.5830  0.583  0.583 0.417 0.417

A.K.





From: Joanna Zhang zjoanna2...@gmail.com
To: arun smartpink...@yahoo.com 
Sent: Tuesday, February 26, 2013 11:32 PM
Subject: Re: [R] cumulative sum by group and under some criteria


ok. 
1) for each row in the data, I want to simulate a sample of 1000 
observations(Pm2) for the combination of x, m and another sample of 1000 
observations(Pn2) for the combination of y, n and 
2) get the cumulative distribution of these two samples Fm, Fn, respectively and
3) calculate the percentage of obs  )that are less than the x/m 
(Fmm2-Fm2(x/m)and percentage of obs that are less than the y/n
 (Fnn2-Fn2(y/n)
4) I just want to keep Fmm2 and Fnn2 for each row in the final data
Thanks very much for your help. 

for example, if I simulate a sample of 10 instead of 1000:

 Pm2-rbeta(10, 0.2+1, 0.8+3)  #x=1, m=4
 Pn2-rbeta(10, 0.2, 0.8+4) #y=0, n=4
 Pm2
 [1] 0.19567380 0.10242121 0.21295666 0.23824629 0.52519487 0.10825192 
0.49724191 0.02098218 0.04740662 0.26410004
 Pn2
 [1] 6.857148e-05 1.631983e-01 1.340303e-08 1.309932e-01 2.944966e-03 
1.133654e-01 9.623050e-02 4.091554e-01 1.103247e-01 5.657689e-04
 
 Fm2- ecdf(Pm2)
 Fn2- ecdf(Pn2)
 
 Fmm2-Fm2(1/4)
 Fnn2-Fn2(0)
 Fmm2  
[1] 0.7  # this is the percentage of observation that = 1/4, I want to keep 
this vaule for each row
 Fnn2
[1] 0  # this is the percentage of observation that = 0 , I want to keep this 
value for each row
 




On Tue, Feb 26, 2013 at 10:01 PM, arun smartpink...@yahoo.com wrote:

The values of 'x' an 'm' from res2.  For more information, you can check ?rbeta.
I also don't get what you are up to.
If you want to create 1000 random samples for each combinations of x, m
 
lapply(lapply(unique(apply(cbind(res2$x,res2$m),1,paste,collapse=)),function(i)
 as.numeric(unlist(strsplit(i,,function(x) 
rbeta(1000,0.2+x[1],0.8+x[2]-x[1]))

A.K.








From: Joanna Zhang zjoanna2...@gmail.com
To: arun smartpink...@yahoo.com
Sent: Tuesday, February 26, 2013 10:37 PM

Subject: Re: [R] cumulative sum by group and under some criteria


I don't get it  What values of x and m are used here? I thought it should 
create 1000 random samples from the beta distribution for each combination of 
x,m in the data and this is what I wanted.


In the code, it is creating 1000 values in total from the combination of 
values from x, m,
 Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
 length(Pm2)
#[1] 1000

On Tue, Feb 26, 2013 at 8:56 PM, arun smartpink...@yahoo.com wrote:

??




 From: Joanna Zhang zjoanna2...@gmail.com
To: arun smartpink...@yahoo.com
Sent: Tuesday, February 26, 2013 9:51 PM

Subject: Re: [R] cumulative sum by group and under some criteria



Hi,

#
Pm2-rbeta(1000, 0.2+1, 0.8+3) #obs4 
this is for x=1, m=2

 length(Pm2)
#[1] 1000


Pn2-rbeta(1000, 0.2, 0.8+4)
 length(Pn2)
#[1] 1000
Here, you are creating Pm2 or Pn2 from a single observation.

In the code, it is creating 1000 values in total from the combination of 
values from x, m,
 Pm2-rbeta(1000, 0.2+res2$x, 0.8+res2$m-res2$x)
 length(Pm2)
#[1] 1000

I don't get it here. What values of x and m are used here? I thought it 
should create 1000 observations for each combination of x,m in the data and 
this is what I