Re: [R] sequence that counts up and back down

2009-02-05 Thread Dimitris Rizopoulos

one way is the following:

5 - abs(-4:4)


I hope it helps.

Best,
Dimitris

Monte Milanuk wrote:
I hit a minor sticking point working one of the problems in 'Using R' 
(Verzani).  I'm having difficulty with generating a sequence that goes 
1, 2, 3, 4, 5, 4, 3, 2, 1.  I can make one that counts up, I can make 
one that counts down, etc. but one that counts up then down like this 
(short of just using c() ) is stumping me.


Any help (on or off list) would be appreciated.

Thanks,

Monte

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

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

2009-02-05 Thread Dieter Menne
Wacek Kusnierczyk  idi.ntnu.no> writes:

> equal?  you mean equivalent?  mostly, yes.  briefly, this is why:
> 
> 1. a copy-over from other programming languages;
> 2. to avoid learning yet another operator;
> 3. after having learned the other operator, to avoid that ugly operator;
> 4. after an r guru complained here about people using this instead of
> that, to annoy him.

:-) It's always fun to read

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] Incorrect p value for binom.test?

2009-02-05 Thread Thomas Lumley

On Thu, 5 Feb 2009, Albyn Jones wrote:


The computation 2*sum(dbinom(c(10:25),25,0.061)) does not correspond
to any reasonable definition of p-value.  For a symmetric
distribution, it is fine to use 2 times the tail area of one tail.
For an asymetric distribution, this is silly.



"Silly" is much too strong. There is a perfectly good reason to compare 
2*sum(dbinom(c(10:25),25,0.061)) to a two-sided test threshold.

The argument is that what we are really doing in usual two-sided location tests 
is two one-sided tests at alpha/2 rather than one two-sided test at alpha. The 
null hypothesis is being compared to two different alternatives (better or 
worse vs same) and the decisions about the future would be different depending 
on which tail we ended up using.

This argument says that we we should compare a one-sided tail area such as 
sum(dbinom(c(10:25),25,0.061)) to alpha/2; equivalently that we should compare 
2*sum(dbinom(c(10:25),25,0.061)) to alpha [or to informal standards for 
strength of evidence or whatever you typically do with p-values]. I'm not 
saying that this is the only sensible way to handle and interpret p-values in 
two-sided tests, but I really don't think it can be dismissed as 'silly'.


 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle


PS: Daniel Dennett has described as an occupational hazard for philosophers the tendency to go from "I can't imagine X" to "No one can imagine 
X" to "X is inconceivable".  The transition from "I can't imagine how X would be used" to "X is useless" is somewhat 
similar, as is the Extreme Bayesian transition from "X wasn't derived by a formal consideration of posterior expected loss" to "X can't be 
derived by a formal consideration of posterior expected loss" to "X is incoherent". Why, yes, I am grumpy about a reviewer. How did you guess?

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


Re: [R] Sweave and backslashes

2009-02-05 Thread Dieter Menne
cls59  mac.com> writes:

> I am an avid Sweave user and I am trying to pretty print floating point
> numbers for latex output. For example in my document, I would like:
> 
> 4.2\cdot 10^-{8}
> 
> Instead of:
> 
> 4.2e-08
> 
> The Hmisc package has a nice function for doing this- but Hmisc has a ton of
> dependencies and has proved very unportable to the various machines I work
> on. So, I set out to write my own function that just uses basic R commands,
> it looks like this:

I have my special version of it in the library :

"latexSNdouble" <-
function (val)
{
  # special copy of Hmisc latexSN with 
  require(Hmisc)
  x <- format(val)
  x <- sedit(val, c("e+00", "e-0*", "e-*", "e+0*", "e+*"), c("",
"!times!10^{-*}", 
"!times!10^{-*}", 
"!times!10^{*}", 
"!times!10^{*}"))
  x
}

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

2009-02-05 Thread cruz
There is an interesting article "An Introduction to Text Mining in R"
by Ingo Feinerer on R News Volume 8/2, October 2008
(http://www.r-project.org/doc/Rnews/Rnews_2008-2.pdf)

Check it out


On Fri, Feb 6, 2009 at 9:16 AM, spiketide  wrote:
>
> hi everyone...
>
> i am a newbie to text mining. and i gotta do my project in it i've
> looked up various infos online but still haven't got an idea on where to
> start so please, if anyone gave suggestions on this, it will be really
> helpful...
>
> thanks a lot in advance
>
> --
> View this message in context: 
> http://www.nabble.com/Text-Mining-tp11467848p21864801.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.


[R] How to convert Charagter variables into numeric

2009-02-05 Thread Arup

I am importing a dataset in R where some of the variable are numerical and
some of them are character...but the problem is that R is treating 
numerical variables as character (I am using "is.character" to judge the
type). Now the question is how can I convert these character variables into
numeric and also let me know about the other conversion like "numeric to
categorical","numeric to continuous" etc.Thank you.

Arup  
-- 
View this message in context: 
http://www.nabble.com/How-to-convert-Charagter-variables-into-numeric-tp21867485p21867485.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] R Interface Coming to SAS/IML Studio

2009-02-05 Thread Carlos J. Gil Bellosta
Hello,

I thought this link could be of interest to the list. 

http://support.sas.com/rnd/app/studio/Rinterface2.html

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.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] sequence that counts up and back down

2009-02-05 Thread Monte Milanuk
I hit a minor sticking point working one of the problems in 'Using R' 
(Verzani).  I'm having difficulty with generating a sequence that goes 
1, 2, 3, 4, 5, 4, 3, 2, 1.  I can make one that counts up, I can make 
one that counts down, etc. but one that counts up then down like this 
(short of just using c() ) is stumping me.


Any help (on or off list) would be appreciated.

Thanks,

Monte

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] MLE for right-censored data with covariates

2009-02-05 Thread krogovin

I am a student (and very to new to R) working on a senior design project that
is attempting to determine the demand distributions for single copy
newspaper draws at individual sales outlet locations.  Our sales data is
right-censored, because sell-outs constitute a majority of the data, and we
are also testing the relevance of including covariates (weather,
seasonality, economic condition, etc.).  We are trying to do MLE
calculations to determine each demand distribution and then use those
distributions for demand in the Newsvendor model.  Is there any package (or
combination of packages) to help?  We've been looking at survival...
-- 
View this message in context: 
http://www.nabble.com/MLE-for-right-censored-data-with-covariates-tp21864312p21864312.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] subset problem (reducing from six to two levels)

2009-02-05 Thread Ine

Great, this worked for me, exactly how I needed it.
Thanks for all the replies!


Peter Dalgaard wrote:
> 
> Ine wrote:
>> Hi all,
>> I have got a seemingly simple problem (I am an R starter) with subsetting
>> my
>> data set, but cannot figure out the solution: I want to subset a data set
>> from six to two levels, so that all analyses are done only with these two
>> remaining levels.
>> I tried
>> 
>> TOTAL<-read.delim('total.csv',header=T)
>> SUBSET.OF.TOTAL<-subset(TOTAL, FactorX %in% c("Level1","Level2"))
>> attach(SUBSET.OF.TOTAL)
>> 
>> but R does not eliminate the remaining levels of FactorX, just assigns
>> 'not
>> available' to the data. Like this, the other levels still show up in
>> plots
>> etc., but without data entries. Anybody got a solution how to subset the
>> data so that I eliminate the other levels completely?
>> 
>> Thanks a lot for the help,
>> 
> 
> R does not "assign 'not available'" (look at the subsetted data).
> 
> However, factors do not lose levels just because they are not present in 
> a subset of data. There are good reasons for that, but let's not go 
> there this time (look in the list archives if you care). To get rid of 
> unwanted levels, use
> 
> FactorXX <- factor(FactorX, levels=c("Level1","Level2"))
> 
> or just factor(FactorX) if you know that both levels are present (or 
> don't care).
> 
> 
> -- 
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/subset-problem-%28reducing-from-six-to-two-levels%29-tp21861044p21862189.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] Text Mining

2009-02-05 Thread spiketide

hi everyone...

i am a newbie to text mining. and i gotta do my project in it i've
looked up various infos online but still haven't got an idea on where to
start so please, if anyone gave suggestions on this, it will be really
helpful...

thanks a lot in advance

-- 
View this message in context: 
http://www.nabble.com/Text-Mining-tp11467848p21864801.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] Classification problem

2009-02-05 Thread anil rohilla
Hi List,

 I want to do classification using neural network (e.g Package neural, Amore
etc). How these packages handles nominal variables. Is there any specific
coding we have to use or we have to do dummy coding for each nominal
variable. Any help  will be appreciated. Is any body know how to do
classification using neural network using continous and nominal predictors,
As i am new to this R software. PLease help .

Thanks in advance

-- 
With Regards,
ANIL KUMAR ROHILLA

[[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] Problems in Recommending R

2009-02-05 Thread hadley wickham
On Thu, Feb 5, 2009 at 8:56 PM, Patrick Connolly
 wrote:
> On Sun, 01-Feb-2009 at 11:34PM -0500, Stavros Macrakis wrote:
>
> |> A first step that would make the current Web page look much better
> |> would be to anti-alias the demonstration graphic.  The current graphic
> |> makes R graphics seem (falsely!) to be very primitive. I'm afraid I
> |> don't know how to do the anti-aliasing myself.
> |>
> |> Replacing the fixed-width, typewriter-style font with something a bit
> |> more elegant might also be good
>
> I'd say it would not be good.  Fixed-width fonts are desirable when
> it's for code (of any language).  The example www.knime.org site uses
> proportional fonts for R code which makes it hard to read IMHO.  I
> really dislike that.

But you don't need fixed width fonts for headings...

> What's wrong with a spartan look?  Google has flourished with a
> no-unnecessaries approach to home page clutter.

There's nothing wrong with a spartan look.  There's something wrong
with making simple tasks difficult.  Why not do better if we can?

Hadley


-- 
http://had.co.nz/

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


Re: [R] Sweave and backslashes

2009-02-05 Thread Charles C. Berry

On Thu, 5 Feb 2009, cls59 wrote:



Hello Everyone,

I am an avid Sweave user and I am trying to pretty print floating point
numbers for latex output. For example in my document, I would like:

4.2\cdot 10^-{8}

Instead of:

4.2e-08

The Hmisc package has a nice function for doing this- but Hmisc has a ton of
dependencies and has proved very unportable to the various machines I work
on. So, I set out to write my own function that just uses basic R commands,
it looks like this:

latexNum <- function (x,dig=4,sci=T)
{
   x <- format(x,digits=dig,scientific=sci)

x <- gsub("e\\+00","",x)
x <- gsub("e\\-0([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\-([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\+0([0-9]*)","cdot 10^{\\1}",x)
 x <- gsub("e\\+([0-9]*)","cdot 10^{\\1}",x)

   return(x)
}

Everything works nicely, if I type


latexNum(4*10^-3)


I get

[1] "4\\cdot10^{-3}"

And the following:


cat(latexNum(4*10^-3))


Produces:

4\cdot10^{-3}

However the following in a .Rnw file:

$\Sexpr{latexNum(4*10^-3)}$\\


The syntax Sweave uses is fairly sensitive to backslashes. I might guess 
that this is a feature to protect against runaway expressions.


You need to add a backslash to undo what Sweave does to the backslashes in 
that type of expression.


Put

extra.slash <- function(x) sub('\\','', x, fixed=TRUE)

in an earlier code chunk and then call

\Sexpr(extra.slash( latexNum( 4*10^3 ) ) )

or better still just use a code chunk like this:

@
<>
cat( latexNum( 4*10^3 ) )
@ %def

HTH,

Chuck



Only produces this in the .tex output file:

$4cdot 10^{-3}$\\

No amount of extra backslashing seems to help. Any idea why my escapes are
not being respected?

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
--
View this message in context: 
http://www.nabble.com/Sweave-and-backslashes-tp21864385p21864385.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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


Re: [R] Sweave and backslashes

2009-02-05 Thread Frank E Harrell Jr

cls59 wrote:

Hello Everyone,

I am an avid Sweave user and I am trying to pretty print floating point
numbers for latex output. For example in my document, I would like:

4.2\cdot 10^-{8}

Instead of:

4.2e-08

The Hmisc package has a nice function for doing this- but Hmisc has a ton of
dependencies and has proved very unportable to the various machines I work
on. So, I set out to write my own function that just uses basic R commands,


Please name the dependencies that are bothering you.
Frank Harrell


it looks like this:

latexNum <- function (x,dig=4,sci=T) 
{

x <- format(x,digits=dig,scientific=sci)

 x <- gsub("e\\+00","",x)
 x <- gsub("e\\-0([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\-([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\+0([0-9]*)","cdot 10^{\\1}",x)
 x <- gsub("e\\+([0-9]*)","cdot 10^{\\1}",x)
 
return(x)

}

Everything works nicely, if I type


latexNum(4*10^-3)


I get

[1] "4\\cdot10^{-3}"

And the following:


cat(latexNum(4*10^-3))


Produces:

4\cdot10^{-3}

However the following in a .Rnw file:

$\Sexpr{latexNum(4*10^-3)}$\\

Only produces this in the .tex output file:

$4cdot 10^{-3}$\\

No amount of extra backslashing seems to help. Any idea why my escapes are
not being respected?

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State 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] Copula-GARCH

2009-02-05 Thread ahmed_shamiri
Hello,
 
I have two time series, and I want to obtain copula-GARCH. I know how to model 
the data with GARCH models but how to incorporate the GARCH model with copula 
is what I need.
 
Can anyone give me some tips about the code to estimate the copula-GARCH?
 
Thanks in advance
 
Shamiri




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

2009-02-05 Thread Patrick Connolly
On Sun, 01-Feb-2009 at 11:34PM -0500, Stavros Macrakis wrote:

|> A first step that would make the current Web page look much better
|> would be to anti-alias the demonstration graphic.  The current graphic
|> makes R graphics seem (falsely!) to be very primitive. I'm afraid I
|> don't know how to do the anti-aliasing myself.
|> 
|> Replacing the fixed-width, typewriter-style font with something a bit
|> more elegant might also be good

I'd say it would not be good.  Fixed-width fonts are desirable when
it's for code (of any language).  The example www.knime.org site uses
proportional fonts for R code which makes it hard to read IMHO.  I
really dislike that.

What's wrong with a spartan look?  Google has flourished with a
no-unnecessaries approach to home page clutter.


-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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

2009-02-05 Thread Farley, Robert
I'm trying to plot and compare weighted histograms and I can't seem find
where to start.  I have data similar to this:

 

Miles2LAX   RADAM2005Pct  LAWA2005Pct

35.57.00123.00684

24.74.00118.00187

27.09.00965.00876

16.23.00587.00397

{ ... 87 rows}

 

And I'm trying to compare the weighted distribution of "Miles" using the
two weightings: RADAM2005Pct and LAWA2005Pct.  Where do I begin?  I'd
ultimately like to have the two distributions on the same plot.  E.g.
one cross-hatched right and the other cross-hatched left.

 

 

Do I need to pretend this is a survey and the "percentages' are survey
weights?  How is such a svydesign formed?

 

 

 

 

Thanks in advance.

 

 

 

PS  I can plot a single unweighted histogram as follows:

> 

> SurveyData <- read.table("C:/Data/R/RADAMdata2.csv", header=TRUE,
sep=",", na.strings="NA", dec=".", strip.white=TRUE)

> MyX <- c(0,5,10,15,20,30,40,50,60,120)

> hist(SurveyData$Miles2LAX, breaks = MyX,

+  include.lowest = TRUE, right = TRUE,

+  angle = 45, 

+  main = paste("Histogram of unweighted distances" ),

+  axes = TRUE, plot = TRUE )

> 

>
describe(SurveyData,num.desc=c("mean","median","var","sd","valid.n"),xna
me=NA,maxfac=18,show.pc=TRUE)

Description of SurveyData 

 

Numeric

   meanmedian   varsd   valid.n

RADAM.TAZ 52.1751 766.7 27.6987

Miles2LAX 35.31 32.74 508.1 22.5487

RADAM2005Vol1.2e+05 8.199e+04 2.421e+10 1.556e+0587

RADAM2005Pct0.01149  0.007853 0.00022210.014987

LAWA2005Vol 17676 7.051e+04 265.587

LAWA2005Pct 0.01149  0.004963 0.0003007   0.0173487

 

Factor

29 Palms Alhambra/San Gab  Anaheim
Anaheim/Disneyla   Angeles Forest Baldwin Hills/US Bell Cyn
Beverly Hills Big Bear/ArrowheBrentwood  Burbank
Camarillo  Canoga Park  Castiac   Chatsworth
Chino Commerce  Compton

RADAM.Name 111
11111
11111
11111

Percent 1.15 1.15 1.15
1.15 1.15 1.15 1.15 1.15
1.15 1.15 1.15 1.15 1.15
1.15 1.15 1.15 1.15 1.15

mode = >1 mode  Valid n = 87   87 categories - only first 18 shown

 

> range(SurveyData$Miles2LAX, na.rm = TRUE)

[1]   2.11 113.99

> 

> 

 

 

 

 

 

Robert Farley

Metro

1 Gateway Plaza

Mail Stop 99-23-7

Los Angeles, CA 90012-2952

Voice: (213)922-2532

Fax:(213)922-2868

www.Metro.net 

 

 


[[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] Can you send out an email message through Lotus Notes clients from an R script?

2009-02-05 Thread Elaine Jones


Can R do emailing via the Lotus Notes API like SAS can?  Canyou run a
script and based on results send out an email report?  I just briefly
looked through the packages and didn't see one that looked like it might be
it, but that conclusion was based on the package names only.  Is anyone
using R  to automate emails from their Lotus Notes clients?
[[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] eval and as.name

2009-02-05 Thread Gabor Grothendieck
Try this:

library(quantmod)
s <- c("MSFT","AAPL","ORCL")

f <- function(x) Delt(Cl(getSymbols(x, auto.assign = FALSE)))
Delt3 <- do.call(merge, lapply(s, f))
plot(as.zoo(Delt3), screen = 1, col = 1:3)

On Thu, Feb 5, 2009 at 7:49 PM, Fuchs Ira  wrote:
> VERY nice.  That certainly works. Now how does one plot all three variables
> on one graph? :-)
>
> Thanks very much.
>
> Ira
>
> On Feb 5, 2009, at 7:29 PM, Phil Spector wrote:
>
>> Ira -
>>  As you say, there are many ways to solve this problem.
>> Here's one of them:
>>
>> list=c("MSFT","AAPL","ORCL")
>> getSymbols(list)
>>
>> #First, create a function that will take the name of a variable,
>> #get the Close value from it and pass it to the Delt function:
>>
>> makedelt = function(l){now = get(l) ;
>> Delt(now[,paste(l,".Close",sep='')])}
>>
>> #Now create a list of the results from Delt:
>>
>> allclose = lapply(list,makedelt)
>>
>> #Finally pass the list to Reduce to merge them all together:
>>
>> result = Reduce(merge,allclose)
>>
>> #To better identify the columns, you can use
>>
>> colnames(result) = list
>>
>> Hope this helps.
>>  - Phil Spector
>> Statistical Computing Facility
>> Department of Statistics
>> UC Berkeley
>> spec...@stat.berkeley.edu
>>
>>
>>
>> On Thu, 5 Feb 2009, Fuchs Ira wrote:
>>
>>> These are all great resposes but I think I should have given a
>>> slightly more complete description of the problem.
>>>
>>> I am using the quantmod package and I have called getSymbols with a
>>> character vector that has a list of stock symbols. For example:
>>>
>>> library("quantmod")
>>> list=c("MSFT","AAPL","ORCL")
>>> getSymbols(list)
>>>
>>> this returns 3 objects (MSFT,AAPL, ORCL)
>>>
>>> now imagine that I want to use the Delt function (also in quantmod) to
>>> calculate the percent difference for each of these stocks using their
>>> closing price.
>>>
>>> each closing price is SYMBOL$SYMBOL.Close (can also be retrieved with
>>> Cl(SYMBOL)
>>>
>>> I want to construct the call to Delt with the symbols in list appended
>>> with $SYMBOL.Adjusted
>>>
>>> in other words I want a way to create
>>>
>>> Delt(MSFT$MSFT.Close) merged with Delt(AAPL$AAPL.Close) and so on
>>> (one object having the result of the Delt function for each stock).
>>>
>>> I am sure that there are many ways to solve this particular problem.
>>> Perhaps what I need to understand is how to take the characters in the
>>> list and construct an expression  and then evaluate the expression.
>>>
>>>
>>> On Feb 5, 2009, at 5:50 PM,  wrote:
>>>
 Hi:  there's mget but I couldn't figure out how to use it. if you
 figure
 it out, let me know.
 I'm sure one of the guRus will reply with something that uses mget.
 List
 is slow now
 because Europe is sleeping. Good luck.




 On Thu, Feb 5, 2009 at  5:42 PM, Ira Fuchs wrote:

> Thanks, that is better but doesn't actually solve my problem which

 is
>
> that n is an arbitrary length vector and I'd like to find a way that
> avoids having to enumerate the elements of the character vector.
> Thanks,
> Ira
> - Original Message -
> From: markle...@verizon.net 
> To: Fuchs Ira 
> Sent: Thu Feb 05 17:25:39 2009
> Subject: RE: [R] eval and as.name
>
>
> Hi: below works but it's not much shorter than yours.  there must

 be a
>
> better way so I'm sending off line in order to encourage better
> replies.
>
> sum(get(n[1]),get(n[2]))
>
>
>
>
> On Thu, Feb 5, 2009 at  5:10 PM, Fuchs Ira wrote:
>
>> I'm sure there is a more general way to ask this question but how

 do
>>
>> you use the elements of a character vector as names of objects in

 an
>>
>> expression?
>> For example, say you have:
>>
>> a = c(1,3,5,7)
>> b = c(2,4,6,8)
>>
>> n=c("a","b")
>>
>> and you want to use the names a and b in a function (e.g. sum)
>>
>> sum(eval(as.name(n[1])),eval(as.name(n[2])))
>>
>> works but
>>
>> what is a simpler way to effect this level of indirection?
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

>>>
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, repr

Re: [R] eval and as.name

2009-02-05 Thread Fuchs Ira
VERY nice.  That certainly works. Now how does one plot all three  
variables on one graph? :-)


Thanks very much.

Ira

On Feb 5, 2009, at 7:29 PM, Phil Spector wrote:


Ira -
  As you say, there are many ways to solve this problem.
Here's one of them:

list=c("MSFT","AAPL","ORCL")
getSymbols(list)

#First, create a function that will take the name of a variable,
#get the Close value from it and pass it to the Delt function:

makedelt = function(l){now = get(l) ;  
Delt(now[,paste(l,".Close",sep='')])}


#Now create a list of the results from Delt:

allclose = lapply(list,makedelt)

#Finally pass the list to Reduce to merge them all together:

result = Reduce(merge,allclose)

#To better identify the columns, you can use

colnames(result) = list

Hope this helps.
  - Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu



On Thu, 5 Feb 2009, Fuchs Ira wrote:


These are all great resposes but I think I should have given a
slightly more complete description of the problem.

I am using the quantmod package and I have called getSymbols with a
character vector that has a list of stock symbols. For example:

library("quantmod")
list=c("MSFT","AAPL","ORCL")
getSymbols(list)

this returns 3 objects (MSFT,AAPL, ORCL)

now imagine that I want to use the Delt function (also in quantmod)  
to

calculate the percent difference for each of these stocks using their
closing price.

each closing price is SYMBOL$SYMBOL.Close (can also be retrieved with
Cl(SYMBOL)

I want to construct the call to Delt with the symbols in list  
appended

with $SYMBOL.Adjusted

in other words I want a way to create

Delt(MSFT$MSFT.Close) merged with Delt(AAPL$AAPL.Close) and so on
(one object having the result of the Delt function for each stock).

I am sure that there are many ways to solve this particular problem.
Perhaps what I need to understand is how to take the characters in  
the

list and construct an expression  and then evaluate the expression.


On Feb 5, 2009, at 5:50 PM,  wrote:


Hi:  there's mget but I couldn't figure out how to use it. if you
figure
it out, let me know.
I'm sure one of the guRus will reply with something that uses mget.
List
is slow now
because Europe is sleeping. Good luck.




On Thu, Feb 5, 2009 at  5:42 PM, Ira Fuchs wrote:


Thanks, that is better but doesn't actually solve my problem which

is
that n is an arbitrary length vector and I'd like to find a way  
that

avoids having to enumerate the elements of the character vector.
Thanks,
Ira
- Original Message -
From: markle...@verizon.net 
To: Fuchs Ira 
Sent: Thu Feb 05 17:25:39 2009
Subject: RE: [R] eval and as.name


Hi: below works but it's not much shorter than yours.  there must

be a

better way so I'm sending off line in order to encourage better
replies.

sum(get(n[1]),get(n[2]))




On Thu, Feb 5, 2009 at  5:10 PM, Fuchs Ira wrote:


I'm sure there is a more general way to ask this question but how

do

you use the elements of a character vector as names of objects in

an

expression?
For example, say you have:

a = c(1,3,5,7)
b = c(2,4,6,8)

n=c("a","b")

and you want to use the names a and b in a function (e.g. sum)

sum(eval(as.name(n[1])),eval(as.name(n[2])))

works but

what is a simpler way to effect this level of indirection?

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





[[alternative HTML version deleted]]

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



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 separate char and num within a variable

2009-02-05 Thread Bill Hyman
Thank you!



- Original Message 
From: "markle...@verizon.net" 
To: Bill Hyman 
Sent: Thursday, February 5, 2009 3:35:54 PM
Subject: RE: [R] how to separate char and num within a variable

hi: you can do below but there should possibly be a better way so I'm sending 
offline in
order to encourage better replies from the guRus. good luck.


temp <- "chr1:000889594-000889638"
temp2 <- strsplit(temp, ":|-")
print(temp2)





"chr1:000889594-000889638",




On Thu, Feb 5, 2009 at  6:20 PM, Bill Hyman wrote:

> Hi all,
> 
> I read in a column which looks like "chr1:000889594-000889638", and need to 
> break them into three columns like "chr1:", "000889594" and "000889638". How 
> shall I do in R. Thanks a lot for your suggestions!
> 
> Bill
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 separate char and num within a variable

2009-02-05 Thread Bill Hyman
Thx a lot!



- Original Message 
From: Marc Schwartz 
To: Bill Hyman 
Cc: r-help@r-project.org
Sent: Thursday, February 5, 2009 3:39:53 PM
Subject: Re: [R] how to separate char and num within a variable

on 02/05/2009 05:20 PM Bill Hyman wrote:
> Hi all,
> 
> I read in a column which looks like "chr1:000889594-000889638", and
> need to break them into three columns like "chr1:", "000889594" and
> "000889638". How shall I do in R. Thanks a lot for your suggestions!

See ?strsplit

Vec <- "chr1:000889594-000889638"

> Vec
[1] "chr1:000889594-000889638"

# Use a regular expression, defining the 'split' character
# as either ":" or "-", where the vertical bar means 'or':
> strsplit(Vec, split = ":|-")
[[1]]
[1] "chr1"  "000889594" "000889638"


Note that the split characters are not retained in the result.

Let's presume that you have a column in a data frame of the original
data and wish to split it into 3 columns:

DF <- data.frame(Col = rep(Vec, 10))

> DF
Col
1  chr1:000889594-000889638
2  chr1:000889594-000889638
3  chr1:000889594-000889638
4  chr1:000889594-000889638
5  chr1:000889594-000889638
6  chr1:000889594-000889638
7  chr1:000889594-000889638
8  chr1:000889594-000889638
9  chr1:000889594-000889638
10 chr1:000889594-000889638

Note that by default, 'Col' will be a factor and strsplit() expects a
character vector, thus we do the coercion and use do.call() to create a
character matrix, via rbind(), from the result:

> do.call(rbind, strsplit(as.character(DF$Col), split = ":|-"))
  [,1]   [,2][,3]
[1,] "chr1" "000889594" "000889638"
[2,] "chr1" "000889594" "000889638"
[3,] "chr1" "000889594" "000889638"
[4,] "chr1" "000889594" "000889638"
[5,] "chr1" "000889594" "000889638"
[6,] "chr1" "000889594" "000889638"
[7,] "chr1" "000889594" "000889638"
[8,] "chr1" "000889594" "000889638"
[9,] "chr1" "000889594" "000889638"
[10,] "chr1" "000889594" "000889638"


See ?regex, ?do.call and ?rbind for more information.

HTH,

Marc Schwartz

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


Re: [R] how to separate char and num within a variable

2009-02-05 Thread Bill Hyman
Thx a lot! It works



- Original Message 
From: Wacek Kusnierczyk 
To: Bill Hyman 
Cc: R help 
Sent: Thursday, February 5, 2009 3:38:34 PM
Subject: Re: [R] how to separate char and num within a variable

Bill Hyman wrote:
> Hi all,
>
> I read in a column which looks like "chr1:000889594-000889638", and need to 
> break them into three columns like "chr1:", "000889594" and "000889638". How 
> shall I do in R. Thanks a lot for your suggestions!
>
>  

if strings is your vector of strings, this should do (assuming the
format is stable across all entries):

strsplit(strings, split=':|-')

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.


[R] Sweave and backslashes

2009-02-05 Thread cls59

Hello Everyone,

I am an avid Sweave user and I am trying to pretty print floating point
numbers for latex output. For example in my document, I would like:

4.2\cdot 10^-{8}

Instead of:

4.2e-08

The Hmisc package has a nice function for doing this- but Hmisc has a ton of
dependencies and has proved very unportable to the various machines I work
on. So, I set out to write my own function that just uses basic R commands,
it looks like this:

latexNum <- function (x,dig=4,sci=T) 
{
x <- format(x,digits=dig,scientific=sci)

 x <- gsub("e\\+00","",x)
 x <- gsub("e\\-0([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\-([0-9]*)","cdot 10^{-\\1}",x)
 x <- gsub("e\\+0([0-9]*)","cdot 10^{\\1}",x)
 x <- gsub("e\\+([0-9]*)","cdot 10^{\\1}",x)
 
return(x)
}

Everything works nicely, if I type

> latexNum(4*10^-3)

I get

[1] "4\\cdot10^{-3}"

And the following:

> cat(latexNum(4*10^-3))

Produces:

4\cdot10^{-3}

However the following in a .Rnw file:

$\Sexpr{latexNum(4*10^-3)}$\\

Only produces this in the .tex output file:

$4cdot 10^{-3}$\\

No amount of extra backslashing seems to help. Any idea why my escapes are
not being respected?

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Sweave-and-backslashes-tp21864385p21864385.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] eval and as.name

2009-02-05 Thread Fuchs Ira
These are all great resposes but I think I should have given a  
slightly more complete description of the problem.

I am using the quantmod package and I have called getSymbols with a  
character vector that has a list of stock symbols. For example:

library("quantmod")
list=c("MSFT","AAPL","ORCL")
getSymbols(list)

this returns 3 objects (MSFT,AAPL, ORCL)

now imagine that I want to use the Delt function (also in quantmod) to  
calculate the percent difference for each of these stocks using their  
closing price.

each closing price is SYMBOL$SYMBOL.Close (can also be retrieved with  
Cl(SYMBOL)

I want to construct the call to Delt with the symbols in list appended  
with $SYMBOL.Adjusted

in other words I want a way to create

Delt(MSFT$MSFT.Close) merged with Delt(AAPL$AAPL.Close) and so on   
(one object having the result of the Delt function for each stock).

I am sure that there are many ways to solve this particular problem.   
Perhaps what I need to understand is how to take the characters in the  
list and construct an expression  and then evaluate the expression.


On Feb 5, 2009, at 5:50 PM,  wrote:

> Hi:  there's mget but I couldn't figure out how to use it. if you  
> figure
> it out, let me know.
> I'm sure one of the guRus will reply with something that uses mget.  
> List
> is slow now
> because Europe is sleeping. Good luck.
>
>
>
>
> On Thu, Feb 5, 2009 at  5:42 PM, Ira Fuchs wrote:
>
> > Thanks, that is better but doesn't actually solve my problem which  
> is
> > that n is an arbitrary length vector and I'd like to find a way that
> > avoids having to enumerate the elements of the character vector.
> > Thanks,
> > Ira
> > - Original Message -
> > From: markle...@verizon.net 
> > To: Fuchs Ira 
> > Sent: Thu Feb 05 17:25:39 2009
> > Subject: RE: [R] eval and as.name
> >
> >
> > Hi: below works but it's not much shorter than yours.  there must  
> be a
> > better way so I'm sending off line in order to encourage better
> > replies.
> >
> > sum(get(n[1]),get(n[2]))
> >
> >
> >
> >
> > On Thu, Feb 5, 2009 at  5:10 PM, Fuchs Ira wrote:
> >
> >> I'm sure there is a more general way to ask this question but how  
> do
> >> you use the elements of a character vector as names of objects in  
> an
> >> expression?
> >> For example, say you have:
> >>
> >> a = c(1,3,5,7)
> >> b = c(2,4,6,8)
> >>
> >> n=c("a","b")
> >>
> >> and you want to use the names a and b in a function (e.g. sum)
> >>
> >> sum(eval(as.name(n[1])),eval(as.name(n[2])))
> >>
> >> works but
> >>
> >> what is a simpler way to effect this level of indirection?
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
>


[[alternative HTML version deleted]]

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


Re: [R] eval and as.name

2009-02-05 Thread Wacek Kusnierczyk
Marie Sivertsen wrote:
> Hi,
>
> Why do you use the equals sign for assignment instead of the arrow, is this
> equal?
>
>   

equal?  you mean equivalent?  mostly, yes.  briefly, this is why:

1. a copy-over from other programming languages;
2. to avoid learning yet another operator;
3. after having learned the other operator, to avoid that ugly operator;
4. after an r guru complained here about people using this instead of
that, to annoy him.

hilsen,
vQ


> Mvh.
> Marie
>
> On Thu, Feb 5, 2009 at 11:59 PM, Wacek Kusnierczyk <
> waclaw.marcin.kusnierc...@idi.ntnu.no> wrote:
>
>   
>> you may want to avoid this sort of indirection by using lists with named
>> components:
>>
>> d = list(a=c(1,3,5,7), b=c(2,4,6,8))
>> sum(unlist(d))
>> with(d, sum(a+b))
>> sum(d[['a']], d[['b']])
>> sum(sapply(n, function(v) d[[v]]))
>>
>> and so on.
>>
>> 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.
>>
>>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 separate char and num within a variable

2009-02-05 Thread Marc Schwartz
on 02/05/2009 05:20 PM Bill Hyman wrote:
> Hi all,
> 
> I read in a column which looks like "chr1:000889594-000889638", and
> need to break them into three columns like "chr1:", "000889594" and
> "000889638". How shall I do in R. Thanks a lot for your suggestions!

See ?strsplit

Vec <- "chr1:000889594-000889638"

> Vec
[1] "chr1:000889594-000889638"

# Use a regular expression, defining the 'split' character
# as either ":" or "-", where the vertical bar means 'or':
> strsplit(Vec, split = ":|-")
[[1]]
[1] "chr1"  "000889594" "000889638"


Note that the split characters are not retained in the result.

Let's presume that you have a column in a data frame of the original
data and wish to split it into 3 columns:

DF <- data.frame(Col = rep(Vec, 10))

> DF
Col
1  chr1:000889594-000889638
2  chr1:000889594-000889638
3  chr1:000889594-000889638
4  chr1:000889594-000889638
5  chr1:000889594-000889638
6  chr1:000889594-000889638
7  chr1:000889594-000889638
8  chr1:000889594-000889638
9  chr1:000889594-000889638
10 chr1:000889594-000889638

Note that by default, 'Col' will be a factor and strsplit() expects a
character vector, thus we do the coercion and use do.call() to create a
character matrix, via rbind(), from the result:

> do.call(rbind, strsplit(as.character(DF$Col), split = ":|-"))
  [,1]   [,2][,3]
 [1,] "chr1" "000889594" "000889638"
 [2,] "chr1" "000889594" "000889638"
 [3,] "chr1" "000889594" "000889638"
 [4,] "chr1" "000889594" "000889638"
 [5,] "chr1" "000889594" "000889638"
 [6,] "chr1" "000889594" "000889638"
 [7,] "chr1" "000889594" "000889638"
 [8,] "chr1" "000889594" "000889638"
 [9,] "chr1" "000889594" "000889638"
[10,] "chr1" "000889594" "000889638"


See ?regex, ?do.call and ?rbind for more information.

HTH,

Marc Schwartz

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


Re: [R] how to separate char and num within a variable

2009-02-05 Thread Wacek Kusnierczyk
Bill Hyman wrote:
> Hi all,
>
> I read in a column which looks like "chr1:000889594-000889638", and need to 
> break them into three columns like "chr1:", "000889594" and "000889638". How 
> shall I do in R. Thanks a lot for your suggestions!
>
>   

if strings is your vector of strings, this should do (assuming the
format is stable across all entries):

strsplit(strings, split=':|-')

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] eval and as.name

2009-02-05 Thread Marie Sivertsen
Hi,

Why do you use the equals sign for assignment instead of the arrow, is this
equal?

Mvh.
Marie

On Thu, Feb 5, 2009 at 11:59 PM, Wacek Kusnierczyk <
waclaw.marcin.kusnierc...@idi.ntnu.no> wrote:

>
> you may want to avoid this sort of indirection by using lists with named
> components:
>
> d = list(a=c(1,3,5,7), b=c(2,4,6,8))
> sum(unlist(d))
> with(d, sum(a+b))
> sum(d[['a']], d[['b']])
> sum(sapply(n, function(v) d[[v]]))
>
> and so on.
>
> 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.
>

[[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 separate char and num within a variable

2009-02-05 Thread Bill Hyman
Hi all,

I read in a column which looks like "chr1:000889594-000889638", and need to 
break them into three columns like "chr1:", "000889594" and "000889638". How 
shall I do in R. Thanks a lot for your suggestions!

Bill

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

2009-02-05 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote:
> Fuchs Ira wrote:
>   
>> I'm sure there is a more general way to ask this question but how do
>> you use the elements of a character vector as names of objects in an
>> expression?
>> For example, say you have:
>>
>> a = c(1,3,5,7)
>> b = c(2,4,6,8)
>>
>> n=c("a","b")
>>
>> and you want to use the names a and b in a function (e.g. sum)
>>
>> sum(eval(as.name(n[1])),eval(as.name(n[2])))
>>
>> works but
>>
>> what is a simpler way to effect this level of indirection?
>>
>> 
>
> in this particular case, the simplest i can come up with is:
>
> sum(sapply(n, get))
>
> you may want to avoid this sort of indirection by using lists with named
> components:
>
> d = list(a=c(1,3,5,7), b=c(2,4,6,8))
> sum(unlist(d))
> with(d, sum(a+b))
>   
should have been one of

with(d, sum(a,b))
with(d, a+b)

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] eval and as.name

2009-02-05 Thread Wacek Kusnierczyk
Murray Cooper wrote:
> I am new to R, so maybe I'm missing the point of your question. But
> why wouldn't you just use sum(a,b)?

if you know you want to sum a and b, sure you would.  if you need to sum
the variables named by the components of some dynamic character vector,
you need to lookup ('dereference') the names in some way.

vQ

>
> Murray M Cooper, Ph.D.
> Richland Statistics
> 9800 N 24th St
> Richland, MI, USA 49083
> Mail: richs...@earthlink.net
> - Original Message - From: "Fuchs Ira" 
> To: 
> Sent: Thursday, February 05, 2009 5:10 PM
> Subject: [R] eval and as.name
>
>
>> I'm sure there is a more general way to ask this question but how do 
>> you use the elements of a character vector as names of objects in an
>> expression?
>> For example, say you have:
>>
>> a = c(1,3,5,7)
>> b = c(2,4,6,8)
>>
>> n=c("a","b")
>>
>> and you want to use the names a and b in a function (e.g. sum)
>>
>> sum(eval(as.name(n[1])),eval(as.name(n[2])))
>>
>> works but
>>
>> what is a simpler way to effect this level of indirection?
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] eval and as.name

2009-02-05 Thread Wacek Kusnierczyk
Fuchs Ira wrote:
> I'm sure there is a more general way to ask this question but how do
> you use the elements of a character vector as names of objects in an
> expression?
> For example, say you have:
>
> a = c(1,3,5,7)
> b = c(2,4,6,8)
>
> n=c("a","b")
>
> and you want to use the names a and b in a function (e.g. sum)
>
> sum(eval(as.name(n[1])),eval(as.name(n[2])))
>
> works but
>
> what is a simpler way to effect this level of indirection?
>

in this particular case, the simplest i can come up with is:

sum(sapply(n, get))

you may want to avoid this sort of indirection by using lists with named
components:

d = list(a=c(1,3,5,7), b=c(2,4,6,8))
sum(unlist(d))
with(d, sum(a+b))
sum(d[['a']], d[['b']])
sum(sapply(n, function(v) d[[v]]))

and so on.

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] eval and as.name

2009-02-05 Thread Murray Cooper
I am new to R, so maybe I'm missing the point of your question. But why 
wouldn't you just use sum(a,b)?


Murray M Cooper, Ph.D.
Richland Statistics
9800 N 24th St
Richland, MI, USA 49083
Mail: richs...@earthlink.net
- Original Message - 
From: "Fuchs Ira" 

To: 
Sent: Thursday, February 05, 2009 5:10 PM
Subject: [R] eval and as.name


I'm sure there is a more general way to ask this question but how do  you 
use the elements of a character vector as names of objects in an 
expression?

For example, say you have:

a = c(1,3,5,7)
b = c(2,4,6,8)

n=c("a","b")

and you want to use the names a and b in a function (e.g. sum)

sum(eval(as.name(n[1])),eval(as.name(n[2])))

works but

what is a simpler way to effect this level of indirection?

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

2009-02-05 Thread Fuchs Ira
I'm sure there is a more general way to ask this question but how do  
you use the elements of a character vector as names of objects in an  
expression?

For example, say you have:

a = c(1,3,5,7)
b = c(2,4,6,8)

n=c("a","b")

and you want to use the names a and b in a function (e.g. sum)

sum(eval(as.name(n[1])),eval(as.name(n[2])))

works but

what is a simpler way to effect this level of indirection?

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

2009-02-05 Thread Albyn Jones
The computation 2*sum(dbinom(c(10:25),25,0.061)) does not correspond
to any reasonable definition of p-value.  For a symmetric
distribution, it is fine to use 2 times the tail area of one tail.
For an asymetric distribution, this is silly.

The standard definition given in elementary texts is usually somthing like

 the probability of observing a test statistic at least as 
  extreme as the observed value

or more formally as 

  the smallest significance level at which the observed result would
  lead to rejection of the null hypothesis

Either definition requires further decisions (what does "at least as
extreme" mean?).  In an asymetric distribution, "at least as far from
E(X|H0)"  is not a good interpretation, since deviations in one direction 
may be much less probable than deviations in the other direction.  

Peter's interpretation corresponds both to the interpretation of "at
least as extreme" as "at least as improbable", and also to the
"smallest significance level" interpretation for the test implemented
in binom.test, ie the Clopper-Pearson "exact" test.  2 times the upper
tail area corresponds to neither.  The fact that it is implemented in
SAS and appears in a text do not rescue it from that fundamental
failure to make sense.

albyn

On Thu, Feb 05, 2009 at 09:48:11PM +0100, Peter Dalgaard wrote:
> Michael Grant wrote:
>> I believe the binom.test procedure is producing one tailed p values
>> rather than the two tailed value implied by the alternative hypothesis
>> language.  A textbook and SAS both show 2*9.94e-07 = 1.988e-06 as the
>> two tailed value.  As does the R summation syntax from R below.  It
>> looks to me like the alternative hypothesis language should be revised
>> to something like " ... greater than or equal to ..."  Am I mistaken?
>
>
> Yes. Or maybe, it is a matter of definition. The problem is that
>
> > (0:25)[dbinom(0:25,25,.061) <= dbinom(10,25,.061)]
>  [1] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
>
> so with R's definition of "more extreme", all such values are in the upper 
> tail.
>
> Actually, if you look at the actual distribution, I think you'll agree that 
> it is rather difficult to define a lower tail with positive probability 
> that corresponds to X >= 10.
>
> > round(dbinom(0:25,25,.061),6)
>  [1] 0.207319 0.336701 0.262476 0.130726 0.046708 0.012744
>  [7] 0.002760 0.000487 0.71 0.09 0.01 0.00
> [13] 0.00 0.00 0.00 0.00 0.00 0.00
> [19] 0.00 0.00 0.00 0.00 0.00 0.00
> [25] 0.00 0.00
>
> In any case, you would be hard pressed to find a subset of 0:25 that has 
> the probability that SAS and your textbook claims as the p value.
>
>
>>
>>  
>> M.C.Grant
>>
>>  
>>> 2*sum(dbinom(c(10:25),25,0.061))
>>
>> [1] 1.987976e-06
>>
>>  
>>> binom.test(10,25,0.061)
>>
>>  
>> Exact binomial test
>>
>>  
>> data:  10 and 25 
>> number of successes = 10, number of trials = 25, p-value = 9.94e-07
>>
>> alternative hypothesis: true probability of success is not equal to
>> 0.061 
>> 95 percent confidence interval:
>>
>>  0.2112548 0.6133465 
>> sample estimates:
>>
>> probability of success 
>>0.4
>>
>>
>>  [[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.
>
>
> -- 
>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.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] subset problem (reducing from six to two levels)

2009-02-05 Thread Stephan Kolassa

Hi,

does this help?

http://www.nabble.com/factor-question-to18638814.html#a18638814

HTH,
Stephan


Ine schrieb:

Hi all,
I have got a seemingly simple problem (I am an R starter) with subsetting my
data set, but cannot figure out the solution: I want to subset a data set
from six to two levels, so that all analyses are done only with these two
remaining levels.
I tried

TOTAL<-read.delim('total.csv',header=T)
SUBSET.OF.TOTAL<-subset(TOTAL, FactorX %in% c("Level1","Level2"))
attach(SUBSET.OF.TOTAL)

but R does not eliminate the remaining levels of FactorX, just assigns 'not
available' to the data. Like this, the other levels still show up in plots
etc., but without data entries. Anybody got a solution how to subset the
data so that I eliminate the other levels completely?

Thanks a lot for the help,



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


Re: [R] subset problem (reducing from six to two levels)

2009-02-05 Thread Peter Dalgaard

Ine wrote:

Hi all,
I have got a seemingly simple problem (I am an R starter) with subsetting my
data set, but cannot figure out the solution: I want to subset a data set
from six to two levels, so that all analyses are done only with these two
remaining levels.
I tried

TOTAL<-read.delim('total.csv',header=T)
SUBSET.OF.TOTAL<-subset(TOTAL, FactorX %in% c("Level1","Level2"))
attach(SUBSET.OF.TOTAL)

but R does not eliminate the remaining levels of FactorX, just assigns 'not
available' to the data. Like this, the other levels still show up in plots
etc., but without data entries. Anybody got a solution how to subset the
data so that I eliminate the other levels completely?

Thanks a lot for the help,



R does not "assign 'not available'" (look at the subsetted data).

However, factors do not lose levels just because they are not present in 
a subset of data. There are good reasons for that, but let's not go 
there this time (look in the list archives if you care). To get rid of 
unwanted levels, use


FactorXX <- factor(FactorX, levels=c("Level1","Level2"))

or just factor(FactorX) if you know that both levels are present (or 
don't care).



--
   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] subset problem (reducing from six to two levels)

2009-02-05 Thread Philipp Pagel
On Thu, Feb 05, 2009 at 01:01:59PM -0800, Ine wrote:
> 
> Hi all,
> I have got a seemingly simple problem (I am an R starter) with subsetting my
> data set, but cannot figure out the solution: I want to subset a data set
> from six to two levels, so that all analyses are done only with these two
> remaining levels.
> I tried
> 
> TOTAL<-read.delim('total.csv',header=T)
> SUBSET.OF.TOTAL<-subset(TOTAL, FactorX %in% c("Level1","Level2"))
> attach(SUBSET.OF.TOTAL)
> 
> but R does not eliminate the remaining levels of FactorX,

One solution is to have the factors re-built after subsetting:

foo = factor(c('a','a','b','c','c'))

# unused levels persistent:
> foo[foo=='a']
[1] a a
Levels: a b c

# but:
> factor(foo[foo=='a'])
[1] a a
Levels: a

cu
Philipp


-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] subset problem (reducing from six to two levels)

2009-02-05 Thread Ine

Hi all,
I have got a seemingly simple problem (I am an R starter) with subsetting my
data set, but cannot figure out the solution: I want to subset a data set
from six to two levels, so that all analyses are done only with these two
remaining levels.
I tried

TOTAL<-read.delim('total.csv',header=T)
SUBSET.OF.TOTAL<-subset(TOTAL, FactorX %in% c("Level1","Level2"))
attach(SUBSET.OF.TOTAL)

but R does not eliminate the remaining levels of FactorX, just assigns 'not
available' to the data. Like this, the other levels still show up in plots
etc., but without data entries. Anybody got a solution how to subset the
data so that I eliminate the other levels completely?

Thanks a lot for the help,

-- 
View this message in context: 
http://www.nabble.com/subset-problem-%28reducing-from-six-to-two-levels%29-tp21861044p21861044.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] Incorrect p value for binom.test?

2009-02-05 Thread Peter Dalgaard

Michael Grant wrote:

I believe the binom.test procedure is producing one tailed p values
rather than the two tailed value implied by the alternative hypothesis
language.  A textbook and SAS both show 2*9.94e-07 = 1.988e-06 as the
two tailed value.  As does the R summation syntax from R below.  It
looks to me like the alternative hypothesis language should be revised
to something like " ... greater than or equal to ..."  Am I mistaken?



Yes. Or maybe, it is a matter of definition. The problem is that

> (0:25)[dbinom(0:25,25,.061) <= dbinom(10,25,.061)]
 [1] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

so with R's definition of "more extreme", all such values are in the 
upper tail.


Actually, if you look at the actual distribution, I think you'll agree 
that it is rather difficult to define a lower tail with positive 
probability that corresponds to X >= 10.


> round(dbinom(0:25,25,.061),6)
 [1] 0.207319 0.336701 0.262476 0.130726 0.046708 0.012744
 [7] 0.002760 0.000487 0.71 0.09 0.01 0.00
[13] 0.00 0.00 0.00 0.00 0.00 0.00
[19] 0.00 0.00 0.00 0.00 0.00 0.00
[25] 0.00 0.00

In any case, you would be hard pressed to find a subset of 0:25 that has 
the probability that SAS and your textbook claims as the p value.





 


M.C.Grant

 


2*sum(dbinom(c(10:25),25,0.061))


[1] 1.987976e-06

 


binom.test(10,25,0.061)


 


Exact binomial test

 

data:  10 and 25 


number of successes = 10, number of trials = 25, p-value = 9.94e-07

alternative hypothesis: true probability of success is not equal to
0.061 


95 percent confidence interval:

 0.2112548 0.6133465 


sample estimates:

probability of success 


   0.4


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



--
   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] lattice key inside panel

2009-02-05 Thread Deepayan Sarkar
On Thu, Feb 5, 2009 at 11:28 AM, Dieter Menne
 wrote:
> Deepayan Sarkar  gmail.com> writes:
>
>> > One other thing that has so far eluded me is how to specify two
>> > different kinds of symbols on a single column. The key above shows
>> >
>> > text line text rectangle
>> >
>> > but I would really like to get
>> >
>> > text line
>> > text rectangle
>> >
>> > but this did not seem possible to me. Am I wrong?
>>
>> Not possible with draw.key(), but legends can be arbitrary grobs, so
>> you could construct a suitable one.
>
> I would have guessed that columns=2 would work, but you are right,
> it given an error message (Not enough rows for columns). Why?

It's a warning, not an error. 'columns' are meant to spread out
multiple rows into several "column blocks", but there is only one row
here.

-Deepayan

>
> Dieter
>
> xyplot(1~1,
>   panel = function(...) {
>   require(grid)
>   panel.xyplot(...)
>   draw.key(list(text=list(lab='catch'),
> columns=2,
> lines=list(lwd=c(2)),
> text=list(lab='landings'),
> rectangles=list(col=rgb(0.1, 0.1, 0, 0.1))),
>  draw = TRUE,
>  vp = viewport(x = unit(0.75, "npc"), y = unit(0.9, "npc")))
>   })
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] R system command on windows

2009-02-05 Thread Stephan Kolassa

?shell

HTH,
Stephan

Aurelie Labbe, Dr. schrieb:

Hi,
 
I am trying to use the R command "system"  under windows (XP). If I try the simple command system("mkdir toto") to create a directory toto, it tells me that it cannot find the command mkdir...

Does anybody knows how  it works ? Is it a path problem ? Maybe the answer is 
simple: I am a R user under Unix/Linux and I don't know well R under windows.
 
Thanks !

Aurelie

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

2009-02-05 Thread Uwe Ligges



Aurelie Labbe, Dr. wrote:

Hi,
 
I am trying to use the R command "system"  under windows (XP). If I try the simple command system("mkdir toto") to create a directory toto, it tells me that it cannot find the command mkdir...

Does anybody knows how  it works ? Is it a path problem ? Maybe the answer is 
simple: I am a R user under Unix/Linux and I don't know well R under windows.




See ?system which tells you to execute the Windows command shell 
(cmd.exe) which is required to run mkdir or easier, just use the wrapper 
function shell() as in:

shell("mkdir toto")

Uwe Ligges





Thanks !
Aurelie

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

2009-02-05 Thread Aurelie Labbe, Dr.
Hi,
 
I am trying to use the R command "system"  under windows (XP). If I try the 
simple command system("mkdir toto") to create a directory toto, it tells me 
that it cannot find the command mkdir...
Does anybody knows how  it works ? Is it a path problem ? Maybe the answer is 
simple: I am a R user under Unix/Linux and I don't know well R under windows.
 
Thanks !
Aurelie

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

2009-02-05 Thread Aurelie Labbe, Dr.
Hi,
 
I am trying to use the R command "system"  under windows (XP). If I try the 
simple command system("mkdir toto") to create a directory toto, it tells me 
that it cannot find the command mkdir...
Does anybody knows how  it works ? Is it a path problem ? Maybe the answer is 
simple: I am a R user under Unix/Linux and I don't know well R under windows.
 
Thanks !
Aurelie

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

2009-02-05 Thread ele . fanti
Hi there,

as a newbie in R I have a question on the plm package for panel data:

How do I actually manage to get data into the pdata.frame format?
i.e. how do I declare id and time? I already tried various things and got even 
more error messages. for example

> country <- 
> c("AGO","BWA","DRC","LSO","MDG","MWI","MUS","MOZ","NAM","SYC","ZAF","SWZ","TZA","ZMB","ZWE")
> time1 <- c(1991:2006)
> pdata.frame(EMPR1,id=country,time=time1)
serie SYC  is NA and has been removed
Fehler in (function(x, i) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x,  
: 
rekursives Indizieren auf Level 2 fehlgeschlagen

where EMPR is a data.frame with 16 rows (time) and 15 columns (countries).

Thank you,
Kirsten
--

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

2009-02-05 Thread Michael Grant
I believe the binom.test procedure is producing one tailed p values
rather than the two tailed value implied by the alternative hypothesis
language.  A textbook and SAS both show 2*9.94e-07 = 1.988e-06 as the
two tailed value.  As does the R summation syntax from R below.  It
looks to me like the alternative hypothesis language should be revised
to something like " ... greater than or equal to ..."  Am I mistaken?

 

M.C.Grant

 

> 2*sum(dbinom(c(10:25),25,0.061))

[1] 1.987976e-06

 

> binom.test(10,25,0.061)

 

Exact binomial test

 

data:  10 and 25 

number of successes = 10, number of trials = 25, p-value = 9.94e-07

alternative hypothesis: true probability of success is not equal to
0.061 

95 percent confidence interval:

 0.2112548 0.6133465 

sample estimates:

probability of success 

   0.4


[[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] seq(along= surprise

2009-02-05 Thread baptiste auguie

Perhaps this is what was intended?



sims <- list(length=100)



do.call(seq, sims)


seq by itself does not expect a list, but do.call() can create the  
appropriate call if a list is what you want to pass to the function.


Hope this helps,

baptiste

On 5 Feb 2009, at 19:46, Uwe Ligges wrote:




Uwe Ligges wrote:



Kjetil Halvorsen wrote:

This surprised me:


reps <- 100
sims <- list(length=reps)
sims

$length
[1] 100


for(i in seq(along=sims))print(i)

[1] 1

This is R 2.8.1.



What is surprising?

sims is now a list that contains 1 element called "length" with a
numeric value of 100.
Then seq(along=sims) is exactly 1, because sims has length 1.
Hence i is printed once (1 iteration of the loop) and is 1 in the  
first

(and only) iteration.

Uwe


I should have added that you probably want

sims <- vector(mode="list", length=100)

Uwe






Kjetil

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


_

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

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

2009-02-05 Thread ele . fanti
Hi there,

as a newbie in R I have a question on the plm package for panel data:

How do I actually manage to get data into the pdata.frame format?
i.e. how do I declare id and time? I already tried various things and got even 
more error messages. for example

> country <- 
> c("AGO","BWA","DRC","LSO","MDG","MWI","MUS","MOZ","NAM","SYC","ZAF","SWZ","TZA","ZMB","ZWE")
> time1 <- c(1991:2006)
> pdata.frame(EMPR1,id=country,time=time1)
serie SYC  is NA and has been removed
Fehler in (function(x, i) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x,  
: 
rekursives Indizieren auf Level 2 fehlgeschlagen

where EMPR is a data.frame with 16 rows (time) and 15 columns (countries).

Thank you,
Kirsten
-- 


--

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

2009-02-05 Thread Uwe Ligges



Uwe Ligges wrote:



Kjetil Halvorsen wrote:

This surprised me:


reps <- 100
sims <- list(length=reps)
sims

$length
[1] 100


for(i in seq(along=sims))print(i)

[1] 1

This is R 2.8.1.



What is surprising?

sims is now a list that contains 1 element called "length" with a 
numeric value of 100.

Then seq(along=sims) is exactly 1, because sims has length 1.
Hence i is printed once (1 iteration of the loop) and is 1 in the first 
(and only) iteration.


Uwe


I should have added that you probably want

sims <- vector(mode="list", length=100)

Uwe






Kjetil

[[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] Legend for radial.plot?

2009-02-05 Thread Jason Rupert
Using plotrix, is it possible to create a legend for the following and attach 
it to the radial.plot?
 
posmat<-matrix(sample(2:9,30,TRUE),nrow=3)
 radial.plot(posmat,labels=paste("X",1:10,sep=""),rp.type="p",
  main="Spiderweb plot",line.col=2:4,show.grid=FALSE,lwd=1:3,
  radial.lim=c(0,10))

 
Thanks.


  
[[alternative HTML version deleted]]

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


Re: [R] Reading images

2009-02-05 Thread Jorge Ivan Velez
Hi there,
Take a look at this:
http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/rimage/html/read.jpeg.html

HTH,

Jorge


On Thu, Feb 5, 2009 at 1:01 PM, gabo  wrote:

> Hi
>
> Can anyone tell me how to convert an image file (a jpg file for instance)
> into a matrix file?
>
> The command image(blabla) transforms a matrix into an image file, I am
> searching exactly the inverse.
>
> Thanks...
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] seq(along= surprise

2009-02-05 Thread Uwe Ligges



Kjetil Halvorsen wrote:

This surprised me:


reps <- 100
sims <- list(length=reps)
sims

$length
[1] 100


for(i in seq(along=sims))print(i)

[1] 1

This is R 2.8.1.



What is surprising?

sims is now a list that contains 1 element called "length" with a 
numeric value of 100.

Then seq(along=sims) is exactly 1, because sims has length 1.
Hence i is printed once (1 iteration of the loop) and is 1 in the first 
(and only) iteration.


Uwe




Kjetil

[[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] maptools: Test if point is in polygon

2009-02-05 Thread Renaud Lancelot
See function pip (point in polygon) in package splancs.

Renaud

2009/2/5 Rainer M Krug 

> On Thu, Feb 5, 2009 at 3:21 PM, Aleksandr Andreev
>  wrote:
> > In R's maptools package, is there a built-in function to test if a
> > given point is "inside" a given polygon on the map?  The map was
> > loaded from an ESRI Shapefile. The point's latitude and longitude are
> > known.
>
> If everything else fails, convert the shape file into a raster and
> "drill down" at the location of the points.
>
> Rainer
>
> >
> > Thank you!
> >
> > Aleks
> >
> > --
> > 
> > Aleksandr Andreev
> > Fulbright Fellow
> > Graduate School of Management
> > St Petersburg State 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.
> >
>
>
>
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Faculty of Science
> Natural Sciences Building
> Private Bag X1
> University of Stellenbosch
> Matieland 7602
> South Africa
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Renaud LANCELOT
Département Systèmes Biologiques du CIRAD
CIRAD, Biological Systems Department

Campus International de Baillarguet
TA 30 / B
F34398 Montpellier
Tel   +33 (0)4 67 59 37 17
Secr. +33 (0)4 67 59 37 37
Fax   +33 (0)4 67 59 37 95

[[alternative HTML version deleted]]

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


Re: [R] Reading images

2009-02-05 Thread Sarah Goslee
There's lots of info in the mailing list archives on this topic - 2 minutes with
google would have gotten you to read.jpeg and saved you some time.

Sarah

On Thu, Feb 5, 2009 at 1:01 PM, gabo  wrote:
> Hi
>
> Can anyone tell me how to convert an image file (a jpg file for instance)
> into a matrix file?
>
> The command image(blabla) transforms a matrix into an image file, I am
> searching exactly the inverse.
>
> Thanks...
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] lattice key inside panel

2009-02-05 Thread Dieter Menne
Deepayan Sarkar  gmail.com> writes:

> > One other thing that has so far eluded me is how to specify two
> > different kinds of symbols on a single column. The key above shows
> >
> > text line text rectangle
> >
> > but I would really like to get
> >
> > text line
> > text rectangle
> >
> > but this did not seem possible to me. Am I wrong?
> 
> Not possible with draw.key(), but legends can be arbitrary grobs, so
> you could construct a suitable one.

I would have guessed that columns=2 would work, but you are right,
it given an error message (Not enough rows for columns). Why?

Dieter

xyplot(1~1,
   panel = function(...) {
   require(grid)
   panel.xyplot(...)
   draw.key(list(text=list(lab='catch'),
 columns=2,
 lines=list(lwd=c(2)),
 text=list(lab='landings'),
 rectangles=list(col=rgb(0.1, 0.1, 0, 0.1))),
  draw = TRUE,
  vp = viewport(x = unit(0.75, "npc"), y = unit(0.9, "npc")))
   })

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Unexpected mfrow, layout behavior (pdf still has multiple pages)

2009-02-05 Thread Paul Johnston
You are correct, thank you. I added a new subsection 'Graphics
Devices' in http://wiki.r-project.org/rwiki/doku.php?id=tips:surprises:traps
to document this behavior.

Paul

On Thu, Feb 5, 2009 at 4:58 AM, Peter Dalgaard  wrote:
> Paul Johnston wrote:
>> My goal is to create a graph with one column and three rows into a
>> single graphic. The mfrow, mfcol, and layout functions all have the
>> same effect: three graphs are produced in a single pdf file, having
>> one graph per page.  This is not what I want (I didn't want multiple
>> pages).  Just before I sent this post, I was able to generate the
>> desired output with split.screen.  Is this the expected behavior of
>> mfrow and layout?
>
> If you call them before opening the device, then yes, they will not
> affect that device, but presumably some other device...
>
>-p
>
>>
>> Paul
>>
>> 
>>
>> My code is as follows (ToruosityPlot and DiameterPlot are essentially
>> identical to LDRPlot).
>>
>> layout(matrix(1:3, ncol=1))
>> #par(mfrow=c(3,1))
>>
>> pdf("results.pdf", width=4, height=3, pointsize=4, colormodel="cmyk",
>> onefile=TRUE)
>>
>> TortuosityPlot(left, right)
>> DiameterPlot(left, right)
>> LDRPlot(left, right)
>>
>> dev.off()
>>
>> LDRPlot <- function(left, right)
>>   {
>> plot(left$x, left$LDR, bty="n", ann=FALSE, xlim=c(-1500, 1000),
>> ylim=c(1.0, 1.5))
>> abline(v=0, col=gray(.90))
>> lines(left$x, left$LDR, col="green4", lty="solid")
>> points(left$x, left$LDR, bg="limegreen", pch=21)
>> lines(right$x, right$LDR, col="blue4", lty="dashed")
>> points(right$x, right$LDR, bg="blue", pch=21)
>> #title(main="LDR", xlab="Distance (um)", ylab="LDR",
>> col.main="black", col.lab=gray(.4), cex.main=1.2, cex.lab=1.0,
>> font.main=4, font.lab=3)
>>   }
>>
>>
>> platform   i386-apple-darwin8.11.1
>> arch   i386
>> os darwin8.11.1
>> system i386, darwin8.11.1
>> status
>> major  2
>> minor  8.1
>> year   2008
>> month  12
>> day22
>> svn rev47281
>> language   R
>> version.string R version 2.8.1 (2008-12-22)
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> --
>   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.


[R] seq(along= surprise

2009-02-05 Thread Kjetil Halvorsen
This surprised me:

> reps <- 100
> sims <- list(length=reps)
> sims
$length
[1] 100

> for(i in seq(along=sims))print(i)
[1] 1
>

This is R 2.8.1.

Kjetil

[[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] Non-linear optimisation

2009-02-05 Thread Ravi Varadhan
Hi,

I don't understand your Matlab code.  However, let me say this:

 - you could use "L-BFGS-B" algorithm in optim() or nlminb(), if you only have 
box constraints

 - you could use ConstrOptim(), if you only have linear inequality constraints

 - you could use Rdonlp2 if you have more general equality/inequality 
constraints

Best,
Ravi.



Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: ehxpieterse 
Date: Thursday, February 5, 2009 2:03 pm
Subject: [R]  Non-linear optimisation
To: r-help@r-project.org


>  Hi there,
>  
>  I have a piece of Matlab code I use to optimise a trding strategy. If 
> there
>  are any Matlab/R specialists out there, I would appreciate your help 
> in
>  doing the exact same optimisation in R.
>  
>  I suspect I would use nlm() in R but am not sure where to define my
>  constraints.
>  
>  I have attached my Matlab code below for reference.
>  
>  Many thanks.
>  
>  Constraints
>  function [c,ceq]=TriskellConstraints(X)
>  global objFunc_vol;
>  [a,b] = objFunc_vol(X);
>  c(1) = b-6.5;
>  c(2) = std(X(:))-6.5;
>  ceq = [];
>  end
>  
>  Optimise
>  global objFunc_vol
>  objFunc_vol = @(C) compute_strategy_before_fees(prices, C, floor, cap,
>  m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
>  fixed_fees, var_fees);
>  
>  objFunc_vol(C);
>  
>  objFunc = @(C) compute_strategy_before_fees(prices, C, floor, cap,
>  m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
>  fixed_fees, var_fees);
>  
>  objFunc(C);
>  
>  options = optimset('MaxIter',1000,'MaxFunEvals',1000);
>  
>  tic;
>  
>  % OPTIMISE
>  
>  %M =
>  
> fmincon(objFunc,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9),@TriskellConstraints,options);
>  M =
>  
> fmincon(objFunc_vol,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9),@TriskellConstraints,options);
>  [Z, ZZ] = compute_strategy_after_fees(prices, C, floor, cap, m_ret_reb,
>  prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
>  var_fees, dates, variation_cap_property, eurusd);
>  [Y, YY] = compute_strategy_after_fees(prices, M, floor, cap, m_ret_reb,
>  prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
>  var_fees, dates, variation_cap_property, eurusd);
>  
>  timespent = toc/60; %converts to minutes
>  
>  
>  -- 
>  View this message in context: 
>  Sent from the R help mailing list archive at Nabble.com.
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  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] See source code for survplot function in Design package

2009-02-05 Thread David M Smith
Uwe Ligges actually had a nice write-up on finding source code for functions
like this in R-news a couple of years ago.  You can find it here:
http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf (see p44)

There are some other tips for finding R source code here:

http://blog.revolution-computing.com/2009/02/finding-the-source.html

# David Smith

On Thu, Feb 5, 2009 at 2:10 PM, Dieter Menne
wrote:

> Eleni Rapsomaniki  mail.cryst.bbk.ac.uk> writes:
>
> > I know one way to see the code for a hidden function, say function_x,
> > is using default.function_x (e.g. summary.default). But how can I see
> > the code for imported packages that have no namespace (in this case
> > Design)?
>
> Just type the name without ()
>
> library(Design)
> Surv
>
>
> For namespaces, you might also try
>
> getAnywhere(myfunctioname)
>
> But note that what you see is the bare-bones codes, not the source.
> To see comments, for example, better download the code from CRAN,
> e.g. from:
>
> http://cran.at.r-project.org/web/packages/abind/index.html
>
>
> 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.
>



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

[[alternative HTML version deleted]]

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


Re: [R] Target Plot?

2009-02-05 Thread Jason Rupert
I had a bit of problems with my email, so if any one responded to this I may 
have not received it.  
 
Is there any chance you can repost any ideas you might have? 
 
Right now I am looking at the plotrix package, but I have not been able to put 
together what I'm looking for. 
 
Thank you again for your feedback and insights. 

--- On Tue, 2/3/09, Jason Rupert  wrote:

From: Jason Rupert 
Subject: [R] Target Plot?
To: r-help@r-project.org
Date: Tuesday, February 3, 2009, 7:00 PM

I've done a little snooping around the R Gallery Site
(http://addictedtor.free.fr/graphiques/) and the "Statistics with R"
site (http://zoonek2.free.fr/UNIX/48_R/all.html), but I can't seem to find
what I'm looking for.  

Here is the type of plot I would like to draw:
(1) 2-D three axis plot where each axis is separated by 120-degrees (would be
great if the number of axis was configurable)
(2) Would like the value at the origin of the axis to be configurable, and then
have each axis to be increasing equally out from the origin, e.g. have the
origin have a value of 0.5 and each axis increase from there
(3) Would then like to be able to lay concentrically increasing circles over
the axis so that they intersect each axis 
(4) Data values would only lye on the axis.  

I would like to put together this plot to show how far each variable is from
the target variable, so I'm thinking this would be a target plot where the
value of the target would be configurable.  (I guess normalization would have
similar result, but I would like to show the actual values.)

I guess the result would look kind of like a dart board or something similar. 

Thank you for any insights that can be provided, especially if something like
this already exist.  






  
[[alternative HTML version deleted]]

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



  
[[alternative HTML version deleted]]

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


Re: [R] See source code for survplot function in Design package

2009-02-05 Thread Marc Schwartz
on 02/05/2009 10:54 AM Eleni Rapsomaniki wrote:
> Dear R users,
> 
> I know one way to see the code for a hidden function, say function_x, is
> using default.function_x (e.g. summary.default). But how can I see the
> code for imported packages that have no namespace (in this case Design)?
> 
> Many Thanks
> Eleni

The easiest way is probably to use getAnywhere():

library(Design)

> getAnywhere("survplot")
A single object matching ‘survplot’ was found
It was found in the following places
  package:Design
with value

function (fit, ...)
UseMethod("survplot")


This tells you that the function is in package Design and has certain
dispatch methods associated with it. There is also the absence of any
indication of a namespace being present.

The next step would be:

> methods(survplot)
[1] survplot.Design
[2] survplot.residuals.psm.censored.normalized
[3] survplot.survfit

which tells you which methods are present for the function. Note also
that there is no 'default' method.

Note that the methods for survplot() are not hidden within a namespace,
as they would normally be followed by a '*' in the output of methods().
Had this been the case, you could use:

  Design:::survplot.Design


Thus, you can just use:

> survplot.Design
function (fit, ..., xlim, ylim = if (loglog) c(-5, 1.5) else if (what ==
"survival" & missing(fun)) c(0, 1), xlab, ylab, time.inc,
what = c("survival", "hazard"), type = c("tsiatis", "kaplan-meier"),
conf.type = c("log-log", "log", "plain", "none"), conf.int = FALSE,
conf = c("bars", "bands"), add = FALSE, label.curves = TRUE,
abbrev.label = FALSE, lty, lwd = par("lwd"), col = 1, adj.subtitle,
loglog = FALSE, fun, n.risk = FALSE, logt = FALSE, dots = FALSE,
dotsize = 0.003, grid = FALSE, srt.n.risk = 0, sep.n.risk = 0.056,
adj.n.risk = 1, y.n.risk, cex.n.risk = 0.6, pr = FALSE)
{
what <- match.arg(what)
if (.R.)
ylim <- ylim
type <- match.arg(type)
conf.type <- match.arg(conf.type)
conf <- match.arg(conf)
psmfit <- inherits(fit, "psm") || (length(fit$fitFunction) &&
any(fit$fitFunction == "psm"))
if (what == "hazard" && !psmfit)
stop("what=\"hazard\" may only be used for fits from psm")
if (what == "hazard" & conf.int > 0) {
warning("conf.int may only be used with what=\"survival\"")
conf.int <- FALSE
}
...


and the same for the other methods for the function.

In general, for methods that are within a namespace, you can use:

  namespace:::function.method

or:

  getAnywhere("function.method")


See ?getAnywhere and ?methods

HTH,

Marc Schwartz

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


Re: [R] See source code for survplot function in Design package

2009-02-05 Thread Frank E Harrell Jr

Eleni Rapsomaniki wrote:

Dear R users,

I know one way to see the code for a hidden function, say function_x, is 
using default.function_x (e.g. summary.default). But how can I see the 
code for imported packages that have no namespace (in this case Design)?


Many Thanks
Eleni


> methods(survplot)
[1] survplot.Design
[2] survplot.residuals.psm.censored.normalized
[3] survplot.survfit

Type any one of those function names to see the full code.  Or go to 
http://biostat.mc.vanderbilt.edu/cgi-bin/viewvc.cgi/Design/trunk/ as 
detailed in the home page for Design: 
http://biostat.mc.vanderbilt.edu/s/Design


Frank



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

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




--
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] See source code for survplot function in Design package

2009-02-05 Thread Dieter Menne
Eleni Rapsomaniki  mail.cryst.bbk.ac.uk> writes:

> I know one way to see the code for a hidden function, say function_x,  
> is using default.function_x (e.g. summary.default). But how can I see  
> the code for imported packages that have no namespace (in this case  
> Design)?

Just type the name without ()

library(Design)
Surv


For namespaces, you might also try 

getAnywhere(myfunctioname)

But note that what you see is the bare-bones codes, not the source.
To see comments, for example, better download the code from CRAN,
e.g. from:

http://cran.at.r-project.org/web/packages/abind/index.html


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] Reading images

2009-02-05 Thread gabo
Hi

Can anyone tell me how to convert an image file (a jpg file for instance)
into a matrix file?

The command image(blabla) transforms a matrix into an image file, I am
searching exactly the inverse.

Thanks...

[[alternative HTML version deleted]]

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


[R] Non-linear optimisation

2009-02-05 Thread ehxpieterse

Hi there,

I have a piece of Matlab code I use to optimise a trding strategy. If there
are any Matlab/R specialists out there, I would appreciate your help in
doing the exact same optimisation in R.

I suspect I would use nlm() in R but am not sure where to define my
constraints.

I have attached my Matlab code below for reference.

Many thanks.

Constraints
function [c,ceq]=TriskellConstraints(X)
global objFunc_vol;
[a,b] = objFunc_vol(X);
c(1) = b-6.5;
c(2) = std(X(:))-6.5;
ceq = [];
end

Optimise
global objFunc_vol
objFunc_vol = @(C) compute_strategy_before_fees(prices, C, floor, cap,
m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
fixed_fees, var_fees);

objFunc_vol(C);

objFunc = @(C) compute_strategy_before_fees(prices, C, floor, cap,
m_ret_reb, prices_TR, hedge_fund, vg, euribor, last_reb_date, Maturity,
fixed_fees, var_fees);

objFunc(C);

options = optimset('MaxIter',1000,'MaxFunEvals',1000);

tic;

% OPTIMISE

%M =
fmincon(objFunc,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9),@TriskellConstraints,options);
M =
fmincon(objFunc_vol,C,[],[],[],[],repmat(-20,12,9),repmat(20,12,9),@TriskellConstraints,options);
[Z, ZZ] = compute_strategy_after_fees(prices, C, floor, cap, m_ret_reb,
prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
var_fees, dates, variation_cap_property, eurusd);
[Y, YY] = compute_strategy_after_fees(prices, M, floor, cap, m_ret_reb,
prices_TR, Hedge_Fund, vg, euribor, last_reb_date, Maturity, fixed_fees,
var_fees, dates, variation_cap_property, eurusd);

timespent = toc/60; %converts to minutes


-- 
View this message in context: 
http://www.nabble.com/Non-linear-optimisation-tp21856818p21856818.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] liknage analysis

2009-02-05 Thread Federico Calboli
Dear All,

is there a package in R that implements parametric and non parametric  
genetic linkage analysis (with both case/control or quantitative  
phenos)? I tried using Merlin, which could not deal with pedigrees the  
size I have, and SimWalk2 does not look like the answer either --for  
instance I do not have a recombination map, just a position map and I  
doubt SW2 would like that.

I had a look in the archives and on CRAN but nothing popped out as  
being the R equivalent of linkage analysis software (though I just had  
a quick look).

Best,

Federico

--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com




[[alternative HTML version deleted]]

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


[R] ThinkCell type waterfall charts in R?

2009-02-05 Thread Millo Giovanni
Hello Kerstin, 

I had done something like this in the past but can't find it any more,
so I've put up a very raw example you might want to sophisticate upon. 
The idea is that of drawing an empty high-level plot and then putting
some low-level elements (mainly bars and connecting lines) into it
according to the coordinates of the data. Attached below, I hope it
helps and avoids you the sin of importing ppt charts into LaTeX
(aaargh!). 

PS The 'grid' package can help you produce more sophisticated (possibly
more "corporate-like", if this is a virtue...) graphs while retaining
the level of automation possible with R: e.g., for using Sweave for
automatic report generation. I'm sending you some examples by separate
mail. 

Best,
Giovanni

examples:  cascadeplot(rnorm(10)); cascadeplot(c(3,2,-7,5,8,3,-9,10))

cascadeplot <- function(x, barwidth=2, barspace=1,
colpalette=rep(grey(0.5), length(x)),
linecol="orange", ...) {
## how many bars? one for each data point
barnum <- length(x)

## total graph width
grw <- (barnum+1)*barspace+barnum*barwidth

## graph height
l.grh <- min(cumsum(x),0)
u.grh <- max(cumsum(x))+1

## draw an empty plot with the required dims
## (passing on any graphic parm you like, e.g. 'title')
plot(0:grw, ylim=c(l.grh,u.grh), xlim=c(0,grw), type="n", ...)

## draw x axis
lines(c(0,grw), c(0,0), col="blue")

## init vector (this will be useful later)
ytxtpos <- rep(NA, length(x))

## for each data point draw a polygon
## starting from the level reached by the
## previous bar

for(i in 1:length(x)) {
## each bar has 4 verices, abcd
## x coordinates for them:
## left vertices: ab, right: cd
## so bars are drawn like a->b->c->d
leftx <- barspace+(barspace+barwidth)*(i-1)
rightx <- leftx+barwidth
xcoo <- c(leftx, leftx, rightx, rightx)
## y coord.:
## lower y:
if(i==1) {
lowy <- 0
} else {
lowy <- cumsum(x)[i-1]
}
highy <- cumsum(x)[i]
ycoo <- c(lowy, highy, highy, lowy)
polygon(xcoo, ycoo, col=colpalette[i], ...)

## now draw the connecting lines between
## the current and the previous bar
if(i > 1) {
lines(x=c(leftx-barspace,leftx),
  y=c(lowy,lowy),
  col=linecol)
}

## save top-bar position for label
ytxtpos[i] <- max(lowy, highy)+0.05*(u.grh-l.grh)
}

## lastly, put the values on top of the bars
xtxtpos <- (1:length(x))*(barwidth+barspace)-barwidth/2
text(xtxtpos,ytxtpos,labels=as.character(x))
}



## original message below
--

Message: 157
Date: Tue, 03 Feb 2009 11:30:51 +0100
From: Kerstin 
Subject: Re: [R] ThinkCell type waterfall charts in R?
To: Jim Lemon 
Cc: r-help@r-project.org
Message-ID: <49881cdb.3090...@open-innovation-projects.org>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Jim Lemon wrote:
> Kerstin wrote:
>> Hi all,
>>
>> with PowerPoint and ThinkCell one can draw something they call
>> waterfall chart and it looks like this:
>> http://www.think-cell.com/products/images/waterfall.gif
>>
>> I found discussions on waterfall charts in the archive of this
>> mailinglist, but unfortunately they looked totally different. Other 
>> names for this type of plot seem to be bridge chart, cascade chart, 
>> stair case chart, etc. but neither of them brought successful 
>> results. So I decided to ask you directly on the list.
>>
>> Does anyone have an idea on how I could plot this type of chart in R?
> Well Kirsten, it's a real challenge trying to find something that you
> _can't_ plot in R. Perhaps if you sent some data to the mailing list 
> and a description of how the various counts (?) are related to one 
> another, some R-nut may reply with what you want.
>
> Jim
Thanks a lot for your quick reply.

In the attached pdf you can see the chart I would like to draw with R. I

could of course make my life easier and use the Power Point chart, but 
importing a ppt chart into Latex would not make me sleep very well, 
besides the fact that all other plots in my document will come from R 
and I don't want this one to look totally different...

Cheers
Kerstin

-- next part --
A non-text attachment was scrubbed...
Name: Waterfall.pdf
Type: application/pdf
Size: 9761 bytes
Desc: not available
URL:


--


Giovanni Millo
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 4, 
34132 Trieste (Italy)
tel. +39 040 671184 
fax  +39 040 671160

Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/li

Re: [R] Numeric class and sasxport.get

2009-02-05 Thread Frank E Harrell Jr

Sebastien Bihorel wrote:
Ok, just so as I get that straight, is the 'labelled' class something 
that you created in your package or a readily available class in base R?


It's something we added for the Hmisc package.
Signing off,
Frank



*Sebastien Bihorel, PharmD, PhD*
PKPD Scientist
Cognigen Corp
Email: sebastien.biho...@cognigencorp.com 


Phone: (716) 633-3463 ext. 323


Frank E Harrell Jr wrote:

Sebastien Bihorel wrote:

I also realized the flaw after testing the script on various datasets...

Following up on your last note:
1- Is that the reason why the class of integer and regular numeric 
variable is solely "labelled" following sasxport.get?


Yes.  R gurus might correct me but just creating a numeric vector 
doesn't create a 'hard' class, add adding your own class attribute 
equal to 'numeric' or 'integer' might cause a problem downstream.



2- Can class be 'soft' for other 'kind' of variables?


Not that I can recall.

3- Would you anticipate the following wrapper function to generate 
incompatibilities with other R functions?


I'm going to beg off on that.  I'm not enough of an expert on the 
impact of adding such classes.


Frank




SASxpt.get <- function(file, force.single = TRUE,
 method=c('read.xport','dataload','csv'), 
formats=NULL, allow=NULL,

 out=NULL, keep=NULL, drop=NULL, as.is=0.5, FUN=NULL) {

 foo <- sasxport.get(file=file, force.single=force.single, 
method=method,

 formats=formats, allow=allow, out=out, keep=keep,
 drop=drop, as.is=as.is, FUN=FUN)

 # For each variable of class "labelled" (and only "labelled"), add 
the native class as a second class argument


 sglClassVarInd <- which(lapply(lapply(unclass(foo),class),length)==1)

 for (i in 1:length(sglClassVarInd)){
   x <- foo[,sglClassVarInd[i]]  if (class(x)=="labelled") 
class(foo[,sglClassVarInd[i]]) <- c(class(x), class(unclass(x)))

 }
 return(foo)
}


*Sebastien Bihorel, PharmD, PhD*
PKPD Scientist
Cognigen Corp
Email: sebastien.biho...@cognigencorp.com 


Phone: (716) 633-3463 ext. 323


Frank E Harrell Jr wrote:

Sebastien Bihorel wrote:

Thanks a lot Frank,

One last question, though. I was tempted to remove all attributes 
of my variables after the sasxport.get call using

foo <- sasxport.get(...)
foo <- as.data.frame(lapply(unclass(foo),as.vector))
Since I never worked with the objects of class 'labeled', I was 
wondering what I will loose by removing this attribute.


Not a good idea, for many reasons including dates and other types.

And the labelled type is need if you subset the data, in order to 
keep the labels.


Note that your original issue is related to "class" being "soft" for 
integers and regular numerics:


 x <- 1:3
> attributes(x)
NULL
> class(x)
[1] "integer"
> x <- runif(3)
> class(x)
[1] "numeric"
> attributes(x)
NULL

Frank



*Sebastien Bihorel, PharmD, PhD*
PKPD Scientist
Cognigen Corp
Email: sebastien.biho...@cognigencorp.com 


Phone: (716) 633-3463 ext. 323


Frank E Harrell Jr wrote:

sebastien.biho...@cognigencorp.com wrote:
The problem is actually not related to a broken command but a 
attempt of
operational qualification of R. A few years ago, my company 
developed a

set of scripts for the 'operational qualification' of Splus. We are
switching to R so I am currently trying to port the scripts to R.
All Splus scripts imported SAS data using the importData 
function, which I
substituted by sasxport.get. One particular script returns the 
class of

each variable of the imported data frame; the output must match the
expected values: numeric, factor, integer, etc... The R 
'translation' with

sasxport.get is thus problematic.
If there is no easy tweak of the function, we will probably have 
to remove

this script from our list of 'qualification' scripts.

Although it would be nice


Then my advice is to write your own wrapper function for 
sasxport.get that takes its output, looks for labelled variables, 
and adds a new class of your choosing depending on properties of 
the variable, making sure that you write methods needed for that 
class (if any).  Then test your new function, not sasxport.get 
explicitly.


Frank




Sebastien Bihorel wrote:

Frank,

It is a non existing issue for me if the variables of class 
"labelled"

(and only "labelled") can only be numerical variables (integer or
numeric).

Sebastien

'labelled' can apply to any type of vector.  I'm not clear on the
problem this causes you.  Please provide a command that is 
broken by

this behavior.

Frank


Frank E Harrell Jr wrote:

Sebastien Bihorel wrote:

Dear R-users,

The sasxport.get function (from the Hmisc package) automatically
defines the class of imported variables. I have noticed that the
class of theoretically numeric variables is simply "labelled",
although character variables might end up been defined

Re: [R] Sweave and \Sexpr{}

2009-02-05 Thread Dieter Menne
Felipe Carrillo  yahoo.com> writes:

> It is working now although I still have to specify the path to Sweave.sty
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
> and it doesn't evaluate \Sexpr{} when I simply use \usepackage{Sweave}. I
placed Sweave.sty in the same
> folder where my rnw and tex file reside.

If it works, keep it. If you, like me, do not like explicit paths, either 
copy Sweave.sty to the local tex directory and update your database; in 
Miktex, this is from the settings gui.

Or add the Sweave path in share to you local tex directory (from the
same dialog, next tab).

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] How do I get my IT department to "bless" R?

2009-02-05 Thread Christian Langkamp

I know on the website there are some pretty reputable sponsors of the
software who at some stage donated some (presumably significant) amount of
money out of thankfulness because some project worked and the software
helped in some way.

In order to push however the use of that software, might it not be just
simply possible to start producing a List of corporate projects where the
software was used with someone in the hierarchy saying: 
1. It helped the project (we managed to reduce the complexity, it was more
stable, flexible, ...)
2. We saved costs
3. The project actually was worth doing and wasn't just pasttime of an
employee who just hasn't realized that he is in a company now, and not
messing around at Uni

Maybe also include cases where it didn't work
1. Key personel left the project, nobody to pick up the left stuff
2. Found out that it was the wrong tool (missing features, too complex, ...)

And the moment one has a list including a couple of cases, ideally also a
case similar to the stuff one wants to do, one can move onwards in ones own
company: 'Our competitor / customer / great admired idol is doing it, why
don't we ?'

Chances are that such a list already has been started somewhere, it just
hasn't been linked properly.
-- 
View this message in context: 
http://www.nabble.com/How-do-I-get-my-IT-department-to-%22bless%22-R--tp21739359p21856976.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] Does the "labpt" object in the Polygons-class represent the centroid of the polygon

2009-02-05 Thread Rizzo . Michael

Hello,

I need to calculate the centroids of some spatial polygons that I have
placed into a Polygons-class object.  Is the labeling point in the
Polygons-class the centroid of the polygon?

Thank you for your help.

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


[R] See source code for survplot function in Design package

2009-02-05 Thread Eleni Rapsomaniki

Dear R users,

I know one way to see the code for a hidden function, say function_x,  
is using default.function_x (e.g. summary.default). But how can I see  
the code for imported packages that have no namespace (in this case  
Design)?


Many Thanks
Eleni

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


Re: [R] Sweave and \Sexpr{}

2009-02-05 Thread Felipe Carrillo
Thaks Eric and Dieter:
It is working now although I still have to specify the path to Sweave.sty 
\usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
and it doesn't evaluate \Sexpr{} when I simply use \usepackage{Sweave}. I 
placed Sweave.sty in the same folder where my rnw and tex file reside.


--- On Thu, 2/5/09, Eric R.  wrote:

> From: Eric R. 
> Subject: Re: [R] Sweave and \Sexpr{}
> To: r-help@r-project.org
> Date: Thursday, February 5, 2009, 1:03 AM
> Felipe:
> 
> See Leisch's FAQ A18.  
> 
> http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html#x1-2A.18
> 
> You likely have R2HTML loaded (likely because you are using
> Tinn-R) and that
> causes some difficulties for Sweave that are easily solved
> as described in
> the FAQ.
> 
> 
> 
> Felipe Carrillo wrote:
> > 
> > Hi: 
> > I am trying to create a dynamic latex table using
> \Sexpr{} but it's not
> > evaluating it. I also tried the example below without
> Sweave and also
> > fails. I have also copied the Sweave.sty to my working
> directory but
> > nothing seems to work. Do I need to have certain
> package in order to run
> > \Sexpr{}?
> > 
> > \documentclass[a4paper]{article}
> > \usepackage{C:/R/R-2.8.1/share/texmf/Sweave}
> > \begin{document}
> > 
> > <>=
> > library(lattice)
> > library(xtable)
> > data(cats, package="MASS")
> > @ 
> > 
> > \section*{The Cats Data}
> > 
> > Consider the \texttt{cats} regression example from
> Venables \& Ripley
> > (1997). The data frame contains measurements of heart
> and body weight
> > of \SExpr{nrow(cats)} cats
> (\Sexpr{sum(cats$Sex=="F")} female,
> > \Sexpr{sum(cats$Sex=="M")} male).
> > 
> > A linear regression model of heart weight by sex and
> gender can be
> > fitted in R using the command
> > <<>>=
> > lm1 = lm(Hwt~Bwt*Sex, data=cats)
> > lm1
> > @ 
> > Tests for significance of the coefficients are shown
> in
> > Table~\ref{tab:coef}, a scatter plot including the
> regression lines is
> > shown in Figure~\ref{fig:cats}.
> > 
> > \SweaveOpts{echo=false}
> > 
> > <>=
> > xtable(lm1, caption="Linear regression model for
> cats data.",
> > label="tab:coef")
> > @ 
> > 
> > \begin{figure}
> >   \centering
> > <>=
> > 
> > print(xyplot(Hwt~Bwt|Sex, data=cats,
> type=c("p", "r")))
> > @  
> >   \caption{The cats data from package MASS.}
> >   \label{fig:cats}
> > \end{figure}
> > \begin{center}
> > \end{center}
> > 
> > \end{document}
> > 
> > 
> > Felipe D. Carrillo  
> > Supervisory Fishery Biologist  
> > Department of the Interior  
> > US Fish & Wildlife Service  
> > California, USA
> > 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> > 
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Sweave-and-%5CSexpr%7B%7D-tp21841963p21847606.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] R-help Digest, Vol 72, Issue 3

2009-02-05 Thread Charles Geyer
> Date: Mon, 2 Feb 2009 12:56:15 +0100
> From: friedrich.lei...@stat.uni-muenchen.de
> Subject: Re: [R] Problems in Recommending R
> To: thomas.petzo...@tu-dresden.de
> Cc: "r-help@r-project.org" ,
>   user-2...@r-project.org,p...@stat.auckland.ac.nz
> Message-ID: <18822.57183.637787.426...@lxh5.stat.uni-muenchen.de>
> Content-Type: text/plain; charset=iso-8859-1
> 
> > On Mon, 02 Feb 2009 08:44:21 +0100,
> > Thomas Petzoldt (TP) wrote:
> 
>   > Hi,
>   > you are probably right, though I must say that I like *spartanic and 
>   > efficient* homepages and I don't think that the example given by the 
>   > first mail is a good prototype for the R homepage. But, yes, occasional 
>   > face lifting may be adequate.  Anti-aliasing is of course simple, but 
>   > that's probably not the point. (And I know that there are graphics 
>   > experts with a masters in psychology between us.)
> 
>   > So, why not a new Homepage Graphics Competition 2009? There is still 
>   > some time until useR!2009 in Rennes:
> 
>   > http://www2.agrocampus-ouest.fr/math/useR-2009/
> 
> Perhaps we should extend that to a competition for the complete design
> of the homepage?
> 
> We often get emails like the first in this thread that R could do with
> an update on homepage design (I fully agree) ... but actually nobody
> volunteers to do it. Hence, we still have what I did when the
> worldwide number of R users was probably less than 1000.
> 
> For technical reasons there are some conditions: the homepage is
> maintained via SVN like the R sources, so all should be plain HTML, no
> content management system etc.

For my course web pages I am now using the Perl Template Toolkit
(http://template-toolkit.org/).  This allows all the benefits of a CMS
with with none of the overhead.  On one of my web pages, such as
http://www.stat.umn.edu/geyer/5101/, all of the fritterware (headers,
navigation, contents, footers) is added by PTT.  The source is clean,
and everything is as consistent as if done by a CMS.

The process is this.

   * edit the PTT source, which contains only HTML interspersed with
 PPT commands for "include navigation here" and so forth.

   * bin/build in the top level directory

   * static HTML+CSS web pages are produced for the server.

Think of PTT as sort of an Sweave for web pages.

Yes, there is no handholding, but R and handholding?  Are you serious?

Since I assume the R pages wouldn't look at all like my class web pages,
I wouldn't presume to get into details yet.  But I would gladly provide
the source tree for any of my course web sites as an example for anyone
who wants to try the PTT.

> Ad frames: the main reason that I used them in the first place is to
> have the menus etc in only one file, no need for updating several
> files when a link changes. Today I would probably use iframes, but any
> other soultion is fine, too.

The best solution is NO FRAMES.  Let the PTT organize the pages.

> Another plus would be if we could use the same design for CRAN, and
> that means no server-trickery like server-side includes etc (because
> we do not control the server setup of the mirrors).

No problem.  I use basically the same design for all my class web pages.
Just copy the PTT macro definitions and edit slightly.

> 
> Best,
> Fritz
> 
> -- 
> ---
> Prof. Dr. Friedrich Leisch 
> 
> Institut f?r Statistik  Tel: (+49 89) 2180 3165
> Ludwig-Maximilians-Universit?t  Fax: (+49 89) 2180 5308
> Ludwigstra?e 33
> D-80539 M?nchen http://www.statistik.lmu.de/~leisch
> ---
>Journal Computational Statistics --- http://www.springer.com/180 
>   M?nchner R Kurse --- http://www.statistik.lmu.de/R

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

2009-02-05 Thread Shimrit Abraham
HI,

I'm calling the garch() function several times within a for-loop and I would
like to suppress the output that the function generates. Setting
garch.control(trace = F) does not seem to help. Any suggestions on how to
solve this problem?

Thanks,

S.A.

[[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] A way to "lock down" the order of bars for ggplot "dodged"histogram

2009-02-05 Thread Jason Rupert
Thierry, 
 
Thank you for such a quick response. 
 
I changed the code, but I seem to get the same response.  Ugh.  Maybe I am 
missing a step.  Thank you again for any feedback. 
 
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
Group_df$Person <- factor(Group_df$Person, levels = c("Them", "You", "Me")) 
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)), Person), 
nrow) 
names(counts) <- c("Bin", "Person", "Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar", 
stat="identity", width = 0.9, xlab="Person") +  facet_grid(. ~ Bin) 


--- On Thu, 2/5/09, ONKELINX, Thierry  wrote:

From: ONKELINX, Thierry 
Subject: RE: [R] A way to "lock down" the order of bars for ggplot 
"dodged"histogram
To: jasonkrup...@yahoo.com, R-help@r-project.org
Cc: ggpl...@googlegroups.com
Date: Thursday, February 5, 2009, 10:17 AM

Dear Jason,

Convert Person to a factor with the levels in the order that you want.

Group_df$Person <- factor(Group_df$Person, levels = c("Them",
"You", "Me")) 

HTH,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology
and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
thierry.onkel...@inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more than
asking him to perform a post-mortem examination: he may be able to say what the
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens
Jason Rupert
Verzonden: donderdag 5 februari 2009 17:09
Aan: R-help@r-project.org
CC: ggpl...@googlegroups.com
Onderwerp: [R] A way to "lock down" the order of bars for ggplot
"dodged"histogram

It appears that ggplot reorder the data for a
"dodged" histogram based on whether or not a specific variable has a
value in the first bin. 
 
I would like to be able to absolutely force the order of the variables in the
bin.  For example, say I have three variables Me, You, and Them. 
 
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)),
Person), nrow) 
names(counts) <- c("Bin", "Person",
"Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar",
stat="identity", width = 0.9, xlab="Person") + 
facet_grid(. ~ Bin) 
 
However, I absolutely must have the bar order be Them, You, Me.   Is there
a to fix the order of the bars so that they are always in the Them, You, Me
order? 
 
Thank you again for any feedback you can provide.  
 
 


  
[[alternative HTML version deleted]]


Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd
is
door een geldig ondertekend document. The views expressed in  this message
and any annex are purely those of the writer and may not be regarded as stating

an official position of INBO, as long as the message is not confirmed by a duly

signed document.



  
[[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] optimal control, maximization with several variables?

2009-02-05 Thread Ravi Varadhan
I assume that you are looking to solve, in R, the constrained optimization 
problem:

H (u1, u2) = a*u1+b*u2+c*f1(u2)+lambda*(x') 
with constraints: 0
Date: Thursday, February 5, 2009 8:47 am
Subject: [R] optimal control, maximization with several variables?
To: R-help@r-project.org


> Dear all,
>  I would like to solve the following problem, which can be done with 
> optimal control theory or dynamic programming:
>  
>  max(x,y) a*u1+b*u2+c*f1(u2)   s.t.  0  
>  which can be rewritten if optimal control theory should be applied as
>  
>  H=a*u1+b*u2+c*f1(u2)+lambda*(x') s.t. 0  
>  The maximum principle conditions would solve the problem.
>  However in steady state conditions the system simplifies further with 
> u1=x' und lambda=a.
>  Is it possible to solve this problem in R and if yes then how?
>  It might be sufficient for me to maximize a simple nonlinear function
>  f(x,y) w.r.t. x and y.
>  Does anyone know how to do it? I tried optim and genoud but untill 
> now it did not work.
>  Best wishes
>  Frederik
>  
>  
>  
>  -- 
>  Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
>  für nur 17,95 Euro/mtl.!* 
>  
>  __
>  R-help@r-project.org mailing list
>  
>  PLEASE do read the posting guide 
>  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] tm Module in R

2009-02-05 Thread ryan

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

2009-02-05 Thread stenka1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Chi-squared test adjusted for multiple comparisons? Harbe'stest?

2009-02-05 Thread Murray Cooper

Categorical data analysis is definitely the way you want to go.
Which test you use depends on how you are going to use the results.

For "quick and dirty" I would suggest using Fisher's exact test on all
2x2 submatricies of counts. In this case, with 4 treatments you have
6 possible 2x2 submatricies. See "fishers.test" function.

Another possibility would be a log-linear model, to model Ln(p/q).

Murray M Cooper, Ph.D.
Richland Statistics
9800 N 24th St
Richland, MI, USA 49083
Mail: richs...@earthlink.net

- Original Message - 
From: "Laura Lucia Prieto Godino" 

To: 
Sent: Thursday, February 05, 2009 7:06 AM
Subject: [R] Chi-squared test adjusted for multiple comparisons? 
Harbe'stest?




Hi!

I have some data that looks like this
up down percentaje
uew_21 20 14 58.82
uew_20_5 27 40 40.29
uew_20 8 13 38.09
uew_19_5 17 42 28.81



So I have 4 experimental conditions and I am counting number of
animals in the up and down compartment and the calculating the
percentage, I want to know which one of the conditions is different
from each other. If the data wouldn't be percentage I would runt a
kruskal-wallis test to check for general differences and then when
significan a post-hoc test, comparing differents pairs with Man-
Whitney (wilcoxon function in R) with a bonferroni correction for
multiple comparisons. But as the data are in the percentaje form, I
know I need to analize them with either a chi squared or a g-test, but
I have no idea if I can do such a test with many comparissons or how
to do it in R, as well I have seen a paper in which they do something
similar and they are using a Harber's chi squared test. Does anybody
know how to do that in R?

Thank you  very much for your help, and thanks to the jim and chuck
for answering my previous statistical question!

Lucia

[[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] A way to "lock down" the order of bars for ggplot "dodged"histogram

2009-02-05 Thread ONKELINX, Thierry
Dear Jason,

Convert Person to a factor with the levels in the order that you want.

Group_df$Person <- factor(Group_df$Person, levels = c("Them", "You", "Me")) 

HTH,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology 
and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
thierry.onkel...@inbo.be 
www.inbo.be 

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Jason Rupert
Verzonden: donderdag 5 februari 2009 17:09
Aan: R-help@r-project.org
CC: ggpl...@googlegroups.com
Onderwerp: [R] A way to "lock down" the order of bars for ggplot 
"dodged"histogram

It appears that ggplot reorder the data for a "dodged" histogram based on 
whether or not a specific variable has a value in the first bin. 
 
I would like to be able to absolutely force the order of the variables in the 
bin.  For example, say I have three variables Me, You, and Them. 
 
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)), Person), 
nrow) 
names(counts) <- c("Bin", "Person", "Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar", 
stat="identity", width = 0.9, xlab="Person") +  facet_grid(. ~ Bin) 
 
However, I absolutely must have the bar order be Them, You, Me.   Is there a to 
fix the order of the bars so that they are always in the Them, You, Me order? 
 
Thank you again for any feedback you can provide.  
 
 


  
[[alternative HTML version deleted]]


Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed 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.


Re: [R] The Origins of R

2009-02-05 Thread Murray Cooper

Consider yourself lucky!
I'm sure there are many people who would
prefer not to see their name in the NYT. ;-)

Murray Coooper

- Original Message - 
From: "Duncan Murdoch" 

To: "Mark Difford" 
Cc: 
Sent: Thursday, February 05, 2009 10:16 AM
Subject: Re: [R] The Origins of R



On 2/5/2009 1:05 AM, Mark Difford wrote:
I think that all appeared on January 8 in Vance's blog posting, with a 
comment on it by David M Smith on Jan 9.  So those people have -27 days


Then there was no need for vituperative comments (not from you, of 
course):
simply point doubters to the right place, as you have done. But Mr. 
Vance's

comments only deepen the "mystery."

If Mr. Vance was aware of the true origins of R, why did he choose to
misrepresent them in his article, which is what got the publicity and 
which

is the item that most people saw/read? Most right-thinking people don't,
wouldn't, or haven't taken the matter further than that. Their 
criticisms,
as mine have been, have been aimed at the NY Times and Mr. Vance's lack 
of

ethics. It also seems clear from Mr. Vance's comments that there was no
editorial or sub-editorial meddling.


That's not what I read in the posting to this list that I cited.

I doubt if Ashlee Vance is reading this list, so it doesn't really seem 
fair to blame him if he doesn't respond to your attacks.


So I'm not complaining, but the main problem I saw in his article was that 
it didn't mention me.  I knew Robert Gentleman (even had an office next to 
him!) before he started R:  surely that must have been a key influence. 
Why else did he move to the far side of the globe?  And not only that, but 
to compound the insult, the NY Times has failed to mention me every day 
since then!


Duncan Murdoch



The knee-jerk reaction ? Well, it is almost amusing to see how sensitive
some very hard-nosed individuals on this list can be, or have become.

Regards, Mark.

still to wait.

Duncan Murdoch-2 wrote:


On 2/4/2009 3:53 PM, Mark Difford wrote:

>>> Indeed.  The postings exuded a tabloid-esque level of slimy

 nastiness.


Hi Rolf,

It is good to have clarification, for you wrote "..,the postings...,"
tarring everyone with the same brush. And it was quite a nasty brush. 
It

also is conjecture that "this was due to an editor or sub-editor," i.e.
the
botched article.

I think that what some people are waiting for are factual statements 
from
the parties concerned. Conjecture is, well, little more than 
conjecture.


I think that all appeared on January 8 in Vance's blog posting, with a 
comment on it by David M Smith on Jan 9.  So those people have -27 days 
still to wait.


Duncan Murdoch




Regards, Mark.


Rolf Turner-3 wrote:



On 4/02/2009, at 8:15 PM, Mark Difford wrote:



Indeed.  The postings exuded a tabloid-esque level of slimy 
nastiness.


Indeed, indeed. But I do not feel that that is necessarily the  case. 
Credit
should be given where credit is due. And that, I believe is the 
issue that
is getting (some) people hot and bothered. Certainly, Trevor Hastie 
in his
reply to the NY Times article, was not too happy with this aspect  of 
the

story.

Granted, his comments were not made on this list, but the objection 
is
essentially the same. I would not call what he had to say "Mischief 
making"
or smacking of a "tabloid-esque level of slimy nastiness." The knee- 
jerk
reaction seems to be that this is a criticism of R. It is not. It is 
a

criticism of a poorly researched article.

It also is an undeniable and inescapable fact that most S code runs 
in R.


The problem is not with criticism of the NY Times article, although 
as Pat
Burns and others have pointed out this criticism was somewhat 
misdirected
and unrealistic considering the exigencies of newspaper editing.  The 
problem

was with a number of posts that cast aspersions upon the integrity of
Ihaka and Gentleman.  It is these posts that exuded tabloid-esque 
slimy

nastiness.

I am sure that Ross and Robert would never dream of failing to give 
credit
where credit is due and it is almost certainly the case that they 
explained
the origins of R in the S language to the writer of the NYT article 
(wherefrom

the explanation was cut in the editing process).

Those of us on this list (with the possible exception of one or two 
nutters)
would take it that it goes without saying that R was developed on the 
basis
of S --- we all ***know*** that.  To impugn the integrity of Ihaka 
and Gentleman,
because an article which *they didn't write* failed to mention this 
fact, is

unconscionable.

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] split dataset randomly in prediction and validation set

2009-02-05 Thread Dieter Menne
Els Verfaillie  ugent.be> writes:

> For a geostatistical analysis, I would like to split my dataset randomly
> into 2 parts: a prediction set (with 2/3 of my data) and a validation set
> (with 1/3 of my data). Both datasets will thus contain different data.  Any
> suggestions?

Normally, you will not do this once, but round-robin. There are a few
packages around that help you in doing this (check for cross-validation),
but in most cases doing it by hand can be easier to understand 4 years 
later.

Dieter

# randomize your data; may not be required
set.seed(4711)
df = data.frame(x=rnorm(100),y=rnorm(100))[sample(1:nrow(df)),]
ncrossval = 3
# Fiddling required when length of data is not evenly divisble by ncrossval
df$group = rep(1:ncrossval,nrow(df)/+1)[1:nrow(df)]
for (group in 1:ncrossval)
{
  small = df[df$group==group,]
  big = df[df$group!=group,]
  # do your work with small and big
  str(small)
  str(big)
}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] A way to "lock down" the order of bars for ggplot "dodged" histogram

2009-02-05 Thread Jason Rupert
It appears that ggplot reorder the data for a "dodged" histogram based on 
whether or not a specific variable has a value in the first bin. 
 
I would like to be able to absolutely force the order of the variables in the 
bin.  For example, say I have three variables Me, You, and Them. 
 
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)), Person), 
nrow) 
names(counts) <- c("Bin", "Person", "Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar", 
stat="identity", width = 0.9, xlab="Person") +  facet_grid(. ~ Bin) 
 
However, I absolutely must have the bar order be Them, You, Me.   Is there a to 
fix the order of the bars so that they are always in the Them, You, Me order? 
 
Thank you again for any feedback you can provide.  
 
 


  
[[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] The Origins of R

2009-02-05 Thread Roy Mendelssohn
Can we give this a rest  (or take it offline)?  This is the R-Help  
mail list, and I fail to grasp how anyone is being helped to use R by  
this endless discussion.


-Roy M.


**
"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] change individual label colours in a cluster plot?

2009-02-05 Thread Jim Ottaway
> patricia garcía gonzález  writes:

> Hi,

> If you have a variable, that defines what you want to differentiate
> (sociology, economics etc.) then you can add color depending on the
> value of that variable. You will have to convert it to numeric if it is
> not. An example would be

> plot( iris[ , 1 ], iris[ , 2], col = iris[ , 3 ] )


Thank you.  I'm not sure that I can do that with an hclust object,
though: perhaps something using the text function and the order data in
the hclust object might work?

Currently, I'm good getting results using a script to edit the
postscript output, but I'm keen to find an R solution, if only to
improve my understanding of R graphicss.

Yours sincerely,
-- 
Jim Ottaway

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

2009-02-05 Thread Mark Difford

Duncan Murdoch wrote:

>> So I'm not complaining, but the main problem I saw in his article was 
>> that it didn't mention me.  I knew Robert Gentleman (even had an office 
>> next to him!) before he started R:  surely that must have been a key 
>> influence.

I am sorry to hear that. If I understand you correctly, it seems that Mr.
Vance made an even more botched job of parts of his article than one would
have thought possible. The proverbial curate's egg, it seems.

Regards, Mark.


Duncan Murdoch-2 wrote:
> 
> On 2/5/2009 1:05 AM, Mark Difford wrote:
 I think that all appeared on January 8 in Vance's blog posting, with a 
 comment on it by David M Smith on Jan 9.  So those people have -27 days 
>> 
>> Then there was no need for vituperative comments (not from you, of
>> course):
>> simply point doubters to the right place, as you have done. But Mr.
>> Vance's
>> comments only deepen the "mystery."
>> 
>> If Mr. Vance was aware of the true origins of R, why did he choose to
>> misrepresent them in his article, which is what got the publicity and
>> which
>> is the item that most people saw/read? Most right-thinking people don't,
>> wouldn't, or haven't taken the matter further than that. Their
>> criticisms,
>> as mine have been, have been aimed at the NY Times and Mr. Vance's lack
>> of
>> ethics. It also seems clear from Mr. Vance's comments that there was no
>> editorial or sub-editorial meddling.
> 
> That's not what I read in the posting to this list that I cited.
> 
> I doubt if Ashlee Vance is reading this list, so it doesn't really seem 
> fair to blame him if he doesn't respond to your attacks.
> 
> So I'm not complaining, but the main problem I saw in his article was 
> that it didn't mention me.  I knew Robert Gentleman (even had an office 
> next to him!) before he started R:  surely that must have been a key 
> influence.  Why else did he move to the far side of the globe?  And not 
> only that, but to compound the insult, the NY Times has failed to 
> mention me every day since then!
> 
> Duncan Murdoch
> 
>> 
>> The knee-jerk reaction ? Well, it is almost amusing to see how sensitive
>> some very hard-nosed individuals on this list can be, or have become.
>> 
>> Regards, Mark.
>> 
>> still to wait.
>> 
>> Duncan Murdoch-2 wrote:
>>> 
>>> On 2/4/2009 3:53 PM, Mark Difford wrote:
>> >>> Indeed.  The postings exuded a tabloid-esque level of slimy  
  nastiness.
 
 Hi Rolf,
 
 It is good to have clarification, for you wrote "..,the postings...,"
 tarring everyone with the same brush. And it was quite a nasty brush.
 It
 also is conjecture that "this was due to an editor or sub-editor," i.e.
 the
 botched article.
 
 I think that what some people are waiting for are factual statements
 from
 the parties concerned. Conjecture is, well, little more than
 conjecture.
>>> 
>>> I think that all appeared on January 8 in Vance's blog posting, with a 
>>> comment on it by David M Smith on Jan 9.  So those people have -27 days 
>>> still to wait.
>>> 
>>> Duncan Murdoch
>>> 
>>> 
 
 Regards, Mark.
 
 
 Rolf Turner-3 wrote:
> 
> 
> On 4/02/2009, at 8:15 PM, Mark Difford wrote:
> 
>>
 Indeed.  The postings exuded a tabloid-esque level of slimy  
 nastiness.
>>
>> Indeed, indeed. But I do not feel that that is necessarily the  
>> case. Credit
>> should be given where credit is due. And that, I believe is the  
>> issue that
>> is getting (some) people hot and bothered. Certainly, Trevor Hastie  
>> in his
>> reply to the NY Times article, was not too happy with this aspect  
>> of the
>> story.
>>
>> Granted, his comments were not made on this list, but the objection
>> is
>> essentially the same. I would not call what he had to say "Mischief  
>> making"
>> or smacking of a "tabloid-esque level of slimy nastiness." The knee- 
>> jerk
>> reaction seems to be that this is a criticism of R. It is not. It is
>> a
>> criticism of a poorly researched article.
>>
>> It also is an undeniable and inescapable fact that most S code runs  
>> in R.
> 
> The problem is not with criticism of the NY Times article, although  
> as Pat
> Burns and others have pointed out this criticism was somewhat  
> misdirected
> and unrealistic considering the exigencies of newspaper editing.  The  
> problem
> was with a number of posts that cast aspersions upon the integrity of
> Ihaka and Gentleman.  It is these posts that exuded tabloid-esque
> slimy
> nastiness.
> 
> I am sure that Ross and Robert would never dream of failing to give  
> credit
> where credit is due and it is almost certainly the case that they  
> explained
> the origins of R in the S language to the writer of the NYT article  
> (wherefrom
> the explanation was cut

Re: [R] eliminating control characters from formatted data files

2009-02-05 Thread David Epstein



Murray Cooper wrote:
> 
> This may be a case of "If all you have is a hammer, everything looks like
> a 
> nail".
> If all you want to do is remove the last line if it contains a CONTROL-Z, 
> why
> not use something like perl to process the files?
> 
My first thought was to use perl, and this would have saved a lot of my
time, in the short run. However, I'm trying to learn R, and the way to learn
a programming language is to use it. I've learned a lot about R from this
exercise, much more than has been revealed on this forum.
David
-- 
View this message in context: 
http://www.nabble.com/eliminating-control-characters-from-formatted-data-files-tp21847583p21853836.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] The Origins of R

2009-02-05 Thread Duncan Murdoch

On 2/5/2009 1:05 AM, Mark Difford wrote:
I think that all appeared on January 8 in Vance's blog posting, with a 
comment on it by David M Smith on Jan 9.  So those people have -27 days 


Then there was no need for vituperative comments (not from you, of course):
simply point doubters to the right place, as you have done. But Mr. Vance's
comments only deepen the "mystery."

If Mr. Vance was aware of the true origins of R, why did he choose to
misrepresent them in his article, which is what got the publicity and which
is the item that most people saw/read? Most right-thinking people don't,
wouldn't, or haven't taken the matter further than that. Their criticisms,
as mine have been, have been aimed at the NY Times and Mr. Vance's lack of
ethics. It also seems clear from Mr. Vance's comments that there was no
editorial or sub-editorial meddling.


That's not what I read in the posting to this list that I cited.

I doubt if Ashlee Vance is reading this list, so it doesn't really seem 
fair to blame him if he doesn't respond to your attacks.


So I'm not complaining, but the main problem I saw in his article was 
that it didn't mention me.  I knew Robert Gentleman (even had an office 
next to him!) before he started R:  surely that must have been a key 
influence.  Why else did he move to the far side of the globe?  And not 
only that, but to compound the insult, the NY Times has failed to 
mention me every day since then!


Duncan Murdoch



The knee-jerk reaction ? Well, it is almost amusing to see how sensitive
some very hard-nosed individuals on this list can be, or have become.

Regards, Mark.

still to wait.

Duncan Murdoch-2 wrote:


On 2/4/2009 3:53 PM, Mark Difford wrote:
>>> Indeed.  The postings exuded a tabloid-esque level of slimy  

 nastiness.


Hi Rolf,

It is good to have clarification, for you wrote "..,the postings...,"
tarring everyone with the same brush. And it was quite a nasty brush. It
also is conjecture that "this was due to an editor or sub-editor," i.e.
the
botched article.

I think that what some people are waiting for are factual statements from
the parties concerned. Conjecture is, well, little more than conjecture.


I think that all appeared on January 8 in Vance's blog posting, with a 
comment on it by David M Smith on Jan 9.  So those people have -27 days 
still to wait.


Duncan Murdoch




Regards, Mark.


Rolf Turner-3 wrote:



On 4/02/2009, at 8:15 PM, Mark Difford wrote:



Indeed.  The postings exuded a tabloid-esque level of slimy  
nastiness.


Indeed, indeed. But I do not feel that that is necessarily the  
case. Credit
should be given where credit is due. And that, I believe is the  
issue that
is getting (some) people hot and bothered. Certainly, Trevor Hastie  
in his
reply to the NY Times article, was not too happy with this aspect  
of the

story.

Granted, his comments were not made on this list, but the objection is
essentially the same. I would not call what he had to say "Mischief  
making"
or smacking of a "tabloid-esque level of slimy nastiness." The knee- 
jerk

reaction seems to be that this is a criticism of R. It is not. It is a
criticism of a poorly researched article.

It also is an undeniable and inescapable fact that most S code runs  
in R.


The problem is not with criticism of the NY Times article, although  
as Pat
Burns and others have pointed out this criticism was somewhat  
misdirected
and unrealistic considering the exigencies of newspaper editing.  The  
problem

was with a number of posts that cast aspersions upon the integrity of
Ihaka and Gentleman.  It is these posts that exuded tabloid-esque slimy
nastiness.

I am sure that Ross and Robert would never dream of failing to give  
credit
where credit is due and it is almost certainly the case that they  
explained
the origins of R in the S language to the writer of the NYT article  
(wherefrom

the explanation was cut in the editing process).

Those of us on this list (with the possible exception of one or two  
nutters)
would take it that it goes without saying that R was developed on the  
basis
of S --- we all ***know*** that.  To impugn the integrity of Ihaka  
and Gentleman,
because an article which *they didn't write* failed to mention this  
fact, is

unconscionable.

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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reprod

Re: [R] maptools: Test if point is in polygon

2009-02-05 Thread Rainer M Krug
On Thu, Feb 5, 2009 at 3:21 PM, Aleksandr Andreev
 wrote:
> In R's maptools package, is there a built-in function to test if a
> given point is "inside" a given polygon on the map?  The map was
> loaded from an ESRI Shapefile. The point's latitude and longitude are
> known.

If everything else fails, convert the shape file into a raster and
"drill down" at the location of the points.

Rainer

>
> Thank you!
>
> Aleks
>
> --
> 
> Aleksandr Andreev
> Fulbright Fellow
> Graduate School of Management
> St Petersburg State 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.
>



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

Centre of Excellence for Invasion Biology
Faculty of Science
Natural Sciences Building
Private Bag X1
University of Stellenbosch
Matieland 7602
South Africa

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] maptools: Test if point is in polygon

2009-02-05 Thread baptiste auguie
I don't know about the maptools package but one general way to do this  
would be to compute the convex hull (?chull)  of the augmented set of  
points and test if the point belongs to it.


Hope this helps,

baptiste



On 5 Feb 2009, at 13:21, Aleksandr Andreev wrote:


In R's maptools package, is there a built-in function to test if a
given point is "inside" a given polygon on the map?  The map was
loaded from an ESRI Shapefile. The point's latitude and longitude are
known.

Thank you!

Aleks

--

Aleksandr Andreev
Fulbright Fellow
Graduate School of Management
St Petersburg State 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.


_

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] change individual label colours in a cluster plot?

2009-02-05 Thread patricia garcía gonzález

Hi, 

If you have a variable, that defines what you want to differentiate (sociology, 
economics etc.) then you can add color depending on the value of that  
variable. You will have to convert it to numeric if it is not.
An example would be

plot( iris[ , 1 ], iris[ , 2], col = iris[ , 3 ] )


Regards


Patricia

> To: r-h...@stat.math.ethz.ch
> From: j.otta...@lse.ac.uk
> Date: Thu, 5 Feb 2009 13:44:21 +
> Subject: [R] change individual label colours in a cluster plot?
> 
> I am doing some bibliometric analysis of interdisciplinarity using
> cluster analysis of co-authorship.
> 
> I'd like to be able to specify the colour of individual authors in the
> labels to show a prior grouping by discipline (red for sociology
> authors, blue for economics authors, ..., that sort of thing).
> 
> Is there any way of doing this sort of thing? I'm hoping for something like:
> 
> h <- hclust(authors.dist)
> 
> h$labels <- colorlabels(c("red", "blue",..., "green"))
> 
> plot(h)
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

_


[[alternative HTML version deleted]]

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


Re: [R] overlay plot question

2009-02-05 Thread Doran, Harold
Did you want something like this:

library(lattice)
x <- plogis(.x, location=0, scale=1)
y <-  plogis(.x, location=2, scale=4)
xvals <- seq(-7.6, 7.6, length=100)
xyplot(x+y ~ xvals,  type = c("g", "l")) 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of David Kaplan
> Sent: Wednesday, February 04, 2009 5:25 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] overlay plot question
> 
> Greetings all,
> 
> I have two logistic plots coming from two calls to plogis.  
> The code is
> 
> .x <- seq(-7.6, 7.6, length=100)
>   plot(.x, plogis(.x, location=0, scale=1), xlab="x", 
> ylab="Density",  main="Logistic Distribution: location = 0, 
> scale = 1", type="l")
>   abline(h=0, col="gray")
>  
> 
> .y <- seq(-7.6, 7.6, length=100)
>   plot(.x, plogis(.x, location=2, scale=4), xlab="x", ylab="Density",
>   main="Logistic Distribution: location = 2, scale = 4", 
> type="l")  abline(h=0, col="gray")
>  
>  remove(.x)
> 
>  remove(.y)
> 
> 
> I would like to overlay these on one plot.  Notice here the 
> y-axis is different.  But I would like to axis to be 0 to 1 
> as in the first plot.
> 
> Any suggestions would be greatly appreciated.
> 
> Thanks in advance,
> 
> David
> 
> 
> --
> ==
> =
> David Kaplan, Ph.D.
> Professor
> Department of Educational Psychology
> University of Wisconsin - Madison
> Educational Sciences, Room, 1061
> 1025 W. Johnson Street
> Madison, WI 53706
> 
> email: dkap...@education.wisc.edu
> homepage:
> http://www.education.wisc.edu/edpsych/default.aspx?content=kaplan.html
> Phone: 608-262-0836
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Three questions about DSE

2009-02-05 Thread Rebecca Sela
I have been using the dse1 and dse2 packages to estimate a model in which the 
underlying state is an ARMA(2,2) and the observed variables are equal to the 
state plus noise.  I am describing this model using a state space model.

First, in estimation, is there a way to restrict two of the estimated 
coefficients to be equal to each other?  In order to desribe an ARMA(2,2) model 
using a state space model, I must restrict the innovation variance to have its 
two non-zero elements equal to each other, and I haven't figured out how to do 
that.

Second, I am using the smoother to extract the signal using the code in the 
attached file.  The estimated value of the signal in the last period is 0, but 
all the estimated values are right.  Is there something I am missing here?

Finally, sometimes the smoother fails, but the filtered version of the signal 
is fine.  (That will not be the case with the attached code.)  Is there a known 
reason why this sometimes occurs?

Thank you in advance for all of your help!

Rebecca

--
Rebecca Sela
Doctoral Candidate
Statistics Group/IOMS
Stern School of Business__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 individual label colours in a cluster plot?

2009-02-05 Thread Jim Ottaway
I am doing some bibliometric analysis of interdisciplinarity using
cluster analysis of co-authorship.

I'd like to be able to specify the colour of individual authors in the
labels to show a prior grouping by discipline (red for sociology
authors, blue for economics authors, ..., that sort of thing).

Is there any way of doing this sort of thing? I'm hoping for something like:

h <- hclust(authors.dist)

h$labels <- colorlabels(c("red", "blue",..., "green"))

plot(h)

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

2009-02-05 Thread hadley wickham
On Thu, Feb 5, 2009 at 8:32 AM, hadley wickham  wrote:
>>  > I don't think you should completely rule out javascript.  It's
>>  > possible to use it in ways that add to the utility of a page, while
>>  > not detracting from it if not available.
>>
>> OK, what particularly do you have in mind?

Some more ideas:

Because we are limited in terms of server side interactivity, you
could write a small script that sniffs the user agent and presents the
matching version of R most prominently.

Or use an ip2geo service to guess which cran mirror is geographically
closest and move that to the top of the list of mirrors. (e.g.
http://www.petefreitag.com/item/683.cfm)

Hadley

-- 
http://had.co.nz/

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

2009-02-05 Thread hadley wickham
>  > I don't think you should completely rule out javascript.  It's
>  > possible to use it in ways that add to the utility of a page, while
>  > not detracting from it if not available.
>
> OK, what particularly do you have in mind?

Here's a few of examples off the top of my head.  These are things
that would add to the aesthetic appeal/usability of the site, without
distracting from the main content and without making the site unusable
if javascript is turned off.

 * instead of a single graphic from the r graph gallery, you could
have a slideshow of a random selection of many graphics (e.g.
http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/)

 * you could use a js client side web analytics service (like google
analytics) to collect usage statistics across all cran mirrors in one
place (wouldn't work for packages, just pages)

 * you could use jsMath (http://www.math.union.edu/~dpvc/jsMath/) to
convert from tex style math formulas to nicely styled formulas

 * you could use amberjack (http://amberjack.org/) to help people
learn where the important parts of the site are

 * you could use a lightboxing technique when zooming into screenshot
thumbnails, e.g. http://fancy.klade.lv/

These techniques all degrade well so if you don't have javascript you
don't missing functionality.

Hadley

-- 
http://had.co.nz/

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