[R] how to access Internet from within R?

2009-06-26 Thread Michael
Let's say I have some automation tasks where I have to fill a table
field on a webpage, and then submit it to the server, and then obtain
the returned value (a typical web query), how to do that in R?

Thanks a lot!

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


Re: [R] how to access Internet from within R?

2009-06-26 Thread Barry Rowlingson
On Fri, Jun 26, 2009 at 7:21 AM, Michaelcomtech@gmail.com wrote:
 Let's say I have some automation tasks where I have to fill a table
 field on a webpage, and then submit it to the server, and then obtain
 the returned value (a typical web query), how to do that in R?


 The RCurl package will let you construct POST requests to web pages -
this is the mechanism that the web uses to send form data to web
servers. The response comes back to the function in RCurl.

 That's if you know in advance the names of the required form fields.
Otherwise you have to do a 'GET' request to get the form (which should
be some HTML), then write some R to parse that and work out what is
what, then send a POST with your response. Sounds like you don't need
to do that if you know what the form is expecting.

 See the help for postForm in RCurl package. Basic usage is:

postForm(http://example.com/form/response.html,.params=list(name=me,text=this
is my response, vote=2)

 couldn't really be easier :)

Barry

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

2009-06-26 Thread Prof Brian Ripley

On Fri, 26 Jun 2009, David Scott wrote:


Andrew Yee wrote:

A naive question:  what happened to the xlsReadWrite package?
http://cran.r-project.org/web/packages/xlsReadWrite/

It says that it was removed from the CRAN repository.


Note that it was archived, not removed entirely.  That is done
with packages that no longer install and we don't get an update.

The immediate problem with xlsReadWrite was that it was Windows-only 
and would not install under Windows in pre-2.9.0.



Are there any plans for it be available again?


The second issue was binary code in the package which is at least 
heavily frowned on in the CRAN source repository (we host BRugs 
elsewhere for that reason).



There was a problem with proprietary code.


Only in so far as it was binary.  There are a number of CRAN packages 
with non-open-source code.



Pick up the latest version from Hans-Peter Suter's website

http://treetron.googlepages.com/


Which says the problem was the binary code.




David Scott
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

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



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

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


[R] multiple figure windows

2009-06-26 Thread Nattu
Hi,

Is it possible to plot in multiple windows. for example Figure 1 in one
window and Figure 2 in seperate window simultanously ?

thanks,
Nataraju

-- 
No relationship is Static .. You either Step up or Step down

[[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] Optimization and Linear Programming in R

2009-06-26 Thread Chris.Wilcox
Dear List,

My student and I are looking for an optimizer for a nonlinear optimization 
problem we are working on.  The problem we are working on is to try to pick a 
set of islands on which to eradicate rats for seabird conservation.  We have 
about 50 islands, each of which has some subset of 17 seabird species.  Rats 
are present on all islands, and will cause the seabirds to go extinct unless 
they are removed.  Removing rats on islands costs different amounts depending 
on which island is chosen.  The decision problem is to pick the set of islands 
which will save the most seabird species within a given budget.  Here we use 
a nonlinear function to calculate the objective.  The function is the 
proportion of individuals of each species saved divided by the total number of 
birds, times the log of the same number, summed up across all of the islands 
that are chosen to be in the set that is saved.

We have a single constraint, which is a budget in our case.  The contribution 
to this constraint is the product of the cost of each island times the decision 
vector.  Our decision variable is a binary vector (1 for removing rats from an 
island, 0 for not removing them).  The objective function is as I have 
explained above.

We are looking for a solver that can deal with this nonlinear integer 
programming problem.  We looked at a number of packages on the CRAN Task View: 
Optimization and Mathematical Programming, however, we have not been able to 
locate one that will suit our purposes.  The essential features are we need to 
be able to write a nonlinear function for the objective (hopefully a self 
contained one as we need to include some data in it), we need to be able to use 
a binary decision (or parameter) vector, and we need to be able to use a 
constraint.  Any suggestions as to packages or other software that will work 
for our problem would be much appreciated.

Thanks,

Chris Wilcox and Greg Thonier

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

2009-06-26 Thread Alain Guillet

Hi,

I want to make my R program run in batch under Windows XP. To do so, I 
create a bat file with the command RCMD BATCH --vanilla program.R 
program.out and I use the bat file with the scheduled task of Windows 
XP. Then I log off.
It works up to the log off of another user on the same computer with 
R-2.9.1 but this problem doesn't appear with R-1.9.1 on the same 
machine. Is anything wrong in the syntax of my bat file? Thanks.


Regards,
Alain

--
Alain Guillet
Statistician and Computer Scientist

SMCS - Institut de statistique - Université catholique de Louvain
Bureau d.126
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50

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


Re: [R] Calculating home ranges using mcp in adehabitat

2009-06-26 Thread Eric R.

Tom:

The structure of your dataframe (mydata) differs from the structure of the
example dataframe (puechabon) in that the example dataframe has the
structure 'locs' in which resides the x,y data and the individual
identifier.

The clue to your difficulty could be found when you asked to see the object
xy you created and were greeted with 

 xy[1:19,]
NULL
indicating it was empty.

Here is a toy example of what you want to do to successfully use mcp()

library(adehabitat)
mydata - data.frame(Name='XDRY', X=runif(20)-21, Y=runif(20)+64)
mydata
xy - mydata[,c(X,Y)]
id - mydata[,Name]
xy[1:20,]
mcp(xy,id,percent=95)


Tom Mason wrote:
 
 Hello,
 
 I've been trying to calculate home range sizes (for Icelandic geese!)
 using minimum convex polygons with the adehabitat package. I've tried to
 use the R code shown by demo(homerange) in adehabitat and when that didn't
 work I've fiddled around with it but to no avail...Below is the output of
 the demo that I've attempted to follow, followed by a subset of my data
 (for one individual) and the code I've been trying. Can anyone tell me
 where I may be going wrong???
 
 
 #Demo output...
 
 data(puechabon)
 
 xy-puechabon$locs[,c(X,Y)]
 
 id-puechabon$locs$Name
 
 ## The data are:
 xy[1:4,] ## relocations coordinates
X   Y
 1 699889 3161559
 2 700046 3161541
 3 698840 3161033
 4 699809 3161496
 
 id[1:4]  ## ID
 [1] Brock Brock Brock Brock
 Levels: Brock Calou Chou Jean
 
 ###
 ###
 ###
 ### Home ranges
 
 ## MCP
 hr-mcp(xy, id) ## home range estimation
 
 
 
 # My attempts...
 
 mydata
Name XY
 1  XDRY -21.98389 64.06457
 2  XDRY -21.99759 64.08291
 3  XDRY -21.98784 64.06467
 4  XDRY -21.98333 64.06058
 5  XDRY -21.97889 64.06257
 6  XDRY -21.98284 64.06044
 7  XDRY -21.97886 64.06358
 8  XDRY -21.99741 64.08124
 9  XDRY -21.99715 64.08330
 10 XDRY -22.00397 64.09331
 11 XDRY -21.99811 64.08239
 12 XDRY -22.00453 64.09337
 13 XDRY -21.99713 64.08299
 14 XDRY -21.99608 64.08307
 15 XDRY -21.99646 64.08352
 16 XDRY -21.99326 64.08361
 17 XDRY -22.00770 64.09090
 18 XDRY -21.98160 64.06400
 19 XDRY -21.97966 64.06367
 
 xy-mydata$locs[,c(X,Y)]
 id-mydata$locs$Name
 
 xy[1:19,]
 NULL
 id[1:19,]
 NULL
 
 mcp(xy,id,percent=95)
 Error in if (length(id) != nrow(xy)) stop(xy and id should be of the same
 length) : 
   argument is of length zero
 
 
 #I've also tried things like the code below. But didn't know how to
 incorporate 'locs' into this...
 
 xy-cbind(X,Y)
 id-Name[1:19]
 
 xy[1:19,]
   XY
  [1,] -21.98389 64.06457
  [2,] -21.99759 64.08291
  [3,] -21.98784 64.06467
  [4,] -21.98333 64.06058
  [5,] -21.97889 64.06257
  [6,] -21.98284 64.06044
  [7,] -21.97886 64.06358
  [8,] -21.99741 64.08124
  [9,] -21.99715 64.08330
 [10,] -22.00397 64.09331
 [11,] -21.99811 64.08239
 [12,] -22.00453 64.09337
 [13,] -21.99713 64.08299
 [14,] -21.99608 64.08307
 [15,] -21.99646 64.08352
 [16,] -21.99326 64.08361
 [17,] -22.00770 64.09090
 [18,] -21.98160 64.06400
 [19,] -21.97966 64.06367
 
 id-Name[1:19]
 id[1:19]
  [1] XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY
 [12] XDRY XDRY XDRY XDRY XDRY XDRY XDRY XDRY
 Levels: XDRY
 
 mcp(xy,id,percent=95)
 Error in apply(xy, 2, mean) : dim(X) must have a positive length
 
 xy1-xy[1:19,]
 id1-id[1:19]
 mcp(xy1,id1,percent=95)
 Error in apply(xy, 2, mean) : dim(X) must have a positive length
 
 
 Would be most grateful for any suggestions to where I'm going wrong!
 
 
 Tom Mason,
 University of Exeter,
 UK.
 
 
 
 
 
 
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Calculating-home-ranges-using-mcp-in-adehabitat-tp24207532p24216560.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] Converting S-plus project folders to R

2009-06-26 Thread Uwe Ligges



dbosley wrote:

I have many S-plus project folders that I need to convert to R workspaces.
For the smaller project folders ( 200MB), using data.dump with oldStyle
= T and data.restore (in the foreign package) within R seems to work
fine. However, I have several project folders that are quite large (~ 4GB).
When I use this procedure to try to convert these project folders, R always
crashes when I perform the data.restore command. Does anyone have any
suggestions?


No suggestion, just to be sure:
I hope R gives an error message rather than a crash?

Best,
Uwe Ligges





Thanks,
Dave Bosley





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


Re: [R] multiple figure windows

2009-06-26 Thread Uwe Ligges



Nattu wrote:

Hi,

Is it possible to plot in multiple windows. for example Figure 1 in one
window and Figure 2 in seperate window simultanously ?



Sure, just start another device as in:

 x11()
 plot(1:10)
 x11()
 plot(1:10)

Uwe Ligges



thanks,
Nataraju



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] panel.text and saving to pdf

2009-06-26 Thread Uwe Ligges
To get reproducible results, I highly recommend to print the lattice 
graphics directly into the desired device, i.e. start the pdf (or jpeg 
or whatever) device before printing.


Best,
Uwe Ligges



Willem Vervoort wrote:

Dear all,

I am not sure what I am doing wrong, but I have some unexplained behaviour when 
saving a lattice graph including text to a pdf file. The text seems to move 
around. It must have something to do with the way coordinates are set in 
devices other than jpg.

Any suggestions would be helpful
Willem

Here is some example code

setwd(c:/willem/research/misc)
today - format(Sys.Date(),%Y%m%d)


x - runif(500)
y - rnorm(500)

foo - data.frame(x = x, y = y, z = rep(c(a,b),250))
require(lattice)

xyplot(x~y|z,data=foo)
panel.text(370,470,silly graph,cex=1.2,font=2)
savePlot(paste(today, jpgplot,sep=_),type=jpg) # this plots fine and text 
is as on the screen
savePlot(paste(today, pdfplot,sep=_),type=pdf) # text has moved

pdf(paste(today,pdfplot2.pdf,sep=_)) # no difference using pdf
xyplot(x~y|z,data=foo)
panel.text(370,470,silly graph,cex=1.2,font=2)
dev.off()

# There is also no difference 

   _   
platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  9.0 
year   2009
month  04  
day17  
svn rev48333   
language   R   
version.string R version 2.9.0 (2009-04-17)


-
Dr. R.W. Vervoort
McCaughey Senior Lecturer Hydrology and Catchment Management
Faculty of Agriculture, Food and Natural Resources,
Bldg A04, The University of Sydney, NSW 2006
http://tinyurl.com/mccaughey
http://blogs.usyd.edu.au/waterhydrosu
ph: +61 2 9351 8744
fax: +61 2 9351 4953

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] panel.text and saving to pdf

2009-06-26 Thread Dieter Menne
Willem Vervoort w.vervoort at usyd.edu.au writes:

 I am not sure what I am doing wrong, but I have some unexplained behaviour
when saving a lattice graph
 including text to a pdf file. The text seems to move around. It must have
something to do with the way
 coordinates are set in devices other than jpg.
 
 today - format(Sys.Date(),%Y%m%d)
 
 x - runif(500)
 y - rnorm(500)
 
 foo - data.frame(x = x, y = y, z = rep(c(a,b),250))
 require(lattice)
 
 xyplot(x~y|z,data=foo)
 panel.text(370,470,silly graph,cex=1.2,font=2)

Take this plot, resize its window: you will note that the silly graph moves
relative to the graphics. The same is true for the higher-resolution pdf 
output. 
To get around this, and to have the text positioned in a relative scaled
position, you could create a special panel function and call panel.text there.
See the examples at the bottom of the xyplot documentation page.

Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] to raise in a loop more than 1

2009-06-26 Thread damien landais
I would raise x,y and z in a loop but I won't raise of 1. I tried this but it 
doesn't work

mydata=matrix(nrow=1500,ncol=3)
i=1
for(x in 0:10){
for(y in 0:20){
for(z in 0:10){
mydata[i,]=c(x,y,z)
i=i+1
z=z+2}
y=y+4}
x=x+2}

And I would have something like that 
x   y   z
0   0   0
0   0   2
0   0   4
0   0   6
0   0   8
0   0   10 
0   4   0
0   4   2
...

Could anybody help me?
I don't work on a special package to do it...

Thanks

Cordialement
Damien Landais

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] JRI - problem to access stats package

2009-06-26 Thread GRAN

Hi Geoff,
Tks a lot for your reply.
There are many points we do not understand.
Can you clarify those one:

- At first, why do you speak about an eclipse plugin ?
We have compiled R and JRI together, so we get a jar file. We finally 
include this jar file inside our java project as a referenced libraries. 
So we do not understand why you are speaking about plugins and 
MANIFEST.MF file.


- Nevermind, which MANIFEST.MF file are you speaking about ? the one of 
the JRI plugin ? (if a JRI plugin exists...)


- Last things, you speak about a build.properties. In our project we 
haven't any. Is there a work around to do the same ?


Tks for any help,
Antoine





Hi Antoine,

I have got this to work on Windows, the process should be the same for
Linux.

For an eclipse plugin you will need to add the following to your
MANIFEST.MF file:

Bundle-ClassPath: whatever you normally have,
lib/JRI.jar
Bundle-NativeCode: /lib/jri.dll; osname=winxp; processor=x86

You will also need to ensure that the *R* executable is in your path and
that *R_HOME* is set.

I did this by creating a simple batch file containing the following in a
directory called *rootfiles* within our feature, the same should work for
a .sh :

set PATH=%CD%\*R* install\exe;%PATH%
set *R_HOME*=%CD%\*R* install
eclipse.exe

I then added the following line to the build.properties file of the
feature:
*root*=*rootfiles*

This tells eclipse to copy the content of the directory to the *root* of
the application on install.

If you then *run* eclipse from the batch file, it should work.

--

Geoff Gibbs
mangosolutions
data analysis that delivers

Tel +44 (0)1249 767 700

Mob +44 (0)7791 855 620


-Original Message-
From: *r*-help-boun...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=0 
[mailto:*r*-help-boun...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=1]

On Behalf Of GRAN
Sent: 25 June 2009 09:40
To: *r*-h...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=2

Subject: [*R*] JRI - problem to access *stats* package

Hello,

I am a new *R* user. More precisely, I am working with JRI (on a Eclipse
Java6 project under Ubuntu9).

I have difficulties to access *some* *R* packages (For example: package
*stats*, object Normal, function pnorm).

I have tried many *solutions* to set the *right* path but nothing have
succeed:
For example:
LD_LIBRARY_PATH=${*R_HOME*}/lib:${*R_HOME*}/bin:${*R_HOME*}/library

Inside the  java code, I have also tried such methods:
Note that *r* is the *REngine* object coming from the connection to *R*

  
*r*.eval(dyn.load(\/home/gran/workspace/*R*-2.9.0/library/*stats*/libs/*stats* 


.*so*\,
local = TRUE, now = TRUE));
  *r*.eval(*require*(*stats*));
  *r*.eval(autoload(\Normal\, \*stats*\));
  *r*.eval(search());
  *r*.eval(ls(\Autoloads\));
  System.out.println(*r*.eval(.Autoloaded));
  *r*.eval(zval = .95);
  System.out.println(*r*.eval(print(zval)));
  *r*.eval(p3 = pnorm(3*zval));
  System.out.println(*r*.eval(print(p3)));

It gives as a *result*:

  [STRING *stats*]
  [*REAL** (0.95)]
  null   -- p3 = null because pnorm is unknown

Do you know how to use the *stats* package with JRI ?
Thanks in advance,
Antoine

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: to raise in a loop more than 1

2009-06-26 Thread Petr PIKAL
Hi

does

expand.grid(z=seq(0,6,2), y=seq(0,8,4), x=seq(0,10,2))

do what you want?

Petr

r-help-boun...@r-project.org napsal dne 26.06.2009 11:15:42:

 I would raise x,y and z in a loop but I won't raise of 1. I tried this 
but it 
 doesn't work
 
 mydata=matrix(nrow=1500,ncol=3)
 i=1
 for(x in 0:10){
 for(y in 0:20){
 for(z in 0:10){
 mydata[i,]=c(x,y,z)
 i=i+1
 z=z+2}
 y=y+4}
 x=x+2}
 
 And I would have something like that 
 x   y   z
 0   0   0
 0   0   2
 0   0   4
 0   0   6
 0   0   8
 0   0   10 
 0   4   0
 0   4   2
 ...
 
 Could anybody help me?
 I don't work on a special package to do it...
 
 Thanks
 
 Cordialement
 Damien Landais
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] panel.text and saving to pdf

2009-06-26 Thread willem vervoort
Hi Uwe,

I should send these messages from my member e-mail number

Thanks for that.
As you can see from the last bit of my code, I tried that, but it gave
the same results. I had a look at pdf.options() but didn't see
anything there either to make the text stay on the same spot. It seems
to also happen if you use png().


Willem




From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Sent: Fri 6/26/2009 6:47 PM
To: Willem Vervoort
Cc: r-help@r-project.org
Subject: Re: [R] panel.text and saving to pdf


To get reproducible results, I highly recommend to print the lattice
graphics directly into the desired device, i.e. start the pdf (or jpeg
or whatever) device before printing.

Best,
Uwe Ligges



Willem Vervoort wrote:
 Dear all,

 I am not sure what I am doing wrong, but I have some unexplained behaviour 
 when saving a lattice graph including text to a pdf file. The text seems to 
 move around. It must have something to do with the way coordinates are set in 
 devices other than jpg.

 Any suggestions would be helpful
 Willem

 Here is some example code

 setwd(c:/willem/research/misc)
 today - format(Sys.Date(),%Y%m%d)


 x - runif(500)
 y - rnorm(500)

 foo - data.frame(x = x, y = y, z = rep(c(a,b),250))
 require(lattice)

 xyplot(x~y|z,data=foo)
 panel.text(370,470,silly graph,cex=1.2,font=2)
 savePlot(paste(today, jpgplot,sep=_),type=jpg) # this plots fine and 
 text is as on the screen
 savePlot(paste(today, pdfplot,sep=_),type=pdf) # text has moved

 pdf(paste(today,pdfplot2.pdf,sep=_)) # no difference using pdf
 xyplot(x~y|z,data=foo)
 panel.text(370,470,silly graph,cex=1.2,font=2)
 dev.off()

 # There is also no difference

_
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status
 major  2
 minor  9.0
 year   2009
 month  04
 day17
 svn rev48333
 language   R
 version.string R version 2.9.0 (2009-04-17)

 -
 Dr. R.W. Vervoort
 McCaughey Senior Lecturer Hydrology and Catchment Management
 Faculty of Agriculture, Food and Natural Resources,
 Bldg A04, The University of Sydney, NSW 2006
 http://tinyurl.com/mccaughey
 http://blogs.usyd.edu.au/waterhydrosu
 ph: +61 2 9351 8744
 fax: +61 2 9351 4953

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

2009-06-26 Thread Laura Bonnett
Dear Sir,

Thank you for your response.  You were correct, I had 1 linearly
dependent column.  I have solved this problem and now the rank of
'covaeb' is 17 (qr(covaeb)$rank = 17).  However, I still get the same
error message when I use covaeb in the 'crr' function.

 fit=crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)
8 cases omitted due to missing values
Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
  system is computationally singular: reciprocal condition number = 3.45905e-25

Are there any other reasons why this may be happening?

Thank you,

Laura

2009/6/25 Ravi Varadhan rvarad...@jhmi.edu:
 This means that your design matrix or model matrix is rank deficient, i.e it
 does not have linearly independent columns.  Your predictors are collinear!


 Just take your design matrices covaea or covaeb with 17 predcitors and
 compute their rank or try to invert them.  You will see the problem.

 Ravi.

 
 ---

 Ravi Varadhan, Ph.D.

 Assistant Professor, The Center on Aging and Health

 Division of Geriatric Medicine and Gerontology

 Johns Hopkins University

 Ph: (410) 502-2619

 Fax: (410) 614-9625

 Email: rvarad...@jhmi.edu

 Webpage:
 http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
 tml



 
 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of Laura Bonnett
 Sent: Thursday, June 25, 2009 11:39 AM
 To: r-help@r-project.org
 Subject: [R] crr - computationally singular

 Dear R-help,

 I'm very sorry to ask 2 questions in a week.  I am using the package 'crr'
 and it does exactly what I need it to when I use the dataset a.
 However, when I use dataset b I get the following error message:
 Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
  system is computationally singular: reciprocal condition number =
 1.28654e-24

 This is obviously as a result of a problem with the data but apart from
 dataset a having 1674 rows and dataset b having 701 rows there is really no
 difference between them.

 The code I am using is as follows where covaea and covaeb are matrices of
 covarites, all coded as binary variables.
 In case a:
 covaea -
 cbind(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pgu
 1a,pgu2a,log(agea),firstinta/1000,totsezbasea)
 fita - crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)

 and in case b:
 covaeb -
 cbind(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,sty
 pe4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb))
 fitb - crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)

 csaea and csaeb are the censoring indicators for a and b respectively which
 equal 1 for the event of interest, 2 for the competing risks event and 0
 otherwise.

 Can anyone suggest a reason for the error message?  I've tried running fitb
 with variants of covaeb and irrespective of the order of the covariates in
 the matrix, the code runs fine with 16 of the 17 covariates included but
 then produces an error message when the 17th is added.

 Thank you for your help,

 Laura

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Odp: code that will use two data sets which differ in size.

2009-06-26 Thread Petr PIKAL
Petr Pikal
petr.pi...@precheza.cz
724008364, 581252140, 581252257


r-help-boun...@r-project.org napsal dne 26.06.2009 05:31:27:

 Hi all,
 
 This is a really basic question but I can't figure it out.
 
 I am trying to write a piece of code that will  use two datasets, z and 
m..
 This code is meant to assign the mean of selected values in dataset m to 
a new
 column z$c in datset z but the rows and columns of the two data sets 
differ.
 
 I managed to write this down but think I am missing something standard 
but 
 basic,I will really appreciate if someone could point out where I' am 
going 
 wrong or help me out with a piece of code for this.Google did not help 
me even
 and the R manuals gave me hints.
 
 The shoulders will never grow beyond the head.
 
 for (k in 1:nrow(z))
 + for (g in 1:nrow(m))
 + for (l in 1:3)
 + for (j in 15:43){
 + z$ccs[k]-mean(m[m$soi[g]==lm$week[g]==j,]$CCS,na.rm=TRUE)}

Maybe that I have no idea what is z I get an error too.

 for (k in 1:nrow(z))
+ + for (g in 1:nrow(m))
+ + for (l in 1:3)
+ + for (j in 15:43){
+ + z$ccs[k]-mean(m[m$soi[g]==lm$week[g]==j,]$CCS,na.rm=TRUE)}
Error in nrow(z) : object 'z' not found

What kind of error do you have?

If you do not post some reproducible example it would be quite difficult 
to understand what you want to get as a result. I believe some *apply 
trick could help but without knowing what you want it could be just rough 
guessing.

Regards
Petr

 
 
 
 
 
 
 
 
 
 
[[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] JRI - problem to access stats package

2009-06-26 Thread Geoff Gibbs
Sorry for the confusion, I obviously misunderstood.

I thought you were trying to use R in an eclipse application, not an
application written using eclipse.

As far as I am aware, if the path and R_HOME environment variables are
set then all should work OK.

I think from you examples that the path is set correctly, it may be that
you are using print() to get the value that you are getting null, as I
understand it print() returns invisibly after displaying the value on
screen, as there is no screen the evaluation of print does nothing but
return the result of the call. I suspect you simply want to use
System.out.println(r.eval(p3)).


--

Geoff Gibbs
mangosolutions
data analysis that delivers

Tel +44 (0)1249 767 700

Mob +44 (0)7791 855 620


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of GRAN
Sent: 26 June 2009 11:01
To: r-help@r-project.org
Cc: antoine grimault
Subject: [R] JRI - problem to access stats package

Hi Geoff,
Tks a lot for your reply.
There are many points we do not understand.
Can you clarify those one:

- At first, why do you speak about an eclipse plugin ?
We have compiled R and JRI together, so we get a jar file. We finally
include this jar file inside our java project as a referenced libraries.

So we do not understand why you are speaking about plugins and
MANIFEST.MF file.

- Nevermind, which MANIFEST.MF file are you speaking about ? the one of
the JRI plugin ? (if a JRI plugin exists...)

- Last things, you speak about a build.properties. In our project we
haven't any. Is there a work around to do the same ?

Tks for any help,
Antoine





Hi Antoine,

I have got this to work on Windows, the process should be the same for
Linux.

For an eclipse plugin you will need to add the following to your
MANIFEST.MF file:

Bundle-ClassPath: whatever you normally have,  lib/JRI.jar
Bundle-NativeCode: /lib/jri.dll; osname=winxp; processor=x86

You will also need to ensure that the *R* executable is in your path and
that *R_HOME* is set.

I did this by creating a simple batch file containing the following in a
directory called *rootfiles* within our feature, the same should work
for a .sh :

 set PATH=%CD%\*R* install\exe;%PATH%
 set *R_HOME*=%CD%\*R* install
 eclipse.exe

I then added the following line to the build.properties file of the
feature:
*root*=*rootfiles*

This tells eclipse to copy the content of the directory to the *root* of
the application on install.

If you then *run* eclipse from the batch file, it should work.

-- 

Geoff Gibbs
mangosolutions
data analysis that delivers

Tel +44 (0)1249 767 700

Mob +44 (0)7791 855 620


-Original Message-
From: *r*-help-boun...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=0
[mailto:*r*-help-boun...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=1]
On Behalf Of GRAN
Sent: 25 June 2009 09:40
To: *r*-h...@... 
http://www.nabble.com/user/SendEmail.jtp?type=postpost=24199629i=2
Subject: [*R*] JRI - problem to access *stats* package

Hello,

I am a new *R* user. More precisely, I am working with JRI (on a Eclipse
Java6 project under Ubuntu9).

I have difficulties to access *some* *R* packages (For example: package
*stats*, object Normal, function pnorm).

I have tried many *solutions* to set the *right* path but nothing have
succeed:
For example:
LD_LIBRARY_PATH=${*R_HOME*}/lib:${*R_HOME*}/bin:${*R_HOME*}/library

Inside the  java code, I have also tried such methods:
Note that *r* is the *REngine* object coming from the connection to
*R*

   
*r*.eval(dyn.load(\/home/gran/workspace/*R*-2.9.0/library/*stats*/libs
/*stats* 

.*so*\,
local = TRUE, now = TRUE));
   *r*.eval(*require*(*stats*));
   *r*.eval(autoload(\Normal\, \*stats*\));
   *r*.eval(search());
   *r*.eval(ls(\Autoloads\));
   System.out.println(*r*.eval(.Autoloaded));
   *r*.eval(zval = .95);
   System.out.println(*r*.eval(print(zval)));
   *r*.eval(p3 = pnorm(3*zval));
   System.out.println(*r*.eval(print(p3)));

It gives as a *result*:

   [STRING *stats*]
   [*REAL** (0.95)]
   null   -- p3 = null because pnorm is unknown

Do you know how to use the *stats* package with JRI ?
Thanks in advance,
Antoine

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

2009-06-26 Thread Roger Bivand

The problem is that the binary Ubuntu install of gdal has not made sure that
its dependencies are properly satisfied, so you'll need to do this manually.
You can also make sure that the directory the GRASS libraries are found in
is seen by ldconfig, either that or making sure that your running R sees
LD_LIBRARY_PATH. This is a very detailed question, more suited to GRASS or
GDAL lists, or R-sig-geo. You'll see when you have the solution because the
GDAL utilities will work at the shell, for example gdalinfo --formats - I
think that it doesn't at the moment.

Roger Bivand


epoizot wrote:
 
 
 
 Zeljko Vrba wrote:
 
 On Wed, Jun 10, 2009 at 08:21:06AM +0200, Poizot Emmanuel wrote:
 Error in fun(...) :
GDAL Error 1: libgrass_I.so: Ne peut ouvrir le fichier d'objet 
 partagé: Aucun fichier ou dossier de ce type  (sorry  for the french :)
 )
 
 
 It would have been far more useful had you translated the error message
 to
 english than to have apologized.
 
 Try doing
 
 export LD_LIBRARY_PATH=/path/to/dir/where/so/is/located
 
 before starting R from the shell.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 Hi,
 
 I tried this but with no success. Still enable to load the library rgdal
 and so GeoXp.
 This problem of for me now of high importance as I need to export
 interpolated data sets to grids. and rgdal allows that kind of operations.
 Regards
 

-- 
View this message in context: 
http://www.nabble.com/GeoXp-package-tp23964536p24218092.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame

Stavros Macrakis wrote:

On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyramecrap...@gmail.com wrote:
  

The man page Stavros quotes states that the class attribute of the result is
taken from 'test', which clearly is not the case:



Actually, the behavior is documented pretty clearly:

 The mode of the answer will be coerced from logical to
 accommodate first any values taken from 'yes' and then
 any values taken from 'no'.

Whether this is a good design or not is another issue  Perhaps the
justification is that it avoids evaluating the yes or no arguments (to
determine their class) in cases where their value is not needed.
  


Thank you for pointing me to this.  Now I get a headache from trying to 
figure out what does mode have to do with class - I thought that the 
class of the result should be that of test, and that the mode is 
something entirely different.  Why does coercing the mode also affect 
the class?  If the man page said The class attribute is taken from 
test, and it will be coerced ... or The mode of the result is taken 
from test, and it will be coreced ..., would this be wrong?  What is 
the class-mode mixture about?


Why does this fail:

 r = as.raw(TRUE)
 ifelse(TRUE, r, r) = error

This gives an error which I take for saying that raw cannot be coerced 
to logical, but yes it can:


 as.logical(r) = TRUE

and raw can even be used as the condition vector in ifelse:

 ifelse(r, 1, 2) = 1

Best regards,
Craig



Example:

 ifelse(c(T,F),1,a) = c(1,a)

This has the same effect as

res - c(T,F)
res[1] - 1
res[2] - a

which is in fact pretty much the way it is implemented.

  

And also, I find myself incapable of making sense of the may in the mode
of the result may depend on the value of 'test' - may in what sense?



See the examples at the end of ? ifelse

 -s



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

2009-06-26 Thread Van Wyk, Jaap
I am trying to reproduce Figure 10.5 of Loader's book: Local Regression and 
Likelihood. The code provided in the book does not seem to work.
I have managed (a while ago) to get the accompanied R-code for the figures in 
the book (file called lffigs.R) from somewhere - cannot find it on the web 
anymore. The code in the .R script file does not work either.
Could anybody please direct me in finding an updated version of this document, 
or help me correct the code given in the file. The (out-of-date) code is as 
follows:

   data(claw54)
  fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315), ev =
grid(100, ll = -3.5, ur = 2.7))
  fit2 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.985), ev =
grid(100, ll = -3.5, ur = 2.7))
  x - seq(-3.5, 2.7, length.out = 200)
  y - dnorm(x, -1., 0.1) + dnorm(x, -0.5, 0.1) + dnorm(x, 0, 0.1) + dnorm(x,
0.5, 0.1) + dnorm(x, 1., 0.1)
  y - (y + 5 * dnorm(x))/10
  plot(fit1, get.data = T, main = h=0.315, ylim = c(0, max(y)))
  lines(x, y, lty = 2)
  plot(fit2, get.data = T, main = h=0.985, ylim = c(0, max(y)))
  lines(x, y, lty = 2)

THANKS FOR ANY ASSISTANCE.
ps: This code differs from that in the book. I have tried both, without 
success. Even if I just use, for example,
fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315))
I do not get the same result.

Jacob L van Wyk, Dept. of Statistics, University of Johannesburg (APK),
Box 524, Auckland Park, 2006.
Office: +27 11 559 3080, Fax: +27 11 559 2499



This email and all contents are subject to the following disclaimer:

http://www.uj.ac.za/UJ_email_legal_disclaimer.htm

[[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] Matching data to a new column

2009-06-26 Thread Kubasiewicz, Laura

Hi all,

I wonder if anyone can help,

I have a dataframe with columns for...

'I.D'  'age'  'mothers I.D'
01 5   03
02 6   06
03 16 NA
04 8   06
05 3   NA
06 17 NA

I need to create a new column for 'mothers age' which puts the age of the 
individual with 'mothers i.d' into the row for her offspring (so individual 01 
would have 16 in the mothers age column, as thats the age of individual 03)

Hope that makes sense, any help appreciated,

Thanks
Laura

[[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] Matching data to a new column

2009-06-26 Thread Dieter Menne
Kubasiewicz, Laura laura.kubasiewicz08 at imperial.ac.uk writes:

 I have a dataframe with columns for...
 
 'I.D'  'age'  'mothers I.D'
 01 5   03
 02 6   06
 03 16 NA
 04 8   06
 05 3   NA
 06 17 NA
 
 I need to create a new column for 'mothers age' which puts the age of the
individual with 'mothers i.d' into
 the row for her offspring (so individual 01 would have 16 in the mothers age
column, as thats the age of
 individual 03)
 

That's at typical join in SQL language, and it is handled in R with function
merge. In your special case, you would merge the dataframe with itself, 
so something like

merge(fr,fr, by... and check the NA cases)

Dieter

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

2009-06-26 Thread Liviu Andronic
Hello,

On 6/26/09, chris.wil...@csiro.au chris.wil...@csiro.au wrote:
  We are looking for a solver that can deal with this nonlinear integer 
 programming problem.  We looked at a number of packages on the CRAN Task 
 View: Optimization and Mathematical Programming, however, we have not been 
 able to locate one that will suit our purposes.  The essential features are 
 we need to be able to write a nonlinear function for the objective (hopefully 
 a self contained one as we need to include some data in it), we need to be 
 able to use a binary decision (or parameter) vector, and we need to be able 
 to use a constraint.  Any suggestions as to packages or other software that 
 will work for our problem would be much appreciated.

There is `solnp', part of the Integer and Nonlinear Optimization in R
(RINO) project [1]. It is still in early beta, though.

[1] http://r-forge.r-project.org/projects/rino/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread Fredrik Karlsson
Dear list,

Sorry for asking this very silly question on the list, but I seem to
have made my life complicated by going into string manipulation in
vectors.
What I need is to get the last part of a sting (the two last tokens,
separated by a space), and of course, this should be done for all
strings in a vector, creating a new vector of exual size.

So,

a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

should be made into a vector

 c( L*H H%, H* H%,  L*H %,   L*H % )

I have tried strsplit, but it seems to produce a structure I cannot
get to work in this context. Any ideas on how to solve this?

Thankful for all the help I can get.

/Fredrik


-- 
Life is like a trumpet - if you don't put anything into it, you don't
get anything out of 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] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread jim holtman
This should do it

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )
 # split the strings
 x - strsplit(a, ' ')
 # get last two tokens
 sapply(x, function(.tokens) paste(tail(.tokens, 2), collapse=' '))
[1] L*H H% H* H%  L*H %  L*H %




On Fri, Jun 26, 2009 at 7:21 AM, Fredrik Karlsson dargo...@gmail.comwrote:

 Dear list,

 Sorry for asking this very silly question on the list, but I seem to
 have made my life complicated by going into string manipulation in
 vectors.
 What I need is to get the last part of a sting (the two last tokens,
 separated by a space), and of course, this should be done for all
 strings in a vector, creating a new vector of exual size.

 So,

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

 should be made into a vector

  c( L*H H%, H* H%,  L*H %,   L*H % )

 I have tried strsplit, but it seems to produce a structure I cannot
 get to work in this context. Any ideas on how to solve this?

 Thankful for all the help I can get.

 /Fredrik


 --
 Life is like a trumpet - if you don't put anything into it, you don't
 get anything out of 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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] Optimization and Linear Programming in R

2009-06-26 Thread Hans W Borchers
 Chris.Wilcox at csiro.au writes:

 Dear List,
 
 [...]
 
 We are looking for a solver that can deal with this nonlinear integer 
 programming problem. We looked at a number of packages on the CRAN Task 
 View: Optimization and Mathematical Programming, however, we have not 
 been able to locate one that will suit our purposes. The essential 
 features are we need to be able to write a nonlinear function for the 
 objective (hopefully a self contained one as we need to include some 
 data in it), we need to be able to use a binary decision (or parameter) 
 vector, and we need to be able to use a constraint. Any suggestions as 
 to packages or other software that will work for our problem would be 
 much appreciated. 

What you desribe appears to be a 'Mixed Integer NonLinear Programming' 
(MINLP) problem. R may not be the right place to look for such kind of 
solvers. You can have a look into the NEOS Optimization Software Guide 
or into the Projects page of the COmputational INfrastructure for
Operations Research (COIN-OR).

The 'Bonmin' COIN-OR project could perhaps provide an appropriate solver 
for this problem. The RINO project on 'R-forge' plans to provide Rbonmin 
and Rlago packages, but this may take some time.

Perhaps by reconsidering your problem approach you can (at least partly) 
linearize your target function or see if it can be made convex, etc.; it 
did not sound to be too complex.

--Hans Werner

P.S.: As far as I know, 'solnp' does not solve mixed integer problems.

 Thanks,
 
 Chris Wilcox and Greg Thonier


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] to raise in a loop more than 1

2009-06-26 Thread Rau, Roland
Dear Damien, 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of damien landais
 Sent: Friday, June 26, 2009 11:16 AM
 To: R-help@r-project.org
 Subject: [R] to raise in a loop more than 1
 
 I would raise x,y and z in a loop but I won't raise of 1. I 
 tried this but it doesn't work
 
 mydata=matrix(nrow=1500,ncol=3)
 i=1
 for(x in 0:10){
 for(y in 0:20){
 for(z in 0:10){
 mydata[i,]=c(x,y,z)
 i=i+1
 z=z+2}
 y=y+4}
 x=x+2}
 
 And I would have something like that 
 x   y   z
 0   0   0
 0   0   2
 0   0   4
 0   0   6
 0   0   8
 0   0   10 
 0   4   0
 0   4   2
 ...
 

I am not exactly sure what you want. If my guess is correct, this will
reproduce the desired output:

x - seq(from=0, to=10, by=2)
y - seq(from=0, to=20, by=4)
z - seq(from=0, to=10, by=2)

mydata2 - expand.grid(x=as.factor(x), y=as.factor(y), z=as.factor(z))
mydata3 - with(mydata2,
mydata2[order(x,y,z),]
)
head(mydata3, n=8)


Hope this helps,
Roland

--
This mail has been sent through the MPI for Demographic Research.  Should you 
receive a mail that is apparently from a MPI user without this text displayed, 
then the address has most likely been faked. If you are uncertain about the 
validity of this message, please check the mail header or ask your system 
administrator for assistance.

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


Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Stavros Macrakis
It gives me a headache, too!  I think you'll have to wait for a more
expert user than me to supply explanations of these behaviors and
their rationales.

 -s


On 6/26/09, Craig P. Pyrame crap...@gmail.com wrote:
 Stavros Macrakis wrote:
 On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyramecrap...@gmail.com
 wrote:

 The man page Stavros quotes states that the class attribute of the result
 is
 taken from 'test', which clearly is not the case:


 Actually, the behavior is documented pretty clearly:

  The mode of the answer will be coerced from logical to
  accommodate first any values taken from 'yes' and then
  any values taken from 'no'.

 Whether this is a good design or not is another issue  Perhaps the
 justification is that it avoids evaluating the yes or no arguments (to
 determine their class) in cases where their value is not needed.


 Thank you for pointing me to this.  Now I get a headache from trying to
 figure out what does mode have to do with class - I thought that the
 class of the result should be that of test, and that the mode is
 something entirely different.  Why does coercing the mode also affect
 the class?  If the man page said The class attribute is taken from
 test, and it will be coerced ... or The mode of the result is taken
 from test, and it will be coreced ..., would this be wrong?  What is
 the class-mode mixture about?

 Why does this fail:

   r = as.raw(TRUE)
   ifelse(TRUE, r, r) = error

 This gives an error which I take for saying that raw cannot be coerced
 to logical, but yes it can:

   as.logical(r) = TRUE

 and raw can even be used as the condition vector in ifelse:

   ifelse(r, 1, 2) = 1

 Best regards,
 Craig


 Example:

  ifelse(c(T,F),1,a) = c(1,a)

 This has the same effect as

 res - c(T,F)
 res[1] - 1
 res[2] - a

 which is in fact pretty much the way it is implemented.


 And also, I find myself incapable of making sense of the may in the
 mode
 of the result may depend on the value of 'test' - may in what sense?


 See the examples at the end of ? ifelse

  -s




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] to raise in a loop more than 1

2009-06-26 Thread jim holtman
I assume that you are getting this error:

 mydata=matrix(nrow=1500,ncol=3)
 i=1
 for(x in 0:10){
+ for(y in 0:20){
+ for(z in 0:10){
+ mydata[i,]=c(x,y,z)
+ i=i+1
+ z=z+2}
+ y=y+4}
+ x=x+2}
Error in mydata[i, ] = c(x, y, z) : subscript out of bounds
No suitable frames for recover()
 i
[1] 1501

You have indexed outside the limits.  For what you are doing, you need the
matrix to be 11*21*11=2451

 mydata=matrix(nrow=2541,ncol=3)
 i=1
 for(x in 0:10){
+ for(y in 0:20){
+ for(z in 0:10){
+ mydata[i,]=c(x,y,z)
+ i=i+1
+ z=z+2}
+ y=y+4}
+ x=x+2}

 head(mydata)
 [,1] [,2] [,3]
[1,]000
[2,]001
[3,]002
[4,]003
[5,]004
[6,]005

You still don't get what you are expecting because you are trying to change
the loop variable within the loop which is not allowed (or really ignored).

On Fri, Jun 26, 2009 at 5:15 AM, damien landais damien.land...@tdf.frwrote:

 I would raise x,y and z in a loop but I won't raise of 1. I tried this but
 it doesn't work

 mydata=matrix(nrow=1500,ncol=3)
 i=1
 for(x in 0:10){
 for(y in 0:20){
 for(z in 0:10){
 mydata[i,]=c(x,y,z)
 i=i+1
 z=z+2}
 y=y+4}
 x=x+2}

 And I would have something like that
 x   y   z
 0   0   0
 0   0   2
 0   0   4
 0   0   6
 0   0   8
 0   0   10
 0   4   0
 0   4   2
 ...

 Could anybody help me?
 I don't work on a special package to do it...

 Thanks

 Cordialement
 Damien Landais

 __
 R-help@r-project.org mailing list
 https://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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] apply on xts

2009-06-26 Thread David Winsemius
The way to get the best answers on r-help (and the method advised in  
the Posting Guide)  is to offer the audience a specification of the  
libraries being used, to create examples that illustrate the sort of  
input expected, to offer the code that is being used,  and to clearly  
specify what output is needed. I only saw one of those aspects in your  
posting.


The lack of example input was the feature that held me off from  
further efforts, although others may have had their own reasons. You  
may think ticker objects are a well defined data type, but they are  
not so for me.


(You should also send plain text, again as the Posting Guide specifies.)

--
DW

On Jun 25, 2009, at 11:27 PM, R_help Help wrote:

Thanks David for reading for me. Anyhow, is there better way to do  
looping on xts objects than using apply? Thanks again.


adschai

On Thu, Jun 25, 2009 at 12:39 AM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Jun 24, 2009, at 9:26 PM, R_help Help wrote:

Hi,

I do not understand why after I called apply on a function that  
returns an
xts (getIdvAdjSeries) it returns a matrix whose columns are just  
numeric

value of time series in xts instead of a list of xts objects.

Basically, I called the following:

apply(matrix(tickers,ncol=1),1,FUN=getDivAdjSeries)

getDivAdjSeries - function(ticker) {
  seriesName - paste(ticker,Adjusted,sep=.);
  command - parse(text=paste(ticker,[,',seriesName,'],sep=));
  s - eval(command);
  dimnames(s)[[2]] - ticker;
  command - parse(text=paste(ticker,@index,sep=));
  s - xts(s,index=eval(command));
  return(s);
}

This doesn't seem to work. Can anyone shed some light please? Thank  
you.


That would appear to be the expected behavior after reading the Value
section of the help page for apply.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] crr - computationally singular

2009-06-26 Thread David Winsemius
Still the same reasons. It is possible to have collinearity without  
having any one column be a multiple of another.


 xyz - data.frame(x=sample(1:1000, 5), y=sample(1:1000, 5) ,  
xx=sample(1:1000, 5) ,yy=sample(1:1000, 5) )

 xyz$z - xyz$x + xyz$y + xyz$xx
 solve(xyz)
Error in solve.default(xyz) :
  system is computationally singular: reciprocal condition number =  
6.39164e-20


On Jun 26, 2009, at 6:22 AM, Laura Bonnett wrote:


Dear Sir,

Thank you for your response.  You were correct, I had 1 linearly
dependent column.  I have solved this problem and now the rank of
'covaeb' is 17 (qr(covaeb)$rank = 17).  However, I still get the same
error message when I use covaeb in the 'crr' function.


fit=crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)

8 cases omitted due to missing values
Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE =  
base)) :
 system is computationally singular: reciprocal condition number =  
3.45905e-25


Are there any other reasons why this may be happening?

Thank you,

Laura

2009/6/25 Ravi Varadhan rvarad...@jhmi.edu:
This means that your design matrix or model matrix is rank  
deficient, i.e it
does not have linearly independent columns.  Your predictors are  
collinear!



Just take your design matrices covaea or covaeb with 17  
predcitors and

compute their rank or try to invert them.  You will see the problem.

Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml







-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On

Behalf Of Laura Bonnett
Sent: Thursday, June 25, 2009 11:39 AM
To: r-help@r-project.org
Subject: [R] crr - computationally singular

Dear R-help,

I'm very sorry to ask 2 questions in a week.  I am using the  
package 'crr'

and it does exactly what I need it to when I use the dataset a.
However, when I use dataset b I get the following error message:
Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE =  
base)) :

 system is computationally singular: reciprocal condition number =
1.28654e-24

This is obviously as a result of a problem with the data but apart  
from
dataset a having 1674 rows and dataset b having 701 rows there is  
really no

difference between them.

The code I am using is as follows where covaea and covaeb are  
matrices of

covarites, all coded as binary variables.
In case a:

covaea -
cbind 
(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pgu

1a,pgu2a,log(agea),firstinta/1000,totsezbasea)
fita - crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)


and in case b:

covaeb -
cbind 
(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,sty

pe4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb))
fitb - crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)


csaea and csaeb are the censoring indicators for a and b  
respectively which
equal 1 for the event of interest, 2 for the competing risks event  
and 0

otherwise.

Can anyone suggest a reason for the error message?  I've tried  
running fitb
with variants of covaeb and irrespective of the order of the  
covariates in
the matrix, the code runs fine with 16 of the 17 covariates  
included but

then produces an error message when the 17th is added.

Thank you for your help,

Laura

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] The Claw Density and LOCFIT

2009-06-26 Thread Mark Difford

Hi Jaap,

 Could anybody please direct me in finding an updated version of this
 document, or help me
 correct the code given in the file. The (out-of-date) code is as follows:

You are not helping yourself, or anyone else, by not including the error
messages you get when trying to execute your code. The matter is in fact
quite straightfowards: ev does not accept an evaluation structure called
grid. The current documentation for locfit does tell you this: ?locfit.raw
(sub ev). When I executed your code I got

   fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315),
 ev = 
+ grid(100, ll = -3.5, ur = 2.7)) 
Error in grid(100, ll = -3.5, ur = 2.7) : 
  unused argument(s) (ll = -3.5, ur = 2.7)

This explicitly tells you that the problem lies with the call to ev =
grid(...), which should in fact be ev = lfgrid(...). The following works for
me and should do so for you.

fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315), ev = 
   lfgrid(100, ll = -3.5, ur = 2.7)) 

HTH,
Mark.

R version 2.10.0 Under development (unstable) (2009-06-20 r48806) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=English_South Africa.1252  LC_CTYPE=English_South Africa.1252   
[3] LC_MONETARY=English_South Africa.1252 LC_NUMERIC=C 
[5] LC_TIME=English_South Africa.1252

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

other attached packages:
[1] locfit_1.5-4lattice_0.17-25 akima_0.5-2 DPpackage_1.0-7
ade4_1.4-11 Design_2.2-0   
[7] survival_2.35-4 Hmisc_3.6-0

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


Van Wyk, Jaap wrote:
 
 I am trying to reproduce Figure 10.5 of Loader's book: Local Regression
 and Likelihood. The code provided in the book does not seem to work.
 I have managed (a while ago) to get the accompanied R-code for the figures
 in the book (file called lffigs.R) from somewhere - cannot find it on the
 web anymore. The code in the .R script file does not work either.
 Could anybody please direct me in finding an updated version of this
 document, or help me correct the code given in the file. The (out-of-date)
 code is as follows:
 
data(claw54)
   fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315),
 ev =
 grid(100, ll = -3.5, ur = 2.7))
   fit2 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.985),
 ev =
 grid(100, ll = -3.5, ur = 2.7))
   x - seq(-3.5, 2.7, length.out = 200)
   y - dnorm(x, -1., 0.1) + dnorm(x, -0.5, 0.1) + dnorm(x, 0, 0.1) +
 dnorm(x,
 0.5, 0.1) + dnorm(x, 1., 0.1)
   y - (y + 5 * dnorm(x))/10
   plot(fit1, get.data = T, main = h=0.315, ylim = c(0, max(y)))
   lines(x, y, lty = 2)
   plot(fit2, get.data = T, main = h=0.985, ylim = c(0, max(y)))
   lines(x, y, lty = 2)
 
 THANKS FOR ANY ASSISTANCE.
 ps: This code differs from that in the book. I have tried both, without
 success. Even if I just use, for example,
 fit1 - locfit( ~ claw54, deg = 0, kern = gauss, alpha = c(0, 0.315))
 I do not get the same result.
 
 Jacob L van Wyk, Dept. of Statistics, University of Johannesburg (APK),
 Box 524, Auckland Park, 2006.
 Office: +27 11 559 3080, Fax: +27 11 559 2499
 
 
 
 This email and all contents are subject to the following disclaimer:
 
 http://www.uj.ac.za/UJ_email_legal_disclaimer.htm
 
   [[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.
 
 

-- 
View this message in context: 
http://www.nabble.com/The-Claw-Density-and-LOCFIT-tp24218274p24220007.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] crr - computationally singular

2009-06-26 Thread Laura Bonnett
But I have centred all the dummy variables for the covariates...

2009/6/26 David Winsemius dwinsem...@comcast.net:
 Still the same reasons. It is possible to have collinearity without having
 any one column be a multiple of another.

 xyz - data.frame(x=sample(1:1000, 5), y=sample(1:1000, 5) ,
 xx=sample(1:1000, 5) ,yy=sample(1:1000, 5) )
 xyz$z - xyz$x + xyz$y + xyz$xx
 solve(xyz)
 Error in solve.default(xyz) :
  system is computationally singular: reciprocal condition number =
 6.39164e-20

 On Jun 26, 2009, at 6:22 AM, Laura Bonnett wrote:

 Dear Sir,

 Thank you for your response.  You were correct, I had 1 linearly
 dependent column.  I have solved this problem and now the rank of
 'covaeb' is 17 (qr(covaeb)$rank = 17).  However, I still get the same
 error message when I use covaeb in the 'crr' function.

 fit=crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)

 8 cases omitted due to missing values
 Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
  system is computationally singular: reciprocal condition number =
 3.45905e-25

 Are there any other reasons why this may be happening?

 Thank you,

 Laura

 2009/6/25 Ravi Varadhan rvarad...@jhmi.edu:

 This means that your design matrix or model matrix is rank deficient, i.e
 it
 does not have linearly independent columns.  Your predictors are
 collinear!


 Just take your design matrices covaea or covaeb with 17 predcitors
 and
 compute their rank or try to invert them.  You will see the problem.

 Ravi.


 
 ---

 Ravi Varadhan, Ph.D.

 Assistant Professor, The Center on Aging and Health

 Division of Geriatric Medicine and Gerontology

 Johns Hopkins University

 Ph: (410) 502-2619

 Fax: (410) 614-9625

 Email: rvarad...@jhmi.edu

 Webpage:

 http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
 tml




 
 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of Laura Bonnett
 Sent: Thursday, June 25, 2009 11:39 AM
 To: r-help@r-project.org
 Subject: [R] crr - computationally singular

 Dear R-help,

 I'm very sorry to ask 2 questions in a week.  I am using the package
 'crr'
 and it does exactly what I need it to when I use the dataset a.
 However, when I use dataset b I get the following error message:
 Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base))
 :
  system is computationally singular: reciprocal condition number =
 1.28654e-24

 This is obviously as a result of a problem with the data but apart from
 dataset a having 1674 rows and dataset b having 701 rows there is really
 no
 difference between them.

 The code I am using is as follows where covaea and covaeb are matrices of
 covarites, all coded as binary variables.
 In case a:

 covaea -
 cbind(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pgu
 1a,pgu2a,log(agea),firstinta/1000,totsezbasea)
 fita - crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)

 and in case b:

 covaeb -
 cbind(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,sty
 pe4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb))
 fitb - crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)

 csaea and csaeb are the censoring indicators for a and b respectively
 which
 equal 1 for the event of interest, 2 for the competing risks event and 0
 otherwise.

 Can anyone suggest a reason for the error message?  I've tried running
 fitb
 with variants of covaeb and irrespective of the order of the covariates
 in
 the matrix, the code runs fine with 16 of the 17 covariates included but
 then produces an error message when the 17th is added.

 Thank you for your help,

 Laura

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

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



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


[R] Optimization and Linear Programming in R

2009-06-26 Thread R P Herrold

On Fri, 26 Jun 2009, Liviu Andronic wrote:


There is `solnp', part of the Integer and Nonlinear Optimization in R
(RINO) project [1]. It is still in early beta, though.

[1] http://r-forge.r-project.org/projects/rino/


I do not find it at the indicated location on:
http://r-forge.r-project.org/R/?group_id=162

[herr...@centos-5 R2spec]$ wget \
http://r-forge.r-project.org/src/contrib/Rsolnp_0.1.tar.gz
HTTP request sent, awaiting response... 404 Not Found
09:37:55 ERROR 404: Not Found.
[herr...@centos-5 R2spec]$

-- Russ herrold

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


Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame

Stavros Macrakis wrote:

It gives me a headache, too!  I think you'll have to wait for a more
expert user than me to supply explanations of these behaviors and
their rationales.
  


Thanks, Stavros.  I hope someone with expertise will shed more light on 
this, and in the meantime I'll try to learn more from the manuals.


Best regards,
Craig



 -s


On 6/26/09, Craig P. Pyrame crap...@gmail.com wrote:
  

Stavros Macrakis wrote:


On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyramecrap...@gmail.com
wrote:

  

The man page Stavros quotes states that the class attribute of the result
is
taken from 'test', which clearly is not the case:



Actually, the behavior is documented pretty clearly:

 The mode of the answer will be coerced from logical to
 accommodate first any values taken from 'yes' and then
 any values taken from 'no'.

Whether this is a good design or not is another issue  Perhaps the
justification is that it avoids evaluating the yes or no arguments (to
determine their class) in cases where their value is not needed.

  

Thank you for pointing me to this.  Now I get a headache from trying to
figure out what does mode have to do with class - I thought that the
class of the result should be that of test, and that the mode is
something entirely different.  Why does coercing the mode also affect
the class?  If the man page said The class attribute is taken from
test, and it will be coerced ... or The mode of the result is taken
from test, and it will be coreced ..., would this be wrong?  What is
the class-mode mixture about?

Why does this fail:

  r = as.raw(TRUE)
  ifelse(TRUE, r, r) = error

This gives an error which I take for saying that raw cannot be coerced
to logical, but yes it can:

  as.logical(r) = TRUE

and raw can even be used as the condition vector in ifelse:

  ifelse(r, 1, 2) = 1

Best regards,
Craig




Example:

 ifelse(c(T,F),1,a) = c(1,a)

This has the same effect as

res - c(T,F)
res[1] - 1
res[2] - a

which is in fact pretty much the way it is implemented.


  

And also, I find myself incapable of making sense of the may in the
mode
of the result may depend on the value of 'test' - may in what sense?



See the examples at the end of ? ifelse

 -s

  




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

2009-06-26 Thread Etienne B. Racine



dreamworx wrote:
 
 Appologies if this is a simple problem. I have a matrix which is 86x3 and
 each row contains three integers. The problem I have is that some of the
 rows of integers are repeated in other rows and I only wish to have one
 copy of these rows.
 
 Is there a function that I can use which will identify these repeated rows
 and delete them from the matrix? I have searched for help with this
 problem but the only function I have found is 'grep' which I'm not sure is
 of any use.
 

?unique

# generate data
set.seed(1001)
m - matrix(sample(1:3,20*3,TRUE),ncol=3);m

# get unique values
unique(m)

As you can see, row 7 and 20 are 1,1,1... and you get only one row with
1,1,1 in the second matrix.

-- 
View this message in context: 
http://www.nabble.com/Deleting-repeated-rows-tp24219989p24220573.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread John Kane

I have the feeling that this is a very clumsy way to do it but I think it does 
what you want.
=
a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )
mylist - strsplit(a, )
pick - function(x) {tail(x,2) }
unlist(pick(mylist)

=


--- On Fri, 6/26/09, Fredrik Karlsson dargo...@gmail.com wrote:

 From: Fredrik Karlsson dargo...@gmail.com
 Subject: [R] How do I get just the two last tokens of each string in a vector?
 To: R-Help List r-h...@stat.math.ethz.ch
 Received: Friday, June 26, 2009, 7:21 AM
 Dear list,
 
 Sorry for asking this very silly question on the list, but
 I seem to
 have made my life complicated by going into string
 manipulation in
 vectors.
 What I need is to get the last part of a sting (the two
 last tokens,
 separated by a space), and of course, this should be done
 for all
 strings in a vector, creating a new vector of exual size.
 
 So,
 
 a - c( %L H*L L*H H%, %L H* H%,  %L L*H
 %,   %L L*H % )
 
 should be made into a vector
 
  c( L*H H%, H* H%,  L*H %,   L*H
 % )
 
 I have tried strsplit, but it seems to produce a structure
 I cannot
 get to work in this context. Any ideas on how to solve
 this?
 
 Thankful for all the help I can get.
 
 /Fredrik
 
 
 -- 
 Life is like a trumpet - if you don't put anything into
 it, you don't
 get anything out of 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.
 


  __
Make your browsing faster, safer, and easier with the new Internet Explorer® 8. 
Optimized for Yahoo! Get it Now for 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 the xlsReadWrite package

2009-06-26 Thread Andrew Yee
Thanks for the detailed clarification.
Perhaps the page here
http://cran.r-project.org/web/packages/xlsReadWrite/ could
include these explanations as well.  I imagine I'm not the only user with
these questions!

Thanks,
Andrew

On Fri, Jun 26, 2009 at 2:48 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote:

 On Fri, 26 Jun 2009, David Scott wrote:

  Andrew Yee wrote:

 A naive question:  what happened to the xlsReadWrite package?
 http://cran.r-project.org/web/packages/xlsReadWrite/

 It says that it was removed from the CRAN repository.


 Note that it was archived, not removed entirely.  That is done
 with packages that no longer install and we don't get an update.

 The immediate problem with xlsReadWrite was that it was Windows-only and
 would not install under Windows in pre-2.9.0.

  Are there any plans for it be available again?


 The second issue was binary code in the package which is at least heavily
 frowned on in the CRAN source repository (we host BRugs elsewhere for that
 reason).

  There was a problem with proprietary code.


 Only in so far as it was binary.  There are a number of CRAN packages with
 non-open-source code.

  Pick up the latest version from Hans-Peter Suter's website

 http://treetron.googlepages.com/


 Which says the problem was the binary code.



 David Scott
 _
 David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
 Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
 Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

 Graduate Officer, Department of Statistics
 Director of Consulting, Department of Statistics

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


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


[[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] How to create separate plots for all combinations of some factors

2009-06-26 Thread Lane, Jim
Hi, All

I have a data frame as follows: 

 data.class(tapes)
[1] data.frame
 names(tapes)
[1] dateloc classdrp datascratch
reclaim total  

Date is a date; loc, class and drp are factors; the rest are numerics.
I want to generate separate plots by date for the numeric variables for
all combinations of the factors. I tried to do this as follows:

 by(tapes,list(loc,class,drp),plot(date,scratch))
Error in FUN(X[[1L]], ...) : could not find function FUN 

As well as the error I get a single plot for all values of scratch and
date which is meaningless. What am I going wrong here? 

For clarification what I want would be done is SAS as something like:

 proc gplot;
  plot scratch*date;
  by loc class drp;
  quit; run;



Jim Lane
Capacity Planner
RBC Financial Group
315 Front St W
6th Floor - H14
Toronto, Ontario CANADA
M5V 3A4
416-348-6024

Display of superior knowledge is as great a vulgarity
as display of superior wealth - greater indeed, inasmuch
as knowledge should tend more definitely than wealth
towards discretion and good manners.

- H. W. Fowler, Modern English Usage

___

This e-mail may be privileged and/or confidential, and the sender does not 
waive any related rights and obligations.
Any distribution, use or copying of this e-mail or the information it contains 
by other than an intended recipient is unauthorized.
If you received this e-mail in error, please advise me (by return e-mail or 
otherwise) immediately.  

Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce 
pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il 
contient par une personne autre que le (les) destinataire(s) désigné(s) est 
interdite.
Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser 
immédiatement, par retour de courrier électronique ou par un autre moyen.

[[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] Matching data to a new column

2009-06-26 Thread John Kane

x - I.D  age  'MID'
01 5   03
02 6   06
03 16 NA
04 8   06
05 3   NA
06 17 NA

xx - read.table(textConnection(x), header=TRUE); xx
closeAllConnections()

ag1 - xx[, c(1,2)] ; ag1
ag2 - xx[, c(1,3)] ; ag2
names(ag2[2]) - I.D

merge(ag1,ag2, by=I.D)


--- On Fri, 6/26/09, Kubasiewicz, Laura laura.kubasiewic...@imperial.ac.uk 
wrote:

 From: Kubasiewicz, Laura laura.kubasiewic...@imperial.ac.uk
 Subject: [R] Matching data to a new column
 To: r-help@r-project.org r-help@r-project.org
 Received: Friday, June 26, 2009, 6:55 AM
 
 Hi all,
 
 I wonder if anyone can help,
 
 I have a dataframe with columns for...
 
 'I.D'  'age'  'mothers I.D'
 01     5   
    03
 02     6   
    06
 03     16     NA
 04     8   
    06
 05     3   
    NA
 06     17     NA
 
 I need to create a new column for 'mothers age' which puts
 the age of the individual with 'mothers i.d' into the row
 for her offspring (so individual 01 would have 16 in the
 mothers age column, as thats the age of individual 03)
 
 Hope that makes sense, any help appreciated,
 
 Thanks
 Laura
 
     [[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.
 


  __
Be smarter than spam. See how smart SpamGuard i
ions in Mail and switch to New Mail today or register for free at 
http://mail.yahoo.ca

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


Re: [R] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread Fredrik Karlsson
HI Jim,

Thank you! Works perfectly.

/Fredrik

On Fri, Jun 26, 2009 at 1:00 PM, jim holtmanjholt...@gmail.com wrote:
 This should do it

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )
 # split the strings
 x - strsplit(a, ' ')
 # get last two tokens
 sapply(x, function(.tokens) paste(tail(.tokens, 2), collapse=' '))
 [1] L*H H% H* H%  L*H %  L*H %




 On Fri, Jun 26, 2009 at 7:21 AM, Fredrik Karlsson dargo...@gmail.com
 wrote:

 Dear list,

 Sorry for asking this very silly question on the list, but I seem to
 have made my life complicated by going into string manipulation in
 vectors.
 What I need is to get the last part of a sting (the two last tokens,
 separated by a space), and of course, this should be done for all
 strings in a vector, creating a new vector of exual size.

 So,

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

 should be made into a vector

  c( L*H H%, H* H%,  L*H %,   L*H % )

 I have tried strsplit, but it seems to produce a structure I cannot
 get to work in this context. Any ideas on how to solve this?

 Thankful for all the help I can get.

 /Fredrik


 --
 Life is like a trumpet - if you don't put anything into it, you don't
 get anything out of 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.



 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?




-- 
Life is like a trumpet - if you don't put anything into it, you don't
get anything out of 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] predicted values after fitting gamma2 function

2009-06-26 Thread David Winsemius


On Jun 25, 2009, at 11:30 PM, Steven Matthew Anderson wrote:

Question: after fitting a gamma function to some data, how do I get  
predicted values?  I'm a SAS programmer, I new R, and am having  
problems getting my brain to function with the concept of object as  
class   The following is specifics of what I am doing:


I'm trying to determine the pdf from data I have created in a  
simulation.

I have generated frequency counts using the following:

 Max.brks - pretty(range(Max.Spread$Distance), 100)
 Max.f-hist(x=Max.Spread$Distance,
  breaks=Max.brks,plot=FALSE )
 Max.cnt-as.data.frame(cbind(sim,Max.f$mids,Max.f$counts))
 colnames(Max.cnt)-c(Simulation,MidPoint,Count)

then I fit this to a gamma distribution function:


Using a non-base function without including the appropriate require()  
or library() call is a bit like asking a SAS programmer to debug code  
but not telling what PROC it's from;


 modl- 
vglm 
(Count 
~ 
MidPoint 
,gamma2 
,data 
= 
subset(Max.cnt,select=(simulation,MidPoint,Count),trace=TRUE,crit=c)

 print(coef(modl2,matrix=TRUE))
 print(summary(modl2))

This produces the output:


snipped output



Now - how do I get this information to give me predicted values  
given the same x-values I used in the experimental model (i.e. from  
Max.brks - pretty(range(Max.Spread$Distance), 100)).


Most regression functions in R, and vglm is no exception, have predict  
methods. The default is to give back predictions for the data from  
which the parameters were estimated, but if you want predictions on  
specific new values there is a newdata option.


?predict.vglm


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] crr - computationally singular

2009-06-26 Thread Ravi Varadhan

How did you determine that you have full rank model matrix comprising 17
predictors?  Are you able to invert the model matrix using `solve'?  If not,
you still have collinearity problem.

If you are, then the problem might be in the Newton's method used by `crr'
to solve the partial-likelihood optimization.  The hessian matrix of the
parameters might be singular during the iterations.  If this is the case,
your best bet would be to just simplify the model, i.e. use fewer
predictors.  

Ravi.


---

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvarad...@jhmi.edu

Webpage:
http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h
tml







-Original Message-
From: Laura Bonnett [mailto:l.j.bonn...@googlemail.com] 
Sent: Friday, June 26, 2009 6:22 AM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] crr - computationally singular

Dear Sir,

Thank you for your response.  You were correct, I had 1 linearly dependent
column.  I have solved this problem and now the rank of 'covaeb' is 17
(qr(covaeb)$rank = 17).  However, I still get the same error message when I
use covaeb in the 'crr' function.

 fit=crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)
8 cases omitted due to missing values
Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
  system is computationally singular: reciprocal condition number =
3.45905e-25

Are there any other reasons why this may be happening?

Thank you,

Laura

2009/6/25 Ravi Varadhan rvarad...@jhmi.edu:
 This means that your design matrix or model matrix is rank deficient, 
 i.e it does not have linearly independent columns.  Your predictors are
collinear!


 Just take your design matrices covaea or covaeb with 17 predcitors 
 and compute their rank or try to invert them.  You will see the problem.

 Ravi.

 --
 --
 ---

 Ravi Varadhan, Ph.D.

 Assistant Professor, The Center on Aging and Health

 Division of Geriatric Medicine and Gerontology

 Johns Hopkins University

 Ph: (410) 502-2619

 Fax: (410) 614-9625

 Email: rvarad...@jhmi.edu

 Webpage:
 http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Vara
 dhan.h
 tml



 --
 --
 


 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Laura Bonnett
 Sent: Thursday, June 25, 2009 11:39 AM
 To: r-help@r-project.org
 Subject: [R] crr - computationally singular

 Dear R-help,

 I'm very sorry to ask 2 questions in a week.  I am using the package 'crr'
 and it does exactly what I need it to when I use the dataset a.
 However, when I use dataset b I get the following error message:
 Error in drop(.Call(La_dgesv, a, as.matrix(b), tol, PACKAGE = base)) :
  system is computationally singular: reciprocal condition number =
 1.28654e-24

 This is obviously as a result of a problem with the data but apart 
 from dataset a having 1674 rows and dataset b having 701 rows there is 
 really no difference between them.

 The code I am using is as follows where covaea and covaeb are matrices 
 of covarites, all coded as binary variables.
 In case a:
 covaea -
 cbind(sexa,fsha,fdra,nsigna,eega,th1a,th2a,stype1a,stype2a,stype3a,pg
 u
 1a,pgu2a,log(agea),firstinta/1000,totsezbasea)
 fita - crr(snearma$with.Withtime,csaea,covaea,failcode=2,cencode=0)

 and in case b:
 covaeb -
 cbind(sexb,fshb,fdrb,nsignb,eegb,th1b,th2b,stype1b,stype2b,stype3b,st
 y
 pe4b,stype5b,pgu1b,pgu2b,(ageb/10)^(-1),firstintb,log(totsezbaseb))
 fitb - crr(snearmb$with.Withtime,csaeb,covaeb,failcode=2,cencode=0)

 csaea and csaeb are the censoring indicators for a and b respectively 
 which equal 1 for the event of interest, 2 for the competing risks 
 event and 0 otherwise.

 Can anyone suggest a reason for the error message?  I've tried running 
 fitb with variants of covaeb and irrespective of the order of the 
 covariates in the matrix, the code runs fine with 16 of the 17 
 covariates included but then produces an error message when the 17th is
added.

 Thank you for your help,

 Laura

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

Re: [R] Calculating distance between spatial points

2009-06-26 Thread Ian Fiske

If your goal is to get the distance between geographic points, you might try
computing the distance along the great circle arc and forget about
projection.  Several packages have functions that do this.  See
https://stat.ethz.ch/pipermail/r-help/2007-October/144546.html.

hope that helps,
Ian



Tim Clark wrote:
 
 
 Dear List,
 
 I am trying to determine the speed an animal is traveling on each leg of a
 track.  My data is in longitude and latitude, so I am using the package
 rgdal to convert it into a spatial points data frame and transform it to
 UTM.  I would then like to find the difference between successive
 longitudes and latitudes, find the euclidean distance between points, and
 compute the speed of the animal on each leg.
 
 [ removed from quote ]
 
 Aloha,
 
 Tim
 
 
 
 Tim Clark
 Department of Zoology 
 University of Hawaii
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Calculating-distance-between-spatial-points-tp24212875p24220923.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] changing the loss function in the logistic regression?

2009-06-26 Thread Michael
Hi all,

Is there a way to change the loss function in the logistic regression?
Or we could provide a customized loss function in the logistic
regression so we could use that loss function in the Cross Validation
in logistic regression?

Thanks a lot!

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

2009-06-26 Thread Michael
Hi all,

Lots of big IT companies are renting out their computing facilities.
Amazon has one such service. In my understanding, this will
dramatically improve the speed of my R program -- currently the cross
validation and model selection part is the bottle neck. It take a few
days to just finish optimal parameter tuning via CV.

Could anybody shed some lights on this? Is it completely transparent
to move my R program to a rented parallel computing facility?

Moreover, at my PC level, I have a 4-core PC, is there anything we
could do in R to speed up my CV programs?

Thanks a lot!

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


Re: [R] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread Stavros Macrakis
One way is:

a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

 sub(^.*(^| )([^ ]+ [^ ]+$),\\2,a)
[1] L*H H% H* H%  L*H %  L*H %

Just be aware that this is not terribly efficient for very large strings.

-s

On Fri, Jun 26, 2009 at 7:21 AM, Fredrik Karlssondargo...@gmail.com wrote:
 Dear list,

 Sorry for asking this very silly question on the list, but I seem to
 have made my life complicated by going into string manipulation in
 vectors.
 What I need is to get the last part of a sting (the two last tokens,
 separated by a space), and of course, this should be done for all
 strings in a vector, creating a new vector of exual size.

 So,

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

 should be made into a vector

  c( L*H H%, H* H%,  L*H %,   L*H % )

 I have tried strsplit, but it seems to produce a structure I cannot
 get to work in this context. Any ideas on how to solve this?

 Thankful for all the help I can get.

 /Fredrik


 --
 Life is like a trumpet - if you don't put anything into it, you don't
 get anything out of 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.


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

2009-06-26 Thread Peter Dalgaard
I've rolled up R-2.9.1.tar.gz a few hours ago.

This is a maintenance release and fixes a number of mostly minor issues.

See the full list of changes below.

You can get it from

http://cran.r-project.org/src/base/R-2/R-2.9.1.tar.gz

or wait for it to be mirrored at a CRAN site nearer to you. Binaries
for various platforms will appear in due course.

For the R Core Team

Peter Dalgaard


These are the md5sums for the freshly created files, in case you wish
to check that they are uncorrupted:


70447ae7f2c35233d3065b004aa4f331  INSTALL
433182754c05c2cf7a04ad0da474a1d0  README
4f004de59e24a52d0f500063b4603bcb  OONEWS
ff4bd9073ef440b1eb43b1428ce96872  ONEWS
11a746c387c5a94f172a27939b96dd4c  NEWS
7abcbbc7480df75a11a00bb09783db90  THANKS
070cca21d9f8a6af15f992edb47a24d5  AUTHORS
a6f89e2100d9b6cdffcea4f398e37343  COPYING.LIB
eb723b61539feef013de476e68b5c50a  COPYING
020479f381d5f9038dcb18708997f5da  RESOURCES
8ea34a9306ef5cf5dc03b45883586129  FAQ
54a79eebdf0cec3fd2c489fc94d99b00  R-2.9.1.tar.gz
54a79eebdf0cec3fd2c489fc94d99b00  R-latest.tar.gz

Here is the relevant part of the NEWS file:

CHANGES IN R VERSION 2.9.1

NEW FEATURES

o   New function anyDuplicated(x) returns 0 (= FALSE) or the index
of the first duplicated entry of x.

o   matplot(), matlines() and matpoints() now also obey a 'lend'
argument, determining line end styles. (Wish of PR#13619).

o   bw.SJ(), bw.bcv() and bw.ucv() now gain an optional 'tol'
argument allowing more accurate estimates.

o   new.packages() no longer regards packages with the same name
as a member of an installed bundle as 'new' (this is now
consistent with the dependency checks in install.packages()).

It no longer reports on partially installed bundles (since
members can be updated individually if a bundle is unbundled).

o   old.packages() and hence updates.packages() will look for
updates to members of package bundles before updates to the
whole bundle: this allow bundles to be split and installations
updated.

o   nlminb() gives better non-convergence messages in some cases.

o   S3 method dispatch will support S4 class inheritance for S3
methods, for primitives and via UseMethod(), if the argument
S3methods=TRUE is given to setClass().  S4 method dispatch
will use S3 per-object inheritance if S3Class() is set on the
object.  See ?Methods and the paper referenced there.

o   R CMD INSTALL is more tolerant of (malformed) packages with a
'man' directory but no validly named .Rd files.

o   R CMD check now reports where options are used that cause some
of the checks to be skipped.

o   RSiteSearch has been updated to be consistent with the new
layout of the search site itself, which now includes separate
options for vignettes, views, and r-sig-mixed-models, as well
as changed names for r-help. (Contributed by Jonathan Baron.)

o   That R CMD check makes use of a
pkg/tests/Examples/pkg-Ex.Rout.save file as a reference
result is now documented in 'Writing R Extensions'.

DEPRECATED  DEFUNCT

o   print.atomic() (defunct since 1.9.0) has been removed since it
caused confusion for an S4 class union atomic.

o   png(type=cairo1) is deprecated -- it was only needed for
platforms with 1.0 = cairo  1.2.

BUG FIXES

o   The ... argument was not handled properly when ... was found
in the enclosure of the current function, rather than in the
function header itself.  (This caused integrate() to fail in
certain cases.)

o   col2rgb(#0080, TRUE) would return the background colour.
(Reported by Hadley Wickham.)

o   interaction() now ensures that the levels of the result are unique.

o   packageDescription() and hence sessionInfo() now report the correct
package version also for a non-attached loaded namespace of
a version different from the default lib.loc.

o   smoothScatter() now also works when e.g. xlim[2]  xlim[1].

o   Invalid use of sprintf() such as sprintf(%S%) now give an error
instead of a segmentation fault, as do very unusual cases such as
sprintf(%s, tryCatch(stop(), error=identity)).  (It was
always documented that misuse could crash R in
platform-dependent ways.)

o   parse_Rd() would mishandle braces when they occurred at
the start of a line within an R string in an Rd file (reported
by Alex Couture-Beil) or when they occurred in an R comment
(reported by Mark Bravington).

o   readNEWS() missed version numbers with more than one digit.

o   building R --without-x no longer fails (PR#13665)

o   printCoefmat(cbind(0,1)) now works too (PR#13677)

o   bw.SJ(c(1:99, 1e6)) now works too.

o   Rd2txt() could not handle empty descriptions of items in an Rd

[R] Anova with multiple responses without loop

2009-06-26 Thread Sungeun Kim
Hello,



I have one question about Anova in car package. Here is my situation:



I have a response matrix (Y), consisting of 7 different responses for a
group of subjects, 2 categorical factors (A, B), 3 covariates (C,D,E). I
would like to know the main effects of 2 factors and the interaction between
them on each of 7 responses. So, I used



Linear regression (lm) and Anova with a model, Y[,i]~A+B+A:B+C+D+E in a
loop. This worked as I expected it to work.

However, I want to know how to perform the same task without using any loop
to increase the performance.



Basically, my question is



How to perform multiples of LM and Anova without using a loop. If anyone
know how to do this, would you advise me?



Thank you in advance for your any help.


-- 
Sungeun Kim

[[alternative HTML version deleted]]

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


Re: [R] changing the loss function in the logistic regression?

2009-06-26 Thread Frank E Harrell Jr

Michael wrote:

Hi all,

Is there a way to change the loss function in the logistic regression?
Or we could provide a customized loss function in the logistic
regression so we could use that loss function in the Cross Validation
in logistic regression?

Thanks a lot!


The goal is to use a loss function that yields optimality, with a 
sensible definition of optimality.  For many purposes, maximum 
likelihood or penalized maximum likelihood is optimum.  So don't change 
the optimality criteria just because you are cross-validating a 
different measure.


By the way, it's often not a good idea to cross-validate a different 
measure.  At least the accuracy index should be information-preserving. 
 Deviance, log-likelihood, and AIC are your friends.


Frank

--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

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


Re: [R] Matching data to a new column

2009-06-26 Thread Luc Villandre

Hi Laura,

The function merge() works well, but another elegant to do it would 
involve match().


(Assuming your data.frame object is called x)

x$motherAge - with(x, age[match(mothers.I.D,I.D)])

Cheers,

--
*Luc Villandré*
/Biostatistician
McGill University Health Center -
Montreal Children's Hospital Research Institute/


John Kane wrote:

x - I.D  age  'MID'
01 5   03
02 6   06
03 16 NA
04 8   06
05 3   NA
06 17 NA

xx - read.table(textConnection(x), header=TRUE); xx

closeAllConnections()

ag1 - xx[, c(1,2)] ; ag1
ag2 - xx[, c(1,3)] ; ag2
names(ag2[2]) - I.D

merge(ag1,ag2, by=I.D)


--- On Fri, 6/26/09, Kubasiewicz, Laura laura.kubasiewic...@imperial.ac.uk 
wrote:

  

From: Kubasiewicz, Laura laura.kubasiewic...@imperial.ac.uk
Subject: [R] Matching data to a new column
To: r-help@r-project.org r-help@r-project.org
Received: Friday, June 26, 2009, 6:55 AM

Hi all,

I wonder if anyone can help,

I have a dataframe with columns for...

'I.D'  'age'  'mothers I.D'
01 5   
   03
02 6   
   06

03 16 NA
04 8   
   06
05 3   
   NA

06 17 NA

I need to create a new column for 'mothers age' which puts
the age of the individual with 'mothers i.d' into the row
for her offspring (so individual 01 would have 16 in the
mothers age column, as thats the age of individual 03)

Hope that makes sense, any help appreciated,

Thanks
Laura

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





  __
Be smarter than spam. See how smart SpamGuard i
ions in Mail and switch to New Mail today or register for free at 
http://mail.yahoo.ca

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

2009-06-26 Thread Dirk Eddelbuettel

On 26 June 2009 at 07:40, Michael wrote:
| Hi all,
| 
| Lots of big IT companies are renting out their computing facilities.
| Amazon has one such service. In my understanding, this will
| dramatically improve the speed of my R program -- currently the cross
| validation and model selection part is the bottle neck. It take a few
| days to just finish optimal parameter tuning via CV.
| 
| Could anybody shed some lights on this? Is it completely transparent
| to move my R program to a rented parallel computing facility?
| 
| Moreover, at my PC level, I have a 4-core PC, is there anything we
| could do in R to speed up my CV programs?

Try this link:   http://lmgtfy.com/?q=parallel+computing+with+R

A survey paper on parallel computing with R by Schmidberger et al will be
fortcoming shortly in Journal of Statistical Software -- that is at
http://jstatsoft.org and a Google query will lead to preprints.

Also note that R has a support site network called 'CRAN' which contains so
called 'Task Views'. Amnong these you may find this one of interest:

   http://cran.r-project.org/web/views/HighPerformanceComputing.html

As to your initial question:  yes, people do use R on the Amazon service.

Dirk

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread Gabor Grothendieck
Here is a similar solution using strapply in gsubfn.
The pattern matches non-spaces, [^ ]+, followed by a space
followed by non-spaces followed by end-of-string, $.

 library(gsubfn)
 strapply(a, [^ ]+ [^ ]+$, simplify = c)
[1] L*H H% H* H%  L*H %  L*H %


On Fri, Jun 26, 2009 at 7:21 AM, Fredrik Karlssondargo...@gmail.com wrote:
 Dear list,

 Sorry for asking this very silly question on the list, but I seem to
 have made my life complicated by going into string manipulation in
 vectors.
 What I need is to get the last part of a sting (the two last tokens,
 separated by a space), and of course, this should be done for all
 strings in a vector, creating a new vector of exual size.

 So,

 a - c( %L H*L L*H H%, %L H* H%,  %L L*H %,   %L L*H % )

 should be made into a vector

  c( L*H H%, H* H%,  L*H %,   L*H % )

 I have tried strsplit, but it seems to produce a structure I cannot
 get to work in this context. Any ideas on how to solve this?

 Thankful for all the help I can get.

 /Fredrik


 --
 Life is like a trumpet - if you don't put anything into it, you don't
 get anything out of 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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Converting S-plus project folders to R

2009-06-26 Thread Bosley, David
Thanks for the reply. Sometimes R does crash (quits completely). Other times, 
it just hangs after giving an error box with some sort of exception code, even 
though it looks like it's still trying to execute the data.restore. 

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Friday, June 26, 2009 2:21 AM
To: Bosley, David
Cc: r-help@r-project.org
Subject: Re: [R] Converting S-plus project folders to R



dbosley wrote:
 I have many S-plus project folders that I need to convert to R workspaces.
 For the smaller project folders ( 200MB), using data.dump with 
 oldStyle = T and data.restore (in the foreign package) within R 
 seems to work fine. However, I have several project folders that are quite 
 large (~ 4GB).
 When I use this procedure to try to convert these project folders, R 
 always crashes when I perform the data.restore command. Does anyone 
 have any suggestions?

No suggestion, just to be sure:
I hope R gives an error message rather than a crash?

Best,
Uwe Ligges




 Thanks,
 Dave Bosley
 
 
 

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

2009-06-26 Thread Michael
I guess when we move to Amazon AWS,

we have to rewrite the whole R programs?

On Fri, Jun 26, 2009 at 8:05 AM, Dirk Eddelbuettele...@debian.org wrote:

 On 26 June 2009 at 07:40, Michael wrote:
 | Hi all,
 |
 | Lots of big IT companies are renting out their computing facilities.
 | Amazon has one such service. In my understanding, this will
 | dramatically improve the speed of my R program -- currently the cross
 | validation and model selection part is the bottle neck. It take a few
 | days to just finish optimal parameter tuning via CV.
 |
 | Could anybody shed some lights on this? Is it completely transparent
 | to move my R program to a rented parallel computing facility?
 |
 | Moreover, at my PC level, I have a 4-core PC, is there anything we
 | could do in R to speed up my CV programs?

 Try this link:   http://lmgtfy.com/?q=parallel+computing+with+R

 A survey paper on parallel computing with R by Schmidberger et al will be
 fortcoming shortly in Journal of Statistical Software -- that is at
 http://jstatsoft.org and a Google query will lead to preprints.

 Also note that R has a support site network called 'CRAN' which contains so
 called 'Task Views'. Amnong these you may find this one of interest:

   http://cran.r-project.org/web/views/HighPerformanceComputing.html

 As to your initial question:  yes, people do use R on the Amazon service.

 Dirk

 --
 Three out of two people have difficulties with fractions.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Modifying Sweave.sty to allow escapes with fancyvrb package in LaTeX

2009-06-26 Thread Frank E Harrell Jr

Dear Colleagues:

In an attempt to have things like # See page \pageref{this} inside 
comments in R code chunks I have modified Sweave.sty as below.  I have 
followed fancyvrb's manual with regard to the use of the commandchars 
argument.  But when compiling with LaTeX (using attached test file) I 
get a LaTeX error


(/usr/share/texmf-texlive/tex/latex/ae/t1aett.fd)
! Missing \endcsname inserted.
to be read again
   \global
l.25  } else y - 4

The line in question is 
\DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom=\lstset{fancyvrb=true},commandchars=\\\{\}}


Can anyone give me a pointer to how to properly change Sweave.sty to 
allow it to use fancyvrb in this way?  I am following the model in 
SweaveListingUtils for having Sweave use the listings package to do 
pretty-printing.


Thanks very much
Frank


Sweavel.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{Sweavel}{}

\RequirePackage{listings,ifthen,graphicx,fancyvrb,relsize}
\RequirePackage{ifthen}
\newboolean{swe...@gin}
\setboolean{swe...@gin}{true}
\newboolean{swe...@ae}
\setboolean{swe...@ae}{true}

\declareoption{nogin}{\setboolean{swe...@gin}{false}}
\declareoption{noae}{\setboolean{swe...@ae}{false}}
\ProcessOptions

\IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}

\ifthenelse{\boolean{swe...@gin}}{\setkeys{gin}{width=0.8\textwidth}}{}%
\ifthenelse{\boolean{swe...@ae}}{%
  \RequirePackage[T1]{fontenc}
  \RequirePackage{ae}
}{}%

%\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom=\lstset{fancyvrb=true},commandchars=\\\{\}}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}

\newenvironment{Schunk}{}{}

\newcommand{\Sconcordance}[1]{%
  \ifx\pdfoutput\undefined%
  \csname newcount\endcsname\pdfoutput\fi%
  \ifcase\pdfoutput\special{#1}%
  \else\immediate\pdfobj{#1}\fi}

--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University
\documentclass{article}
\usepackage[nogin]{Sweavel}
\begin{document}

\lstloadlanguages{R}
\lstset{language=R,fancyvrb=true,escapechar=`,%
 basicstyle=\smaller,commentstyle=\ttfamily\itshape\smaller,%
 keywordstyle=\bf,%
 showstringspaces=false,%
 xleftmargin=4ex,literate={-}{{$\leftarrow$}}2{-}{{$\twoheadleftarrow$}}2 {~}{{$\sim$}}1 {=}{{$\leq$}}2 {=}{{$\geq$}}2 {^}{{$^\wedge$}}1,%
 alsoother={$},alsoletter={.-},%
 otherkeywords={!,!=,~,$,*,\,\%/\%,\%*\%,\%\%,-,-,/}}%


This is page \pageref{this}.\label{this}
\begin{Schunk}
\begin{Sinput}
b - 4
a - b   # this is a test line
i - 2
if(i==3) {  # another line, for y^2 \pageref{this}
  y - 3^3
  z - 'this string'
  qqcat - y ~ pol(x,2)
 } else y - 4
\end{Sinput}
\end{Schunk}

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


[R] Determining if swap memory is turned off

2009-06-26 Thread Prof. John C Nash
In order to run some performance tests on optimization tools, I want to 
be able
to avoid the use of swap memory. In *nix systems, at least Linux ones, I 
can issue
a 'sudo swapoff -a' command and use just the RAM available.  If I don't 
do this, at
some point swap will be used, the disk goes ballistic and the machine is 
unresponsive
because it is thrashing data to the swap.  I suspect others have 
encountered this
too. Clearly I'd rather fail out than get into the thrashing situation. 
Generally I
prefer no swap -- memory is cheap enough that it is easier not to worry 
about these
sorts of woes. However, I'd like to make packages I'm developing 
bullet-proof.


What I need to know is if there are similar facilities on other 
platforms and how to
use them. I see memory.size and memory.limit for Windows -- making R 
less platform
independent -- and they seem to work on a WinXP virtual machine I have 
available.
However, I suspect that the memory.limit includes the swap. When I was 
running
Windoze, I tried valiantly to get the PageFile.sys killed and found it 
kept being set
up again despite following all the recommended steps. (I needed to avoid 
the
plaintext of an encrypted file being saved for me!)  I know nothing 
about Mac

swap and how to control it.

Advice welcome.  Below is a crude but self-contained example.

John Nash

## memcrash.R -- try to hit the wall with memory

cat(memcrash.R -- try to hit the wall\n)
cat(You should have swap turned off\n)
temp-readline(Do you?)
if (temp != y) stop(Fix swap)

for (j in 1:10) {
  n - 5^j
  cat(building matrix of order ,n,\n)
  A-matrix(nrow=n, ncol=n)
} # end loop

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


Re: [R] How to create separate plots for all combinations of some factors

2009-06-26 Thread David Winsemius


You did not supply any executable examples for testing, but perhaps  
you could benefit by looking at:


?expand.grid
?tapply

Those to split or index your data for all combinations of factors.

?mapply  # to do the plotting.


On Jun 26, 2009, at 9:54 AM, Lane, Jim wrote:


Hi, All

I have a data frame as follows:


data.class(tapes)

[1] data.frame

names(tapes)

[1] dateloc classdrp datascratch
reclaim total

Date is a date; loc, class and drp are factors; the rest are numerics.
I want to generate separate plots by date for the numeric variables  
for

all combinations of the factors. I tried to do this as follows:


by(tapes,list(loc,class,drp),plot(date,scratch))

Error in FUN(X[[1L]], ...) : could not find function FUN


Welcome to functional programming. Generally with R when you pass  
arguments, you need to create a function that receives those  
arguments, unless you happen to know that the proper objects would be  
coming to plot (and then you would not use (date, scratch).  Perhaps  
(ObWAG, untested, complete guesswork) :


by(tapes, list(loc,class,drp), function(x) { with(x,  
plot(date,scratch))} )


(I generally try tapply() first rather than using by().)

# What gets passed to the function is not named date and scratch  
in any case, but is named whatever you use in the function argument  
list. You need to pull that object apart  properly within the function.




As well as the error I get a single plot for all values of scratch and
date which is meaningless. What am I going wrong here?

For clarification what I want would be done is SAS as something like:

An executable example would have been a better way of getting an  
accurate answer.


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Converting S-plus project folders to R

2009-06-26 Thread Uwe Ligges



Bosley, David wrote:
Thanks for the reply. Sometimes R does crash (quits completely). Other times, it just hangs after giving an error box with some sort of exception code, even though it looks like it's still trying to execute the data.restore. 



- Hmmm, that should not happen. Can you generate some reproducible 
example (e.g. by generating some random numbers in some file?)?
- I guess we are talking about R-2.9.0? Today's release of R-2.9.1 won't 
fix it probably, but it is worth to try at least.


Best wishes,
Uwe Ligges









-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Friday, June 26, 2009 2:21 AM

To: Bosley, David
Cc: r-help@r-project.org
Subject: Re: [R] Converting S-plus project folders to R



dbosley wrote:

I have many S-plus project folders that I need to convert to R workspaces.
For the smaller project folders ( 200MB), using data.dump with 
oldStyle = T and data.restore (in the foreign package) within R 
seems to work fine. However, I have several project folders that are quite large (~ 4GB).
When I use this procedure to try to convert these project folders, R 
always crashes when I perform the data.restore command. Does anyone 
have any suggestions?


No suggestion, just to be sure:
I hope R gives an error message rather than a crash?

Best,
Uwe Ligges





Thanks,
Dave Bosley





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Determining if swap memory is turned off

2009-06-26 Thread John C Frain
On windows XP | start | Control Panel | System | Advanced |
Performance | Settings | Advanced | Virtual Memory | and select No
Pagefile.  I suspect Vista is similar.

John

2009/6/26 Prof. John C Nash nas...@uottawa.ca:
 In order to run some performance tests on optimization tools, I want to be
 able
 to avoid the use of swap memory. In *nix systems, at least Linux ones, I can
 issue
 a 'sudo swapoff -a' command and use just the RAM available.  If I don't do
 this, at
 some point swap will be used, the disk goes ballistic and the machine is
 unresponsive
 because it is thrashing data to the swap.  I suspect others have encountered
 this
 too. Clearly I'd rather fail out than get into the thrashing situation.
 Generally I
 prefer no swap -- memory is cheap enough that it is easier not to worry
 about these
 sorts of woes. However, I'd like to make packages I'm developing
 bullet-proof.

 What I need to know is if there are similar facilities on other platforms
 and how to
 use them. I see memory.size and memory.limit for Windows -- making R less
 platform
 independent -- and they seem to work on a WinXP virtual machine I have
 available.
 However, I suspect that the memory.limit includes the swap. When I was
 running
 Windoze, I tried valiantly to get the PageFile.sys killed and found it kept
 being set
 up again despite following all the recommended steps. (I needed to avoid the
 plaintext of an encrypted file being saved for me!)  I know nothing about
 Mac
 swap and how to control it.

 Advice welcome.  Below is a crude but self-contained example.

 John Nash

 ## memcrash.R -- try to hit the wall with memory

 cat(memcrash.R -- try to hit the wall\n)
 cat(You should have swap turned off\n)
 temp-readline(Do you?)
 if (temp != y) stop(Fix swap)

 for (j in 1:10) {
  n - 5^j
  cat(building matrix of order ,n,\n)
  A-matrix(nrow=n, ncol=n)
 } # end loop

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




-- 
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com

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


Re: [R] Placing text outside graph boundary

2009-06-26 Thread Greg Snow
If you are using base graphics:

Create an outer margin using something like: par(oma=c(0,0,3,0))

Then use mtext with the outer argument to place the text in the outer margin.

Hope this helps,

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


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Payam Minoofar
 Sent: Thursday, June 25, 2009 5:51 PM
 To: r-help@r-project.org
 Subject: [R] Placing text outside graph boundary
 
 Hello,
 
 Is possible to place a label on a multipanel figure outside the
 boundaries of any single one of the existing graphs in a panel?
 
 Specifically, I have a function that creates a panel with quartz() and
 then fills it with 6 graphs consisting of exactly the same plot for 6
 different groups. I would like to add one title for the entire figure
 at the top of the figure, but I cannot figure out how to do that
 without anchoring the title one of the graphs.
 
 Is it possible to do that?
 
 Thank you very much.
 
 Payam
 --
 Payam Minoofar, Ph.D.
 Scientist
 Meissner Filtration Products
 4181 Calle Tesoro
 Camarillo, CA 93012
 USA
 +1 805 388 9911
 +1 805 388 5948 fax
 payam.minoo...@meissner.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] GeoXp package

2009-06-26 Thread epoizot

Hi,

I resolved partially my problem, by adding the path of the grass library
where is located libgrass_I.so. So I add the following line to my .bashrc
file:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr.lib/grass/lib
Now, I can install and load rgdal and GeoXp libraries from R.

Thanks for your help.

Emmanuel Poizot



Roger Bivand wrote:
 
 The problem is that the binary Ubuntu install of gdal has not made sure
 that its dependencies are properly satisfied, so you'll need to do this
 manually. You can also make sure that the directory the GRASS libraries
 are found in is seen by ldconfig, either that or making sure that your
 running R sees LD_LIBRARY_PATH. This is a very detailed question, more
 suited to GRASS or GDAL lists, or R-sig-geo. You'll see when you have the
 solution because the GDAL utilities will work at the shell, for example
 gdalinfo --formats - I think that it doesn't at the moment.
 
 Roger Bivand
 
 
 epoizot wrote:
 
 
 
 Zeljko Vrba wrote:
 
 On Wed, Jun 10, 2009 at 08:21:06AM +0200, Poizot Emmanuel wrote:
 Error in fun(...) :
GDAL Error 1: libgrass_I.so: Ne peut ouvrir le fichier d'objet 
 partagé: Aucun fichier ou dossier de ce type  (sorry  for the french :)
 )
 
 
 It would have been far more useful had you translated the error message
 to
 english than to have apologized.
 
 Try doing
 
 export LD_LIBRARY_PATH=/path/to/dir/where/so/is/located
 
 before starting R from the shell.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 Hi,
 
 I tried this but with no success. Still enable to load the library rgdal
 and so GeoXp.
 This problem of for me now of high importance as I need to export
 interpolated data sets to grids. and rgdal allows that kind of
 operations.
 Regards
 
 
 

-- 
View this message in context: 
http://www.nabble.com/GeoXp-package-tp23964536p24219649.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] calculate AIC

2009-06-26 Thread rongrongily1215

Dear all,
 
I want to calculate AIC values of PLSR models. But I find that AIC and 
extractAIC functions in R could not be used to calculate AIC values of PLSR 
models. Now I write a section of code(below) to calculate it. But I don't known 
whether the result is right or not. If I am wrong, please give me some 
suggestions. Thanks a lot.
 
Rong Huang
 
data-data.frame(
y=c(-1,-1,-0.9,-0.88,-0.85,-0.41,-0.38,-0.04,0,0.1,0.23,0.3,0.32,
0.42,0.43,0.48,0.77,0.82,0.82,0.89,0.92,1.02,1.03,1.07,1.13,1.36,1.36,1.4,1.41,
1.55,1.84),
X1=c(-0.101,-0.1629,-0.1004,-0.4688,-0.1005,-0.1006,-0.098,-0.1478,-0.5146,
-0.1611,-0.1619,-0.1442,-0.2566,-0.1308,-0.16,-0.1634,-0.1623,-0.1469,-0.148,
-0.1628,-0.161,-0.1618,-0.1619,-0.1612,-0.1603,-0.161,-0.0938,-0.1616,-0.1628,
-0.1611,-0.076),
X2=c(-1.6953,-0.9866,-1.7833,-1.1233,-1.7022,-1.7001,-1.6017,-0.8415,-0.9508,
-0.9389,-1.0148,-0.861,-1.3785,-1.6241,-1.0883,-2.0914,-1.5157,-0.7912,-0.8419,
-0.8149,-0.7935,-0.8606,-0.8699,-0.7949,-0.7832,-0.824,-1.0875,-0.8313,-0.8149,
-0.7949,-1.0338),
X3=c(250.4,307.8,396.2,342.3,380.0,282.8,328.0,405.0,353.6,304.8,280.4,
353.6,328.8,328.8,328.3,216.2,328.5,320.6,372.6,340.2,332.0,321.6,321.6,
336.1,333.8,332.3,387.1,320.6,340.2,354.0,313.8),
X4=c(3.007,3.686,7.23,5.73,7.239,4.06 5,5.96,9.52,5.67,4.888,5.354,5.681,
7.372,7.372,6.811,4.654,6.18,6.994,8.47,8.466,6.113,6.695,6.695,7.269,6.205,
6.838,9.3,6.994,7.408,7.869,6.755),
X5=c(0.25,0.67,0.28,0.52,0.25,0.25,0.25,0.67,0.54,0.67,0.67,0.54,0.2,0.2,
0.67,0.67,0.67,0.67,0.67,0.67,0.67,0.67,0.67,0.67,0.67,0.67,1.08,0.67,0.67,
0.67,0.51)
)
ncomp-5
model-plsr(y~ 
.,data=data,ncomp=ncomp,validation=LOO,x=TRUE,y=TRUE,model=TRUE)
y-model$y
y.hat-model$fitted.value[,,ncomp]
residuals-model$residuals[,,ncomp]
sigmaML-sqrt(mean(residuals^2))
loglik-sum(dnorm(y,y.hat,sigmaML,log=T))
AIC--2*loglik+2*(ncomp+1)



  ___ 
  好玩贺卡等你发,邮箱贺卡全新上线! 

[[alternative HTML version deleted]]

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


[R] Deleting repeated rows

2009-06-26 Thread dreamworx

Appologies if this is a simple problem. I have a matrix which is 86x3 and
each row contains three integers. The problem I have is that some of the
rows of integers are repeated in other rows and I only wish to have one copy
of these rows.

Is there a function that I can use which will identify these repeated rows
and delete them from the matrix? I have searched for help with this problem
but the only function I have found is 'grep' which I'm not sure is of any
use.
-- 
View this message in context: 
http://www.nabble.com/Deleting-repeated-rows-tp24219989p24219989.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] parallel R?

2009-06-26 Thread cls59


losemind wrote:
 
 
 Moreover, at my PC level, I have a 4-core PC, is there anything we
 could do in R to speed up my CV programs?
 
 

I have seen one very nice paper that compared parallelization options for R:

http://epub.ub.uni-muenchen.de/8991/



losemind wrote:
 
 
 we have to rewrite the whole R programs?
 
 

I would like to disclaim that I haven't had the time to parallelize any of
my R scripts. That being said, I noticed that many of the packages above
implement parallelized versions of the apply() functions. Maybe taking
advantage of apply wherever possible is a way to ensure you can get some
benefit from parallelization without rewriting large portions of code.

Hope this helps!

-Charlie





-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/parallel-R--tp24221547p24223277.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] Optimization and Linear Programming in R

2009-06-26 Thread Greg Snow
One option is to use optim with method='SANN' which is simulate annealing.  The 
parameter vector is your vector of 0's and 1's, the fn argument is the function 
that you are trying to maximize with respect to the par vector (sounds like you 
have that pretty much worked out), then the gr argument is a function that will 
randomly change the par vector, here is where you put in the budget constraint, 
only do changes that meet the budget.

There are a couple of control parameters that you need to set, see the last set 
of examples to optim.

Hope this helps, 

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


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of chris.wil...@csiro.au
 Sent: Friday, June 26, 2009 1:24 AM
 To: r-help@r-project.org
 Subject: [R] Optimization and Linear Programming in R
 
 Dear List,
 
 My student and I are looking for an optimizer for a nonlinear
 optimization problem we are working on.  The problem we are working on
 is to try to pick a set of islands on which to eradicate rats for
 seabird conservation.  We have about 50 islands, each of which has some
 subset of 17 seabird species.  Rats are present on all islands, and
 will cause the seabirds to go extinct unless they are removed.
 Removing rats on islands costs different amounts depending on which
 island is chosen.  The decision problem is to pick the set of islands
 which will save the most seabird species within a given budget.  Here
 we use a nonlinear function to calculate the objective.  The function
 is the proportion of individuals of each species saved divided by the
 total number of birds, times the log of the same number, summed up
 across all of the islands that are chosen to be in the set that is
 saved.
 
 We have a single constraint, which is a budget in our case.  The
 contribution to this constraint is the product of the cost of each
 island times the decision vector.  Our decision variable is a binary
 vector (1 for removing rats from an island, 0 for not removing them).
 The objective function is as I have explained above.
 
 We are looking for a solver that can deal with this nonlinear integer
 programming problem.  We looked at a number of packages on the CRAN
 Task View: Optimization and Mathematical Programming, however, we have
 not been able to locate one that will suit our purposes.  The essential
 features are we need to be able to write a nonlinear function for the
 objective (hopefully a self contained one as we need to include some
 data in it), we need to be able to use a binary decision (or parameter)
 vector, and we need to be able to use a constraint.  Any suggestions as
 to packages or other software that will work for our problem would be
 much appreciated.
 
 Thanks,
 
 Chris Wilcox and Greg Thonier
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] R: Deleting repeated rows

2009-06-26 Thread Guazzetti Stefano
?unique
as an example
 mat-matrix(c(1,2,3,1,1,2,1,2,3,4,7,5), ncol=3, byrow=T)
 mat #rows 1 and 3 are identical
 [,1] [,2] [,3]
[1,]123
[2,]112
[3,]123
[4,]475

 unique(mat)
 [,1] [,2] [,3]
[1,]123
[2,]112
[3,]475

Stefano

-Messaggio originale-
Da: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org]per conto di dreamworx
Inviato: venerdì 26 giugno 2009 15.10
A: r-help@r-project.org
Oggetto: [R] Deleting repeated rows



Appologies if this is a simple problem. I have a matrix which is 86x3 and
each row contains three integers. The problem I have is that some of the
rows of integers are repeated in other rows and I only wish to have one copy
of these rows.

Is there a function that I can use which will identify these repeated rows
and delete them from the matrix? I have searched for help with this problem
but the only function I have found is 'grep' which I'm not sure is of any
use.
-- 
View this message in context: 
http://www.nabble.com/Deleting-repeated-rows-tp24219989p24219989.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.

Rispetta l'ambiente: Se non ti è necessario, non stampare questa mail.


Le informazioni contenute nel presente messaggio di posta elettronica e in 
ogni suo allegato sono da considerarsi riservate e il destinatario della email 
è l'unico autorizzato
ad usarle, copiarle e, sotto la propria responsabilità, divulgarle. Chiunque 
riceva questo messaggio per errore senza esserne il destinatario deve 
immediatamente rinviarlo
al mittente cancellando l'originale. Eventuali dati personali e sensibili 
contenuti nel presente messaggio e/o suoi allegati vanno trattati nel rispetto 
della normativa 
in materia di privacy ( DLGS n.196/'03).


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] panel.text and saving to pdf

2009-06-26 Thread Deepayan Sarkar
On Fri, Jun 26, 2009 at 1:53 AM, Dieter
Mennedieter.me...@menne-biomed.de wrote:
 Willem Vervoort w.vervoort at usyd.edu.au writes:

 I am not sure what I am doing wrong, but I have some unexplained behaviour
 when saving a lattice graph
 including text to a pdf file. The text seems to move around. It must have
 something to do with the way
 coordinates are set in devices other than jpg.

 today - format(Sys.Date(),%Y%m%d)

 x - runif(500)
 y - rnorm(500)

 foo - data.frame(x = x, y = y, z = rep(c(a,b),250))
 require(lattice)

 xyplot(x~y|z,data=foo)
 panel.text(370,470,silly graph,cex=1.2,font=2)

 Take this plot, resize its window: you will note that the silly graph moves
 relative to the graphics. The same is true for the higher-resolution pdf 
 output.

Yes, and that this even works at all is an accident of implementation.
Once a lattice graph is drawn, the only officially supported way to
add to it is to use trellis.focus() (or it's underlying grid
equivalent downViewport()), e.g.;

xyplot(1:10 ~ 1:10)
trellis.focus(toplevel) ## has coordinate system [0,1] x [0,1]
panel.text(0.5, 0.2, silly graph, cex = 1.2, font = 2)
trellis.unfocus()

If you know beforhand what you want to add, another option is to use
the page argument:

xyplot(1:10 ~ 1:10,
   page = function(n) {
   panel.text(0.5, 0.2, silly graph, cex = 1.2, font = 2)
   })

-Deepayan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 95% confidence interval coverage

2009-06-26 Thread Seunghee Baek
Hi R-users,
I would like to compute 95%CI coverage for each bootstrapped sample.
But, I don't know how to get 95% CI of estimate for each bootstrapped sample.
I could only see the estimate of each bootstrapped sample. 

Thanks,
Becky

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

2009-06-26 Thread David M Smith
On Fri, Jun 26, 2009 at 8:28 AM, Michaelcomtech@gmail.com wrote:
 I guess when we move to Amazon AWS,

 we have to rewrite the whole R programs?

Not necessarily. I use foreach (currently available in our REvolution
R Enterprise distribution and coming very soon to CRAN), and test out
the parallel code on my dual-core laptop. When I'm ready to run the
big job, I just launch (say) 10 instances on Amazon EC2, use
joinSleigh() to hook them together, and then just run the same foreach
code. Now the same code is running on 10 distributed machines, no
rewrite necessary.

There's an extended example using foreach here:
http://blog.revolution-computing.com/2009/05/parallelized-backtesting-with-foreach.html

# David Smith


-- 
David M Smith da...@revolution-computing.com
Director of Community, REvolution Computing www.revolution-computing.com
Tel: +1 (206) 577-4778 x3203 (San Francisco, USA)

Check out our upcoming events schedule at www.revolution-computing.com/events

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


[R] Indexing a list with a list

2009-06-26 Thread Greg Hirson

Dear list,

I have two lists: one with data and one with TRUE/FALSE values for data 
I want to further analyze (see example below). I have been able to use a 
for loop to extract the data that I want to keep, but think that there 
probably exists a way to do it without a loop. Any ideas?


#sample data
set.seed(100)
example = list(letters[1:10], letters[1:10], letters[1:10])
ind = list(as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1, 
10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)), 
as.logical(sample(0:1, 10, rep=TRUE)))


#loop method
for (i in 1:length(example)) print(example[[i]][ind[[i]]])

#result
[1] c g i
[1] a b e f j
[1] a b c d g h i


Thank you for the help.

Greg

--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

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


Re: [R] Indexing a list with a list

2009-06-26 Thread jim holtman
Your example has one more element in 'ind' than 'example' and that is what
causes the error, but this should be close.

 #sample data
 set.seed(100)
 example = list(letters[1:10], letters[1:10], letters[1:10])
 ind = list(as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)))

 mapply(function(a,b)a[b], example, ind)
[[1]]
[1] c g i

[[2]]
[1] a b e f j

[[3]]
[1] a b c d g h i

[[4]]
[1] b d e f h i

Warning message:
In mapply(function(a, b) a[b], example, ind) :
  longer argument not a multiple of length of shorter



On Fri, Jun 26, 2009 at 2:27 PM, Greg Hirson ghir...@ucdavis.edu wrote:

 Dear list,

 I have two lists: one with data and one with TRUE/FALSE values for data I
 want to further analyze (see example below). I have been able to use a for
 loop to extract the data that I want to keep, but think that there probably
 exists a way to do it without a loop. Any ideas?

 #sample data
 set.seed(100)
 example = list(letters[1:10], letters[1:10], letters[1:10])
 ind = list(as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1,
 10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)),
 as.logical(sample(0:1, 10, rep=TRUE)))

 #loop method
 for (i in 1:length(example)) print(example[[i]][ind[[i]]])

 #result
 [1] c g i
 [1] a b e f j
 [1] a b c d g h i


 Thank you for the help.

 Greg

 --
 Greg Hirson
 ghir...@ucdavis.edu

 Graduate Student
 Agricultural and Environmental Chemistry

 1106 Robert Mondavi Institute North
 One Shields Avenue
 Davis, CA 95616

 __
 R-help@r-project.org mailing list
 https://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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] Indexing a list with a list

2009-06-26 Thread Greg Hirson

Jim,

Thank you for your help. I had a feeling it would be an apply function 
that could help.


Kind regards,

Greg

jim holtman wrote:
Your example has one more element in 'ind' than 'example' and that is 
what causes the error, but this should be close.
 
 #sample data

 set.seed(100)
 example = list(letters[1:10], letters[1:10], letters[1:10])
 ind = list(as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)),
+as.logical(sample(0:1, 10, rep=TRUE)))
   
 mapply(function(a,b)a[b], example, ind)

[[1]]
[1] c g i

[[2]]
[1] a b e f j

[[3]]
[1] a b c d g h i

[[4]]
[1] b d e f h i

Warning message:
In mapply(function(a, b) a[b], example, ind) :
  longer argument not a multiple of length of shorter



On Fri, Jun 26, 2009 at 2:27 PM, Greg Hirson ghir...@ucdavis.edu 
mailto:ghir...@ucdavis.edu wrote:


Dear list,

I have two lists: one with data and one with TRUE/FALSE values for
data I want to further analyze (see example below). I have been
able to use a for loop to extract the data that I want to keep,
but think that there probably exists a way to do it without a
loop. Any ideas?

#sample data
set.seed(100)
example = list(letters[1:10], letters[1:10], letters[1:10])
ind = list(as.logical(sample(0:1, 10, rep=TRUE)),
as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1, 10,
rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)))

#loop method
for (i in 1:length(example)) print(example[[i]][ind[[i]]])

#result
[1] c g i
[1] a b e f j
[1] a b c d g h i


Thank you for the help.

Greg

-- 
Greg Hirson

ghir...@ucdavis.edu mailto:ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

__
R-help@r-project.org mailto:R-help@r-project.org mailing list
https://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.




--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?


--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

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


Re: [R] Indexing a list with a list

2009-06-26 Thread Henrique Dallazuanna
You have four elements in ind and three elements in example, then, try this

mapply('[', example, ind[1:3])

On Fri, Jun 26, 2009 at 3:27 PM, Greg Hirson ghir...@ucdavis.edu wrote:

 Dear list,

 I have two lists: one with data and one with TRUE/FALSE values for data I
 want to further analyze (see example below). I have been able to use a for
 loop to extract the data that I want to keep, but think that there probably
 exists a way to do it without a loop. Any ideas?

 #sample data
 set.seed(100)
 example = list(letters[1:10], letters[1:10], letters[1:10])
 ind = list(as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1,
 10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)),
 as.logical(sample(0:1, 10, rep=TRUE)))

 #loop method
 for (i in 1:length(example)) print(example[[i]][ind[[i]]])

 #result
 [1] c g i
 [1] a b e f j
 [1] a b c d g h i


 Thank you for the help.

 Greg

 --
 Greg Hirson
 ghir...@ucdavis.edu

 Graduate Student
 Agricultural and Environmental Chemistry

 1106 Robert Mondavi Institute North
 One Shields Avenue
 Davis, CA 95616

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




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

[[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] (performance) time in Windows vs Linux

2009-06-26 Thread Cézar Freitas
Hi, all.

I began to migrate my R codes from Windows to Linux and surprised me
with an old question. I simplified the problem and made a little test to 
compare times at same
computer and the Linux time is worse (not so little) than Windows time:
28 vs 53 seconds.

I make an example (below) to facilitate all to see the difference.
I also build from source (it's my first time) a version of R to compare with 
the distributed (compiled) R version. The times are similar to the other Linux 
version.

I supposed R on Linux should be faster (32 and 64 bit) than windows version. Is 
this difference because 64 bit R version is slower than 32 bits one? I started 
the machine in both sittuations and checked free memory.

Tecnichal details:
Machine: Intel Core 2 Duo DDR2 4 Gb RAM
Windows version: XP Professional - 32 bits
R version: 2.9* binaries
Linux version: Ubuntu 8* (Hardy) - 64 bits
R version: 2.9* binaries and 2.9* compiled from source

Thanks to all,
Cezar Freitas

 #code
 N = 5
 n = 15000
 
 #makes data
 dad = as.data.frame(cbind(sample(N,N,replace=FALSE), rpois(N,30)))
 names(dad) = c(id,age)
 
 aux = as.data.frame(cbind(sample(N,n,replace=FALSE), round(runif(n),4)))
 names(aux) = c(id,score)
 
 #calculates time
 set.seed(790) #to be equal to everyone
 system.time({
   dad$score = 0
   subdad = subset(dad, id%in%aux$id)
   for(k in 1:(dim(subdad)[1])){
     temp = aux$score[aux$id==subdad$id[k]]
     if(length(temp)) subdad$score[k] = temp
   }
 })
 
 #windows time
 #   user  system elapsed
 #  27.81    0.00   27.82
 
 #linux usual compilation time
 #   user  system elapsed
 # 52.635   0.016  52.748
 
 #linux (my compilation) time
 #   user  system elapsed
 # 52.567   0.016  52.588
 #==END OF CODE




  

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.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] 50993 point distance matrix, too big to as.matrix, looking for another way to calculate point-level summary

2009-06-26 Thread leif olson
Hello, Im working on a 50933 point count bird abundance dataset. I've
succeeded in calculating a distance matrix for this entire set, but I don't
have sufficient memory to convert this to a matrix, as below...
abun.dist - dist(abun.mat[1:50993,1:235)
test - rowMeans(as.matrix(abun.dist))
Error in matrix(0, size, size) : too many elements specified

ive been able to run a hclust() clustering procedure, due to the fact that
hclust() makes a call to fortran code, but id like to be able to generate a
calinski index for each of the clusters to assess the validity.
Unfortunately, all the validation routines I have found are all native R
code, and usually call as.matrix, resulting in the same error i receive
above.
What I'd like to figure out is how to just go through, one point at a time,
and calculate the values i need. But I've been unable to come up with code
to call the correct positions in the dist vector, can anyone suggest some
code that might do this? Thanks...

...leif

-- 

-- 
First they ignore you, then they laugh at you, then they fight you, then you
win
- Mohandas Gandhi

[[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] Automatically placing a legend in an area with the most white space...

2009-06-26 Thread Jason Rupert


At one point I believe I heard of an R package that would automatically find 
the most empty space in a plot, and then that answer could then be used to 
intelligently place a legend.  

I would like to try to apply that R package to the contrived example shown 
below, so thank you for any hints or tips that can be provided.   

x = seq(0, 1000, by = 1)
y1_vals-rnorm(1000, mean = 0, sd = 50)
y2_vals-rnorm(1000, mean = 25, sd = 40)
y3_vals-rnorm(1000, mean = 115, sd = 40)

plot(x_vals, y1_vals, pch=22, col=dark red, bg = dark red, cex =0.3)
points(x_vals, y2_vals, pch=22, col=dark blue, bg = dark blue, cex =0.3)
points(x_vals, y3_vals, pch=22, col=dark green, bg = dark green, cex =0.3)

abline(h=0, col=dark red, lwd=1.5, lty=6)
abline(h=25, col=dark blue, lwd=1.5, lty=6)
abline(h=115, col=dark green, lwd=1.5, lty=6)

legend(topright, c(Best Guess 1 , Best Guess 2, Best Guess 3), 
bg=white, lwd = 2, title = Randomness:)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] (performance) time in Windows vs Linux

2009-06-26 Thread Zeljko Vrba
On Fri, Jun 26, 2009 at 12:23:35PM -0700, Cézar Freitas wrote:
 
 I supposed R on Linux should be faster (32 and 64 bit) than windows version. 
 Is this difference because 64 bit R version is slower than 32 bits one? I 
 started the machine in both sittuations and checked free memory.
 
I suspect that the compiler is to blame.  Download Intel's C and C++ compiler
for linux (it is free for personal use), try to compile R with it, and see
what results you get (and report them here!).  Of course, if you have the
time and are willing to tinker :)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] gradient fill of a grid.polygon

2009-06-26 Thread baptiste auguie
Dear list,

Following a recent enquiry, I've been playing with the idea of creating a
colour gradient for a polygon, using the Grid package. The idea is to draw a
number of stripes of different colours, using the grid.clip function. Below
is my current attempt at this,


library(grid)

rotate.polygon - function(g, angle=0){ # utility function, works fine

matR - matrix(c(cos(angle), -sin(angle), sin(angle), cos(angle)),
nrow = 2)
gravity.x = unit(mean(g$x),npc)
gravity.y = unit(mean(g$y),npc)

x.center = convertX(g$x - gravity.x ,npc,TRUE)
y.center = convertY(g$y - gravity.y ,npc,TRUE)

new.xy - matrix(c(x.center, y.center),
ncol=2) %*% matR

editGrob(g, x=unit(new.xy[,1],npc) + gravity.x,
y=unit(new.xy[,2],npc) + gravity.y)
}


gradient.polygon - function(g, n=100,
 cols=colorRampPalette(c(#E41A1C, #377EB8, #4DAF4A, #984EA3))(n),
 alpha=0.5,
 stripe=FALSE, angle=0){

vp = viewport(angle = angle)
g =  rotate.polygon(g, - angle)

gx - grobWidth(g)
gy - grobHeight(g)

dx - unit(convertX(gx, npc, valueOnly = TRUE)/(n-1), npc) # width of
the stripes

startx - min(g$x)
starty - min(g$y)


for(ii in seq(1, n)){
 grid.clip(x= startx + (ii-1) * dx , y=starty,
   width= 1.0*dx, # fudge factor of 1.2 seems needed to overlap well
   height=gy,
   just=bottom)
if(stripe){
  if(ii%%2)# plotting only every other slice
grid.draw(editGrob(g, gp=gpar(fill=cols[ii], col=cols[ii], alpha=alpha)))
}else{
grid.draw(editGrob(g, gp=gpar(fill=cols[ii], col=cols[ii], alpha=alpha)))
}
}

}

g -
polygonGrob(x=c(0, 0.5, 1), y=c(0.5, 1, 0.5), gp=gpar(fill=NA,
col=grey90))
g2 -
polygonGrob(x=c(0, 0.5, 1), y=c(0.5, 0, 0.5), gp=gpar(fill=NA,
col=grey90))

grid.rect(gp=gpar(fill=black))
grid.rect(y=1, gp=gpar(fill=white))
gradient.polygon(g)
gradient.polygon(g2)


Now, I have a (large) number of issues here,

1) the stripes don't exactly blend well, at least on the quartz device. I
can add a fudge factor for their width but then the overlap might be
visible if alpha is not unity.

2) a serious flaw is the rotation that's not working at the moment. My
initial thought was to rotate the grob (triangle here), paint it with the
gradient, and plot the result in a rotated viewport with opposite rotation
angle. I'm still hopeful it might work, but see 3).

3) each stripe is directly plotted, as opposed to saved as a grob. I tried
to use either a gList or a gTree to store the output of the for loop, but I
didn't understand why the result wouldn't appear on screen with grid.draw.
What's the best structure to hold together these different slices? It is
presumably this object that I should be plotting eventually in the right
orientation.


Sorry for the length of this email, I hope it's clear with the code above.


Best regards,

baptiste

[[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] Heteroskedasticity and Autocorrelation in SemiPar package

2009-06-26 Thread Susan Chen
Hi all,

Does anyone know how to report heteroskedasticity and 
autocorrelation-consistent standard errors when using the spm command in 
SemiPar package? Suppose the original command is 
sp1-spm(y~x1+x2+f(x3), random=~1,group=id)

Any suggestion would be greatly appreciated.

Thanks,
Susan


  
[[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] Alternate error structures in lme4?

2009-06-26 Thread bamsel

Hi R users, 

The nlme library enabled several alternate error structures useful for
longitudinal or repeated-measures data. For example, a continuous AR(1)
process:

model_2 = update(model_1, correlation = corCAR1(form = ~ time | subject))

Does anybody know if this is available in lme4?

Thank you
Ben
-- 
View this message in context: 
http://www.nabble.com/Alternate-error-structures-in-lme4--tp24226643p24226643.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] (performance) time in Windows vs Linux

2009-06-26 Thread milton ruser
Hi there,

I have both systems on a DELL 64bit machine.
I compiled R 2.9.0 on both systems, to get 64bits capability.
Surpriselly, on Linux (Ubuntu with I installed 3 month ago) I spent 41s to
run the same test you did, and less time (35s) under Vista. In fact I had
noticed that I not have gained time when running under linux (I had done
jobs that run for several days). But somethings I gain with memory
managment, because for some programs or steps, windows say that memory is
full, while Linux run up to the end of the job.

good luck

milton

On Fri, Jun 26, 2009 at 4:01 PM, Zeljko Vrba zv...@ifi.uio.no wrote:

 On Fri, Jun 26, 2009 at 12:23:35PM -0700, Cézar Freitas wrote:
 
  I supposed R on Linux should be faster (32 and 64 bit) than windows
 version. Is this difference because 64 bit R version is slower than 32 bits
 one? I started the machine in both sittuations and checked free memory.
 
 I suspect that the compiler is to blame.  Download Intel's C and C++
 compiler
 for linux (it is free for personal use), try to compile R with it, and see
 what results you get (and report them here!).  Of course, if you have the
 time and are willing to tinker :)

 __
 R-help@r-project.org mailing list
 https://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-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] (performance) time in Windows vs Linux

2009-06-26 Thread Uwe Ligges
Yes, under 64-bit it is sometimes slower and it highly depends on the 
problem and the compiler you have. Note also that nobody managed to get 
a 64-bit Windows R binary compiled with gcc so far.
Remember, 10 years ago there was the SUN Ultra Sparc III and above 
architecture, and gcc was known to produce extremely inefficient 64-bit 
binaries for that platform. Things got somewhat better in the meantime.


With the tests I used 32-bit R compiled with gcc was roughly 10% slower 
on Windows than under Linux - but as I said, it depends on the problem. 
Trying loops versus matrix operations is a way to specify a two very 
different problems, for example.


Uwe Ligges





Cézar Freitas wrote:

Hi, all.

I began to migrate my R codes from Windows to Linux and surprised me
with an old question. I simplified the problem and made a little test to 
compare times at same
computer and the Linux time is worse (not so little) than Windows time:
28 vs 53 seconds.

I make an example (below) to facilitate all to see the difference.
I also build from source (it's my first time) a version of R to compare with 
the distributed (compiled) R version. The times are similar to the other Linux 
version.

I supposed R on Linux should be faster (32 and 64 bit) than windows version. Is 
this difference because 64 bit R version is slower than 32 bits one? I started 
the machine in both sittuations and checked free memory.

Tecnichal details:
Machine: Intel Core 2 Duo DDR2 4 Gb RAM
Windows version: XP Professional - 32 bits
R version: 2.9* binaries
Linux version: Ubuntu 8* (Hardy) - 64 bits
R version: 2.9* binaries and 2.9* compiled from source

Thanks to all,
Cezar Freitas

 #code
 N = 5
 n = 15000
 
 #makes data

 dad = as.data.frame(cbind(sample(N,N,replace=FALSE), rpois(N,30)))
 names(dad) = c(id,age)
 
 aux = as.data.frame(cbind(sample(N,n,replace=FALSE), round(runif(n),4)))

 names(aux) = c(id,score)
 
 #calculates time

 set.seed(790) #to be equal to everyone
 system.time({
   dad$score = 0
   subdad = subset(dad, id%in%aux$id)
   for(k in 1:(dim(subdad)[1])){
 temp = aux$score[aux$id==subdad$id[k]]
 if(length(temp)) subdad$score[k] = temp
   }
 })
 
 #windows time

 #   user  system elapsed
 #  27.810.00   27.82
 
 #linux usual compilation time

 #   user  system elapsed
 # 52.635   0.016  52.748
 
 #linux (my compilation) time

 #   user  system elapsed
 # 52.567   0.016  52.588
 #==END OF CODE




  

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] How to read a specific dataset, not the entire data, from HDF5?

2009-06-26 Thread Daehyok Shin
Hi. Recently I am working for  a project to generate massive numeric data.
After storing them in HDF5 using PyTables, we are trying to use R for
data analysis and visualisation.
Surprising to me, however, I could not find a R package to allow the
reading of a specific dataset (or its slide) in a HDF5 file.
I found I can read and write only the entire data using hdf5 package
and I could not locate rhdf5 in bioconductor.
Each dataset is huge, so selecting a specific dataset is a mandatory
function for my project.
Could you give me a hint for the solution? Thanks.

-- 
DH

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread Miguel Bernal
Dear R-users, 

I am trying to develop a function that takes another function as an argument, 
changes its default values and returns a list of things, among which the 
initial function with its default arguments changed. An example of what i 
will like to obtain below:

## initial function

myfun - function(x, a=19, b=21){ return(a * x + b) }

## this is the function i will like to create 
## (does not work as it is written here)

mysecond.fun - function(a, b, c = myfun(a=2, b=15)){
return(list(a=a, b=b c=c))
}

So I would be able to call:

mysecond.fun$c(x=12)

And this will be equivalent of calling:

myfun(x=12, a=2, b=15 ) ## i.e. i have changed the default values of myfun and
## stored it in a new function mysecond.fun$c

Any help will be greatly appreciated!

Miguel Bernal.



Current address:
Ocean Modeling group,   
Institute of Marine and Coastal Sciences
University of Rutgers   
71 Dudley Road, New Brusnkwick, 
New Jersey 08901, USA   
email: mber...@marine.rutgers.edu
phone: +1 732 932 3692  
Fax: +1 732 932 8578
-
Permanent address:
Instituto Español de Oceanografía   
Centro Oceanográfico de Cádiz
Puerto Pesquero, Muelle de Levante, s/n
Apdo. 2609, 11006 Cádiz, Spain
email: miguel.ber...@cd.ieo.es
phone: +34 956 294189
Fax: +34 956 294232

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


Re: [R] changing the loss function in the logistic regression?

2009-06-26 Thread Michael
Hi Frank,

Thanks for your help!

I want to incorporate lift score as the optimization objective. How to
do that in logistic regression?

Thanks!

On Fri, Jun 26, 2009 at 7:47 AM, Frank E Harrell
Jrf.harr...@vanderbilt.edu wrote:
 Michael wrote:

 Hi all,

 Is there a way to change the loss function in the logistic regression?
 Or we could provide a customized loss function in the logistic
 regression so we could use that loss function in the Cross Validation
 in logistic regression?

 Thanks a lot!

 The goal is to use a loss function that yields optimality, with a sensible
 definition of optimality.  For many purposes, maximum likelihood or
 penalized maximum likelihood is optimum.  So don't change the optimality
 criteria just because you are cross-validating a different measure.

 By the way, it's often not a good idea to cross-validate a different
 measure.  At least the accuracy index should be information-preserving.
  Deviance, log-likelihood, and AIC are your friends.

 Frank

 --
 Frank E Harrell Jr   Professor and Chair           School of Medicine
                     Department of Biostatistics   Vanderbilt University


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


[R] Where can I find information on how to subsample a time series?

2009-06-26 Thread Ted Byers
I suspect I'm looking in the wrong places, so guidance to the relevant
documentation would be as welcome as a little code snippet.

I have time series data stored in a MySQL database.  There is the usual DATE
field, along with a double precision number: there are daily values
(including only normal working days: Monday through Friday).  I actually
have to do a couple things here.  Because of how the result is to be used, I
need to first create two time series.  The first is the delta between 22
working days, and the second is the delta between 66 working days.  I have
hundreds of these datasets, and some go back 30 years.  I need to estimate
the correlation between 22 day deltas (i.e. is the delta for one month
correlated with that of the previous month) and between the 22 day delta and
the 66 day delta that ends the day before the the first day of the 22 day
delta.  However, I KNOW the statistical properties of the time series are
not constant (so the usual assumptions do not apply to the entire series).
Therefore, I want to subsample finely enough to get a reasonably sensible
correlation and examine how that changes through time.  (There are no tests
of significance here: I just want to explore just how much the properties of
these series change through time).

I have C++ code, admittedly not written particularly efficiently, that does
this.  The question is, is it possible to do this reasonably efficiently
using R?

Thanks

Ted

[[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] Heteroskedasticity and Autocorrelation in SemiPar package

2009-06-26 Thread Liviu Andronic
On Fri, Jun 26, 2009 at 10:11 PM, Susan Chensuen...@yahoo.com wrote:
 Does anyone know how to report heteroskedasticity and 
 autocorrelation-consistent standard errors when using the spm command in 
 SemiPar package? Suppose the original command is
 sp1-spm(y~x1+x2+f(x3), random=~1,group=id)

There's HAC() in library(gmm), which is a modification from the
sandwich::vcovHAC(), designed to accept as input any vectors (and not
only specific objects, such as lm).

The sandwich::vcovHAC() can also be relatively easily extended to
accept other fits as input (not only lm or glm, for example), but this
would require some understanding of the internals of both SemiPar and
sandwich. You might enquire if the author of SemiPar is interested in
adding such functionality. For technical details, check the first
vignette of sandwich.

Once you get HAC covariance matrix for your fit, you can use either
lmtest::coeftest or library(car) to obtain the HAC std errs.
Liviu

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


Re: [R] changing the loss function in the logistic regression?

2009-06-26 Thread Frank E Harrell Jr

Michael wrote:

Hi Frank,

Thanks for your help!

I want to incorporate lift score as the optimization objective. How to
do that in logistic regression?

Thanks!


Please re-read my note.

Models should be fitted using proper scoring rules.  Otherwise the 
resulting fit is bogus.


Thanks
Frank



On Fri, Jun 26, 2009 at 7:47 AM, Frank E Harrell
Jrf.harr...@vanderbilt.edu wrote:

Michael wrote:

Hi all,

Is there a way to change the loss function in the logistic regression?
Or we could provide a customized loss function in the logistic
regression so we could use that loss function in the Cross Validation
in logistic regression?

Thanks a lot!

The goal is to use a loss function that yields optimality, with a sensible
definition of optimality.  For many purposes, maximum likelihood or
penalized maximum likelihood is optimum.  So don't change the optimality
criteria just because you are cross-validating a different measure.

By the way, it's often not a good idea to cross-validate a different
measure.  At least the accuracy index should be information-preserving.
 Deviance, log-likelihood, and AIC are your friends.

Frank

--
Frank E Harrell Jr   Professor and Chair   School of Medicine
Department of Biostatistics   Vanderbilt University






--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

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


[R] correspondence analysis question

2009-06-26 Thread Data Analytics Corp.

Hi,

I have a matrix of 31 rows and 8 columns.  The rows represent attributes 
of a product and the columns represent segments in a market.  The cell 
values are utilities scaled so that the sum of the utilities across 
attributes for a segment equals 100.  I want to find which attributes 
are closely related to which segments.  I ran a CA on the matrix and got 
an interesting plot.  For example, attributes 4 and 6 are close to 
segment 1 and rows 1 and 2 are close to segment 7.  Is there any way 
to calculate a measure of closeness from the ca output so that I can 
develop groups of attributes for each segment?  I'd like to be able to 
have a list of attributes for each segment and a weight on how important 
(close?) an attribute is for that segment.  Any suggestions?


Thanks,

Walt



--


Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ 08536

(V) 609-936-8999
(F) 609-936-3733
dataanalyt...@earthlink.net
www.dataanalyticscorp.com

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


Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Peter Dalgaard

Craig P. Pyrame wrote:

Stavros Macrakis wrote:

It gives me a headache, too!  I think you'll have to wait for a more
expert user than me to supply explanations of these behaviors and
their rationales.
  


Thanks, Stavros.  I hope someone with expertise will shed more light on 
this, and in the meantime I'll try to learn more from the manuals.




Well first, you (and others) should shake any bees relating to raw 
objects out of your bonnet. The raw type should be viewed as an add-on 
enabling access to low-level data structures, not as a fundamental data 
type in R. The original data modes are logical, numeric, character, with 
upwards coercion rules (and some further twiddles for storage modes of 
numerics).


One particular aspect is that in the original system, logical works as a 
wild card type that can be coerced to all the others (hence NA has 
mode logical, which causes some confusion at first notice).





Why does this fail:

  r = as.raw(TRUE)
  ifelse(TRUE, r, r) = error

This gives an error which I take for saying that raw cannot be coerced
to logical, but yes it can:

  as.logical(r) = TRUE



Wrong. Or rather, irrelevant. The error is

 ifelse(TRUE,r,r)
Error in ans[test  !nas] - rep(yes, length.out = length(ans))[test   :
  incompatible types (from raw to logical) in subassignment type fix

Notice subassignment type fix. This corresponds to this sort of operation

 r - as.raw(TRUE)
 x - TRUE
 x[1] - r
Error in x[1] - r :
  incompatible types (from raw to logical) in subassignment type fix

Now, notice that when the coercion is bigger to smaller the fix is to 
coerce on the left side


 y - rep(TRUE,5)
 y[1] - 5
 y
[1] 5 1 1 1 1


So the thing that might be expected here would be that x be coerced to 
raw before the assignment, but this is not implemented. I.e. you could 
have had the effect of.


 x - as.raw(x)
 x[1] - r
 x
[1] 01

This is designed not to happen automatically. I didn't write the code 
but I suppose one possible reason is that the raw mode does not allow 
missing values (or negative numbers for that matter, everything is 0-255).


It also cuts the other way - no subassignment fixes are defined for raw:

 x - as.raw(1:10)
 x[3] - NA
Error in x[3] - NA :
  incompatible types (from logical to raw) in subassignment type fix
 x[3] - TRUE
Error in x[3] - TRUE :
  incompatible types (from logical to raw) in subassignment type fix
 x[3] - 4
Error in x[3] - 4 :
  incompatible types (from double to raw) in subassignment type fix
 x[3] - 4L
Error in x[3] - 4L :
  incompatible types (from integer to raw) in subassignment type fix






and raw can even be used as the condition vector in ifelse:

  ifelse(r, 1, 2) = 1


Yes, but that's a different issue. Ifelse has the C language convention 
that anything nonzero is TRUE.


 ifelse(pi,2,1)
[1] 2



--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

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


Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread David Winsemius


On Jun 26, 2009, at 12:52 PM, Miguel Bernal wrote:


Dear R-users,

I am trying to develop a function that takes another function as an  
argument,
changes its default values and returns a list of things, among which  
the
initial function with its default arguments changed. An example of  
what i

will like to obtain below:

## initial function

myfun - function(x, a=19, b=21){ return(a * x + b) }

## this is the function i will like to create
## (does not work as it is written here)

mysecond.fun - function(a, b, c = myfun(a=2, b=15)){

 ^^
Two things: a) I doubt that is possible in that manner and b) you  
couldn't possibly get myfun to work, because you are not passing it  
the correct number of arguments.




return(list(a=a, b=b c=c))

 ^
Third concern, missing comma.

}

So I would be able to call:

mysecond.fun$c(x=12)


Not in this language. Maybe in some other. Maybe you are in the wrong  
help list? You should instead provide a specification of the inputs  
and outputs you expect rather than a hashed up view of how you think R  
should accept functional arguments.


Perhaps something like this:

myfun - function(x, a=19, b=21){ return(a * x + b) }
mysecond.fun - function(x, a, b){ c - myfun(x, a=2, b=15)
  list(a=a, b=b, c=c)  }

 mysecond.fun(x=12, 2 , 3)
$a
[1] 2

$b
[1] 3

$c
[1] 39

 # c= 2 * 12 + 15



And this will be equivalent of calling:

myfun(x=12, a=2, b=15 ) ## i.e. i have changed the default values of  
myfun and

## stored it in a new function mysecond.fun$c

Any help will be greatly appreciated!

Miguel Bernal.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Alternate error structures in lme4?

2009-06-26 Thread Ben Bolker



bamsel wrote:
 
 Hi R users, 
 
 The nlme library enabled several alternate error structures useful for
 longitudinal or repeated-measures data. For example, a continuous AR(1)
 process:
 
 model_2 = update(model_1, correlation = corCAR1(form = ~ time | subject))
 
 Does anybody know if this is available in lme4?
 
 

It's not, and probably won't be any time soon; the author (Doug Bates)
has stated that it's not at the top of his list, and he's a very busy guy.
(1) Is there a reason that you can't use nlme?  (2) Further messages
should probably be directed to the r-sig-mixed-mod...@r-project.org
mailing list.

  Ben Bolker

-- 
View this message in context: 
http://www.nabble.com/Alternate-error-structures-in-lme4--tp24226643p24227667.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] ANOVA with means and SDs as input

2009-06-26 Thread Emmanuel Charpentier
Le jeudi 25 juin 2009 à 12:15 +0200, Sebastian Stegmann a écrit :
 Dear R-community,
 
 I'm struggling with a paper that reports only fragmented results of a
 2by2by3 experimental design. However, Means and SDs for all cells are given.
 
 Does anyone know a package/function that helps computing an ANOVA with only
 Means and SDs as input (resulting in some sort of effect size and
 significance test)?
 
 The reason why I'm interested is simple: I'm conducting a meta-analysis. If
 I included only what the authors would like to show the world, the results
 would be somewhat biased...

What you aim to do is not, as far as I can tell, possible using
already-programmed solutions in R packages. Some packages offer very
close solutions (e. g. lme()) but lack some necessary options (e. g. the
ability to fix intra-level variance in lme() : varFixed() works as
documented, not as what its name suggests...).

Why not use some established meta-analysis package such as meta or
rmeta ? You may have to recompute some variances or effect sizes, but it
can usually be done.

If you aim to go a bit farther (i. e. more than 2-groups comparisons),
the newly-released metafor package seems quite interesting. Wolfgang
Viechtbauer aimed to offer a tool for meta-regression, and the current
stage of the package (0.5.something IIRC) seems to be quite useable, if
somewhat counter-intuitive in places.

I'd recommend to have a look at it. WV didn't think useful to include
the vignettes and documentation for mima(), predecessor of metafor,
which explains quite nicely the motivation and algorithms he used. Too
bad... However, this documentation is still available on his Web site.
Be aware that the current main interface to the rma() function
(workhorse of the package) does not (yet ?) follow the usual format for
regression-like functions common to many R packages (the (formula, data,
subset, etc...) format). For example, you may make meta-regression, but
you'll have to code the model matrix yourself. Similarly, the necessary
bricks for (e. g.) indirect comparisons are here, but you'll have to
build them yourself (bring your wheelbarrow an some mortar...).

An alternative to be seriously considered : Bayesian modeling.
Meta-analysis is one of the rare medical domains where journal reviewers
won't immediately reject a paper at the sight of the B***sian word... As
far as I know, psychological journals are not as asinine. Here again,
some manual work will be in order. Some tutorial material is readily
available (google Bayesian meta analysis tutorial, which should lead
you to the various Statistics in Medicine tutorials, among other
things).

 I've combed through the web and my various books on R, but it's not that
 easy to find. Or is it?

Variance analysis through manual decomposition of sum of squares ?
Hugh ... I did that when I first learned anova(so long a time ago that I
am uncomfortable to think of it. In these times, even a pocket
calculator was too expensive for a random student (therefore forbidden
in exams), and I learned to cope with slide rule...). Tiring and messy.
Furthermore, manual algorithms (i. e. simple, non-iterative
algorithms) exists only for the simplest (e. g. one-way anova) or ideal
(e. g. balanced two-way anova with equal group sizes) cases ;
furthermore, modern critiques of the bases of such works cast some
doubts on their foundations (e. g. random- and mixed-effect anova)...

Therefore, the art is fast forgotten, if not totally lost. If you
insist, I might try to unearth my copy of Winer's handbook (ca. 1959)
and look up specific questions.

HTH,

Emmanuel Charpentier

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


Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread baptiste auguie
Is this what you want?

myfun - function(x, a=19, b=21){ return(a * x + b) }

mysecond.fun - function(a, b, cc=myfun, cc.args=list(a=2,b=15) ){
list(a=a, b=b, cc = function(x) cc(x, cc.args$a, cc.args$b))
}

mysecond.fun(a=1,b=2)$cc(x=12)

It may be that you're after a Curry (*) function, as in,

Curry -  # from roxygen
function (f, ..., .left=TRUE)
{
.orig = list(...)
function(...){
if(.left) {args - c(.orig, list(...))} else {args - c(list(...),
.orig)}
 do.call(f, args)
}
}

I believe there are some recent discussions on currying in the archives.

(*): http://en.wikipedia.org/wiki/Currying


HTH,

baptiste





2009/6/26 Miguel Bernal mber...@marine.rutgers.edu

 Dear R-users,

 I am trying to develop a function that takes another function as an
 argument,
 changes its default values and returns a list of things, among which the
 initial function with its default arguments changed. An example of what i
 will like to obtain below:

 ## initial function

 myfun - function(x, a=19, b=21){ return(a * x + b) }

 ## this is the function i will like to create
 ## (does not work as it is written here)

 mysecond.fun - function(a, b, c = myfun(a=2, b=15)){
 return(list(a=a, b=b c=c))
 }

 So I would be able to call:

 mysecond.fun$c(x=12)

 And this will be equivalent of calling:

 myfun(x=12, a=2, b=15 ) ## i.e. i have changed the default values of myfun
 and
## stored it in a new function mysecond.fun$c

 Any help will be greatly appreciated!

 Miguel Bernal.


 
 Current address:
 Ocean Modeling group,
 Institute of Marine and Coastal Sciences
 University of Rutgers
 71 Dudley Road, New Brusnkwick,
 New Jersey 08901, USA
 email: mber...@marine.rutgers.edu
 phone: +1 732 932 3692
 Fax: +1 732 932 8578
 -
 Permanent address:
 Instituto Español de Oceanografía
 Centro Oceanográfico de Cádiz
 Puerto Pesquero, Muelle de Levante, s/n
 Apdo. 2609, 11006 Cádiz, Spain
 email: miguel.ber...@cd.ieo.es
 phone: +34 956 294189
 Fax: +34 956 294232

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




-- 

_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
__

[[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] Where can I find information on how to subsample a time series?

2009-06-26 Thread Whit Armstrong
assuming you pull the data you want into x and y:

w...@ubuntu:~$ R
 library(fts)
 x - fts()
 y - fts()
 xy.cor.200 - moving.cor(x,y,200)
 tail(xy.cor.200)
 [,1]
2012-03-12 -0.3009635
2012-03-13 -0.2923489
2012-03-14 -0.2824015
2012-03-15 -0.2662689
2012-03-16 -0.2566354
2012-03-17 -0.2537089
2012-03-18 -0.2490421
2012-03-19 -0.2391911
2012-03-20 -0.2263381
2012-03-21 -0.2113029


which is just using c++ to do the calculation.

here is the template function for correlation that fts uses:
http://github.com/armstrtw/tslib/blob/5b0fe2fc5ecb393d1dca097c2c19008227eb6c7e/tslib/vector.summary/cor.hpp

-Whit

On Fri, Jun 26, 2009 at 4:57 PM, Ted Byersr.ted.by...@gmail.com wrote:
 I suspect I'm looking in the wrong places, so guidance to the relevant
 documentation would be as welcome as a little code snippet.

 I have time series data stored in a MySQL database.  There is the usual DATE
 field, along with a double precision number: there are daily values
 (including only normal working days: Monday through Friday).  I actually
 have to do a couple things here.  Because of how the result is to be used, I
 need to first create two time series.  The first is the delta between 22
 working days, and the second is the delta between 66 working days.  I have
 hundreds of these datasets, and some go back 30 years.  I need to estimate
 the correlation between 22 day deltas (i.e. is the delta for one month
 correlated with that of the previous month) and between the 22 day delta and
 the 66 day delta that ends the day before the the first day of the 22 day
 delta.  However, I KNOW the statistical properties of the time series are
 not constant (so the usual assumptions do not apply to the entire series).
 Therefore, I want to subsample finely enough to get a reasonably sensible
 correlation and examine how that changes through time.  (There are no tests
 of significance here: I just want to explore just how much the properties of
 these series change through time).

 I have C++ code, admittedly not written particularly efficiently, that does
 this.  The question is, is it possible to do this reasonably efficiently
 using R?

 Thanks

 Ted

        [[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] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame

Dear Peter,

Thank you for the explanations. Some further questions are inlined below.

Best regards,
Craig


Peter Dalgaard wrote:

Craig P. Pyrame wrote:

Stavros Macrakis wrote:

It gives me a headache, too! I think you'll have to wait for a more
expert user than me to supply explanations of these behaviors and
their rationales. 


Thanks, Stavros. I hope someone with expertise will shed more light 
on this, and in the meantime I'll try to learn more from the manuals.


Well first, you (and others) should shake any bees relating to raw 
objects out of your bonnet. The raw type should be viewed as an add-on 
enabling access to low-level data structures, not as a fundamental 
data type in R. The original data modes are logical, numeric, 
character, with upwards coercion rules (and some further twiddles 
for storage modes of numerics).


I think I've seen examples in the list's archives where downwards 
coercion rules were used, but I am not sure.





One particular aspect is that in the original system, logical works as 
a wild card type that can be coerced to all the others (hence NA has 
mode logical, which causes some confusion at first notice).


That's right, I find it confusing at first.





Why does this fail:
  r = as.raw(TRUE)  ifelse(TRUE, r, r) = error
This gives an error which I take for saying that raw cannot be coerced
to logical, but yes it can:
  as.logical(r) = TRUE
 
Wrong. Or rather, irrelevant. The error is

 ifelse(TRUE,r,r)
Error in ans[test  !nas] - rep(yes, length.out = length(ans))[test  
:  incompatible types (from raw to logical) in subassignment type fix
Notice subassignment type fix. This corresponds to this sort of 
operation

 r - as.raw(TRUE)
 x - TRUE
 x[1] - r
Error in x[1] - r :  incompatible types (from raw to logical) in 
subassignment type fix
Now, notice that when the coercion is bigger to smaller the fix is 
to coerce on the left side


What do you mean by coercion from bigger to smaller? What I thought 
should happen in the example above is to have x coerced upwards to logical.




 y - rep(TRUE,5)
 y[1] - 5
 y
[1] 5 1 1 1 1

So the thing that might be expected here would be that x be coerced to 
raw before the assignment, 


No, I would expect upwards coercion, just as in the example immediately 
above. I would expect r to be coerced to logical.




but this is not implemented. I.e. you could have had the effect of.
 x - as.raw(x)
 x[1] - r
 x
[1] 01


No, I would rather expect to have the effect of:

 x[1] - as.logical(r)




This is designed not to happen automatically. I didn't write the code 
but I suppose one possible reason is that the raw mode does not allow 
missing values (or negative numbers for that matter, everything is 
0-255).
It also cuts the other way - no subassignment fixes are defined for 
raw:

 x - as.raw(1:10)
 x[3] - NA
Error in x[3] - NA :  incompatible types (from logical to raw) in 
subassignment type fix

 x[3] - TRUE
Error in x[3] - TRUE :  incompatible types (from logical to raw) in 
subassignment type fix

 x[3] - 4
Error in x[3] - 4 :  incompatible types (from double to raw) in 
subassignment type fix

 x[3] - 4L
Error in x[3] - 4L :  incompatible types (from integer to raw) in 
subassignment type fix




I don't understand any of these. If you can do the following:

 as.raw(TRUE) = 1
 as.raw(4L) = 04
 as.raw(-1) = 00, with a warning
 as.raw(NA) = 00, with a warning

Why can't this be done automatically. What would be wrong in having this 
done automatically, with a warning if needed?


 


and raw can even be used as the condition vector in ifelse:
  ifelse(r, 1, 2) = 1


Yes, but that's a different issue. Ifelse has the C language 
convention that anything nonzero is TRUE.

 ifelse(pi,2,1)
[1] 2
 


That's a news for me. The man page does not explain that!  It says 
test: an object which can be coerced to logical mode and also Missing 
values in test give missing values in the result.  If ifelse were 
working the C way, I would expect 1 as the result here:


 ifelse(as.raw(1), 1, 2) = error
 as.raw(1) == 0 = FALSE

The raw 1 is nonzero.

Best regards,
Craig

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Constrained corr matrix closest to a given corr matrix

2009-06-26 Thread Serguei Kaniovski

Dear All!

Is there any code to find a constrained correlation matrix closest in 
some sense (preferably in the sense of the geometric approximation) to a 
given correlation matrix? By constrained I mean with some elements 
constrained, or, simply, set to zero. I have read in a paper that says 
this can be accomplished with Lagrange multipliers and an optimization 
routine.


Thanks a lot!
Serguei Kaniovski

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


Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread Miguel Bernal
That was indeed what i was looking for (thanks also for the currying cite). I 
also wanted flexibility on the number of arguments you can pass to the 
function, which can be achieved by:

myfun - function(x, a=19, b=21){ return(a * x + b) }

mysecond.fun -
  function(dumb1, dumb2, cc=myfun, cc.args=list(a=2, b=5)){
fun.args - formals(cc)
fun.args[match(names(cc.args), names(fun.args))] - cc.args
formals(cc) - fun.args
list(a=dumb1, b=dumb2, cc = cc)
  }

test - mysecond.fun(1, 2)

myfun(2) ## 59
test$cc(2) ## 9


Thanks both of you for your replies, 

Miguel.


On Friday 26 June 2009 18:20:54 baptiste auguie wrote:
 Is this what you want?

 myfun - function(x, a=19, b=21){ return(a * x + b) }

 mysecond.fun - function(a, b, cc=myfun, cc.args=list(a=2,b=15) ){
 list(a=a, b=b, cc = function(x) cc(x, cc.args$a, cc.args$b))
 }

 mysecond.fun(a=1,b=2)$cc(x=12)

 It may be that you're after a Curry (*) function, as in,

 Curry -  # from roxygen
 function (f, ..., .left=TRUE)
 {
 .orig = list(...)
 function(...){
 if(.left) {args - c(.orig, list(...))} else {args - c(list(...),
 .orig)}
  do.call(f, args)
 }
 }

 I believe there are some recent discussions on currying in the archives.

 (*): http://en.wikipedia.org/wiki/Currying


 HTH,

 baptiste





 2009/6/26 Miguel Bernal mber...@marine.rutgers.edu

  Dear R-users,
 
  I am trying to develop a function that takes another function as an
  argument,
  changes its default values and returns a list of things, among which the
  initial function with its default arguments changed. An example of what i
  will like to obtain below:
 
  ## initial function
 
  myfun - function(x, a=19, b=21){ return(a * x + b) }
 
  ## this is the function i will like to create
  ## (does not work as it is written here)
 
  mysecond.fun - function(a, b, c = myfun(a=2, b=15)){
  return(list(a=a, b=b c=c))
  }
 
  So I would be able to call:
 
  mysecond.fun$c(x=12)
 
  And this will be equivalent of calling:
 
  myfun(x=12, a=2, b=15 ) ## i.e. i have changed the default values of
  myfun and
 ## stored it in a new function mysecond.fun$c
 
  Any help will be greatly appreciated!
 
  Miguel Bernal.
 
 
  
  Current address:
  Ocean Modeling group,
  Institute of Marine and Coastal Sciences
  University of Rutgers
  71 Dudley Road, New Brusnkwick,
  New Jersey 08901, USA
  email: mber...@marine.rutgers.edu
  phone: +1 732 932 3692
  Fax: +1 732 932 8578
  -
  Permanent address:
  Instituto Español de Oceanografía
  Centro Oceanográfico de Cádiz
  Puerto Pesquero, Muelle de Levante, s/n
  Apdo. 2609, 11006 Cádiz, Spain
  email: miguel.ber...@cd.ieo.es
  phone: +34 956 294189
  Fax: +34 956 294232
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



-- 

Current address:
Ocean Modeling group,   
Institute of Marine and Coastal Sciences
University of Rutgers   
71 Dudley Road, New Brusnkwick, 
New Jersey 08901, USA   
email: mber...@marine.rutgers.edu
phone: +1 732 932 3692  
Fax: +1 732 932 8578
-
Permanent address:
Instituto Español de Oceanografía   
Centro Oceanográfico de Cádiz
Puerto Pesquero, Muelle de Levante, s/n
Apdo. 2609, 11006 Cádiz, Spain
email: miguel.ber...@cd.ieo.es
phone: +34 956 294189
Fax: +34 956 294232

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


  1   2   >