Re: [R] Doing pairwise comparisons using either Duncan, Tukey or LSD

2009-02-19 Thread Chuck Cleland
On 2/19/2009 11:51 AM, Saeed Ahmadi wrote:
> Hi,
> 
> I have a basic and simple question on how to code pairwise (multiple) mean
> compariosn between levels of a factor using one of the Duncan, Tukey or LSD.

  Here is one approach:

library(multcomp)

summary(glht(lm(Petal.Width ~ Species, data = iris), linfct =
mcp(Species = "Tukey")))

> Thanks in advance,
> Saeed  

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

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

2009-02-19 Thread Christos Hatzis
It seems to be in optimize.c

Rgonzui has a very nice search facility for source of R or CRAN packages
(however it is against R 2.8.0 source):
http://rgonzui.nakama.ne.jp/R/markup/R-2.8.0/src/main/optimize.c?fm=c&q=nlm#
l378

-Christos

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Ravi Varadhan
> Sent: Thursday, February 19, 2009 1:00 PM
> To: r-help@r-project.org
> Subject: [R] Source code for nlm()
> 
> Hi,
>  
> Where can I find the source code for nlm()?  I dowloaded the 
> R2.8.1.tar.gz file and looked at all the .c and .f files, but 
> couldn't find either nlm.c or nlm.f
>  
> There is an nlm.r file, but that is not useful.
>  
> Thanks for any help,
> 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/Varadhan.html
> 
>  
> 
> --
> --
> 
> 
>  
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
>

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

2009-02-19 Thread Duncan Murdoch

On 19/02/2009 1:00 PM, Ravi Varadhan wrote:

Hi,
 
Where can I find the source code for nlm()?  I dowloaded the R2.8.1.tar.gz

file and looked at all the .c and .f files, but couldn't find either nlm.c
or nlm.f
 
There is an nlm.r file, but that is not useful.


I don't see why you say it's not useful, because it's the starting point 
to find the code.


See

 Ligges, U. (2006): R Help Desk: Accessing the Sources. R News 6 (4), 
43-45. http://cran.r-project.org/doc/Rnews/


for the next steps.  (To save you some time:  look in 
src/main/optimize.c.  But Uwe's article would have got you there pretty 
quickly).


Duncan Murdoch

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

2009-02-19 Thread Christian Ruckert

nicro schrieb:

Hi 2 questions-
1. Is there a package that will allow me to run R scripts (entirely) from
Java?
2. If so, is there a way to capture the output of those scripts, (including
images) and embed them in my SWT java app?

My challenge is I have a java app that does some statistical chores- it
would be fantastic if the users could use their R skills to modify a script
in whatever R environment they like and then my app could use that script to
calculate the results and display them in the app.

I have found StatET and JavaGD with rJava/JRI and read through all the
docs... its seems possible that some combination may give me what I want,
but its not very clear.


The JRI part from the rJava package does exactly what you want. Simple 
data types like numbers or strings are directly returned as java 
objects. But I'm afraid for the images you have to use the files system 
indirection.


If needed I can post an example,

Christian

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Doing pairwise comparisons using either Duncan, Tukey or LSD

2009-02-19 Thread Kingsford Jones
try:

example(TukeyHSD)


hth,
Kingsford Jones

On Thu, Feb 19, 2009 at 9:51 AM, Saeed Ahmadi  wrote:
>
> Hi,
>
> I have a basic and simple question on how to code pairwise (multiple) mean
> compariosn between levels of a factor using one of the Duncan, Tukey or LSD.
>
> Thanks in advance,
> Saeed
> --
> View this message in context: 
> http://www.nabble.com/Doing-pairwise-comparisons-using-either-Duncan%2C-Tukey-or-LSD-tp22104786p22104786.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Using R in Java?

2009-02-19 Thread Roy Mendelssohn

See also Biocep:

http://biocep-distrib.r-forge.r-project.org/

-Roy M.

On Feb 19, 2009, at 10:42 AM, Christian Ruckert wrote:


nicro schrieb:

Hi 2 questions-
1. Is there a package that will allow me to run R scripts  
(entirely) from

Java?
2. If so, is there a way to capture the output of those scripts,  
(including

images) and embed them in my SWT java app?
My challenge is I have a java app that does some statistical  
chores- it
would be fantastic if the users could use their R skills to modify  
a script
in whatever R environment they like and then my app could use that  
script to

calculate the results and display them in the app.
I have found StatET and JavaGD with rJava/JRI and read through all  
the
docs... its seems possible that some combination may give me what I  
want,

but its not very clear.


The JRI part from the rJava package does exactly what you want.  
Simple data types like numbers or strings are directly returned as  
java objects. But I'm afraid for the images you have to use the  
files system indirection.


If needed I can post an example,

Christian

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


**
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."

**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

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

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"

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

2009-02-19 Thread Ravi Varadhan
Thank you, Chris and Duncan.  It never occurred to me to look in optimize.c
since optimize() does univariate minimization.  Furthermore, now I know that
the underlying Fortran code (OPTIF9) is from the UNCMIN library (may be this
should be mentioned in the help page, although once can get to this
information from the second reference).  

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/Varadhan.html

 





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Duncan Murdoch
Sent: Thursday, February 19, 2009 1:17 PM
To: Ravi Varadhan
Cc: r-help@r-project.org
Subject: Re: [R] Source code for nlm()

On 19/02/2009 1:00 PM, Ravi Varadhan wrote:
> Hi,
>  
> Where can I find the source code for nlm()?  I dowloaded the 
> R2.8.1.tar.gz file and looked at all the .c and .f files, but couldn't 
> find either nlm.c or nlm.f
>  
> There is an nlm.r file, but that is not useful.

I don't see why you say it's not useful, because it's the starting point to
find the code.

See

  Ligges, U. (2006): R Help Desk: Accessing the Sources. R News 6 (4),
43-45. http://cran.r-project.org/doc/Rnews/

for the next steps.  (To save you some time:  look in src/main/optimize.c.
But Uwe's article would have got you there pretty quickly).

Duncan Murdoch

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

2009-02-19 Thread Bryan Coon
Wow, very interesting!  The netbeans example looks similar to what I
want, which is based on Eclipse RCP.

I will explore this more, as well as the JRI indirect method suggested
by Christian.

Thanks!

-Original Message-
From: Roy Mendelssohn [mailto:roy.mendelss...@noaa.gov] 
Sent: Thursday, February 19, 2009 10:47 AM
To: Christian Ruckert
Cc: Bryan Coon; r-help@r-project.org
Subject: Re: [R] Using R in Java?

See also Biocep:

http://biocep-distrib.r-forge.r-project.org/

-Roy M.

On Feb 19, 2009, at 10:42 AM, Christian Ruckert wrote:

> nicro schrieb:
>> Hi 2 questions-
>> 1. Is there a package that will allow me to run R scripts  
>> (entirely) from
>> Java?
>> 2. If so, is there a way to capture the output of those scripts,  
>> (including
>> images) and embed them in my SWT java app?
>> My challenge is I have a java app that does some statistical  
>> chores- it
>> would be fantastic if the users could use their R skills to modify  
>> a script
>> in whatever R environment they like and then my app could use that  
>> script to
>> calculate the results and display them in the app.
>> I have found StatET and JavaGD with rJava/JRI and read through all  
>> the
>> docs... its seems possible that some combination may give me what I  
>> want,
>> but its not very clear.
>
> The JRI part from the rJava package does exactly what you want.  
> Simple data types like numbers or strings are directly returned as  
> java objects. But I'm afraid for the images you have to use the  
> files system indirection.
>
> If needed I can post an example,
>
> Christian
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

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

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"



THIS EMAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT(S) AND MAY 
CONTAIN CONFIDENTIAL INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR 
DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, PLEASE 
CONTACT THE SENDER BY REPLY EMAIL AND DESTROY ALL COPIES OF THE ORIGINAL 
MESSAGE.

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

2009-02-19 Thread Julien Beguin
Hello R users,

I have some troubles to modify the "per default" legend in the
scatterplot.matrix using the car package. Here is my code:


scatterplot.matrix(~ a + b + c,
   groups=treatment,
   by.groups=F,
   data=newfile3,
   smooth=T,
   pch=c(16,4),
   cex=1.3,
   labels=label,
   cex.labels=1.3,
   font.labels=2,
   col=c("black","dark grey","black","black"),
   legend.plot=T,
   )
legend("topright",c("fenced","unefenced"), fill=NULL,bty="o",cex=3)


In my dataset, the variable "treatment" contains two levels that are coded "N"
and "Y" (for No and Yes) and appear in my "per default" legend that is located
in the buttomright of my 3x3 scatterplot. I would like to replace N by a list
of character: "unfenced" and Y by "fenced", as well as moving the legend in
another place in my graphic... is someone know how to do that with a
scatterplot?

Thank's

Julien

--
Julien Beguin
Etudiant-chercheur au doctorat
Laboratoire d'analyse quantitative des paysages, local 2113
Faculté de Foresterie et de Géomatique
Université Laval
2405 rue de la Terrasse, G1V 0A6 Québec (Qc)
Tel: (418) 656-2131 poste 2620

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


[R] using stepAIC with negative binomial regression - error message

2009-02-19 Thread t c
Ben,

I tried playing with the "na.action" but that didn't seem to help.  I didn't 
know of the na.omit function.  It made it much easier to get rid of all the 
missing values in the file, and now the regression model is running.

I hadn't put interactions in the model yet since it wasn't even running.  
Cosday, sinday, and daylength are strongly collinear.  The full model with 
interactions keeps all three in, plus all interactions between them.

Thanks for your help!

Tim





  
[[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] colored maps again

2009-02-19 Thread Greg Snow
The problem is that the order and number of polygons in map does not match your 
data (most likely).

Try:

library(maps)
library(plotrix)
state.col<-color.scale(state.x77[,'HS Grad'],0,0,c(0,1))
 map("state",fill=TRUE,col=state.col)

nms <- map('state', plot=FALSE)$names
nms <- sub(':.*$','',nms)
ind <- match(nms, tolower(state.name))

map('state', fill=TRUE, col=state.col[ind])

Now try it with your data, just replace state.name with the names of the states 
in the order of your data if it is different (possibly the rownames).

You may also want to look at state.vbm in the TeachingDemos package (works with 
maptools rather than maps) as another way to plot colored maps of the USA that 
is less affected by geographical area.

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 Alina Sheyman
> Sent: Thursday, February 19, 2009 9:46 AM
> To: r-help@r-project.org
> Subject: [R] colored maps again
> 
> I'm trying to create a colored map that would show the number of
> students
> per state.
> My data frame consists of two columns - state and count.
> I'm using the following code
> 
> library(maps)
> map("usa")
> library(plotrix)
> state.col<-color.scale(gre$count,0,0,c(0,1))
>  map("state",fill=TRUE,col=state.col)
> 
> I'm getting a map, but the values are not being mapped to correct
> states.
> What do I need to do to fix that?
> 
>   [[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] Roadmap for selecting an approach to analyzing repeated measures data

2009-02-19 Thread Frank E Harrell Jr

Dear Group,

At http://biostat.mc.vanderbilt.edu/tmp/summary.pdf I have put a draft 
of a roadmap for choosing a method for analyzing serial (longitudinal) 
data.  If anyone has feedback about this, including adding criteria for 
judging methods that I may have missed, I would appreciate hearing from you.


Thanks
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] Getting the difference between two data frames

2009-02-19 Thread Ferry
Dear R users,

I have the following data:
x <- data.frame( myX = c(1,2,3,4,5,6,7,8,9) )
y <- data.frame( myX = c(1,2,3,4,5,6,7) )

How can I get the difference between data frame x and y? In this case,
I want to get values 8 and 9

I know in SQL we can use minus operator, but I have no idea how to do so in R.

I tried all.equal, diff, and identical, but they don't give me the
actual data difference.

Thank you beforehand,

Ferry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] transform key value pair to column

2009-02-19 Thread Tan, Richard
Hi, is there a good way (instead of a time-consuming for loop) to
transfer a key/value pair dataframe to a dataframe with key as column
and value as row?  For example, I have a dataframe with three columns:
id, code, value:
 
id,code,value
1,hi,10.3
1,lo,5.2
2,hi,19.4
3,hi,20
3,lo,12
4,lo,5.8
 
I want to get a dataframe like this:
 
id,hi,lo
1,10.3,5.2
2,19.4,NA
3,20,12
4,NA,5.8
 
Thank you,
Richard

[[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] everybody loves R...

2009-02-19 Thread Liviu Andronic
On Thu, Feb 19, 2009 at 5:29 PM, Gábor Csárdi  wrote:
> I don't want to be mean, I really like wikidot, but isn't it a better
> solution to use the R wiki instead?
>
> http://wiki.r-project.org/rwiki/doku.php
>
Or even to contribute to existing well-structured sites such as
Quick-R [1]? It would avoid doubling efforts, and dispersing similar
information accross too many places.
Liviu

[1] http://www.statmethods.net/index.html


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] transform key value pair to column

2009-02-19 Thread Wacek Kusnierczyk
see ?stack, for example.

vQ

Tan, Richard wrote:
> Hi, is there a good way (instead of a time-consuming for loop) to
> transfer a key/value pair dataframe to a dataframe with key as column
> and value as row?  For example, I have a dataframe with three columns:
> id, code, value:
>  
> id,code,value
> 1,hi,10.3
> 1,lo,5.2
> 2,hi,19.4
> 3,hi,20
> 3,lo,12
> 4,lo,5.8
>  
> I want to get a dataframe like this:
>  
> id,hi,lo
> 1,10.3,5.2
> 2,19.4,NA
> 3,20,12
> 4,NA,5.8
>  
> Thank you,
> Richard
>
>   [[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] everybody loves R...

2009-02-19 Thread Wacek Kusnierczyk
Liviu Andronic wrote:
> On Thu, Feb 19, 2009 at 5:29 PM, Gábor Csárdi  wrote:
>   
>> I don't want to be mean, I really like wikidot, but isn't it a better
>> solution to use the R wiki instead?
>>
>> http://wiki.r-project.org/rwiki/doku.php
>>
>> 
> Or even to contribute to existing well-structured sites such as
> Quick-R [1]? It would avoid doubling efforts, and dispersing similar
> information accross too many places.
>
>   

well, if the purpose is to have the message 'everybody loves r' imposed
on as many as possible, dispersing similar information across places is
one way to go ;)

vQ

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] transform key value pair to column

2009-02-19 Thread Rowe, Brian Lee Yung (Portfolio Analytics)
Try this:

> dummy
  id code value
1  1   hi  10.3
2  1   lo   5.2
3  2   hi  19.4
4  3   hi  20.0
5  3   lo  12.0
6  4   lo   5.8

> reshape(dummy, idvar='id', timevar='code', direction='wide')
  id value.hi value.lo
1  1 10.3  5.2
3  2 19.4   NA
4  3 20.0 12.0
6  4   NA  5.8

Brian

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Wacek Kusnierczyk
Sent: Thursday, February 19, 2009 5:39 PM
To: Tan, Richard
Cc: r-help@r-project.org
Subject: Re: [R] transform key value pair to column


see ?stack, for example.

vQ

Tan, Richard wrote:
> Hi, is there a good way (instead of a time-consuming for loop) to
> transfer a key/value pair dataframe to a dataframe with key as column
> and value as row?  For example, I have a dataframe with three columns:
> id, code, value:
>  
> id,code,value
> 1,hi,10.3
> 1,lo,5.2
> 2,hi,19.4
> 3,hi,20
> 3,lo,12
> 4,lo,5.8
>  
> I want to get a dataframe like this:
>  
> id,hi,lo
> 1,10.3,5.2
> 2,19.4,NA
> 3,20,12
> 4,NA,5.8
>  
> Thank you,
> Richard
>
>   [[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.

--
This message w/attachments (message) may be privileged, confidential or 
proprietary, and if you are not an intended recipient, please notify the 
sender, do not use or share it and delete it. Unless specifically indicated, 
this message is not an offer to sell or a solicitation of any investment 
products or other financial product or service, an official confirmation of any 
transaction, or an official statement of Merrill Lynch. Subject to applicable 
law, Merrill Lynch may monitor, review and retain e-communications (EC) 
traveling through its networks/systems. The laws of the country of each 
sender/recipient may impact the handling of EC, and EC may be archived, 
supervised and produced in countries other than the country in which you are 
located. This message cannot be guaranteed to be secure or error-free. 
References to "Merrill Lynch" are references to any company in the Merrill 
Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America 
Corporation. Secu!
 rities and Insurance Products: * Are Not FDIC Insured * Are Not Bank 
Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to 
Any Banking Service or Activity * Are Not Insured by Any Federal Government 
Agency. Attachments that are part of this E-communication may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you 
consent to the foregoing.
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] transform key value pair to column

2009-02-19 Thread Tan, Richard
Thank you, works! 

-Original Message-
From: Rowe, Brian Lee Yung (Portfolio Analytics) [mailto:b_r...@ml.com] 
Sent: Thursday, February 19, 2009 5:52 PM
To: Wacek Kusnierczyk; Tan, Richard
Cc: r-help@r-project.org
Subject: RE: [R] transform key value pair to column

Try this:

> dummy
  id code value
1  1   hi  10.3
2  1   lo   5.2
3  2   hi  19.4
4  3   hi  20.0
5  3   lo  12.0
6  4   lo   5.8

> reshape(dummy, idvar='id', timevar='code', direction='wide')
  id value.hi value.lo
1  1 10.3  5.2
3  2 19.4   NA
4  3 20.0 12.0
6  4   NA  5.8

Brian

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Wacek Kusnierczyk
Sent: Thursday, February 19, 2009 5:39 PM
To: Tan, Richard
Cc: r-help@r-project.org
Subject: Re: [R] transform key value pair to column


see ?stack, for example.

vQ

Tan, Richard wrote:
> Hi, is there a good way (instead of a time-consuming for loop) to 
> transfer a key/value pair dataframe to a dataframe with key as column 
> and value as row?  For example, I have a dataframe with three columns:
> id, code, value:
>  
> id,code,value
> 1,hi,10.3
> 1,lo,5.2
> 2,hi,19.4
> 3,hi,20
> 3,lo,12
> 4,lo,5.8
>  
> I want to get a dataframe like this:
>  
> id,hi,lo
> 1,10.3,5.2
> 2,19.4,NA
> 3,20,12
> 4,NA,5.8
>  
> Thank you,
> Richard
>
>   [[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.


--
This message w/attachments (message) may be privileged, confidential or
proprietary, and if you are not an intended recipient, please notify the
sender, do not use or share it and delete it. Unless specifically
indicated, this message is not an offer to sell or a solicitation of any
investment products or other financial product or service, an official
confirmation of any transaction, or an official statement of Merrill
Lynch. Subject to applicable law, Merrill Lynch may monitor, review and
retain e-communications (EC) traveling through its networks/systems. The
laws of the country of each sender/recipient may impact the handling of
EC, and EC may be archived, supervised and produced in countries other
than the country in which you are located. This message cannot be
guaranteed to be secure or error-free. References to "Merrill Lynch" are
references to any company in the Merrill Lynch & Co., Inc. group of
companies, which are wholly-owned by Bank of America Corporation.
Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank
Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a
Condition to Any Banking Service or Activity * Are Not Insured by Any
Federal Government Agency. Attachments that are part of this
E-communication may have additional important disclosures and
disclaimers, which you should read. This message is subject to terms
available at the following link:
http://www.ml.com/e-communications_terms/. By messaging with Merrill
Lynch you consent to the foregoing.

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Getting the difference between two data frames

2009-02-19 Thread Rolf Turner


On 20/02/2009, at 11:23 AM, Ferry wrote:


Dear R users,

I have the following data:
x <- data.frame( myX = c(1,2,3,4,5,6,7,8,9) )
y <- data.frame( myX = c(1,2,3,4,5,6,7) )

How can I get the difference between data frame x and y? In this case,
I want to get values 8 and 9

I know in SQL we can use minus operator, but I have no idea how to  
do so in R.


I tried all.equal, diff, and identical, but they don't give me the
actual data difference.


First of all, you ***don't*** want the ``difference between two data  
frames''.
What you (apparently) want is the ***set difference*** between two  
***vectors***

each of which is (irrelevantly) stored inside a different data frame.

You can get what you want using the function setdiff().  E.g.:

> setdiff(x$myX,y$myX)
[1] 8 9


Data frames as such do not come into it.  You are just confusing the  
issue

by referring to them.  I.e. you could have much more simply said:

``
x <- c(1,2,3,4,5,6,7,8,9)
y <- c(1,2,3,4,5,6,7)

How do I get the difference c(8,9)?''

(Answer: setdiff(x,y).)

cheers,

Rolf



##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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

2009-02-19 Thread Rolf Turner



Is there a way to detect from within R whether, e.g., R has been
started with the --no-restore-data flag set?  So as to be able
to invoke code along the following lines:

if( --no-restore-data flag set) {
do something
} else {
do something else
}

Thanks for any assistance.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Detecting startup flags from within R (never mind, I figured it out).

2009-02-19 Thread Rolf Turner


Just after sending my inquiry I found the answer myself:

Use commandArgs().

Duh!  Sorry for wasting bandwidth.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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

2009-02-19 Thread Barry Rowlingson
2009/2/19 Rolf Turner :
>
>
> Is there a way to detect from within R whether, e.g., R has been
> started with the --no-restore-data flag set?  So as to be able
> to invoke code along the following lines:
>
>if( --no-restore-data flag set) {
>do something
>} else {
>do something else
>}
>
> Thanks for any assistance.

?commandArgs

 > "--no-restore-data" %in% commandArgs()
 [1] TRUE

or false if I hadn't started it with that arg...

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.


[R] change the label size when drawing trees with ape

2009-02-19 Thread Hua Li

Hi All,

I want to be able to change the labe size on a tree
when using ape package so that the graph can look
nicer, but don't know how. Playing with the "font"
doesn't seem to help. (Right now the labels barely
show.) 

Thanks for your help!

Code I'm using now

#-
t1 = "(((1:77.37,2:77.37):9.4,4:86.77):7.56,3:94.33);"
t2 = "((1:12.56,(2:10.11,4:10.11):2.45):1.64,3:14.2);"
t3= 
"(((1:57.54,3:57.54):11.54,4:69.08):4.13,2:73.21);"
t4 =
"(1:59.27,((2:34.77,3:34.77):6.99,4:41.76):17.51);"
t5 =
"(((1:22.26,4:22.26):3.4,3:25.66):15.81,2:41.47);"
t6 = "(((1:23.3,2:23.3):22.2,3:45.5):37.88,4:83.38);"
t7 =
"(((1:18.49,3:18.49):1.14,4:19.63):5.93,2:25.56);"
t8 =
"((1:40.26,2:40.26):31.51,(3:38.99,4:38.99):32.78);"
t9 =
"(1:60.72,((2:15.57,4:15.57):5.07,3:20.64):40.08);"
t10 =
"((1:54.81,3:54.81):13.81,(2:64.24,4:64.24):4.380001);"
t11 =
"((1:61.44,3:61.44):26.94,(2:26.52,4:26.52):61.86);"
t12 =
"((1:11.05,(3:10.15,4:10.15):0.9):68.71,2:79.76);"
t13 =
"(((1:39.53,3:39.53):6.25,4:45.78):3.09,2:48.87);"
t14 =
"((1:55.12,(2:37.99,3:37.99):17.13):18.28,4:73.4);"
t15 =
"((1:73.39,(2:54.24,4:54.24):19.15):20.58,3:93.97);"


library(ape)

ft = c(5,5,5,5)
postscript("test.ps")
par(mfrow=c(5,3))
plot(read.tree(text=t1),font=ft)
plot(read.tree(text=t2),font=ft)
plot(read.tree(text=t3),font=ft)
plot(read.tree(text=t4),font=ft)
plot(read.tree(text=t5),font=ft)
plot(read.tree(text=t6),font=ft)
plot(read.tree(text=t7),font=ft)
plot(read.tree(text=t8),font=ft)
plot(read.tree(text=t9),font=ft)
plot(read.tree(text=t10),font=ft)
plot(read.tree(text=t11),font=ft)
plot(read.tree(text=t12),font=ft)
plot(read.tree(text=t13),font=ft)
plot(read.tree(text=t14),font=ft)
plot(read.tree(text=t15),font=ft)
dev.off()

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


[R] Arima bug?

2009-02-19 Thread rkevinburton
I was looking at the 'R' code associated with arima. I see the following:

upARIMA <- function(mod, phi, theta) {
p <- length(phi)
q <- length(theta)
mod$phi <- phi
mod$theta <- theta
r <- max(p, q + 1)
if (p > 0) 
mod$T[1:p, 1] <- phi
if (r > 1) 
mod$Pn[1:r, 1:r] <- .Call(R_getQ0, phi, theta)
else if (p > 0) 
mod$Pn[1, 1] <- 1/(1 - phi^2)
else mod$Pn[1, 1] <- 1
mod$a[] <- 0
mod
}
 

In particular the statement:

   else if (p > 0) 
mod$Pn[1, 1] <- 1/(1 - phi^2)

If p (the length of the phi vector) is greater than one then it looks like the 
code is trying to assign a vector to a single element which will generate an 
error in 'R'. Much like

x <- 1:3
x[1] <- 1:3

So I was wondering if there is something that I am missing that will 
"guarantee" that the length of the phi vector in this case is always 1. If this 
is not the case then it seems that this is a bug in the arima code.

Comments?

Kevin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 connect R and WinBUGS/OpenBUGS/LinBUGS in Linux in Feb. 2009

2009-02-19 Thread Paul Heinrich Dietrich

Hi Kees,
No harm no foul.  I'm glad you posted that anyway, because now anyone who's
trying to do the same thing and read this will know to seek your 1.1.9
version and stay away from 1.1.15. 

Paul


chaogai-2 wrote:
> 
> I do not know about the ubuntu instructions, they would not help me on
> Suse. The wine version is 1.1.9.
> I thought that was the latest,but when I checked latest is 1.1.15, which
> does indeed throw the blackbox error.
> So, now it does not work for me either
> Sorry I gave bad advise
> 
> kees
> 
> On Thu, 19 Feb 2009 01:38:15 +0100, Paul Heinrich Dietrich
>  wrote:
> 
>>
>> I went to this webpage (http://ubuntuforums.org/showthread.php?t=624644)  
>> and
>> followed the instructions to the letter on getting the latest Wine.  I
>> installed WinBUGS again, but this time I cannot open it in Wine.  It says
>> Black Box, Trap #101, and some text I can't copy/paste here.  Is this the
>> latest Wine that you have, or something different?  Thanks.
>>
>>
>> chaogai-2 wrote:
>>>
>>> Hi,
>>>
>>> For me running winbugs through wine just works. Even when I do not  
>>> specify
>>> any directories.
>>> The example they give in the bugs helpfile was my starting point.
>>> Setup is suse 11.1, latest Wine, R, R2WinBUGS & winbugs.
>>> I assume you first tried without specifying directories?
>>> The directories you use do not work for me, with WINEPATH the culprit.
>>> If you do not have the latest wine I advise to upgrade & not specify
>>> directories.
>>>
>>> Good luck,
>>> Kees
>>>
>>> On Wed, 18 Feb 2009 01:27:18 +0100, Paul Heinrich Dietrich
>>>  wrote:
>>>

 Hi Uwe,
 Thank you for your guidance.  I have installed R2WinBUGS and WinBUGS14
 under
 wine.  Using ?bugs for help, it tells me:

 useWINE: logical; attempt to use the Wine emulator to run 'WinBUGS',
 defaults to 'FALSE' on Windows, and 'TRUE' otherwise. Not available in
 S-PLUS.

 WINE: character, path to 'wine' binary file, it is tried hard (by a  
 guess
 and the utilities 'which' and 'locate')  to get the information
 automatically if not given.

 newWINE: Use new versions of Wine that have 'winepath' utility

 WINEPATH: character, path to 'winepath' binary file, it is tried hard
 (by a
 guess and the utilities 'which' and 'locate')  to get the information
 automatically if not given.

 ..and the following code is a simple Bayesian version of a t-test...

   Directory Paths
 
 MyModelPath <- "/home/me/Compound/R/WinBUGS/"
 MyBUGSPath <- "/home/me/.wine/drive_c/Program Files/WinBUGS14/"
 MyModelFile <- paste(MyModelPath, "model.bug", sep="")
 WINEPATH <- "/usr/bin/wine"

   Create Data Set
 
 # Here is some fake data
 n_draws <- 50
 x <- round(runif(n_draws, 1, 2))
 y <- ifelse(x == 1, rnorm(n_draws, 1, 1), rnorm(n_draws, 1.2, 0.8))
 MyData <- as.data.frame(cbind(y, x))
 y.n <- NROW(MyData$y)
 x.j <- length(unique(x))
 summary(MyData)

 ##  Format Data for WinBUGS
 ##
 MyBUGSData <- list(y=MyData$y, x=MyData$x, n=y.n, x.j=x.j)
 MyBUGSData

 ##  WinBUGS Model File
 ###
 library(R2WinBUGS)
 cat("model
{
for (i in 1:n)
{
y[i] ~ dnorm(mu[i], tau)
mu[i] <- alpha + beta[x[i]]
}
### STZ (Sum-To-Zero) Constraints
beta[1] <- -sum(beta[2:x.j])
### Priors
alpha ~ dnorm(0.0, 1.0E-4)
for (i in 2:x.j)
{
beta[i] ~ dnorm(0.0, 1.0E-4)
}
tau ~ dgamma(0.01, 0.01)
precision <- sqrt(1/tau)
}",
 file=MyModelFile)
 file.show(MyModelFile)

 #  WinBUGS Model
 #
 MyModel <- bugs(MyBUGSData, inits=NULL,
model.file=MyModelFile,
parameters.to.save=c("alpha", "beta", "precision"),
n.chains=3, n.iter=2000, n.burnin=1000, n.thin=1, codaPkg=TRUE,
bugs.directory = MyBUGSPath, working.directory=MyModelPath,
useWINE=TRUE, WINEPATH=WINEPATH, debug=TRUE)

 The output says:

 ERROR:
   cannot open the connection

 I'm wondering if I've misinterpreted how to set my paths with wine,
 because
 I can go to the following path, double-click on WinBUGS14.exe, and open
 it
 just fine: /home/me/.wine/drive_c/Program Files/WinBUGS14/

 I can also go to Applications > Wine > Browse C:\ Drive and navigate to
 WinBUGS.

 Please help if I've done something wrong.  Thanks.
>>>
>>>
>>>
>>> --
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinf

[R] How to unload a dll loaded via library.dynam()?

2009-02-19 Thread Alex F. Bokov
Hello. To save the hassle of quitting and restarting R every time I rebuild the 
package I'm working on (for the purposes of this question called "roots") I 
would like to write a script cleanly remove the package from my R session and 
then load it again. Of course detach("package:roots") works for the native R 
objects in the package. However, the compiled C library remains loaded. Using 
library.dynam.unload as documented results in:

Error in library.dynam.unload("roots.so", 
"~/R/x86_64-pc-linux-gnu-library/2.8/roots/libs/") :
  shared library 'roots' was not loaded

I also tried the above command with the file extension omitted and the last one 
and two levels of the directory path omitted. In both cases I still get the 
"not loaded" error. I've also Googled the list archives and while there were 
several questions like mine, none of them were answered by the list. Am I to 
believe that this is something hardly anybody does? Does this mean everybody 
sits around waiting for R to start up everytime they make a minor change to the 
C source?

If there is a tutorial for doing this, I'd much appreciate the link.

Thank you for your advice.

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

2009-02-19 Thread Peter Dalgaard

rkevinbur...@charter.net wrote:

I was looking at the 'R' code associated with arima. I see the following:

upARIMA <- function(mod, phi, theta) {
p <- length(phi)
q <- length(theta)
mod$phi <- phi
mod$theta <- theta
r <- max(p, q + 1)
if (p > 0) 
mod$T[1:p, 1] <- phi
if (r > 1) 
mod$Pn[1:r, 1:r] <- .Call(R_getQ0, phi, theta)
else if (p > 0) 
mod$Pn[1, 1] <- 1/(1 - phi^2)

else mod$Pn[1, 1] <- 1
mod$a[] <- 0
mod
}
 


In particular the statement:

   else if (p > 0) 
mod$Pn[1, 1] <- 1/(1 - phi^2)





So I was wondering if there is something that I am missing that will

"guarantee" that the length of the phi vector in this case is always 1.

There is. You are only getting there if r > 1 is FALSE, and by the 
definition of r, that can only happen if q==0 and (p==0 or p==1).


--
   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] How to unload a dll loaded via library.dynam()?

2009-02-19 Thread Duncan Murdoch

On 19/02/2009 6:19 PM, Alex F. Bokov wrote:

Hello. To save the hassle of quitting and restarting R every time I rebuild the package I'm working 
on (for the purposes of this question called "roots") I would like to write a script 
cleanly remove the package from my R session and then load it again. Of course 
detach("package:roots") works for the native R objects in the package. However, the 
compiled C library remains loaded. Using library.dynam.unload as documented results in:

Error in library.dynam.unload("roots.so", 
"~/R/x86_64-pc-linux-gnu-library/2.8/roots/libs/") :
  shared library 'roots' was not loaded

I also tried the above command with the file extension omitted and the last one and two 
levels of the directory path omitted. In both cases I still get the "not 
loaded" error. I've also Googled the list archives and while there were several 
questions like mine, none of them were answered by the list. Am I to believe that this is 
something hardly anybody does? Does this mean everybody sits around waiting for R to 
start up everytime they make a minor change to the C source?

If there is a tutorial for doing this, I'd much appreciate the link.



This is more of an R-devel question than R-help, so if this doesn't 
answer your question, please follow up there.


On Windows, the following sort of works:

> library(rgl)
> .dynLibs()
   Filename Dynamic.Lookup
1 F:/R/R-2.8.1/library/methods/libs/methods.dll  FALSE
2 F:/R/R-2.8.1/library/grDevices/libs/grDevices.dll  FALSE
3 F:/R/R-2.8.1/library/stats/libs/stats.dll  FALSE
4 F:/R/R-2.8.1/library/rgl/libs/rgl.dll   TRUE

> library.dynam.unload("rgl", "F:/R/R-2.8.1/library/rgl")

I say "sort of", in that I get no error messages and the dll is no 
longer locked in use as it normally would be in Windows, but reloading 
the package doesn't function properly. It's possible some combination of 
detach() and unloadNamespace() would get a clean unload, but really, I 
normally just quit R and restart.  It's pretty quick to start up, 
compared to the recompile time for the package.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 unload a dll loaded via library.dynam()?

2009-02-19 Thread Gábor Csárdi
Hmmm, I think restarting R is not a very good solution. It is rather
ugly in the first place. But perhaps even more importantly, it can be
rather inconvenient if one has a large data set in the memory and
needs to save/load it just to reload a package that was updated in the
meanwhile.

This happens to me quite often with 20-40Gb of data, so I would really
love to have a solution for proper detach/unload.

Best,
Gabor

On Fri, Feb 20, 2009 at 1:32 AM, Duncan Murdoch  wrote:
> On 19/02/2009 6:19 PM, Alex F. Bokov wrote:
>>
>> Hello. To save the hassle of quitting and restarting R every time I
>> rebuild the package I'm working on (for the purposes of this question called
>> "roots") I would like to write a script cleanly remove the package from my R
>> session and then load it again. Of course detach("package:roots") works for
>> the native R objects in the package. However, the compiled C library remains
>> loaded. Using library.dynam.unload as documented results in:
>>
>> Error in library.dynam.unload("roots.so",
>> "~/R/x86_64-pc-linux-gnu-library/2.8/roots/libs/") :
>>  shared library 'roots' was not loaded
>>
>> I also tried the above command with the file extension omitted and the
>> last one and two levels of the directory path omitted. In both cases I still
>> get the "not loaded" error. I've also Googled the list archives and while
>> there were several questions like mine, none of them were answered by the
>> list. Am I to believe that this is something hardly anybody does? Does this
>> mean everybody sits around waiting for R to start up everytime they make a
>> minor change to the C source?
>>
>> If there is a tutorial for doing this, I'd much appreciate the link.
>
>
> This is more of an R-devel question than R-help, so if this doesn't answer
> your question, please follow up there.
>
> On Windows, the following sort of works:
>
>> library(rgl)
>> .dynLibs()
>   Filename Dynamic.Lookup
> 1 F:/R/R-2.8.1/library/methods/libs/methods.dll  FALSE
> 2 F:/R/R-2.8.1/library/grDevices/libs/grDevices.dll  FALSE
> 3 F:/R/R-2.8.1/library/stats/libs/stats.dll  FALSE
> 4 F:/R/R-2.8.1/library/rgl/libs/rgl.dll   TRUE
>
>> library.dynam.unload("rgl", "F:/R/R-2.8.1/library/rgl")
>
> I say "sort of", in that I get no error messages and the dll is no longer
> locked in use as it normally would be in Windows, but reloading the package
> doesn't function properly. It's possible some combination of detach() and
> unloadNamespace() would get a clean unload, but really, I normally just quit
> R and restart.  It's pretty quick to start up, compared to the recompile
> time for the package.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] residuals from a fractional arima model and other questions

2009-02-19 Thread Horace Tso
Dear list and Martin,

I'm testing different approaches to fit an electricity demand time series and 
come upon the fracdiff package (v 1.3-1) for fitting fractional ARIMA models. 
The following questions are motivated by this package.

1. Despite having a help page, the residuals and fitted functions don't seem to 
have implementation, or did i miss something obvious? Alternatively, having a 
fitted fracdiff object, how do I calculate the residuals? (Please forgive me if 
this is totally obvious which I'm sure it may be. Is it just a matter of 
expanding out the (1-L)^d term?)

2. I don't have access to the cited Haslett & Raftery (1989) paper, but could 
someone explain to me the little cautionary note in the help page stating that 
"nar and nma should not be too large (say < 10) to avoid degeneracy in the 
model." I see that a different implementation of the FARIMA procedure in Splus 
could lead to an explosive, ie. non-stationary model when it's used to fit a 
log volatility data set (Zivot & Wang, p.291). Zivot explains that it might be 
due to canceling roots in the AR and MA polynomials. Is this a caution against 
a similar problem. Which leads to my next question,

3. Is the FARIMA procedure known to be unstable at time? Is there a better way 
(with a different package perhaps) to model long range dependence ?

4. When my model is fitted, i got a warning that it's unable to compute the 
correlation matrix. Output looks like,

Call:
  fracdiff(x = res.iact.ts, nar = 9, nma = 9, M = 100)

*** Warning during fit: unable to compute correlation matrix

Coefficients:
  Estimate Std. Errorz value Pr(>|z|)
d4.745e-01  0.000e+00Inf   <2e-16 ***
ar1  8.897e-01  0.000e+00Inf   <2e-16 ***
ar2 -3.386e-01  0.000e+00   -Inf   <2e-16 ***
ar3  3.339e-01  2.044e-17  1.634e+16   <2e-16 ***
ar4 -4.406e-01  0.000e+00   -Inf   <2e-16 ***
ar5  3.924e-02  6.349e-18  6.182e+15   <2e-16 ***
ar6 -5.184e-01  2.558e-17 -2.026e+16   <2e-16 ***
ar7  8.988e-01  0.000e+00Inf   <2e-16 ***
ar8 -7.568e-01  3.112e-16 -2.432e+15   <2e-16 ***
ar9  3.442e-01  2.175e-22  1.582e+21   <2e-16 ***
ma1 -1.190e-01  1.470e-18 -8.097e+16   <2e-16 ***
ma2 -9.343e-02  0.000e+00   -Inf   <2e-16 ***
ma3  2.140e-01  0.000e+00Inf   <2e-16 ***
ma4 -2.107e-01  0.000e+00   -Inf   <2e-16 ***
ma5 -2.892e-01  0.000e+00   -Inf   <2e-16 ***
ma6 -7.197e-01  2.888e-08 -2.492e+07   <2e-16 ***
ma7  3.021e-01  0.000e+00Inf   <2e-16 ***
ma8 -1.395e-01  0.000e+00   -Inf   <2e-16 ***
ma9 -2.493e-02  3.013e-21 -8.274e+18   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
[d.tol = 0.0001221, M = 100, h = 0.004807]
Log likelihood: -4.562e+05 ==> AIC = 912360.4 [1 deg.freedom]
Last question : why are some of z-values infinite?

Thanks in advance.

Horace Tso



[[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] equivalent function to MatLab 'step' ?

2009-02-19 Thread Carl Witthoft
I have to admit I don't fully understand how MatLab's step() function 
works, but I'm learning that part.   Can someone point me to 
equivalent&related functions in R?


thanks
Carl

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

2009-02-19 Thread Graham Williams
Received Fri 19 Dec 2008  7:38am +1100 from Prof Brian Ripley:
> On Thu, 18 Dec 2008, Francisco Javier Perez Caballero wrote:
>
>> Hi, I'm trying to connect to a Teradata database via RODBC on a Linux 64
>> machine (Red Hat Enterprise Linux 5). 

[...]

>>> library(RODBC)
>>> conn = odbcConnect("thedsn", uid="theuid", pwd="thepass")
>>
>> *** caught segfault ***
>> address (nil), cause 'memory not mapped'

[...]

> Most likely a broken driver.  It seems that several do not support 
> GetInfo correctly: isql does not use it by default.  Debugging will show 
> you where the error actually was.

I came across the same problem recently and could not find any
discussion on the r-sig-db list solving this. Here's my solution.

I have a similar setup - Teradata ODBC driver on amd64 GNU/Linux
(Debian), using the RODBC package, and getting a segfault on
odbcConnect.

odbcConnect calls odbcDriverConnect which in turn .Call's
C_RODBCDriverConnect, which actually succeeds. Then there is a .Call
to C_RODBCGetInfo which results in the segfault. 

I suspect underneath the Teradata driver is crashing on querying a
table that does not exists or that you may not have access to (for me
the default odbc GetInfo seems to try to access the table DBC.Table,
but our setup does not have that available, with DBC.TableX being used
instead!)

I dropped the GetInfo call from odbcDriverConnect  and all is well,
until I query a table that does not exist, and once again the Teradata
driver crashes (also crashes in isql when typing "help" or querying a
table that does not exist).

Regards,
Graham



In case it helps, I use this to connect.

channel <- odbcDriverConnect("DSN=mydsn;UID=user;PWD=password")

with the following function.

odbcDriverConnect <- function (connection = "", case = "nochange",
   believeNRows = TRUE,
   colQuote, tabQuote = colQuote,
   DBMSencoding = "", rows_at_time = 1000,
   bulk_add = NULL)
{
  id <- as.integer(1 + runif(1, 0, 1e+05))
  stat <- .Call(RODBC:::C_RODBCDriverConnect,
  as.character(connection),
id, as.integer(believeNRows))
  if (stat < 0)
  {
warning("ODBC connection failed")
return(stat)
  }
### res <- .Call(C_RODBCGetInfo, attr(stat, "handle_ptr"))
### Also removed references to res in the following.
  if (missing(colQuote)) colQuote <- "\""
  if (missing(case)) case <- "nochange"
  switch(case,
 toupper = case <- 1,
 oracle = case <- 1,
 tolower = case <- 2,
 postgresql = case <- 2,
 nochange = case <- 0,
 msaccess = case <- 0,
 mysql = case <- ifelse(.Platform$OS.type == "windows", 2, 0),
 stop("Invalid case parameter: nochange | toupper | tolower | common db 
names"))
  case <- switch(case + 1, "nochange", "toupper", "tolower")
###   if (is.null(bulk_add))
### bulk_add <- .Call(RODBC:::C_RODBCCanAdd, attr(stat, "handle_ptr"))
  structure(stat, class = "RODBC", case = case, id = id,
believeNRows = believeNRows,
bulk_add = bulk_add, colQuote = colQuote, tabQuote = tabQuote,
encoding = DBMSencoding, rows_at_time = rows_at_time)
}

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


Re: [R] Build R-2.8.1 on AIX5.3

2009-02-19 Thread 亿元五角

Thanks for Ej-ji's help.

 

I have succesfully built R-2.8.1 on AIX,but I also found a problem in my build 
process-- the 783 line on patch file should be  combined with 782 line.


Thanks for Ei-ji again.

Jin

 
> Date: Thu, 19 Feb 2009 09:39:26 +
> From: rip...@stats.ox.ac.uk
> To: nak...@ki.rim.or.jp
> CC: dna_...@hotmail.com
> Subject: Re: [R] Build R-2.8.1 on AIX5.3
> 
> If you do test it, please let me know and I will merge it into the R 
> sources.
> 
> Can we discuss such issues on R-devel, please (see the posting guide).
> Most of the developers do not read R-help (at all, or in any detail).
> 
> On Thu, 19 Feb 2009, Ei-ji Nakama wrote:
> 
> > Hi Jin.
> >
> >> I found there is someone meet same problem when he build R-2.7.0 by 
> >> searching r-help, and he used a patch to resolve this issue. The 
> >> patch¡¯s location is http://prs.ism.ac.jp/~nakama/AIX/changefiles. But I 
> >> can not find a patch R-2.8.1 in this path.
> >>
> >
> > Gnu patch is necessary.(AIX patch can't be used.)
> >
> > http://prs.ism.ac.jp/~nakama/AIX/AIX_R-2.8.1.patch
> >
> > However, this patch is not tried at all.
> > -- 
> > EI-JI Nakama 
> > "\u4e2d\u9593\u6804\u6cbb" 
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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, UK Fax: +44 1865 272595

_
新版手机MSN,满足你多彩需求!参加抢鲜体验活动,领取特色奖品!
http://mobile.msn.com.cn/
[[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] Build R-2.8.1 on AIX5.3

2009-02-19 Thread Ei-ji Nakama
> I have succesfully built R-2.8.1 on AIX,but I also found a problem in my
> build process-- the 783 line on patch file should be  combined with 782
> line.

Oops, mended.
http://prs.ism.ac.jp/~nakama/AIX/AIX_R-2.8.1_fix.patch

Now, I do not have AIX that can be tested.:(

Thank you Jin.
-- 
EI-JI Nakama  
"\u4e2d\u9593\u6804\u6cbb"  

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] importing data to SQLite database with sqldf

2009-02-19 Thread Stephen Tucker
Hi all,

I am attempting to learn SQL through sqldf...

One task I am particularly interested in is merging separate
(presumably large) files into a single table without loading these
files into R as an intermediate step (by loading them into SQLite and
merging them there).

Taking a step back, I've considered these alternatives:

1) I know if I use straight SQLite commands I might use the 'IMPORT'
or 'INSERT INTO' command, which is not terribly flexible...  (I can
read large files line-by-line in Python and use the 'INSERT INTO'
command, which is reasonably fast; I could do this in R as well but my
experience with R's input/output is that it's much slower...? and
sometimes setting up the table column definitions can be tedious if
there are many variables).

2) dbWriteTable() with append=TRUE is very convenient except that it
requires I load the data into R first...

3) sqldf's capability to put data directly into a database is
something I'd like to work out.

So in this case I have a series of tab-delimited text file with the
first line being a header.

For some reason I cannot seem to get it working.  Combining examples 6
and 9 from the Google Code page (and R-help archives), I tried

source("http://sqldf.googlecode.com/svn/trunk/R/sqldf.R";)
(do I need it for SQLite?)
##
sqldf("attach 'mydb.db' as new")
f <- file("myexample.txt")
attr(f,"file.format") <- list(header=TRUE,sep="\t")
sqldf("create table myexample as select * from f",
  stringsAsFactors=FALSE,
  dbname="mydb.db")
## or
f <- file(fi)
sqldf("create table myexample as select * from f",
  stringsAsFactors=FALSE,file.format=list(header=TRUE,sep="\t"),
  dbname="mydb.db")
##
sqldf("select * from myexample",dbname="mydb.db")
gives me tables with 0 rows and 0 columns...

So in any case I have a few questions:

=== 1 
Would this be scalable to files with few GBs of data in them (I guess
I am uncertain of the underlying mechanism for transporting data from
the .txt file to the .db file... I see there is a call the
dbWriteTable() internally in sqldf but through the connection)?  And
is there anything obviously doing wrong above?

=== 2 === 
Since I cannot 'append' rows to existing tables in SQLite (or any SQL
database), I think what I would have to do is to load each of the
files into the database and then 'rbind' them into a new table using
'union all'? The following code is what I have (the part where I read
in each file before dumping into the database file would hopefully be
replaced by the method above, if it can be made to work).

## (1) create a database file
sqldf("attach 'alltables.db' as new")
## (2) convenience function
sql <- function(...) sqldf(...,dbname="alltables.db")
## (3) load data as separate tables
for( fi in list.files(".","txt$") ) {
  mydata <- read.delim(fi)
  sql(sprintf("create table %s as select * from mydata",sub("\\.txt","",fi)))
}
rm(fi,mydata)
## (4) merge tables
tablenames <- as.character(sql("select * from sqlite_master")$name)
sql(paste("create table myfulltable as",
  paste(sprintf("select * from %s",tablenames),
collapse=" union all ")))
## (5) delete separate tables since we have a merged one
for( nm in tablenames ) sql(sprintf("drop table %s",nm))

=== 3 ===
The following command
sqldf("attach 'mydb.db' as new")
DF <- read.delim(fi)
sqldf("create table myexample as select * from DF",dbname="mydb.db")

will usually create a .db file twice the size of the .txt file (for
now I am playing with a files ~500KB so the .db files are around
~1MB). When I create a .db file using SQLite's 'import' command,
RSQLite's dbWriteTable(), or inserting values from the same .txt file
from Python's SQLite interface, I get .db files that are approximately
the same size as the .txt file (~500KB). Is the larger file size for
sqldf's method expected?

Many thanks in advance!

Stephen Tucker

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


Re: [R] problem with comparing a part of string with whole string

2009-02-19 Thread venkata kirankumar
Hi ,

i just attached one file to this mail which contains one modal of my data
and there i have to search for the rows which contains   "SPECIMENTYP %in%
"ADIPOSE TISSUE""
and the rows which contains " "PRESERVED"in  ORGCHARRES
for that i tried with
" r<-subset(rr,SPECIMENTYP %in% "ADIPOSE TISSUE" & grep("IN
DIAMETER",rr$ORGCHARRES),select=c(SPECIMENTYP,ORGCHARRES))"

but i got only the rows having  "ADIPOSE TISSUE"   in  "SPECIMENTYP"

can anyone suggest any of the way for comparision of this type


thanks in advance





On Thu, Feb 19, 2009 at 6:26 PM, Petr PIKAL  wrote:

> Hi
>
> r-help-boun...@r-project.org napsal dne 19.02.2009 13:39:42:
>
> > Hi all,
> >
> > I got one problem with comparing strings like if any string is like
> >
> > "*RIGHT, EPICARDIUM: FOCUS, GRAY-WHITE, SINGLE, APPROX 0.6 CM IN
> DIAMETER*."
> >
> > and i have to compare   "*GRAY-WHITE*"with the above string
> >
> > or otherwise   i have to compare   " *TUMOR BENIGN*"   this
> string
> > with
> >
> > "*MEDULLRY TUMOR BENIGN,TYP PHEOCHROMOCYTOMA*"
> >
> > i tried with split and compare but its not working
>
> Work for regular expressions?
>
> vec="*RIGHT, EPICARDIUM: FOCUS, GRAY-WHITE, SINGLE, APPROX 0.6 CM IN
> DIAMETER*."
> test="GRAY-WHITE"
> regexpr(test, vec)
> [1] 28
> attr(,"match.length")
> [1] 10
>
> Regards
> Petr
>
>
> >
> > can any one suggest how can i compare these type of Strings
> >
> > thanks in advance
> >
>  >[[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] log-minus-log plot

2009-02-19 Thread C.H.
Dear experts,

I would like to know how to plot the log-minus-log plot for survival
analysis (to check the proportional assumption) in R.

Using the AML example.

fit <- survfit(Surv(time, status) ~ x, data=aml)
length(fit$surv) #20

as the length of fit$surv is shorter than aml$x and aml$time. I don't
know how to plot.

Thank you.

Regards,

CH


-- 
CH Chan
Research Assistant - KWH
http://www.macgrass.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] smoothing 2D vector field

2009-02-19 Thread _

Hi all,
is there a function / package in R that provides a function like 
Matlab's conv2 or filter2 for smoothing a vector- / velocity- field.

I unfortunately could not find anything.

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] modifying legend in scatterplot matrix R

2009-02-19 Thread Dieter Menne
Julien Beguin  ulaval.ca> writes:

> scatterplot.matrix(~ a + b + c,
>groups=treatment,
...
>legend.plot=T,
>)
> legend("topright",c("fenced","unefenced"), fill=NULL,bty="o",cex=3)
> 
> 
> In my dataset, the variable "treatment" contains two levels that are coded "N"
> and "Y" (for No and Yes) and appear in my "per default" legend that is located
> in the buttomright of my 3x3 scatterplot. I would like to replace N by a list
> of character: "unfenced" and Y by "fenced", as well as moving the legend in
> another place in my graphic... is someone know how to do that with a
> scatterplot?


In most cases it is easiest to assign new level to the factor;

a = as.factor(c("N","Y","Y","N"))
levels(a)=c("unfenced","fenced")
levels(ar)=c("unfenced","fenced") # if you want to keep orinale


legend has x,y coordinates.

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] write.table

2009-02-19 Thread lauramorg...@bluewin.ch
Hello,
I tried to turn lists into vectors and then bind them together in order to 
create a dataframe but if, after this, I 
try to use the function write.table I get the following error message:
Error in write.table(x, file, nrow(x), p, rnames, sep, eol, na, dec, 
as.integer(quote),  : 
   'list' type not implemented in 'EncodeElement'
 
Here is what I've done:
as.vector(c(unique(portate$Anno)))->anno
as.vector(loadListPO4)->loadPO4
as.vector(loadListPTG)->loadPTG
as.vector(loadListNT)->loadNT
as.vector(loadListNH4)->loadNH4
as.vector(loadListNO3)->loadNO3
as.vector(loadListBOD5)->loadBOD5
as.vector(loadListSiO2)->loadSiO2
cbind(anno,loadPTG,loadPO4,loadNT,loadNH4,loadNO3,loadBOD5,loadSiO2)->carichi
as.data.frame(carichi)->carichi.annui

#if I type  
carichi.annui
#I get
 anno   loadPTG   loadPO4   loadNT  loadNH4  loadNO3 loadBOD5 loadSiO2
1 2002  3.399518  1.382235 390.6959 22.07992 256.2244 492.9177 150.6505
2 2003  1.559606 0.6271712 202.9181 6.198592 145.9498 63.07578 68.08632
3 2004  2.363862 0.9493779 292.0841 12.21207 200.2545 141.0533 105.2409
4 2005  1.64 0.6570313 217.2192  6.58045 155.7393 66.44154  73.0394
5 2006  1.827174 0.7290634 235.7914 7.858396 166.8327  79.2474 80.92576
6 2007  1.742629 0.6891045 228.0253 7.130082 162.6692 71.91434 77.22507
7 2008 0.8382246 0.3612176 110.9079 2.024197 86.60459 25.46127  32.9733

#which looks lika a data frame
#And if I type
is.data.frame(carichi.annui)
# I get this:
[1] TRUE

#but if I try 
write.table(carichi.annui, "carichi.annui.lav")
#It doesn't work?!?!?!
Does someone have an explanation?
Thanks a lot for any 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.


<    1   2