Re: [R] If Command in Plot

2012-09-23 Thread arun
HI,
I guess you want to plot with a subset of your data z1.
z1[with(z1,e0),]
 plot(y~x,data=z1[with(z1,e0),])
A.K.






- Original Message -
From: Bhupendrasinh Thakre vickytha...@gmail.com
To: r-help r-help@r-project.org
Cc: 
Sent: Saturday, September 22, 2012 11:48 PM
Subject: [R] If Command in Plot

Hi Team,

I am trying to very simple plot with command plot.

Question : I am trying to plot (x,y) based on the value of Column e.
If column e value is greater than 0 then plot(x,y) otherwise do not plot it.

Data :

structure(list(x = c(1, 1, 1, 2, 2, 2, 3, 3, 3), y = c(1, 2, 
3, 1, 2, 3, 1, 2, 3), e = c(0, -1, -2, 1, 0, -1, 2, 1, 0)), row.names = c(NA, 
-9L), .Names = c(x, y, e), class = data.frame)

System Info :

R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C/en_US.UTF-8/C/C/C/C

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

other attached packages:
[1] SemiPar_1.0-3        MASS_7.3-18          nlme_3.1-104         
cluster_1.14.2      
[5] RSVGTipsDevice_1.0-4 maptools_0.8-16      lattice_0.20-6       
foreign_0.8-50      
[9] rgdal_0.7-18         sp_0.9-99          

loaded via a namespace (and not attached):
[1] RCurl_1.91-1    grid_2.15.1     tools_2.15.1    twitteR_0.99.19

It's very simple but I am not able to plot it with following commands 

for (i in 1:9) {ifelse(z1$e[[i]]  0 , plot(z1$x,z1$y),plot(z1$x,z1$e))}
Or
ifelse(z1$e  0,plot(z1$x,z1$y),plot(z1$x,z1$e))


Bhupendrasinh Thakre





    [[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] scraping with session cookies

2012-09-23 Thread Heramb Gadgil
This may be because connection to the site via R is taking a lot of time. I
too faced this problem for the site Social-Mention.

I tried very primitive approach. I put the 'if' condition in the loop.

if(length(output)==0){getURL(site)
}else{continue with the code}

It might help you.

Best,
Heramb

On Fri, Sep 21, 2012 at 8:45 PM, CPV ceal...@gmail.com wrote:

 Thanks for your suggestion,
 The issue was resolved by Duncan's recommendation.

 Now I am trying to obtain data from different pages from the same site
 through a loop, however, the getURLContent keeps timing out, the odd part
 is that I can access to the link through a browser with no issues at all!!
 Any ideas why it keeps timing out? Also how can I keep the loop running
 after this error?

 Thanks again for your help!


 On Wed, Sep 19, 2012 at 11:36 PM, Heramb Gadgil 
 heramb.gad...@gmail.comwrote:

 Try this,


 library(RCurl)
 library(XML)

 site-
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
 

 URL-getURL(site)

 Text=htmlParse(URL,asText=T)

 This will give you all the web dat in an HTML-Text format.

 You can use getNodeSet function to extract whatever links or texts that
 you want from that page.


 I hope this helps.

 Best,
 Heramb



 On Wed, Sep 19, 2012 at 10:26 PM, CPV ceal...@gmail.com wrote:

 Thanks again,

 I run the script with the postForm(site, disclaimer_action=I Agree) and
 it does not seem to do anything,
 the webpage is still the disclaimer page thus I am getting the error
 below
 Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function readHTMLTable, for
 signature NULL


 I also downloaded the latest version of RHTMLForms
 (omegahat-RHTMLForms-251743f.zip)
 and it does not seem to install correctly.. I used the code

 install.packages(C:/Users/cess/Downloads/omegahat-RHTMLForms-251743f.zip,
 type=win.binary, repos=NULL)

 Any suggestion of what could be causing these problems?


 On Wed, Sep 19, 2012 at 9:49 AM, Duncan Temple Lang 
 dtemplel...@ucdavis.edu
  wrote:

   You don't need to use the  getHTMLFormDescription() and
 createFunction().
  Instead, you can use the postForm() call.  However,
  getHTMLFormDescription(),
  etc. is more general. But you need the very latest version of the
 package
  to deal with degenerate forms that have no inputs (other than button
  clicks).
 
   You can get the latest version of the RHTMLForms package
   from github
 
git clone g...@github.com:omegahat/RHTMLForms.git
 
   and that has the fixes for handling the degenerate forms with
   no arguments.
 
 D.
 
  On 9/19/12 7:51 AM, CPV wrote:
   Thank you for your help Duncan,
  
   I have been trying what you suggested however  I am getting an error
 when
   trying to create the function fun- createFunction(forms[[1]])
   it says Error in isHidden I hasDefault :
   operations are possible only for numeric, logical or complex types
  
   On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang 
   dtemplel...@ucdavis.edu wrote:
  
   Hi ?
  
   The key is that you want to use the same curl handle
   for both the postForm() and for getting the data document.
  
   site = u =
   
  
 
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
   
  
   library(RCurl)
   curl = getCurlHandle(cookiefile = , verbose = TRUE)
  
   postForm(site, disclaimer_action=I Agree)
  
   Now we have the cookie in the curl handle so we can use that same
 curl
   handle
   to request the data document:
  
   txt = getURLContent(u, curl = curl)
  
   Now we can use readHTMLTable() on the local document content:
  
   library(XML)
   tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors =
  FALSE)
  
  
  
   Rather than knowing how to post the form, I like to read
   the form programmatically and generate an R function to do the
  submission
   for me. The RHTMLForms package can do this.
  
   library(RHTMLForms)
   forms = getHTMLFormDescription(u, FALSE)
   fun = createFunction(forms[[1]])
  
   Then we can use
  
fun(.curl = curl)
  
   instead of
  
 postForm(site, disclaimer_action=I Agree)
  
   This helps to abstract the details of the form.
  
 D.
  
   On 9/18/12 5:57 PM, CPV wrote:
   Hi, I am starting coding in r and one of the things that i want to
 do
  is
   to
   scrape some data from the web.
   The problem that I am having is that I cannot get passed the
 disclaimer
   page (which produces a session cookie). I have been able to collect
  some
   ideas and combine them in the code below but I dont get passed the
   disclaimer page.
   I am trying to agree the disclaimer with the postForm and write the
   cookie
   to a file, but I cannot do it succesfully
   The webpage cookies are written to the file but the value is
 FALSE...
  So
   any ideas of what I should do or what I am doing wrong with?
   Thank you for your help,
  

[R] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert
Dear grid expeRts,

I would like to create a layout with grid that looks like the following, but 
with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and (3,1) 
(and (4,2) and (4,3)) combined to one cell (so that contents can easily be 
centered.

How can this be achieved?

require(grid)
gl - grid.layout(4, 4, widths=unit(c(1, 3, 3, 1), cm),
  heights=unit(c(1, 3, 3, 1), cm))
grid.show.layout(gl)

My goal is to put 4 plots in the larger squares, create some labels in the boxes
(1,2), (1,3), (2,4), (3,4), and put common x-axis and y-axis labels in the
(combined) boxes (2,1), (3,1) and (4,2), (4,3).

With layout() one can simply cbind/rbind boxes to produce the desired
result. With grid.layout() this seems not be the case. Maybe the workflow is
differently here to get the desired result.

Cheers,

Marius

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] grid: How to merge cells in grid.layout?

2012-09-23 Thread Bert Gunter
Inline below.

On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert
marius.hof...@math.ethz.ch wrote:
 Dear grid expeRts,

 I would like to create a layout with grid that looks like the following, but 
 with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and (3,1) 
 (and (4,2) and (4,3)) combined to one cell (so that contents can easily be 
 centered.

 How can this be achieved?

 require(grid)
 gl - grid.layout(4, 4, widths=unit(c(1, 3, 3, 1), cm),
   heights=unit(c(1, 3, 3, 1), cm))
 grid.show.layout(gl)

 My goal is to put 4 plots in the larger squares, create some labels in the 
 boxes
 (1,2), (1,3), (2,4), (3,4), and put common x-axis and y-axis labels in the
 (combined) boxes (2,1), (3,1) and (4,2), (4,3).

Why don't the layout.pos.row and layout.pos.col arguments of
?viewport not do exactly what you appear to want? Perhaps I
misunderstand, but I think what you want to do is just create your
layout as above and then push the viewports you want by suitably
setting these arguments, and then just draw your plots.

 If you're serious about using grid, Murrell's Graphics book is
essential and probably will clarify these issues for you (better than
I can, anyway).


 With layout() one can simply cbind/rbind boxes to produce the desired
 result. With grid.layout() this seems not be the case. Maybe the workflow is
 differently here to get the desired result.

You appear to be mistaken. From ?grid.layout:

This function must NOT be confused with the base R graphics function
layout. In particular, do not use layout in combination with Grid
graphics. The documentation for layout may provide some useful
information and this function should behave identically in comparable
situations. The grid.layout function has added the ability to specify
a broader range of units for row heights and column widths, and allows
for nested layouts (see viewport). 

Cheers,
Bert


 Cheers,

 Marius

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert

Bert Gunter gunter.ber...@gene.com writes:

 Inline below.

 On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert
 marius.hof...@math.ethz.ch wrote:
 Dear grid expeRts,

 I would like to create a layout with grid that looks like the following, but 
 with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and (3,1) 
 (and (4,2) and (4,3)) combined to one cell (so that contents can easily be 
 centered.

 How can this be achieved?

 require(grid)
 gl - grid.layout(4, 4, widths=unit(c(1, 3, 3, 1), cm),
   heights=unit(c(1, 3, 3, 1), cm))
 grid.show.layout(gl)

 My goal is to put 4 plots in the larger squares, create some labels in the 
 boxes
 (1,2), (1,3), (2,4), (3,4), and put common x-axis and y-axis labels in the
 (combined) boxes (2,1), (3,1) and (4,2), (4,3).

 Why don't the layout.pos.row and layout.pos.col arguments of
 ?viewport not do exactly what you appear to want? Perhaps I
 misunderstand, but I think what you want to do is just create your
 layout as above and then push the viewports you want by suitably
 setting these arguments, and then just draw your plots.

... but I will always have two sub-boxes instead of one single box below the
x-axis and to the left of the y-axis. In a single box for the axis labels, one
can easily center a label. But with two boxes, how do you determine the center
of both? 



  If you're serious about using grid, Murrell's Graphics book is
 essential and probably will clarify these issues for you (better than
 I can, anyway).

I know that, thanks for pointing it out. Unfortunately, there is no problem of
the above type mentioned (afaik), that's why I asked.




 With layout() one can simply cbind/rbind boxes to produce the desired
 result. With grid.layout() this seems not be the case. Maybe the workflow is
 differently here to get the desired result.

 You appear to be mistaken. 

I might have described it unsufficiently, but you can do the above with layout()
[I used that trick in many plots before]. The above-mentioned two boxes would
get the same number, so would be treated as one plot region. I was hoping for
something similar with grid.layout. 

It is clear that you can always build your layout with too many boxes as a
rectangular region and only address those viewports where plotting should take
place. But I don't see how one could specify to plot in the center of two
adjacent boxes of the same sizes so that the content looks centered with
respect to both boxes (viewed as a single box).

 From ?grid.layout:

 This function must NOT be confused with the base R graphics function
 layout. In particular, do not use layout in combination with Grid
 graphics. The documentation for layout may provide some useful
 information and this function should behave identically in comparable
 situations. The grid.layout function has added the ability to specify
 a broader range of units for row heights and column widths, and allows
 for nested layouts (see viewport). 

 Cheers,
 Bert


 Cheers,

 Marius

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] BRugs has a bug to use OpenBUGS_PATH

2012-09-23 Thread Uwe Ligges



On 21.09.2012 20:49, R. Michael Weylandt wrote:

On Fri, Sep 21, 2012 at 7:00 PM, Shuguang Sun shugu...@gmail.com wrote:

Hi,

When I used BRugs (Version 0.8.0), I found a bug about the
findOpenBUGS way using OpenBUGS_PATH. I don't know how to contact
the developer, so I think someone here may help me.


The easiest way to get in touch when you have package bugs / questions
is to use the maintainer() function with the package name as an
argument to get an email.


Thanks, got the e-mail, we will take a look and fix, if required,
Uwe Ligges




Cheers,
Michael



The issue is: I want to use OpenBUGS/BRugs in a portable way in
windows, so I set the environment variable OpenBUGS_PATH to tell
BRugs the path to OpenBugs. But the R library BRugs is still failed to
be loaded. I looked in the BRugs' source code, and found that there is
a bug in the BRugs  R  windows  findOpenBUGS.R  file. It contains
the function definition of findOpenBUGS. In line 38 version.inst -
NA should be version.full - NA. Otherwise, version.full can not be
found if I set the environment variable OpenBUGS_PATH.

Thank you all.
Shuguang Sun

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert
Ahh, now I see what you mean... Thanks, that indeed works. 

Cheers,

Marius

Marius Hofert marius.hof...@math.ethz.ch writes:

 Bert Gunter gunter.ber...@gene.com writes:

 Inline below.

 On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert
 marius.hof...@math.ethz.ch wrote:
 Dear grid expeRts,

 I would like to create a layout with grid that looks like the following, 
 but with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and 
 (3,1) (and (4,2) and (4,3)) combined to one cell (so that contents can 
 easily be centered.

 How can this be achieved?

 require(grid)
 gl - grid.layout(4, 4, widths=unit(c(1, 3, 3, 1), cm),
   heights=unit(c(1, 3, 3, 1), cm))
 grid.show.layout(gl)

 My goal is to put 4 plots in the larger squares, create some labels in the 
 boxes
 (1,2), (1,3), (2,4), (3,4), and put common x-axis and y-axis labels in the
 (combined) boxes (2,1), (3,1) and (4,2), (4,3).

 Why don't the layout.pos.row and layout.pos.col arguments of
 ?viewport not do exactly what you appear to want? Perhaps I
 misunderstand, but I think what you want to do is just create your
 layout as above and then push the viewports you want by suitably
 setting these arguments, and then just draw your plots.

 ... but I will always have two sub-boxes instead of one single box below the
 x-axis and to the left of the y-axis. In a single box for the axis labels, one
 can easily center a label. But with two boxes, how do you determine the center
 of both? 



  If you're serious about using grid, Murrell's Graphics book is
 essential and probably will clarify these issues for you (better than
 I can, anyway).

 I know that, thanks for pointing it out. Unfortunately, there is no problem of
 the above type mentioned (afaik), that's why I asked.




 With layout() one can simply cbind/rbind boxes to produce the desired
 result. With grid.layout() this seems not be the case. Maybe the workflow is
 differently here to get the desired result.

 You appear to be mistaken. 

 I might have described it unsufficiently, but you can do the above with 
 layout()
 [I used that trick in many plots before]. The above-mentioned two boxes would
 get the same number, so would be treated as one plot region. I was hoping for
 something similar with grid.layout. 

 It is clear that you can always build your layout with too many boxes as a
 rectangular region and only address those viewports where plotting should take
 place. But I don't see how one could specify to plot in the center of two
 adjacent boxes of the same sizes so that the content looks centered with
 respect to both boxes (viewed as a single box).

 From ?grid.layout:

 This function must NOT be confused with the base R graphics function
 layout. In particular, do not use layout in combination with Grid
 graphics. The documentation for layout may provide some useful
 information and this function should behave identically in comparable
 situations. The grid.layout function has added the ability to specify
 a broader range of units for row heights and column widths, and allows
 for nested layouts (see viewport). 

 Cheers,
 Bert


 Cheers,

 Marius

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


-- 
ETH Zurich
Dr. Marius Hofert
RiskLab, Department of Mathematics
HG E 65.2
Rämistrasse 101
8092 Zurich
Switzerland

Phone +41 44 632 2423
http://www.math.ethz.ch/~hofertj

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] prune in rpart: choose number terminal nodes

2012-09-23 Thread Uwe Ligges



On 21.09.2012 11:49, agent dunham wrote:

Dear community,

I've an rpart object, and I know the CP I want.  I'd like to know if it's
possible also to fix the number of terminal nodes I want.


I don't know of any existing function, but you can write it yourself: 
All the information you need is available from the rpart object.


Uwe Ligges




Thanks in advance,  u...@host.com as u...@host.com



--
View this message in context: 
http://r.789695.n4.nabble.com/prune-in-rpart-choose-number-terminal-nodes-tp4643837.html
Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] aggregate help

2012-09-23 Thread Sam Steingold
Thanks.
Why does

 aggregate(z, list(id=z$id),FUN=list)
  id id  a1  a2
1 10 10, 10, 10 a, a, b x, x, z
2 20 20, 20b, by, y
3 30 30   c   z

work, but

aggregate(z, list(id=z$id),FUN=function(l) {
  t - sort(table(l),decreasing=TRUE)
  list(length(t),t[1],names(t)[1],t[2],names(t)[2])
  })
   id id a1 a2
1 10  1  2  2
2 20  1  1  1
3 30  1  1  1
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs
  
does not?
(I do not want to put the whole list of all possible values into the
return value of aggregate because I am afraid of running out of ram)

 * arun fznegcvax...@lnubb.pbz [2012-09-20 14:24:37 -0700]:

 Hi,
 Try this:

 z1-aggregate(z,list(id=z$id),FUN=paste,sep=,)
 dat1-data.frame(id=z1[,1],a1.total=unlist(lapply(z1[,3],length)),a1.val1=unique(z$a1),a1.num=unlist(lapply(lapply(z1[,3],table),`[`,1)),a1.val2=unlist(lapply(z1[,3],`[`,3)),a1.num2=unlist(lapply(lapply(z1[,3],table),`[`,2)),a2.total=unlist(lapply(z1[,4],length)),a2.val1=unique(z$a2),a2.num=unlist(lapply(lapply(z1[,4],table),`[`,1)),a2.val2=unlist(lapply(z1[,4],`[`,3)),a2.num2=unlist(lapply(lapply(z1[,4],table),`[`,2)))
 dat1

 # id a1.total a1.val1 a1.num a1.val2 a1.num2 a2.total a2.val1 a2.num a2.val2
 #0 10    3   a  2   b   1    3   x  2   z
 #1 20    2   b  2    NA  NA    2   y  2    NA
 #2 30    1   c  1    NA  NA    1   z  1    NA
 #  a2.num2
 #0   1
 #1  NA
 #2  NA
 #It is not an elegant way!


 A.K.



 - Original Message -
 From: Sam Steingold s...@gnu.org
 To: r-help@r-project.org
 Cc: 
 Sent: Thursday, September 20, 2012 2:06 PM
 Subject: [R] aggregate help

 I want to count attributes of IDs:
 z - data.frame(id=c(10,20,10,30,10,20),
                 a1=c(a,b,a,c,b,b),
                 a2=c(x,y,x,z,z,y),
                 stringsAsFactors=FALSE)
 z
   id a1 a2
 1 10  a  x
 2 20  b  y
 3 10  a  x
 4 30  c  z
 5 10  b  z
 6 20  b  y
 I want to get something like
 id a1.tot a1.val1 a1.num1 a1.val2 a1.num2 a2.tot a2.val1 a2.num1 a2.val2 
 a2.num2
 10   3     a      2      b      1       3      x     2       z     1
 20   2     b      2      NA     0       2      y     2       NA    0
 30   1     c      1      NA     0       1      z     1       NA    0
 (except that I don't care what appears in the cells marked with NA)
 I tried this:
 aggregate(z,by=list(id=z$id),function (s) {
   t - sort(table(s),decreasing=TRUE)
   if (length(t) == 1)
     list(length(s),names(t)[1],t[1],junk,0)
   else
     list(length(s),names(t)[1],t[1],names(t)[2],t[2])
 })
   id id a1 a2
 1 10  3  3  3
 2 20  2  2  2
 3 30  1  1  1
 Warning message:
 In format.data.frame(x, digits = digits, na.encode = FALSE) :
   corrupt data frame: columns will be truncated or padded with NAs
 Thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://mideasttruth.com http://think-israel.org
http://jihadwatch.org http://palestinefacts.org http://iris.org.il
Bill Gates is great, as long as `bill' is a verb.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] prune in rpart: choose number terminal nodes

2012-09-23 Thread Prof Brian Ripley

On 23/09/2012 17:32, Uwe Ligges wrote:



On 21.09.2012 11:49, agent dunham wrote:

Dear community,

I've an rpart object, and I know the CP I want.  I'd like to know if it's
possible also to fix the number of terminal nodes I want.


I don't know of any existing function, but you can write it yourself:
All the information you need is available from the rpart object.


Up to a point.  The pruning sequence does not include all possible 
numbers of 'terminal notes' (aka 'leaves').


--
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] Exactly Replicating Stata's Survey Data Confidence Intervals in R

2012-09-23 Thread Thomas Lumley
On Sat, Sep 22, 2012 at 2:51 AM, Anthony Damico ajdam...@gmail.com wrote:

 Survey: Mean estimation

 Number of strata =   1  Number of obs= 183
 Number of PSUs   =  15  Population size  =  9235.4
 Design df=  14

 --
  | Linearized
  |   Mean   Std. Err. [95% Conf. Interval]
 -+
 ell0 |   .0218579   .0226225 -.0266624.0703783
 --

This matches

 svyciprop(~I(ell==0),dclus1,df=14,method=mean)
 2.5%   97.5%
I(ell == 0)  0.0218579 -0.0266624 0.07038

as does this

 confint(svymean(~I(ell==0),dclus1),df=14)
  2.5 %97.5 %
I(ell == 0)FALSE  0.92962174505 1.02666240796
I(ell == 0)TRUE  -0.02666240796 0.07037825495

The df= argument is not explicitly documented in ?svyciprop, but it is
in ?confint.svystat and ?svymean

[I was slowed down a bit by the claim that the Stata intervals were
asymmetric, but in fact they aren't]

   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Background color in a grid plot seems to interfere with plot()

2012-09-23 Thread Marius Hofert
Hi,

Why does the upper left panel (in the plot below) not have a gray background?

Cheers,

Marius


require(grid)
require(gridBase)

pdf(file=Rplot.pdf, width=8, height=8, onefile=FALSE)

## set up the grid layout
gl - grid.layout(5, 5, widths=unit(c(1.8, 8, 0.8, 8, 0.8), cm),
  heights=unit(c(0.8, 8, 0.8, 8, 1.5), cm))
if(FALSE) grid.show.layout(gl)
pushViewport(viewport(layout=gl))

## plot data
par. - par(no.readonly=TRUE) # save plot settings
for(i in 1:2) { # rows
i. - if(i  1) i+2 else i+1 # jumping over gaps
for(j in 1:2) { # columns
j. - if(j  1) j+2 else j+1 # jumping over gaps
pushViewport(viewport(layout.pos.row=i., layout.pos.col=j.))
grid.rect(gp=gpar(fill=gray90)) # background
par(plt=gridPLT())
## plot
plot(1:10, 1:10, log=y, xlab=, ylab=,
 xaxt=if(i==2) s else n, yaxt=if(j==1) s else n)
par(new=TRUE) # to be run after first plot
upViewport()
}
}
par(par.)
dev.off()

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

2012-09-23 Thread MichelleNCSU
On Fri, Sep 21, 2012 at 3:45 PM, David Winsemius [via R]
ml-node+s789695n4643876...@n4.nabble.com wrote:

 On Sep 21, 2012, at 7:17 AM, MichelleNCSU wrote:

 Hello,

 First of all, let me apologize that my statistics background is modest at
 best.

 I am doing some extreme value analysis on model output (WRF) which have
 the
 following dimensions:

 speed(time,lat,lon)

 How is this object structured? Are there multiple time layers where speed is
 measured at lat-lon points are successive times?

The object is over space and time.  It is model output from the
atmospheric science modeling tool WRF
(http://www.mmm.ucar.edu/wrf/users/)

The data is constructed in 3-dimensions where the wind speed has the
dimensions (time, lat lat).
There are 67 times with 106 and 193 points lat and lon at each time.
This is why I was trying to index it to ensure I am able to perform
the task at each grid point.



 I am trying to fit the GPD (gpd.fit) to each point (time,lat,lon) to get a
 return level plot with values at each grid point.  (Map with return level
 by
 location.)

 I'm not really sure conducting extreme value analysis is a safe procedure
 when your stats background is modest at best.

I have been consulting with a professor in the Statistics department
who is an expert in extreme value analysis.  What I am doing is
safe, I just can't seem to get it working correctly.  I will also
run the procedure by her before I publish any research since I do not
have a statistics background.


 Here is some code I tried, following similar structure to languages I'm
 more
 familiar with, but it isn't working.

 Y = as.matrix(time,lat,lon)

 This suggests to me that you come from a different computing universe where
 the as.matrix() function allows multiple objects (presumably vectors) to be
 placed side-by-side and have a matrix object returned. (In this computing
 universe that role is played by the cbind function.) Perhaps:

   Y = cbind(time,lat,lon)   # c standing for column


I apologize, I was under the impression from previous help that the
as.matrix() was the correct way to do this.  I frequently use FORTRAN,
NCL, MATLAB etc.  R is still relatively new to me and most of what I
have worked with is 1-D data  in this program.

When I try the Y = cbind(time,lat,lon) I receive the following error:
Warning message:
In cbind(time, lat, lon) :
  number of rows of result is not a multiple of vector length (arg 1)


 for (t in 1:67)
 + for (j in 1:106)
 + for (i in 1:193)
 + fit(t,j,i)-gpd.fit(speed(t,j,i), threshold=17,ydat = Y)

 I receive errors at this point, and cant figure out how to get individual
 fits at each grid point.

 It's a puzzle to me why you think that passing a single point to a
 regression function will allow any solution. I did a ?? search and find
 that there is `gpd.fit` function in the 'ismev' package, but it (like all
 other regression functions of which I am aware)  appears to take full data
 objects rather than single points. You would not need to use for-loops to

OK-- in other languages I have used (non-statistical), I have looped
through to perform operations on each individual point.  That is what
i am trying to do here.  There are numerous times at each lat/lon
poing.  The speed will vary greatly point-by-point as the terrain and
physical properties driving the speed are different by location.


 pass the object. Perhaps:

   fit -gpd.fit(Y, threshold=17,ydat = Y)
  # Not sure where speed entered the picture.
  # as noted before there is ambiguity in the problem statement
  # Or did you do a prior differentiation operation?
  # perhaps a 1/ first difference on time?
# perhaps ... if gpd.fit follows the usual R conventions
# return the first point
i=1,j=1,k=1
pred.ijk - predict(fit, data,frame(time=i, lat,=j,lon=k) )

This gives the following error:
Error in UseMethod(predict) :
  no applicable method for 'predict' applied to an object of class gpd.fit

? expand.grid  # to cover a range


 Your placement of a functional form on the LHS of a formula also suggests
 recent migration from another statistical universe where assignment is done
 into functions, i.e. forms using parentheses, rather than the
 extraction/insertion operators: [ and  [-, to put values into
 structures with dimensions, like matrices and dataframes.

My mistake.

 I think you really need to do some more self-study of the introductory R
 material rather than making wild guesses at what might work based on
 experience with Python, Perl, or (less likely in view of that effort to
 assign into a function) Matlab.

 You should also read the Posting Guide.


I have worked quite frequently with 1D data, and have studied books
that focus on the 1D data, but have yet to find helpful books on R
focusing on 3D data.  I have the Steward Coles book on Extreme Value
modeling, which I reference frequently.  If there is a book that
focuses on using R over time,lat,lon or other multi-dimensional data,
I would 

[R] How to Write a Model in R that has the Log taken of the Intercept

2012-09-23 Thread Cheryl Johnson
Hi,

I know that +1 is used to specify an intercept in a R model. An example of
this would be: y~x+1

If I want to have a model where the log of the intercept is taken, the
equation y~x+log(1) will not take the log of the intercept.

Any suggestions on how to take the log of the intercept will be appreciated.

Thanks

[[alternative HTML version deleted]]

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


[R] problems with function geese() in geepack

2012-09-23 Thread André Gabriel
Good evening,

 

In my research I am studying the marginal models, where the main goal is on
the structure of the association. 

My practical example has cluster with up to 600 observations and with this
database, the function geese() return me the following message:

 

This application has requested the runtime to terminate it is on unusual
way.

Please contact the application’s support team for more information

 

why this happens?

 

In other hand, when I use the ALR function ordgee(), after a few hours,
models converge.
I do not understand why the function geese () is less efficient
computationally than ordgee ().

If you could help me understand what is happening in this case, I would
appreciate a lot. Any information is valuable for me. 

 

Thanks in advance,


André Gabriel.

 

 

 

 


[[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] Background color in a grid plot seems to interfere with plot()

2012-09-23 Thread Paul Murrell

Hi

On 24/09/12 09:36, Marius Hofert wrote:

Hi,

Why does the upper left panel (in the plot below) not have a gray background?


That is a symptom of the conflict that occurs when the 'graphics' 
package and the 'grid' package both try to initialise a new page.
A good rule of thumb is to start a new page with 'graphics' first and 
THEN add 'grid' stuff ('grid' is better at sharing), so a minor 
adjustment to your code would be (#PAUL marks the changes) ...



pdf(file=Rplot.pdf, width=8, height=8, onefile=FALSE)
#PAUL
# Start (empty) new page with 'graphics'
plot.new()
## set up the grid layout
gl - grid.layout(5, 5, widths=unit(c(1.8, 8, 0.8, 8, 0.8), cm),
  heights=unit(c(0.8, 8, 0.8, 8, 1.5), cm))
pushViewport(viewport(layout=gl))
## plot data
par. - par(no.readonly=TRUE) # save plot settings
for(i in 1:2) { # rows
i. - if(i  1) i+2 else i+1 # jumping over gaps
for(j in 1:2) { # columns
j. - if(j  1) j+2 else j+1 # jumping over gaps
pushViewport(viewport(layout.pos.row=i., layout.pos.col=j.))
grid.rect(gp=gpar(fill=gray90)) # background
par(plt=gridPLT())
## plot
#PAUL
# ALWAYS do this before each new 'graphics' plot
par(new=TRUE)
plot(1:10, 1:10, log=y, xlab=, ylab=,
 xaxt=if(i==2) s else n, yaxt=if(j==1) s else n)
upViewport()
}
}
par(par.)
dev.off()


Hope that helps.

Paul


Cheers,

Marius


require(grid)
require(gridBase)

pdf(file=Rplot.pdf, width=8, height=8, onefile=FALSE)

## set up the grid layout
gl - grid.layout(5, 5, widths=unit(c(1.8, 8, 0.8, 8, 0.8), cm),
  heights=unit(c(0.8, 8, 0.8, 8, 1.5), cm))
if(FALSE) grid.show.layout(gl)
pushViewport(viewport(layout=gl))

## plot data
par. - par(no.readonly=TRUE) # save plot settings
for(i in 1:2) { # rows
 i. - if(i  1) i+2 else i+1 # jumping over gaps
 for(j in 1:2) { # columns
 j. - if(j  1) j+2 else j+1 # jumping over gaps
 pushViewport(viewport(layout.pos.row=i., layout.pos.col=j.))
 grid.rect(gp=gpar(fill=gray90)) # background
 par(plt=gridPLT())
 ## plot
 plot(1:10, 1:10, log=y, xlab=, ylab=,
  xaxt=if(i==2) s else n, yaxt=if(j==1) s else n)
 par(new=TRUE) # to be run after first plot
 upViewport()
 }
}
par(par.)
dev.off()

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



--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

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

2012-09-23 Thread Bazman76
x-matrix(c(1,0,0,0,1,0,0,0,1),nrow=3)
 y-matrix(c(0,0,0,1,0,0,1,1,0),nrow=3)
 z-matrix(c(0,1,0,0,1,0,1,0,0),nrow=3)
 x[z]-y[z]

The resultant matrix x is all zeros except for the last two diagonal cells
which are 1's.
While y is lower triangualr 0's with the remaining cells all ones.

I really don't understand how this deceptively simple looking piece of code
is giving that result can someone explain please.
I'm obviously missing something pretty basic so please keep your answer
suitably basic.



--
View this message in context: 
http://r.789695.n4.nabble.com/Confused-by-code-tp4643946.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Vegan vegdist Jaccard matrix problem

2012-09-23 Thread kbannarm
This is my script:

Madr-read.csv(MadRegSppSite.csv, sep=,, row.names=1)
rownames(Madr) - Madr[,1]
Madr - Madr[,-1] 
MadrJaccard-vegdist(Madr, method=jaccard,binary=FALSE)
MadrJaccard-as.matrix(dist(MadrJaccard))
write.table(MadrJaccard,file=MadrJaccard.csv,sep=,,row.names=T)

The input file is a binary matrix of presence absence of species organized
in rows, and sites in the first column. 
The script is running fine but when I open it in excel (MadrJaccard) the
Jaccard values are between 0 and 4 when the range of values is only supposed
to be between 0 and 1.

I cannot figure out what is going on, does anyone have any ideas?

Thanks in advance



--
View this message in context: 
http://r.789695.n4.nabble.com/Vegan-vegdist-Jaccard-matrix-problem-tp4643948.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] Return level plots

2012-09-23 Thread Roy Mendelssohn
Hi Michelle:


On Sep 23, 2012, at 3:38 PM, MichelleNCSU wrote:

 On Fri, Sep 21, 2012 at 3:45 PM, David Winsemius [via R]
 ml-node+s789695n4643876...@n4.nabble.com wrote:
 
 On Sep 21, 2012, at 7:17 AM, MichelleNCSU wrote:
 
 Hello,
 
 First of all, let me apologize that my statistics background is modest at
 best.
 
 I am doing some extreme value analysis on model output (WRF) which have
 the
 following dimensions:
 
 speed(time,lat,lon)
 
 How is this object structured? Are there multiple time layers where speed is
 measured at lat-lon points are successive times?
 
 The object is over space and time.  It is model output from the
 atmospheric science modeling tool WRF
 (http://www.mmm.ucar.edu/wrf/users/)
 
 The data is constructed in 3-dimensions where the wind speed has the
 dimensions (time, lat lat).
 There are 67 times with 106 and 193 points lat and lon at each time.
 This is why I was trying to index it to ensure I am able to perform
 the task at each grid point.
 


You never mentioned how the data was read into R nor the exact present 
structure.  The output from something like:

str(speed)

would help, as well as the code you used to input the data. 

-Roy


**
The contents of this message do not reflect any position of the U.S. 
Government or NOAA.
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: roy.mendelss...@noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

Old age and treachery will overcome youth and skill.
From those who have been given much, much will be expected 
the arc of the moral universe is long, but it bends toward justice -MLK Jr.

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

2012-09-23 Thread Peter Alspach
Tena koe

I think you probably meant:
x[as.logical(z)] - y[as.logical(z)]

i.e., choosing those elements of × and y where z is 1 (TRUE as logical).  
Whereas what you have written:

×[z] - y[z]

references the 0th (by default indexing starts at 1 so this is empty (see ×[0]) 
and the first element of × and y (repeatedly).

Hope this helps 

Peter Alspach

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Bazman76
Sent: Monday, 24 September 2012 8:53 a.m.
To: r-help@r-project.org
Subject: [R] Confused by code?

x-matrix(c(1,0,0,0,1,0,0,0,1),nrow=3)
 y-matrix(c(0,0,0,1,0,0,1,1,0),nrow=3)
 z-matrix(c(0,1,0,0,1,0,1,0,0),nrow=3)
 x[z]-y[z]

The resultant matrix x is all zeros except for the last two diagonal cells 
which are 1's.
While y is lower triangualr 0's with the remaining cells all ones.

I really don't understand how this deceptively simple looking piece of code is 
giving that result can someone explain please.
I'm obviously missing something pretty basic so please keep your answer 
suitably basic.



--
View this message in context: 
http://r.789695.n4.nabble.com/Confused-by-code-tp4643946.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.

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

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

2012-09-23 Thread Chintanu
Hi,

I have two dataframes (Dataframe_A, Dataframe_B) with the same no. of
columns. The first column of both the dataframes contains unique names.
I wish to have Dataframe_A with the rows that are NOT common to
Dataframe_B.

With merge (), it is possible to get the common rows or to merge rows, but
I am not quite sure how to do it in a simpler way. Any help would be much
appreciated.

Thank you.

Cheers,
Chintanu

[[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] Vegan vegdist Jaccard matrix problem

2012-09-23 Thread Jari.Olsanen
kbannarm kbannarm at hotmail.com writes:

 
 This is my script:
 
 Madr-read.csv(MadRegSppSite.csv, sep=,, row.names=1)
 rownames(Madr) - Madr[,1]
 Madr - Madr[,-1] 
 MadrJaccard-vegdist(Madr, method=jaccard,binary=FALSE)
 MadrJaccard-as.matrix(dist(MadrJaccard))
 write.table(MadrJaccard,file=MadrJaccard.csv,sep=,,row.names=T)
 
 The input file is a binary matrix of presence absence of species organized
 in rows, and sites in the first column. 
 The script is running fine but when I open it in excel (MadrJaccard) the
 Jaccard values are between 0 and 4 when the range of values is only supposed
 to be between 0 and 1.
 
 I cannot figure out what is going on, does anyone have any ideas?
 

You should carefully re-read yout script. 

The key line contains dist(MadrJaccard) which calculates Euclidean
distances of Jaccard dissimilarities. Do not calculate metadistances.

Cheers, Jari Oksanen

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

2012-09-23 Thread Vignesh Prajapati
Hello all,

  I am new to R, I am learning regression and logistic modeling
with categorical predictor variables, when there is only one predictor
categorical variable i can use as.numeric() but when more than two variable
then what is solution? can anyone suggest me?

Thanks
vignesh

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