Re: [R] nlm behaviour and error

2008-06-02 Thread Prof Brian Ripley

It says the value is *missing* (NA), not that the length is wrong.

My quess is that term*bexp is NaN, but you have given us no context to go 
on.


On Tue, 3 Jun 2008, Redding, Matthew wrote:


Hi R-Gurus,

I've been cutting along quite nicely with nlm, until
I threw in the following condition in the function that nlm is
minimising:

   if (((term*bexp) < 0.0001)) {
  #warning(term*bexp, "=term*bexp",psi,"=psi")
  theta<-2000
   }



Now when I run this function anywhere else, there is no problem, whether
or the if's condition is met.

When I use this in nlm:

nlm(f=ssewrap.dist, p=c(292397.7,-.14053,0.03,.0005), .5, 1,
295.15,C,theta)
Error in if (((term * bexp) < 1e-04)) { :
 missing value where TRUE/FALSE needed


Now I know that the condition in the if should only be one logical
value, but is not the condition above evaluated to a single value, and
why does the error only occur when the function is used by nlm?

Any suggestions?

Kind regards,

Matt Redding
DISCLAIMER**...{{dropped:15}}

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



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

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


Re: [R] 'asymmetric span' for 2D loess?

2008-06-02 Thread Prof Brian Ripley

On Mon, 2 Jun 2008, Tokuyasu, Taku wrote:


Hello,

I am interested in performing a 2D loess smooth on microarray data, i.e.
log2 ratios on a 2D grid, using different spans in the horizontal and
vertical directions (the immediate reason being that replicate spots are
laid out in the horizontal direction).  Is it possible to do this in R?
Functions like loess(stats) seem to apply the same span for all
predictors, which carries over to functions like ma2D(marray).


See the next comment.  'span' applies to 2D distances, and I think you 
need to rescale your inputs so Euclidean distance is appropriate.



As an elementary second question, are there circumstances where one
expects to see a substantial difference in the fits between say loess(y
~ x1 + x2) and loess(y ~ x1 * x2) with an interaction term (and if so,
what are they)?



From the help page:


 formula: a formula specifying the numeric response and one to four
  numeric predictors (best specified via an interaction, but
  can also be specified additively).  Will be coerced to a
  formula if necessary.

So the two versions both specify smoothing in 2D.

You can use things like lo(x1) + lo(x2) in some gam fits.

It often helps to read the primary sources, in this case chapters in the 
White Book (Chambers & Hastie, nominally 1992, actually published in 
1991).




Many thanks,

_Taku

Taku A. Tokuyasu, PhD
UCSF Helen Diller Family Comprehensive Cancer Center
San Francisco, CA 94143-0808


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

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


Re: [R] Error/Crash on start up of R (Ubuntu and Wine within Ubuntu)

2008-06-02 Thread Prof Brian Ripley
Either you have a corrupt .RData file in the directory you are starting R 
in or the file is being read incorrectly (e.g. because of a corrupted file 
system or hardware issues).


Reinstalling etc will not remove the .RData file, and you need to do so 
yourself.


Starting R with --vanilla is always a good check for local configuration 
issues.


On Mon, 2 Jun 2008, Patrick M. Joyce wrote:


Hello,

I'm having issues operating R under Ubuntu (Hardy 8.04) though I suspect
this is not necessarily the malady.  I have attempted to run R in ubuntu
as is which worked for awhile and then stopped (using RKWard as the
windowing environment).  I tried removing then re-installing the software
and the same issue (which i'll detail soon) persisted.  I then tried using
WINE to run R using the Windows version of R.  The same error was
presented.

The Ubuntu and WINE errors are slightly different but are more or less the
same...

COMMON ASPECT--I get the following:

Error in load(name, envir = .GlobalEnv):
value of 'SET_ATTRIB' must be a pairlist or NULL, not a 'double'

WINE Variant--I get a windowed box with the title "Information" noting
that "Fatal error: unable to restore saved data in .RData".

UBUNTU Variant--I get a segmentation fault statement and abort options.

I'm going to guess that this is the same issue.  I would presume at this
point that either there is some mistaken setting within the operating
system OR something wrong with the hardware.

I appreciate any help on the matter.

--Patrick

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



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

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


[R] nlm behaviour and error

2008-06-02 Thread Redding, Matthew
Hi R-Gurus, 

I've been cutting along quite nicely with nlm, until
I threw in the following condition in the function that nlm is
minimising:

if (((term*bexp) < 0.0001)) {
   #warning(term*bexp, "=term*bexp",psi,"=psi") 
   theta<-2000
}



Now when I run this function anywhere else, there is no problem, whether
or the if's condition is met.

When I use this in nlm:

nlm(f=ssewrap.dist, p=c(292397.7,-.14053,0.03,.0005), .5, 1,
295.15,C,theta)
Error in if (((term * bexp) < 1e-04)) { : 
  missing value where TRUE/FALSE needed


Now I know that the condition in the if should only be one logical
value, but is not the condition above evaluated to a single value, and
why does the error only occur when the function is used by nlm?

Any suggestions?

Kind regards, 

Matt Redding
DISCLAIMER**...{{dropped:15}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 'asymmetric span' for 2D loess?

2008-06-02 Thread Tokuyasu, Taku

Hello,

I am interested in performing a 2D loess smooth on microarray data, i.e.
log2 ratios on a 2D grid, using different spans in the horizontal and
vertical directions (the immediate reason being that replicate spots are
laid out in the horizontal direction).  Is it possible to do this in R?
Functions like loess(stats) seem to apply the same span for all
predictors, which carries over to functions like ma2D(marray).

As an elementary second question, are there circumstances where one
expects to see a substantial difference in the fits between say loess(y
~ x1 + x2) and loess(y ~ x1 * x2) with an interaction term (and if so,
what are they)?

Many thanks,

_Taku

Taku A. Tokuyasu, PhD
UCSF Helen Diller Family Comprehensive Cancer Center
San Francisco, CA 94143-0808

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Partitioning a large data frame and writing output CSVs

2008-06-02 Thread Moshe Olshansky
Assuming that your data is in a data.frame d, you could do the following:

for (i in 1:999)
{
df <- d[564*(i-1)+(1:564),]
g <- paste("group",i,sep="")
group <- rep(g,564)
newdf <- data.frame(group,df)
filename <- paste("file",i,".csv",sep="")
write.csv(newdf,filename)
}


--- On Tue, 3/6/08, joshgage <[EMAIL PROTECTED]> wrote:

> From: joshgage <[EMAIL PROTECTED]>
> Subject: [R]  Partitioning a large data frame and writing output CSVs
> To: r-help@r-project.org
> Received: Tuesday, 3 June, 2008, 10:58 AM
> Hello,
> 
> I have a large dataset [536436,4]
> 
> I'd like to partition the dataset into 999 groups of
> 564 rows and output
> each group as a CSV files... Obviously I could do this
> longhand  but I know
> it is somehow possible to write a loop to do the same
> thing...
> 
> I'd like to group such that the first group is the
> first 564 rows, the
> second group is the second 564 rows .  the 999th group
> is the 999th 564
> rows...
> 
> In each newly created group, I'd like there to be a new
> column that
> identifies the group... i.e. the first group would have a
> new column in
> which all 564 observations have a character value of
> "group1" 
> 
> Finally I'd also like to output each one of these
> groups as a CSV file with
> a unique name
> 
> Any help with this is very greatly appreciated
> 
> thanks in advance,
> 
> Josh
> -- 
> View this message in context:
> http://www.nabble.com/Partitioning-a-large-data-frame-and-writing-output-CSVs-tp17614022p17614022.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] NOT-SO-SIMPLE function!

2008-06-02 Thread T.D.Rudolph

I am continually amazed at how many ways there are to skin a cat in R!


Gabor Grothendieck wrote:
> 
> In the following cs increases by 1 for each nonzero
> entry in x.  Thus the zeros plus the preceding nonzero
> form runs in cs.  seq(cs)-match(cs,cs) assigns 0
> to the first element of each such run, 1 to the next,
> 2 to the next and so on.  Thus shifting it forward and
> adding 1 gives the number of preceding zeros, num0p1.
> 
> cs <- cumsum(x != 0)
> num0p1 <- head(c(0, seq(cs) - match(cs, cs)), -1) + 1
> ifelse(x == 0, NA, log(x/num0p1))
> 
> On Mon, Jun 2, 2008 at 2:30 PM, T.D.Rudolph <[EMAIL PROTECTED]>
> wrote:
>>
>> I am trying to set up a function which processes my data according to the
>> following rules:
>>
>> 1. if (x[i]==0) NA
>> 2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately
>> preceding
>> it +1))
>>
>> The data this will apply to include a variety of whole numbers not
>> limited
>> to 1 & 0, a number of which may appear consecutively and not separated by
>> zeros.  Below is an example with a detailed explanation of the output
>> desired:
>>
>> x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
>> output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41, NA, NA, 1.098, NA,
>> NA,
>> NA, NA, -0.22, 0)
>>
>> the 1st element, 3, becomes log(3) = 1.098612
>> the 2nd element, 2, becomes log(2) = 0.6931472
>> the 3rd element, 0, becomes NA (cannot log zero).
>> the 4rd element, 1, becomes log(1/(1(number of consecutive zeros
>> immediately
>> preceding it) + 1 (constant))) = log(1/2) =  -0.6931472
>> the 5th element, 0, becomes NA
>> the 6th element, 2, becomes log(2/(1(number of consecutive zeros
>> immediately
>> preceding it) + 1 (constant))) = log(2/3) = -0.4054651
>> the 7th and 8th elements, both zeros, become NA
>> the 9th element, 1, becomes log(1/(2(number of consecutive zeros
>> immediately
>> preceding it) + 1 (constant))) = log(1/3) =  1.098612
>> the 10-13th elements, all zeros, each become NA
>> the 14th element, 4, becomes log(4/(4(number of consecutive zeros
>> immediately preceding it) + 1 (constant))) = log(4/5) = -0.2231436
>> the 15th element, 1, becomes log(1) = 0
>>
>> This one has been in the works for some time and I can't quite seem to
>> crack
>> it.
>> I would be indebted to anyone who could with success - it seemed so
>> simple
>> at the offset!
>> Tyler
>> --
>> View this message in context:
>> http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17607348.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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17615995.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] some problems I have met in LARS

2008-06-02 Thread David Winsemius
feathersea <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> I loaded  the LARS package,and input: data(diabetes),load the
> embedded data  then I found the varialbes are in this form:
> 
>  x.age,x.bmi..(10 of them),X2.age,X2.bmi(64 of them)
> When I input x,R gave me all 10 varialbes,and input X2,it gave me 64 
> variables, but if I input x.age, it returned nothing,I wonder how to
> affiliate those subvariable such as x.age,x.bmi to x,since I create
> a table,name the variable x.1,x,2 ,it came to nothing when I input
> x. 
>   I have never seen this before,can someone give me some keyword ,so 
>   I can search online,thank you very much. 
>  [[alternative HTML version deleted]]

How about posting the code?

-- 
David Winsemius

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

2008-06-02 Thread Gabor Grothendieck
In the following cs increases by 1 for each nonzero
entry in x.  Thus the zeros plus the preceding nonzero
form runs in cs.  seq(cs)-match(cs,cs) assigns 0
to the first element of each such run, 1 to the next,
2 to the next and so on.  Thus shifting it forward and
adding 1 gives the number of preceding zeros, num0p1.

cs <- cumsum(x != 0)
num0p1 <- head(c(0, seq(cs) - match(cs, cs)), -1) + 1
ifelse(x == 0, NA, log(x/num0p1))

On Mon, Jun 2, 2008 at 2:30 PM, T.D.Rudolph <[EMAIL PROTECTED]> wrote:
>
> I am trying to set up a function which processes my data according to the
> following rules:
>
> 1. if (x[i]==0) NA
> 2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
> it +1))
>
> The data this will apply to include a variety of whole numbers not limited
> to 1 & 0, a number of which may appear consecutively and not separated by
> zeros.  Below is an example with a detailed explanation of the output
> desired:
>
> x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
> output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41, NA, NA, 1.098, NA, NA,
> NA, NA, -0.22, 0)
>
> the 1st element, 3, becomes log(3) = 1.098612
> the 2nd element, 2, becomes log(2) = 0.6931472
> the 3rd element, 0, becomes NA (cannot log zero).
> the 4rd element, 1, becomes log(1/(1(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(1/2) =  -0.6931472
> the 5th element, 0, becomes NA
> the 6th element, 2, becomes log(2/(1(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(2/3) = -0.4054651
> the 7th and 8th elements, both zeros, become NA
> the 9th element, 1, becomes log(1/(2(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(1/3) =  1.098612
> the 10-13th elements, all zeros, each become NA
> the 14th element, 4, becomes log(4/(4(number of consecutive zeros
> immediately preceding it) + 1 (constant))) = log(4/5) = -0.2231436
> the 15th element, 1, becomes log(1) = 0
>
> This one has been in the works for some time and I can't quite seem to crack
> it.
> I would be indebted to anyone who could with success - it seemed so simple
> at the offset!
> Tyler
> --
> View this message in context: 
> http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17607348.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] NOT-SO-SIMPLE function!

2008-06-02 Thread Gabor Grothendieck
In the following cs increases by 1 for each nonzero
entry in x.  Thus the zeros plus the preceding nonzero
form runs in cs.  seq(cs)-match(cs,cs) assigns 0
to the first element of each such run, 1 to the next,
2 to the next and so on.  Thus shifting it forward and
adding 1 gives the number of preceding zeros, num0p1.

cs <- cumsum(x != 0)
num0p1 <- head(c(0, seq(cs) - match(cs, cs)), -1) + 1
ifelse(x == 0, NA, log(x/num0p1))

On Mon, Jun 2, 2008 at 2:30 PM, T.D.Rudolph <[EMAIL PROTECTED]> wrote:
>
> I am trying to set up a function which processes my data according to the
> following rules:
>
> 1. if (x[i]==0) NA
> 2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
> it +1))
>
> The data this will apply to include a variety of whole numbers not limited
> to 1 & 0, a number of which may appear consecutively and not separated by
> zeros.  Below is an example with a detailed explanation of the output
> desired:
>
> x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
> output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41, NA, NA, 1.098, NA, NA,
> NA, NA, -0.22, 0)
>
> the 1st element, 3, becomes log(3) = 1.098612
> the 2nd element, 2, becomes log(2) = 0.6931472
> the 3rd element, 0, becomes NA (cannot log zero).
> the 4rd element, 1, becomes log(1/(1(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(1/2) =  -0.6931472
> the 5th element, 0, becomes NA
> the 6th element, 2, becomes log(2/(1(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(2/3) = -0.4054651
> the 7th and 8th elements, both zeros, become NA
> the 9th element, 1, becomes log(1/(2(number of consecutive zeros immediately
> preceding it) + 1 (constant))) = log(1/3) =  1.098612
> the 10-13th elements, all zeros, each become NA
> the 14th element, 4, becomes log(4/(4(number of consecutive zeros
> immediately preceding it) + 1 (constant))) = log(4/5) = -0.2231436
> the 15th element, 1, becomes log(1) = 0
>
> This one has been in the works for some time and I can't quite seem to crack
> it.
> I would be indebted to anyone who could with success - it seemed so simple
> at the offset!
> Tyler
> --
> View this message in context: 
> http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17607348.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] some problems I have met in LARS

2008-06-02 Thread feathersea
 Hi:
I loaded  the LARS package,and input: data(diabetes),load the embedded
data
   then I found the varialbes are in this form:

x.age,x.bmi..(10 of them),X2.age,X2.bmi(64 of them)
   When I input x,R gave me all 10 varialbes,and input X2,it gave me 64
variables,but if I input x.age,it returned nothing,I wonder how to affiliate
those subvariable such as x.age,x.bmi to x,since I create a table,name the
variable x.1,x,2 ,it came to nothing when I input x.
  I have never seen this before,can someone give me some keyword ,so I can
search online,thank you very much.

[[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] Lengthy delay in sourcing a large function

2008-06-02 Thread Gregory. R. Warnes
For such a large chunk of code, you might profit greatly from  
constructing an R package containing your functions.  This will avoid  
the need to parse in the entire set every time, since the functions  
will be "pre-parsed" during the package installation.

-G


On Jun 2, 2008, at 5:45PM , Duncan Murdoch wrote:

> On 02/06/2008 5:28 PM, Dennis Fisher wrote:
> > Colleagues,
> >
> > I have a script that contains ~ 10,000 lines of code.  Most of it is
> > written as small functions.  However, for various reasons, the final
> > function is ~1500 lines of code.  I realize that this may not be
> > optimal but the code evolved that way and breaking it into smaller
> > pieces is complicated because of the passing of arguments.  I have
> > "cat(date())" statements at various places in the code so that I can
> > track the actions as the script is executed.
> >
> > I am running version 2.7.0 on a quad processor Mac and I call the
> > script from the OS:  R --slave < Script.R
> >
> > It takes ~ 5 seconds for R to read the first 8000 lines of code (as
> > indicated by the time difference between the first record of the  
> file
> > and the date issued immediately before the large function).  Then,
> > reading the large function (1500 lines) takes ~ 1 minute.  I have
> > improved the delay by moving some of the code from the large  
> function.
> >
> > I don't understand why the second portion of the code is read so  
> much
> > slower than the first.  In that the code is a function, I presume  
> that
> > nothing within the function is executed until the function is  
> called.
> >
> > Does anyone have any experience with this issue?
>
> I haven't seen this sort of thing.  I just wrote a (very simple and
> repetitive) 4000 line function and R read it in 4 seconds.  I think
> you'll need to post the actual function somewhere to see if your one
> minute timing is reproducible.
>
> It's possible that it happens because R is short of memory, and  
> needs to
> do a lot of swapping and garbage collection for the big function;  
> trying
> to load that function and do nothing else except print the timings  
> might
> be informative.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Gregory R. Warnes, Ph.D.
Associate Professor
Center for Biodefence Immune Modeling
and
Department of Biostatistics and Computational Biology
University of Rochester





[[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] exit function in R?

2008-06-02 Thread Gregory. R. Warnes

Since Frederico indeicated he was running a script, rather than a  
function, I suspect that he would be better served by the

quit("no")

function.


  Jun 2, 2008, at 5:15PM , Rolf Turner wrote:

>
> On 3/06/2008, at 1:18 AM, Federico Abascal wrote:
>
> > Hi,
> > This is likely an stupid question, but I cannot find the solution.
> > I am searching for an "exit" function, to end the execution of an R
> > script if some condition is not filled.
> > Any clue?
>
> Others have suggested using stop().  It might be the case that the
> condition not being fulfilled is not actually a sign of an error,
> but simply of a different, perhaps ``marginal'' situation in which
> a different sort of action or calculation is required.  In which
> case what you want is return().
>
> Trivial e.g.:
>
> foo <- function(x) {
> if(any(x<=0)) return(42)
> y <- sum(log(x))
> y
> }
>
> 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.
>

Gregory R. Warnes, Ph.D.
Associate Professor
Center for Biodefence Immune Modeling
and
Department of Biostatistics and Computational Biology
University of Rochester





[[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] reading a file incrementally

2008-06-02 Thread Scot W. McNary

Hi,

I'm trying to read a file containing html markup (discussion board 
posts) and output the various parts of each post to an field in a record 
in an output file (date, author, title, body).  This is a one-off job 
and I'm trying to use R to do it. 


The file looks something like this:

Created: --- - Dr. Johnsons's article -
concernsAfter writing some text..-- by
Anon.
Created: --- - RE:Dr. Johnson's article - concernsWith
some advance notice about some text-- by
Anon.

So that tags indicate where the field entries begin and end and 
"Created" and "by Anon" indicate the beginning and ending of the post.


The file is named "Module_1.txt". Here is what I have so far:

## adapted from http://finzi.psych.upenn.edu/R/Rhelp02a/archive/64261.html
## gives post beginning and ending points
starts <- gregexpr("Created", readChar("Module_1.txt", 
file.info("Module_1.txt")$size))[[1]]


ends <- gregexpr("by Anon", readChar("Module_1.txt", 
file.info("Module_1.txt")$size))[[1]]


## open connection
chk <- file("Module_1.txt", "r")
#seek(chk, origin = "start", ends[1]) # moves through file

## initalize an array
hold <- array(rep(NA, length(starts)))

## write a function to read the connection
catchtext <- function(start, end, source) {
   for(i in 1:length(starts)) 
{  
   hold[i] <- readChar(chk, nchar = ends[i] - starts[i])

   }
   }

#close(chk)

and my output is
> hold
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
NA NA NA
[26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
NA NA NA
[51] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
NA NA NA
[76] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
NA NA NA
[101] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 
NA NA NA

[126] NA NA

At this point I'm just trying to get the entire file cut up into 
post-sized chunks.  Later I'll go through and output the separate bits 
into fields.  As can be seen, I'm having trouble moving through the 
connection to the places I want to read from it.  Suggestions welcome.


Thanks,

Scot

> version
  _  
platform   i386-pc-mingw32
arch   i386   
os mingw32
system i386, mingw32  
status
major  2  
minor  6.2
year   2008   
month  02 
day08 
svn rev44383  
language   R  
version.string R version 2.6.2 (2008-02-08)


--
Scot McNary
smcnary at charm dot net

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] transforming output of grid.locator() to coordinates of a leaf viewport

2008-06-02 Thread Paul Murrell
Hi


Wittner, Ben, Ph.D. wrote:
> Hadley, In my application the leaf viewports will not overlap, but I guess 
> that
> would not necessarily be the case for all applications. In any event, do you
> happen to know how to transform coordinates in the top-level viewport to
> coordinates in another viewport in the tree? Thanks. -Ben


current.transform() transforms from *inches* within the current viewport
to *inches* on the overall device.  Sounds like you need the inverse
transform.

If you are in a position to be able to enumerate all of your leaf
viewports, then this may be a possible approach:

- for each leaf viewport, visit the viewport and record the
current.transform() for each leaf viewport.  Also record the size of the
current viewport (in inches).
- capture a click on the device (current viewport should be ROOT) in
*inches*, then iterate through the leaf viewports to determine which one
was clicked in.
- to determine whether the click was within the viewport, use something
like the following function (and check whether both new locations are
positive and smaller than the size of the viewport (in inches)):

newloc <- function(loc, trans) {
temploc <- c(loc, 1) %*% trans
(temploc/temploc[3])[-3]
}

Here's a simple example:

# two "leaf" viewports
# (one on the left half of the device, one on the right)
grid.newpage()
pushViewport(viewport(x=0, width=.5, just="left", name="left"))
transLeft <- current.transform()
sizeLeft <- c(convertWidth(unit(1, "npc"), "inches", valueOnly=TRUE),
  convertHeight(unit(1, "npc"), "inches", valueOnly=TRUE))
# Draw a rect for visual reference
grid.rect(gp=gpar(fill=hcl(240, 60, 80)))
upViewport()
pushViewport(viewport(x=.5, width=.5, just="left", name="right"))
sizeRight <- c(convertWidth(unit(1, "npc"), "inches", valueOnly=TRUE),
   convertHeight(unit(1, "npc"), "inches", valueOnly=TRUE))
heightRight <- convertHeight(unit(1, "npc"), "inches", valueOnly=TRUE)
grid.rect(gp=gpar(fill=hcl(120, 60, 80)))
upViewport()

# Get a click
# (current viewport is the ROOT viewport)
click <- grid.locator(unit="inches")

# For each leaf viewport, calculate where the click was
leftClick <- newloc(unlist(click), solve(transLeft))
rightClick <- newloc(unlist(click), solve(transRight))

# Which one was it in ?
all(leftClick > 0 & leftClick < sizeLeft)
all(rightClick > 0 & rightClick < sizeRight)


Does that help ?

Paul



> 
> 
> From: hadley wickham [mailto:[EMAIL PROTECTED]
> Sent: Sun 6/1/2008 3:24 PM
> To: Wittner, Ben, Ph.D.
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] transforming output of grid.locator() to coordinates of a 
> leaf
> viewport
> 
> 
> 
> Ben,
> 
> What if the click occurs over multiple viewports?
> 
> Hadley
> 
> On Mon, Jun 2, 2008 at 6:50 AM, Wittner, Ben, Ph.D.
> <[EMAIL PROTECTED]> wrote:
>> Short form:
>>
>>How do I transform the output of grid.locator() (or
>> grid.locator(unit='npc')) to the native (or npc) coordinates of a viewport
> other
>> than the top-level viewport?
>>
>>Thanks in advance. -Ben
>>
>> Long form:
>>
>>I would like the user to be able to click anywhere on the R
>> graphics window. I would then like to figure out which leaf viewport the user
>> clicked in and compute the native coordinates in that leaf viewport of the
>> user's click.
>>
>>I saw a 2005 response by Paul Murrell to a post by Gabor
>> Grothendieck roughly on this topic in which Paul suggested looking at
>> trellis.focus(). I've looked at trellis.focus() and trellis.clickFocus(), but
>> they don't appear to do what I want in that a) it would appear that my user
>> would have to click twice, once to specify which leaf viewport and then again
> to
>> specify which point in that viewport and b) trellis.clickFocus() appears to
> use
>> lots of information from the trellis package, which I'm not using.
>>
>>So I decided to try to figure out the native coordinates of 
>> the
>> click in each leaf viewport, to a) see whether the click is within the
> plotting
>> region for that viewport and b) use those coordinates to take the appropriate
>> action if it is. But I don't seem to be able to figure out how to translate
> from
>> the top-level viewport coordinates to those of a leaf viewport. I tried
>> interpreting the 3X3 matrix returned by current.transform() as an affine
>> transformation in the x,y plane in homogeneous coordinates, but could make no
>> sense of what I was getting.
>>
>>Thanks for any help. -Ben
>>
>>
>>
>>
>> The information transmitted in this electronic communica...{{dropped:16}}
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> --
> http://had.co.nz/
> 
> 
> 
>

Re: [R] NOT-SO-SIMPLE function!

2008-06-02 Thread Moshe Olshansky
Just a correction - it should be:

> x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
> y <- rep(NA,length(x))
> z <- which(x != 0)
> l <- z - c(0,z[-length(z)])
> y[z] <- log(x[z]/l)
> y
 [1]  1.0986123  0.6931472 NA -0.6931472 NA  0.000 
NA NA -1.0986123
[10] NA NA NA NA -0.2231436  0.000



--- On Tue, 3/6/08, Moshe Olshansky <[EMAIL PROTECTED]> wrote:

> From: Moshe Olshansky <[EMAIL PROTECTED]>
> Subject: Re: [R] NOT-SO-SIMPLE function!
> To: "T.D.Rudolph" <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Received: Tuesday, 3 June, 2008, 12:09 PM
> A simpler solution would be:
> 
> > x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
> > y <- rep(NA,length(x))
> > y
>  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> > z <- which(x != 0)
> > l <- z - c(1,z[-length(z)])
> > y[z] <- log(x[z]/(l+1))
> > y
>  [1]  1.0986123  0.000 NA -1.0986123 NA
> -0.4054651 NA NA -1.3862944
> [10] NA NA NA NA -0.4054651
> -0.6931472
> 
> 
> 
> --- On Tue, 3/6/08, Marc Schwartz
> <[EMAIL PROTECTED]> wrote:
> 
> > From: Marc Schwartz <[EMAIL PROTECTED]>
> > Subject: Re: [R] NOT-SO-SIMPLE function!
> > To: "T.D.Rudolph"
> <[EMAIL PROTECTED]>
> > Cc: r-help@r-project.org
> > Received: Tuesday, 3 June, 2008, 5:59 AM
> > on 06/02/2008 01:30 PM T.D.Rudolph wrote:
> > > I am trying to set up a function which processes
> my
> > data according to the
> > > following rules:
> > > 
> > > 1. if (x[i]==0) NA
> > > 2. if (x[i]>0) log(x[i]/(number of consecutive
> > zeros immediately preceding
> > > it +1)) 
> > > 
> > > The data this will apply to include a variety of
> whole
> > numbers not limited
> > > to 1 & 0, a number of which may appear
> > consecutively and not separated by
> > > zeros.  Below is an example with a detailed
> > explanation of the output
> > > desired:
> > > 
> > > x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1) 
> > > output desired = c(1.098, 0.69, NA, -0.69, NA,
> -0.41,
> > NA, NA, 1.098, NA, NA,
> > > NA, NA, -0.22, 0) 
> > > 
> > > the 1st element, 3, becomes log(3) = 1.098612 
> > > the 2nd element, 2, becomes log(2) = 0.6931472 
> > > the 3rd element, 0, becomes NA (cannot log zero).
> 
> > > the 4rd element, 1, becomes log(1/(1(number of
> > consecutive zeros immediately
> > > preceding it) + 1 (constant))) = log(1/2) = 
> > -0.6931472 
> > > the 5th element, 0, becomes NA 
> > > the 6th element, 2, becomes log(2/(1(number of
> > consecutive zeros immediately
> > > preceding it) + 1 (constant))) = log(2/3) =
> -0.4054651
> > 
> > 
> > The above should be log(2/2) = 0
> > 
> > There is only 1 consecutive zero preceding the 2 in
> the 6th
> > position
> > 
> > > the 7th and 8th elements, both zeros, become NA 
> > > the 9th element, 1, becomes log(1/(2(number of
> > consecutive zeros immediately
> > > preceding it) + 1 (constant))) = log(1/3) = 
> 1.098612 
> > 
> > The above should be log(1/3) = -1.098612 (negative,
> not
> > positive)
> > 
> > > the 10-13th elements, all zeros, each become NA 
> > > the 14th element, 4, becomes log(4/(4(number of
> > consecutive zeros
> > > immediately preceding it) + 1 (constant))) =
> log(4/5)
> > = -0.2231436 
> > > the 15th element, 1, becomes log(1) = 0 
> > > 
> > > This one has been in the works for some time and
> I
> > can't quite seem to crack
> > > it.
> > > I would be indebted to anyone who could with
> success -
> > it seemed so simple
> > > at the offset!
> > > Tyler
> > 
> > I am presuming that you have some typos/errors above
> in
> > your per element 
> > explanation of the processing of the vector.  If so,
> then
> > the following 
> > should work as a first pass and could probably be
> optimized
> > further:
> > 
> > zeroes <- function(x, i)
> > {
> >if (x[i] == 0) {
> >  NA
> >} else if (i == 1) {
> >  log(x[i])
> >} else if (x[i - 1] != 0) {
> >  log(x[i])
> >} else {
> >  rz <- rle(x[1:(i-1)])
> >  log(x[i] / (rz$lengths[length(rz$lengths)] + 1))
> >}
> > }
> > 
> > 
> > x <- c(3, 2, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 4, 1)
> > 
> > 
> >  > sapply(seq(along = x), function(i) zeroes(x, i))
> >   [1]  1.0986123  0.6931472 NA -0.6931472 
>   
> > NA  0.000
> >   [7] NA NA -1.0986123 NA 
>   
> > NA NA
> > [13] NA -0.2231436  0.000
> > 
> > 
> > See ?rle for more information on the identification of
> the
> > sequential 
> > zeroes in the vector.
> > 
> > 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.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do rea

Re: [R] wildcard symbol or character

2008-06-02 Thread Jorge Ivan Velez
Dear John,

Assuming that your information is in the list x, does

substr(x,1,2)

work for you?

HTH,

Jorge


On Mon, Jun 2, 2008 at 10:07 PM, john.polo <[EMAIL PROTECTED]> wrote:

> hello all,
>
> i want to split a list into smaller lists. the list looks like this:
> CW-W730  CW-W720  CW-W710  CW-W700  CW-W690  CW-W680  CW-W670  CW-W660
> CE-W997  CE-W987  CE-W977  CE-W967  CE-W956  CE-W944  CE-W934  CE-W924
> 7W-W760  7W-W750  7W-967W-941   7W-932   7W-923   7W-914   7W-905
>  7E-W565  7E-W555  7E-W545  7E-W535  7E-W525  7E-906   7E-850   7E-840 ...
>
>
> i want the smaller lists to be based on the first two characters, like CW
> or 7E. i tried split() where the f variable =
> c("1E-*","1W-*","2E-*","2W-*","5E-*","5W-*","7E-*","7W-*","CE-*","CW-*"),
> but * doesn't work as a wildcard as i had hoped. can someone tell me the
> appropriate wildcard character/symbol to use, please?
>
> john
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] merging two data sets with no column header

2008-06-02 Thread David Winsemius
kayj <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:

> 
> I have two data sets data1 and data2  with no column names( No
> header). The first coluimn in both data sets represents the case ID.
> How can I tell R to merge the two data sets by the case ID if there
> is no header? Also, In data1 I have more cases and I would like the
> result of the merge to have all the cases in both data1 and data2.
> there may be some duplicate cases. 

If you bring the data into a dataframe, default variable names will be 
assigned. merge would be the function to use but you will need to 
decide if its default behavior is satisfactory.

See whether these examples are illuminating:

vv <- data.frame(V1=1:10, V2=letters[1:10]) 

# read.table("data1.txt", header=FALSE)  would produce a data.frame 
# with # first variable, V1
# However, merge would use all the column names the are shared unless 
# told to not do so. So give the other columns different names:

vv2 <- data.frame(V1=5:14, V8=letters[5:14])
merge(vv,vv2)
merge(vv,vv2,all=TRUE)

# create a duplicate
vv[8,1] <- 7
merge(vv,vv2,all=TRUE)

-- 
David Winsemius

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] {Spam?} Re: High resolution figures for a paper?

2008-06-02 Thread Richard Rowe

zhijie zhang wrote:

Thanks for the above mentioned methods. I will try them one by one.
Thanks again.


On 6/3/08, Sarah Goslee <[EMAIL PROTECTED]> wrote:
  

The production of "publication-quality graphics" has been discussed at
great length on R-sig-eco over the past week or so. The archive is
available here:
https://stat.ethz.ch/pipermail/r-sig-ecology/2008-May/thread.html
and the thread is very near the bottom. Very detailed recommendations
have been provided. (Also see the past two days, which are not of
course in the May archive.)

Sarah

On Mon, Jun 2, 2008 at 11:12 AM, zhijie zhang <[EMAIL PROTECTED]> wrote:


Dear Rusers,
 My manuscript has been conditionally accepted recently. The problem to
generate the high  resolution figures in R for the manuscript cannot be
solved by me.
The journal editor ask me to generate the figures with a minimum
  

resolution


of 500 dpi. I have tried the *menu-driven method* to save the figures as
JPEG (100% printed quality), but the results seem not to be very good. I
have submitted the generated figures twice using the above-mentioned
  

method,


but the Editor think the resolution is still very low.
 Finally, i used the Photoshop to check the figure. It seems that its
resolution for JPEG (100% printed quality) is about 72dpi.
 *Does anybody know a better method to save a figure with user-defined
resolution in R software, especially high resolution? Could u please show
  

me


an example if possible?*
 I hope to save the figures as TIFF/JPEG format at 1000 dpi.
 Thanks a lot.
  

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






  

Why not save as a vector format? Resolution is effectively infinite.

Brian Ripley has produced new and enhanced drivers for recent R releases 
...  File/Save As and choose your poison ... both Postscript (.ps) and 
PDF (.pdf) work very well. GSView can convert postscript to encapsulated 
postscript (eps). In theory SVG should be a way to go, but rendering 
engines seem a bit idiosyncratic, so not worth the blood pressure at 
this stage. If you must use bitmap then ImageMagick will do a good 
conversion with all bells and whistles.


There was a discussion on these lines on R-help in mid April I think,

Richard

--
Dr Richard Rowe
Zoology & Tropical Ecology
School of Marine & Tropical Biology
James Cook University
Townsville 4811
AUSTRALIA

ph +61 7 47 81 4851
fax +61 7 47 25 1570
JCU has CRICOS Provider Code 00117J

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

2008-06-02 Thread Moshe Olshansky
A simpler solution would be:

> x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1)
> y <- rep(NA,length(x))
> y
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> z <- which(x != 0)
> l <- z - c(1,z[-length(z)])
> y[z] <- log(x[z]/(l+1))
> y
 [1]  1.0986123  0.000 NA -1.0986123 NA -0.4054651 
NA NA -1.3862944
[10] NA NA NA NA -0.4054651 -0.6931472



--- On Tue, 3/6/08, Marc Schwartz <[EMAIL PROTECTED]> wrote:

> From: Marc Schwartz <[EMAIL PROTECTED]>
> Subject: Re: [R] NOT-SO-SIMPLE function!
> To: "T.D.Rudolph" <[EMAIL PROTECTED]>
> Cc: r-help@r-project.org
> Received: Tuesday, 3 June, 2008, 5:59 AM
> on 06/02/2008 01:30 PM T.D.Rudolph wrote:
> > I am trying to set up a function which processes my
> data according to the
> > following rules:
> > 
> > 1. if (x[i]==0) NA
> > 2. if (x[i]>0) log(x[i]/(number of consecutive
> zeros immediately preceding
> > it +1)) 
> > 
> > The data this will apply to include a variety of whole
> numbers not limited
> > to 1 & 0, a number of which may appear
> consecutively and not separated by
> > zeros.  Below is an example with a detailed
> explanation of the output
> > desired:
> > 
> > x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1) 
> > output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41,
> NA, NA, 1.098, NA, NA,
> > NA, NA, -0.22, 0) 
> > 
> > the 1st element, 3, becomes log(3) = 1.098612 
> > the 2nd element, 2, becomes log(2) = 0.6931472 
> > the 3rd element, 0, becomes NA (cannot log zero). 
> > the 4rd element, 1, becomes log(1/(1(number of
> consecutive zeros immediately
> > preceding it) + 1 (constant))) = log(1/2) = 
> -0.6931472 
> > the 5th element, 0, becomes NA 
> > the 6th element, 2, becomes log(2/(1(number of
> consecutive zeros immediately
> > preceding it) + 1 (constant))) = log(2/3) = -0.4054651
> 
> 
> The above should be log(2/2) = 0
> 
> There is only 1 consecutive zero preceding the 2 in the 6th
> position
> 
> > the 7th and 8th elements, both zeros, become NA 
> > the 9th element, 1, becomes log(1/(2(number of
> consecutive zeros immediately
> > preceding it) + 1 (constant))) = log(1/3) =  1.098612 
> 
> The above should be log(1/3) = -1.098612 (negative, not
> positive)
> 
> > the 10-13th elements, all zeros, each become NA 
> > the 14th element, 4, becomes log(4/(4(number of
> consecutive zeros
> > immediately preceding it) + 1 (constant))) = log(4/5)
> = -0.2231436 
> > the 15th element, 1, becomes log(1) = 0 
> > 
> > This one has been in the works for some time and I
> can't quite seem to crack
> > it.
> > I would be indebted to anyone who could with success -
> it seemed so simple
> > at the offset!
> > Tyler
> 
> I am presuming that you have some typos/errors above in
> your per element 
> explanation of the processing of the vector.  If so, then
> the following 
> should work as a first pass and could probably be optimized
> further:
> 
> zeroes <- function(x, i)
> {
>if (x[i] == 0) {
>  NA
>} else if (i == 1) {
>  log(x[i])
>} else if (x[i - 1] != 0) {
>  log(x[i])
>} else {
>  rz <- rle(x[1:(i-1)])
>  log(x[i] / (rz$lengths[length(rz$lengths)] + 1))
>}
> }
> 
> 
> x <- c(3, 2, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 4, 1)
> 
> 
>  > sapply(seq(along = x), function(i) zeroes(x, i))
>   [1]  1.0986123  0.6931472 NA -0.6931472
> NA  0.000
>   [7] NA NA -1.0986123 NA
> NA NA
> [13] NA -0.2231436  0.000
> 
> 
> See ?rle for more information on the identification of the
> sequential 
> zeroes in the vector.
> 
> 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.

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

2008-06-02 Thread john.polo

hello all,

i want to split a list into smaller lists. the list looks like this:
CW-W730  CW-W720  CW-W710  CW-W700  CW-W690  CW-W680  CW-W670  CW-W660 
CE-W997  CE-W987  CE-W977  CE-W967  CE-W956  CE-W944  CE-W934  CE-W924 
7W-W760  7W-W750  7W-967W-941   7W-932   7W-923   7W-914   7W-905  
7E-W565  7E-W555  7E-W545  7E-W535  7E-W525  7E-906   7E-850   7E-840 
...



i want the smaller lists to be based on the first two characters, like 
CW or 7E. i tried split() where the f variable = 
c("1E-*","1W-*","2E-*","2W-*","5E-*","5W-*","7E-*","7W-*","CE-*","CW-*"), 
but * doesn't work as a wildcard as i had hoped. can someone tell me the 
appropriate wildcard character/symbol to use, please?


john

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Partitioning a large data frame and writing output CSVs

2008-06-02 Thread jim holtman
This might give you a hint of how to do it.  BTW, were the dimensions
563436x4?

test <- matrix(runif(100*4),ncol=4)
# create groups of 10 rows
group <- rep(1:10, each=10)
new.test <- cbind(test, group=group)
# now get indices to write out
indices <- split(seq(nrow(test)), new.test[, 'group'])
# now write out the files
for (i in names(indices)){
write.csv(new.test[indices[[i]],], file=paste("data.", i, ".csv",
sep=""),
row.names=FALSE)
}


On Mon, Jun 2, 2008 at 8:58 PM, joshgage <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I have a large dataset [536436,4]
>
> I'd like to partition the dataset into 999 groups of 564 rows and output
> each group as a CSV files... Obviously I could do this longhand  but I know
> it is somehow possible to write a loop to do the same thing...
>
> I'd like to group such that the first group is the first 564 rows, the
> second group is the second 564 rows .  the 999th group is the 999th 564
> rows...
>
> In each newly created group, I'd like there to be a new column that
> identifies the group... i.e. the first group would have a new column in
> which all 564 observations have a character value of "group1"
>
> Finally I'd also like to output each one of these groups as a CSV file with
> a unique name
>
> Any help with this is very greatly appreciated
>
> thanks in advance,
>
> Josh
> --
> View this message in context:
> http://www.nabble.com/Partitioning-a-large-data-frame-and-writing-output-CSVs-tp17614022p17614022.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.
>



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

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

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


[R] boost package help

2008-06-02 Thread maomao bao
Hi, 
 
Is there anyone have some experience in the boost package. I used the 
logitboost function to do the two-class classification. 
 
This is the format I used.  
logitboost(xtrain, ytrain, xtest, presel = 2, mfinal = 100) # with feature 
selection
 
 
logitboost(xtrain, ytrain, xtest, presel = 0, mfinal = 100) # without feature 
selection
 
xtrain is n*p, n is sample size, p is dimension
 
The error is always like this 
 
Error in model.frame.default(formula = y ~ bx, weights = w/mean(w), na.action = 
function (x)  :   invalid type (list) for variable 'bx'
 
 
I tried to implement by copying the original code of this function to track 
down but still I don't know what's the reason. 
Could somebody help me with that? 
I greatly appreciate your help!
 
sincerely,
Linda 
_


Refresh_family_safety_052008
[[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] Error/Crash on start up of R (Ubuntu and Wine within Ubuntu)

2008-06-02 Thread Patrick M. Joyce
Hello,

I'm having issues operating R under Ubuntu (Hardy 8.04) though I suspect
this is not necessarily the malady.  I have attempted to run R in ubuntu
as is which worked for awhile and then stopped (using RKWard as the
windowing environment).  I tried removing then re-installing the software
and the same issue (which i'll detail soon) persisted.  I then tried using
WINE to run R using the Windows version of R.  The same error was
presented.

The Ubuntu and WINE errors are slightly different but are more or less the
same...

COMMON ASPECT--I get the following:

Error in load(name, envir = .GlobalEnv):
 value of 'SET_ATTRIB' must be a pairlist or NULL, not a 'double'

WINE Variant--I get a windowed box with the title "Information" noting
that "Fatal error: unable to restore saved data in .RData".

UBUNTU Variant--I get a segmentation fault statement and abort options.

I'm going to guess that this is the same issue.  I would presume at this
point that either there is some mistaken setting within the operating
system OR something wrong with the hardware.

I appreciate any help on the matter.

--Patrick

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Partitioning a large data frame and writing output CSVs

2008-06-02 Thread joshgage

Hello,

I have a large dataset [536436,4]

I'd like to partition the dataset into 999 groups of 564 rows and output
each group as a CSV files... Obviously I could do this longhand  but I know
it is somehow possible to write a loop to do the same thing...

I'd like to group such that the first group is the first 564 rows, the
second group is the second 564 rows .  the 999th group is the 999th 564
rows...

In each newly created group, I'd like there to be a new column that
identifies the group... i.e. the first group would have a new column in
which all 564 observations have a character value of "group1" 

Finally I'd also like to output each one of these groups as a CSV file with
a unique name

Any help with this is very greatly appreciated

thanks in advance,

Josh
-- 
View this message in context: 
http://www.nabble.com/Partitioning-a-large-data-frame-and-writing-output-CSVs-tp17614022p17614022.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] merging two data sets with no column header

2008-06-02 Thread kayj

I have two data sets data1 and data2  with no column names( No header). The
first coluimn in both data sets represents the case ID. How can I tell R to
merge the two data sets by the case ID if there is no header? Also, In data1
I have more cases and I would like the result of the merge to have all the
cases in both data1 and data2. there may be some duplicate cases.

I appreciate if someone can help.

Thanks

-- 
View this message in context: 
http://www.nabble.com/merging-two-data-sets-with-no-column-header-tp17613296p17613296.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] High resolution figures for a paper?

2008-06-02 Thread zhijie zhang
Thanks for the above mentioned methods. I will try them one by one.
Thanks again.


On 6/3/08, Sarah Goslee <[EMAIL PROTECTED]> wrote:
>
> The production of "publication-quality graphics" has been discussed at
> great length on R-sig-eco over the past week or so. The archive is
> available here:
> https://stat.ethz.ch/pipermail/r-sig-ecology/2008-May/thread.html
> and the thread is very near the bottom. Very detailed recommendations
> have been provided. (Also see the past two days, which are not of
> course in the May archive.)
>
> Sarah
>
> On Mon, Jun 2, 2008 at 11:12 AM, zhijie zhang <[EMAIL PROTECTED]> wrote:
> > Dear Rusers,
> >  My manuscript has been conditionally accepted recently. The problem to
> > generate the high  resolution figures in R for the manuscript cannot be
> > solved by me.
> > The journal editor ask me to generate the figures with a minimum
> resolution
> > of 500 dpi. I have tried the *menu-driven method* to save the figures as
> > JPEG (100% printed quality), but the results seem not to be very good. I
> > have submitted the generated figures twice using the above-mentioned
> method,
> > but the Editor think the resolution is still very low.
> >  Finally, i used the Photoshop to check the figure. It seems that its
> > resolution for JPEG (100% printed quality) is about 72dpi.
> >  *Does anybody know a better method to save a figure with user-defined
> > resolution in R software, especially high resolution? Could u please show
> me
> > an example if possible?*
> >  I hope to save the figures as TIFF/JPEG format at 1000 dpi.
> >  Thanks a lot.
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>



-- 
With Kind Regards,

oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:
[***]
Zhi Jie,Zhang ,PHD
Tel:+86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Address:No. 138 Yi Xue Yuan Road,Shanghai,China
Postcode:200032
Email:[EMAIL PROTECTED] <[EMAIL PROTECTED]>
Website: www.statABC.com
[***]
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:

[[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] RJDBC cant find driver class in JDBC jar file

2008-06-02 Thread David Scott



I can't comment on problems with RJDBC but I can say that if you want to 
access MySQL from R, I have had very little difficulty doing it with 
RODBC. The only difficulty I have experienced is in getting the MySQL 5.0 
server started, which after hours of trying I avoided by using MySQL 5.1.


Setup is easiest with Windows but is possible on Linux where Brian Ripley 
has provided information about how to do it. (I think in the README for 
RODBC---I am trying to remember from a year ago. I have done a Windows 
Vista setup in the past couple of weeks.)


You will need:

MySQL (5.1 recommended although it is a development version)
MySQL Connector ODBC
R
RODBC

Some notes on setup on Vista are available at:
http://www.stat.auckland.ac.nz/~dscott/779/UsingMySQLAndODBC.pdf

I think that, like many other useful tools, the linking of R and MySQL 
owes much to Brian Ripley. He has my gratitude for a nice piece of work.



David Scott


On Mon, 2 Jun 2008, Dan Montgomery wrote:


I would like to set up a Windows XP environment with R and MySQL.
This set-up was recommended by a friend who uses this set up, but I
have been unable to get RJDBC to work.  I have installed all of the
software today (June 2 2008), first deleting and then replacing old
versions of software.

The error is as follows:

Error in .jfindClass(as.character(driverClass)[1]) : class not found

This error is produced after running the following code ():

library(RJDBC)
drv <- JDBC("com.mysql.jdbc.Driver",
  "/etc/jdbc/mysql-connector-java-5.1.6-bin.jar",
  identifier.quote="`")

This code was modified from code at www.rforge.net/RJDBC to include
version 5.1.6 of the driver.  Version 3.1.14 gave the same error.  I
think that R is having trouble finding the class (driver) in the .jar
file even though I can see it using winzip.  I have limited knowledge
of R and Java, but use other programing languages for work.  Thank you
for your help.

=
Environment:
=


From CRAN

-R 2.7.0

Installed in R using the command "install.packages("RJDBC",dep=TRUE)"
-RJDBC
-DBI
-rJava


From MySQL.com

-mysql-connector-java-5.1.6-bin.jar
-MySQL 5.0.51b (win32)


From Java.com

-Java 6 update 6

--
Daniel Montgomery
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 Scott Department of Statistics, Tamaki Campus
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000
Email:  [EMAIL PROTECTED]

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

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


Re: [R] Need advise in grab the line number of sorted list in R

2008-06-02 Thread Jason Lee
Hi,

If there are more than one item having the same value, how can i use R to
take the average of the position. E.g:-

   X Y Z
131 22.2 3.4   4.4
132 20.0 3.4   4.4==>Position 2 if queried
150  20.0 12.2 4.5 =>Position 3 if queried
134 20.0 3.4   4.4 ==> Position4 if queried
159  20.0 12.2 4.5==>Position 5 if queried
160  22.0 12.2 4.5

When I query 150 using which, it gives "3" but since in other position the
value are same which is 20.0, how can i get the average of the position
which is (2+3+4+5)/3

Is there any R package which I can use for the above calculation?

On Tue, Jun 3, 2008 at 12:02 AM, Marc Schwartz <[EMAIL PROTECTED]>
wrote:

> on 06/02/2008 08:45 AM Jason Lee wrote:
>
>> Hi,
>>
>> I have a data frame which format is like below:-
>>
>>X Y Z
>> 131 22.2 3.4   4.4
>> 150  20.0 12.2 4.5
>>
>> etc...
>>
>> And I have sorted the data frame. However, I would like to grab one of
>> these
>> elements in the data frame. Also, i would like to number these rows so
>> that
>> when i grab a particular line let say 150, it is able to return me the
>> position of the row rather than the "150". Let say in this example, when i
>> grab a value of 150, it gives me 2 rather than 150.
>>
>>
>> I tried to add anohter extra column of number which is  data$NUMBER =
>> row.names(data) on the sorted data but it seems not giving what I wanted
>> which is the "position" of the row 150.
>>
>> Please advise. Thanks.
>>
>
> Is this what you want?
>
> > DF
>   XY   Z
> 131 22.2  3.4 4.4
> 150 20.0 12.2 4.5
>
>
> > which(row.names(DF) == 150)
> [1] 2
>
>
> See ?which
>
> HTH,
>
> Marc Schwartz
>
>

[[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] RJDBC cant find driver class in JDBC jar file

2008-06-02 Thread Dan Montgomery
I would like to set up a Windows XP environment with R and MySQL.
This set-up was recommended by a friend who uses this set up, but I
have been unable to get RJDBC to work.  I have installed all of the
software today (June 2 2008), first deleting and then replacing old
versions of software.

The error is as follows:

Error in .jfindClass(as.character(driverClass)[1]) : class not found

This error is produced after running the following code ():

library(RJDBC)
drv <- JDBC("com.mysql.jdbc.Driver",
   "/etc/jdbc/mysql-connector-java-5.1.6-bin.jar",
   identifier.quote="`")

This code was modified from code at www.rforge.net/RJDBC to include
version 5.1.6 of the driver.  Version 3.1.14 gave the same error.  I
think that R is having trouble finding the class (driver) in the .jar
file even though I can see it using winzip.  I have limited knowledge
of R and Java, but use other programing languages for work.  Thank you
for your help.

=
Environment:
=

>From CRAN
-R 2.7.0

Installed in R using the command "install.packages("RJDBC",dep=TRUE)"
-RJDBC
-DBI
-rJava

>From MySQL.com
-mysql-connector-java-5.1.6-bin.jar
-MySQL 5.0.51b (win32)

>From Java.com
-Java 6 update 6

--
Daniel Montgomery
[EMAIL PROTECTED]

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

2008-06-02 Thread cgenolin

Hi the list.

I got a probleme with R CMD check. I run a package.skeleton on a very 
simple code (four toy function, no probleme with the R CMD build). But 
on the R CMD check packClassique, I get :


* checking for unstated dependencies in R code ... WARNING
Erreur dans .find.package(package, lib.loc) :  aucun package nommé 
'packClassique' n'est trouvé

Calls:  -> .find.package
Excecution hated [French=Exécution arrêtée]

See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.
* checking S3 generic/method consistency ... WARNING
Erreur dans .find.package(package, lib.loc) :  aucun package nommé 
'packClassique' n'est trouvé

Calls:  -> .find.package
Exécution arrêtée

And so on.

Any idea on what is wrong ?

Christophe

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Lengthy delay in sourcing a large function

2008-06-02 Thread Duncan Murdoch

On 02/06/2008 5:28 PM, Dennis Fisher wrote:

Colleagues,

I have a script that contains ~ 10,000 lines of code.  Most of it is  
written as small functions.  However, for various reasons, the final  
function is ~1500 lines of code.  I realize that this may not be  
optimal but the code evolved that way and breaking it into smaller  
pieces is complicated because of the passing of arguments.  I have  
"cat(date())" statements at various places in the code so that I can  
track the actions as the script is executed.


I am running version 2.7.0 on a quad processor Mac and I call the  
script from the OS:  R --slave < Script.R


It takes ~ 5 seconds for R to read the first 8000 lines of code (as  
indicated by the time difference between the first record of the file  
and the date issued immediately before the large function).  Then,  
reading the large function (1500 lines) takes ~ 1 minute.  I have  
improved the delay by moving some of the code from the large function.


I don't understand why the second portion of the code is read so much  
slower than the first.  In that the code is a function, I presume that  
nothing within the function is executed until the function is called.


Does anyone have any experience with this issue?


I haven't seen this sort of thing.  I just wrote a (very simple and 
repetitive) 4000 line function and R read it in 4 seconds.  I think 
you'll need to post the actual function somewhere to see if your one 
minute timing is reproducible.


It's possible that it happens because R is short of memory, and needs to 
do a lot of swapping and garbage collection for the big function; trying 
to load that function and do nothing else except print the timings might 
be informative.


Duncan Murdoch

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


[R] Lengthy delay in sourcing a large function

2008-06-02 Thread Dennis Fisher
Colleagues,

I have a script that contains ~ 10,000 lines of code.  Most of it is  
written as small functions.  However, for various reasons, the final  
function is ~1500 lines of code.  I realize that this may not be  
optimal but the code evolved that way and breaking it into smaller  
pieces is complicated because of the passing of arguments.  I have  
"cat(date())" statements at various places in the code so that I can  
track the actions as the script is executed.

I am running version 2.7.0 on a quad processor Mac and I call the  
script from the OS:  R --slave < Script.R

It takes ~ 5 seconds for R to read the first 8000 lines of code (as  
indicated by the time difference between the first record of the file  
and the date issued immediately before the large function).  Then,  
reading the large function (1500 lines) takes ~ 1 minute.  I have  
improved the delay by moving some of the code from the large function.

I don't understand why the second portion of the code is read so much  
slower than the first.  In that the code is a function, I presume that  
nothing within the function is executed until the function is called.

Does anyone have any experience with this issue?

Dennis


Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com


[[alternative HTML version deleted]]

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


Re: [R] exit function in R?

2008-06-02 Thread Rolf Turner


On 3/06/2008, at 1:18 AM, Federico Abascal wrote:


Hi,
This is likely an stupid question, but I cannot find the solution.
I am searching for an "exit" function, to end the execution of an R
script if some condition is not filled.
Any clue?


Others have suggested using stop().  It might be the case that the
condition not being fulfilled is not actually a sign of an error,
but simply of a different, perhaps ``marginal'' situation in which
a different sort of action or calculation is required.  In which
case what you want is return().

Trivial e.g.:

foo <- function(x) {
if(any(x<=0)) return(42)
y <- sum(log(x))
y
}

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] boxplot with text and symbols on x

2008-06-02 Thread Greg Snow
An alternative way to draw the symbols (or some approximation of them) is to 
use the my.symbols function from the TeachingDemos package along with ms.male 
and ms.female (or your improvement of these, also from the TeachingDemos 
package).  See the 4th example from ?ms.male (or ?ms.female).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111



> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Birgit Lemcke
> Sent: Thursday, May 29, 2008 6:05 AM
> To: Gabor Grothendieck
> Cc: R Hilfe
> Subject: Re: [R] boxplot with text and symbols on x
>
> Thanks that was a huge help.
>
> Now I am using this:
>
> pdf("InfLengMaxVarHomogeneity.pdf")
> plot(inflorescence_length_Max~Sex,xaxt="n"  #unterdrückt
> "normale x- Achse , ylab="inflorescence length max",
> main="Bartletts Homogeneity for inflorescence length
> Max",data=FemMal_Sex)
> Homo<-bartlett.test(FemMal_Sex$inflorescence_length_Max,FemMal
> _Sex$Sex)
> text( 2, 500, "Bartlett's K-squared=", col='red',adj = c(1,0)
> ) text( 2, 500, round(Homo$statistic,digits=5), col='red'
> ,adj = c(0,0)) text( 2, 480, "df=", col='red',adj = c(1,0) )
> text( 2, 480, Homo$parameter, col='red' ,adj = c(0,0))
>
> text( 2, 460, "p-value=", col='red', adj = c(1,0)) text( 2,
> 460, round(Homo$p.value,digits=5), col='red', adj = c(0,0))
> axis(1,at=c(1,2) #Mache punkte auf Achse in Position 1 und 2
> , lab=expression( "\u2642", "\u2640")) #zeichne dort Mann/Frau Symbole
> dev.off()
>
>
> But the symbols do not appear in the pdf. What is the reason
> for that and how can I create a pdf with the symbols.
>
> Thanks again
>
> Birgit
>
> Am 29.05.2008 um 13:13 schrieb Gabor Grothendieck:
>
> > 1. See ?locator
> > 2. Try this:
> > plot(1:2, pch = c("\u2640", "\u2642"))
> >
> >
> > On Thu, May 29, 2008 at 4:40 AM, Birgit Lemcke
> > <[EMAIL PROTECTED]> wrote:
> >> Hello R-user community!
> >>
> >> I am running R 2.7.0 on a Power Book (Tiger). (I am still R and
> >> statistics
> >> beginner)
> >>
> >> I did the following :
> >>
> >> pdf("InLnegthMaxHomogeneity.pdf")
> >> boxplot(inflorescence_length_Max~Sex, main="Bartletts
> Homogeneity for
> >> inflorescence length",data=FemMal_Sex)
> >> Homo<-bartlett.test(FemMal_Sex$inflorescence_length_Max,FemMal_Sex
> >> $Sex)
> >> text( 2, 500, "Bartlett's K-squared=", col='red',adj =
> c(1,0) ) text(
> >> 2, 500, round(Homo$statistic,digits=5), col='red' ,adj = c
> >> (0,0))
> >> text( 2, 480, "df=", col='red',adj = c(1,0) ) text( 2, 480,
> >> Homo$parameter, col='red' ,adj = c(0,0))
> >>
> >> text( 2, 460, "p-value=", col='red', adj = c(1,0)) text( 2, 460,
> >> round(Homo$p.value,digits=5), col='red', adj = c(0,0))
> >>
> >> dev.off()
> >>
> >>
> >> As I am still not very good in R, I guess it is not the
> easiest way
> >> to implement the text and it was kind of fiddling around
> to find the
> >> right position for the text.
> >> I would be glad if somebody would have an easier solution.
> >>
> >> My second question is about adding symbols (usual male and female
> >> symbol) to
> >> the x-axis to label the boxes.
> >>
> >> I would be very glad if somebody could help mw with this.
> >>
> >> Many thanks in advance.
> >>
> >> Greets
> >>
> >> Birgit
> >>
> >> Birgit Lemcke
> >> Institut für Systematische Botanik
> >> Zollikerstrasse 107
> >> CH-8008 Zürich
> >> Switzerland
> >> Ph: +41 (0)44 634 8351
> >> [EMAIL PROTECTED]
> >>
> >> 175 Jahre UZH
> >> «staunen.erleben.begreifen. Naturwissenschaft zum
> Anfassen.» Weitere
> >> Informationen http://www.175jahre.uzh.ch/naturwissenschaft
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-
> >> guide.html and provide commented, minimal, self-contained,
> >> reproducible code.
> >>
>
> Birgit Lemcke
> Institut für Systematische Botanik
> Zollikerstrasse 107
> CH-8008 Zürich
> Switzerland
> Ph: +41 (0)44 634 8351
> [EMAIL PROTECTED]
>
> 175 Jahre UZH
> «staunen.erleben.begreifen. Naturwissenschaft zum Anfassen.»
> Weitere Informationen http://www.175jahre.uzh.ch/naturwissenschaft
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Ancova: formula with a common intercept

2008-06-02 Thread Rolf Turner


On 3/06/2008, at 2:56 AM, Daniel Brewer wrote:

I have some data with two categorises plus/minus (p53) and a  
particular
time (Time) and the outcome is a continuous vairable (Result).  I  
set up

a maximum model.
ancova <- lm(Result~Time*p53)

summary(ancova)

..
Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.059190.55646   0.1060.916
Time -0.021340.01785  -1.1950.241
p53plus   0.170590.78696   0.2170.830
Time:p53plus  0.118870.02524   4.709 4.62e-05 ***
..

From a plot of the data and the result of the linear model it  
looks like

the two categories share the same intercept.  How do I define this?  I
tried this:

ancova2<-update(ancova,~.-1)
summary(ancova2)

Call:
lm(formula = Result ~ Time + p53 + Time:p53 - 1)
..
Coefficients:
 Estimate Std. Error t value Pr(>|t|)
Time -0.021340.01785  -1.1950.241
p53minus  0.059190.55646   0.1060.916
p53plus   0.229770.55646   0.4130.682
Time:p53plus  0.118870.02524   4.709 4.62e-05 ***

But I do not think that is doing what I want.


You're right --- that's not what you want.  That simply gives you a  
different

parameterization of the original model.  Use either

fit1 <- lm(Result ~ Time + Time:p53)

or

fit2 <- lm(Result ~ Time:p53)

which give 2 different parameterizations of the model you want.

cheers,

Rolf Turner

P. S. I believe that it's strictly speaking incorrect to refer to  
such model as  an
``ancova'' model.  My recollection is that the ``classical'' use of  
the term ancova
refers to models in which the slopes are identical but the intercepts  
(possibly)
different.  So a model in which both slopes and intercepts are  
allowed to differ
from level to level of a factor is not an ancova model.  But it's all  
just jargon

anyway.

R. T.

##
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] NOT-SO-SIMPLE function!

2008-06-02 Thread T.D.Rudolph




You are absolutely correct Marc; thank you for making this assumption!

While it will take some time for me to rightfully understand the logical
ordering of your proposed function, it certainly seems to produce the result
I was looking for, and economically at that.  rle is indeed highly useful in
this context!

Cheers
Tyler

-- 
View this message in context: 
http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17610783.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] Get all X iterations in optim output when controls(trace=6)

2008-06-02 Thread Greg Snow
Here is an alternative approach to saving the itterations:

testfunc <- function(data) {
ms.mat <- matrix(nrow=0, ncol=2)

f1 <- function(ms, data){
ms.mat <<- rbind(ms.mat, ms)
-sum( dnorm(data, mean=ms[1], sd=ms[2], log=TRUE) )
}

out1 <- optim( c(0,1), f1, data=data )

out1$ms.mat <- ms.mat

out1
}

testdat <- rnorm(100, mean=10, sd=3)

testout <- testfunc(testdat)


And here is one way to look at the different steps/iterations/calls (assuming 
you have the TeachingDemos package installed):

plotfunc <- function(data, obj, step=1){
tmp.m <- obj$ms.mat[step,1]
tmp.s <- obj$ms.mat[step,2]
hist(data, freq=FALSE,
main=paste('mean=',round(tmp.m,5),'  sd=',round(tmp.s,5)))
xx <- seq(min(data), max(data), length.out=250)
lines(xx, dnorm(xx, mean=tmp.m, sd=tmp.s ) )
}

TeachingDemos::tkexamp(plotfunc(testdat, testout),
list(step=list('spinbox',init=1,from=1,to=nrow(testout$ms.mat


Hope this helps,


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111



> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Cleber
> Nogueira Borges
> Sent: Friday, May 30, 2008 5:45 PM
> To: [EMAIL PROTECTED]
> Subject: [R] Get all X iterations in optim output when
> controls(trace=6)
>
>
> Hi,
> I would like to get all X iterations in optim output in matrix form.
> I know about the follow approach:
>
> sink("reportOptim")
> optim( ..., control=list( trace=6,..) )
> sink()
> all_iterOptim <- readLines("reportOptim")
> unlink("reportOptim")
> all_iterOptim <- all_iterOptim[ grep( '^X', all_iterOptim ) ]
> ### TODO: the rest !!! :-)
>
> But it is very silly code when the output is large...
> Somebody can help me?
>
> Cleber
>
>
> ___
>
> Experimente já e veja as novidades.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Random Forests regression by strata

2008-06-02 Thread [EMAIL PROTECTED]
Hello, 
I'm trying to sample in Random Forests by a factor, but it is a regression 
problem and I can't figure out how to do this (I can only see how to sample by 
strata in classification).
Thanks
Jesse Lasky

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

2008-06-02 Thread Jorge Ivan Velez
Dear Paul,

Perhaps

read.delim2()

can do the job easily.

HTH,

Jorge

On Mon, Jun 2, 2008 at 3:41 PM, Paul Adams <[EMAIL PROTECTED]> wrote:

> Hello to everyone,
> I have gotten my file to print to screen but when I use read.table I am
> getting an error message that
> says there are" more columns than column names."This is a file that was not
> created by me so I am
> not sure how to investigate and solve this problem.I looked in the help
> file and it suggested an auxilliary function called count.fieldsThe code
> that was used was:
> read.table(file="C:\\Documents and Settings\\Owner\\My Documents\\colon
> cancer1.txt",header=T,row.names=1)
> Any help would be appreciated
> paul
>
>
>
>[[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] NOT-SO-SIMPLE function!

2008-06-02 Thread Marc Schwartz

on 06/02/2008 01:30 PM T.D.Rudolph wrote:

I am trying to set up a function which processes my data according to the
following rules:

1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1)) 


The data this will apply to include a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros.  Below is an example with a detailed explanation of the output
desired:

x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1) 
output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41, NA, NA, 1.098, NA, NA,
NA, NA, -0.22, 0) 

the 1st element, 3, becomes log(3) = 1.098612 
the 2nd element, 2, becomes log(2) = 0.6931472 
the 3rd element, 0, becomes NA (cannot log zero). 
the 4rd element, 1, becomes log(1/(1(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(1/2) =  -0.6931472 
the 5th element, 0, becomes NA 
the 6th element, 2, becomes log(2/(1(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(2/3) = -0.4054651 


The above should be log(2/2) = 0

There is only 1 consecutive zero preceding the 2 in the 6th position

the 7th and 8th elements, both zeros, become NA 
the 9th element, 1, becomes log(1/(2(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(1/3) =  1.098612 


The above should be log(1/3) = -1.098612 (negative, not positive)

the 10-13th elements, all zeros, each become NA 
the 14th element, 4, becomes log(4/(4(number of consecutive zeros
immediately preceding it) + 1 (constant))) = log(4/5) = -0.2231436 
the 15th element, 1, becomes log(1) = 0 


This one has been in the works for some time and I can't quite seem to crack
it.
I would be indebted to anyone who could with success - it seemed so simple
at the offset!
Tyler


I am presuming that you have some typos/errors above in your per element 
explanation of the processing of the vector.  If so, then the following 
should work as a first pass and could probably be optimized further:


zeroes <- function(x, i)
{
  if (x[i] == 0) {
NA
  } else if (i == 1) {
log(x[i])
  } else if (x[i - 1] != 0) {
log(x[i])
  } else {
rz <- rle(x[1:(i-1)])
log(x[i] / (rz$lengths[length(rz$lengths)] + 1))
  }
}


x <- c(3, 2, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 4, 1)


> sapply(seq(along = x), function(i) zeroes(x, i))
 [1]  1.0986123  0.6931472 NA -0.6931472 NA  0.000
 [7] NA NA -1.0986123 NA NA NA
[13] NA -0.2231436  0.000


See ?rle for more information on the identification of the sequential 
zeroes in the vector.


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] more columns that column names

2008-06-02 Thread Julian Burgos

Hi Paul,

The easiest thing to to is to open the file using a text editor (Notepad 
will do) and examine the first few lines.  You can add add a column name 
if needed.


Julian

Paul Adams wrote:

Hello to everyone,
I have gotten my file to print to screen but when I use read.table I am getting 
an error message that
says there are" more columns than column names."This is a file that was not created by me so I am 
not sure how to investigate and solve this problem.I looked in the help file and it suggested an auxilliary function called count.fieldsThe code that was used was:

read.table(file="C:\\Documents and Settings\\Owner\\My Documents\\colon 
cancer1.txt",header=T,row.names=1)
Any help would be appreciated
paul


  
	[[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] more columns that column names

2008-06-02 Thread Paul Adams
Hello to everyone,
I have gotten my file to print to screen but when I use read.table I am getting 
an error message that
says there are" more columns than column names."This is a file that was not 
created by me so I am 
not sure how to investigate and solve this problem.I looked in the help file 
and it suggested an auxilliary function called count.fieldsThe code that was 
used was:
read.table(file="C:\\Documents and Settings\\Owner\\My Documents\\colon 
cancer1.txt",header=T,row.names=1)
Any help would be appreciated
paul


  
[[alternative HTML version deleted]]

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


[R] [R-pkgs] updated RcmdrPlugin.epack is ready

2008-06-02 Thread Erin Hodgess
Dear R People:

I have updated the RcmdrPlugin.epack with new menus, and added:

additive decomposition;
HoltWinters;
Exponential smoothing.

Thanks to many for their help in the process!

Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

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

2008-06-02 Thread hanx
Hello all,

I used pushViewport to create a viewport with a 9*8 layout(using layout: 
lay<-grid.layout(9,8).) In each cell, I used lattice to draw plots. In the final
output, if I used the trellis.device(),i.e., the default device, the 9*8 plots I
intend to draw seem ok in terms of the letter size and everything in each cell.
But if i try to use trellis.device("postscript",file="./conditional.ps",
color=T) to save it, once i opened it in R using system(...), everything in each
cell is not in good shape any more. How can I save the plots as it is in the
default device? Thanks so much.

Sean

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

2008-06-02 Thread Jorge Ivan Velez
Dear Paul,

Probably what is happening is that the file is not located where you're
telling it to R (did you move it recently?). Do you have headers in your
data set? If so, you can try

mydata=read.table(file="C:\\Document and Settings\\All Users\\Desktop\\colon
cancer.txt",header=TRUE)

otherwise, change header=TRUE by header=FALSE.

Both should do the work. To go deep on the syntax and options in read.table,
see ?read.table. Also you can check ?scan and its friends.


HTH,

Jorge




On Mon, Jun 2, 2008 at 2:33 PM, Paul Adams <[EMAIL PROTECTED]> wrote:

>   Hello to everyone,
> I am new to programming in R and am having trouble with the following
> two commands
> 1.I am running a simple 1 line script "read.table(file="C:\\Document and
> Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get
> is "Error in file (file, "r"): cannot
> open the connection In addition warning message In file (file, "r"): cannot
> open file'C:\Document and
> Settings\All Users\Desktop\colon cancer..txt
>
> 2.I am running the simple 1 line script print (file="C:\\Document and
> Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get
> is "error in print.default (file="C:\\
> Document and Settings\\All Users\\Desktop\\colon cancer.txt"): argument x
> is missing,with no default
> I am not sure what I am supposed to enter as argument x.
>
> Any help would be greatly appreciated
> paul
>
>
>
>
>[[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] print and read.table commands

2008-06-02 Thread Richardson, Patrick
?read.table

And don't forget the " at the end of your filename

HTH

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Adams
Sent: Monday, June 02, 2008 2:34 PM
To: r-help@r-project.org
Subject: [R] print and read.table commands

  Hello to everyone,
I am new to programming in R and am having trouble with the following
two commands
1.I am running a simple 1 line script "read.table(file="C:\\Document and 
Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get is 
"Error in file (file, "r"): cannot
open the connection In addition warning message In file (file, "r"): cannot 
open file'C:\Document and
Settings\All Users\Desktop\colon cancer..txt

2.I am running the simple 1 line script print (file="C:\\Document and 
Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get is 
"error in print.default (file="C:\\
Document and Settings\\All Users\\Desktop\\colon cancer.txt"): argument x is 
missing,with no default
I am not sure what I am supposed to enter as argument x.

Any help would be greatly appreciated
paul




[[alternative HTML version deleted]]

This email message, including any attachments, is for th...{{dropped:6}}

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

2008-06-02 Thread Henrique Dallazuanna
Try this:

path <- file.choose()

1)
read.table(path)

2)
file.show(path)

On Mon, Jun 2, 2008 at 3:33 PM, Paul Adams <[EMAIL PROTECTED]> wrote:

>   Hello to everyone,
> I am new to programming in R and am having trouble with the following
> two commands
> 1.I am running a simple 1 line script "read.table(file="C:\\Document and
> Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get
> is "Error in file (file, "r"): cannot
> open the connection In addition warning message In file (file, "r"): cannot
> open file'C:\Document and
> Settings\All Users\Desktop\colon cancer..txt
>
> 2.I am running the simple 1 line script print (file="C:\\Document and
> Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get
> is "error in print.default (file="C:\\
> Document and Settings\\All Users\\Desktop\\colon cancer.txt"): argument x
> is missing,with no default
> I am not sure what I am supposed to enter as argument x.
>
> Any help would be greatly appreciated
> paul
>
>
>
>
>[[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.
>
>


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

[[alternative HTML version deleted]]

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


[R] print and read.table commands

2008-06-02 Thread Paul Adams
  Hello to everyone,
I am new to programming in R and am having trouble with the following 
two commands
1.I am running a simple 1 line script "read.table(file="C:\\Document and 
Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get is 
"Error in file (file, "r"): cannot
open the connection In addition warning message In file (file, "r"): cannot 
open file'C:\Document and 
Settings\All Users\Desktop\colon cancer..txt
 
2.I am running the simple 1 line script print (file="C:\\Document and 
Settings\\All Users\\Desktop\\colon cancer.txt) and the error message I get is 
"error in print.default (file="C:\\
Document and Settings\\All Users\\Desktop\\colon cancer.txt"): argument x is 
missing,with no default
I am not sure what I am supposed to enter as argument x.
 
Any help would be greatly appreciated
paul



  
[[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] NOT-SO-SIMPLE function!

2008-06-02 Thread T.D.Rudolph

I am trying to set up a function which processes my data according to the
following rules:

1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1)) 

The data this will apply to include a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros.  Below is an example with a detailed explanation of the output
desired:

x <- c(3,2,0,1,0,2,0,0,1,0,0,0,0,4,1) 
output desired = c(1.098, 0.69, NA, -0.69, NA, -0.41, NA, NA, 1.098, NA, NA,
NA, NA, -0.22, 0) 

the 1st element, 3, becomes log(3) = 1.098612 
the 2nd element, 2, becomes log(2) = 0.6931472 
the 3rd element, 0, becomes NA (cannot log zero). 
the 4rd element, 1, becomes log(1/(1(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(1/2) =  -0.6931472 
the 5th element, 0, becomes NA 
the 6th element, 2, becomes log(2/(1(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(2/3) = -0.4054651 
the 7th and 8th elements, both zeros, become NA 
the 9th element, 1, becomes log(1/(2(number of consecutive zeros immediately
preceding it) + 1 (constant))) = log(1/3) =  1.098612 
the 10-13th elements, all zeros, each become NA 
the 14th element, 4, becomes log(4/(4(number of consecutive zeros
immediately preceding it) + 1 (constant))) = log(4/5) = -0.2231436 
the 15th element, 1, becomes log(1) = 0 

This one has been in the works for some time and I can't quite seem to crack
it.
I would be indebted to anyone who could with success - it seemed so simple
at the offset!
Tyler
-- 
View this message in context: 
http://www.nabble.com/NOT-SO-SIMPLE-function%21-tp17607348p17607348.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-pkgs] New glmnet package on CRAN

2008-06-02 Thread Trevor Hastie
glmnet is a package that fits the regularization path for linear, two- 
and multi-class logistic regression
models with "elastic net" regularization (tunable mixture of L1 and L2 
penalties).

glmnet uses pathwise coordinate descent, and is very fast.

Some of the features of glmnet:

* by default it computes the path at 100 uniformly spaced (on the log 
scale) values of the regularization parameter
* glmnet appears to be faster than any of the packages that are freely 
available, in some cases by two orders of magnitude.
* recognizes and exploits sparse input matrices (ala Matrix package). 
Coefficient matrices are output in sparse matrix representation.
* penalty is (1-a)*||\beta||_2^2 +a*||beta||_1  where a is between 0 and 
1;  a=0 is the Lasso penalty, a=1 is the ridge penalty.
  For many correlated predictors, a=.95 or thereabouts improves the 
performance of the lasso.

* convenient predict, plot, print, and coef methods
* variable-wise penalty modulation allows each variable to be penalized 
by a scalable amount; if zero that variable always enters
* glmnet uses a symmetric parametrization for multinomial, with 
constraints enforced by the penalization.


Other families such as poisson might appear in later versions of glmnet.

Examples of glmnet speed trials:

Newsgroup data: N=11,000, p=4 Million, two class logistic. 100 values 
along lasso path.   Time = 2mins
14 Class cancer data: N=144, p=16K, 14 class multinomial, 100 values 
along lasso path. Time = 30secs


Authors: Jerome Friedman, Trevor Hastie, Rob Tibshirani.

See our paper http://www-stat.stanford.edu/~hastie/Papers/glmnet.pdf for 
implementation details,

and comparisons with other related software.

--

 Trevor Hastie  [EMAIL PROTECTED]
 Professor & Chair, Department of Statistics, Stanford University
 Phone: (650) 725-2231 (Statistics)  Fax: (650) 725-8977
 (650) 498-5233 (Biostatistics)  Fax: (650) 725-6951
 URL: http://www-stat.stanford.edu/~hastie
 address: room 104, Department of Statistics, Sequoia Hall
  390 Serra Mall, Stanford University, CA 94305-4065

___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problemas usando jri0.4-1 y R 2.7.0

2008-06-02 Thread Julian Burgos

Hola Borja,

Creo que vas a tener muy pocas respuestas a menos que escribas a la 
lista en inglés.  Lamentablemente yo conozco poco de Java y no puedo 
responder tu pregunta.


Saludos,

Julian

Borja Soto Varela wrote:

Hola, es la primera vez que mando un correo a cualquiera de las listas de
correo de R y no se si esta consulta se ajusta al próposito de la r-help
list o debería haberlo mandado a otra de las listas que hay.

Mi problema es el siguiente: Estoy desarrollando un programa en java con
llamadas a R y no puedo usar jri 0.4-1 con la version 2.7 o 2.6 de R.
Curiosamente si me funciona si uso jri 0.4 o la propia 0.4-1 con la version
2.4.

El problema que me da al usar la ultima versión de R es el siguiente:

Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in
java.library.path.


java.lang.UnsatisfiedLinkError: C:\JRI_0.4-1\JRI\jri.dll: No se encontró >

el proceso especificado

   at java.lang.ClassLoader$NativeLibrary.load(Native Method)
   at java.lang.ClassLoader.loadLibrary0(Unknown Source)
   at java.lang.ClassLoader.loadLibrary(Unknown Source)
   at java.lang.Runtime.loadLibrary0(Unknown Source)
   at java.lang.System.loadLibrary(Unknown Source)
   at org.rosuda.JRI.Rengine.(Rengine.java:9)
   at vista.main.Main.main(Main.java:12)


El directorio donde tengo jri.dll lo incluí en el path del sistema en esa
ruta (de hecho con 2.4 funciona sin hacer nada más). Me preguntaba si a
alguien también le ha pasado esto y como se puede solucionar.
Gracias

[[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] RBloomberg date error

2008-06-02 Thread stephen bond

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

2008-06-02 Thread Hans-Jörg Bibiko


On 02.06.2008, at 17:27, Ng Stanley wrote:

I would like to replace "A B" by "A-B" and "AA 
(DD)" by
"AA" using a single gsub. Is that possible besides using two  
gsub ?




Could you be a bit more precisely?

If you are dealing with two fix strings then you can write

ifelse(theString == "A B", "A-B", "AA")

if not, one could find a regexp to solve that problem, but one could  
also use gsub in a cascade:


gsub('regexp1', 'replace1', gsub('regexp2', 'replace2', theString) )  
etc.


--Hans

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

2008-06-02 Thread Duncan Murdoch

On 6/2/2008 11:12 AM, zhijie zhang wrote:

Dear Rusers,
  My manuscript has been conditionally accepted recently. The problem to
generate the high  resolution figures in R for the manuscript cannot be
solved by me.
The journal editor ask me to generate the figures with a minimum resolution
of 500 dpi. I have tried the *menu-driven method* to save the figures as
JPEG (100% printed quality), but the results seem not to be very good. I
have submitted the generated figures twice using the above-mentioned method,
but the Editor think the resolution is still very low.
  Finally, i used the Photoshop to check the figure. It seems that its
resolution for JPEG (100% printed quality) is about 72dpi.
  *Does anybody know a better method to save a figure with user-defined
resolution in R software, especially high resolution? Could u please show me
an example if possible?*
 I hope to save the figures as TIFF/JPEG format at 1000 dpi.
 Thanks a lot.


Don't use the menu, produce the figure directly.  I would recommend 
against using TIFF or JPEG; a vector format like PDF is much easier. 
However, if you really want one of those, open the device explicitly. 
For example,


jpeg("test.jpg", width=5, height=5, units="in", res=500)
plot(rnorm(1000))
dev.off()

This will create a very big file, 2500 by 2500 pixels, meant to be 
displayed as a 5 inch by 5 inch figure.


Duncan Murdoch

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


Re: [R] High resolution figures for a paper?

2008-06-02 Thread Sarah Goslee
The production of "publication-quality graphics" has been discussed at
great length on R-sig-eco over the past week or so. The archive is
available here:
https://stat.ethz.ch/pipermail/r-sig-ecology/2008-May/thread.html
and the thread is very near the bottom. Very detailed recommendations
have been provided. (Also see the past two days, which are not of
course in the May archive.)

Sarah

On Mon, Jun 2, 2008 at 11:12 AM, zhijie zhang <[EMAIL PROTECTED]> wrote:
> Dear Rusers,
>  My manuscript has been conditionally accepted recently. The problem to
> generate the high  resolution figures in R for the manuscript cannot be
> solved by me.
> The journal editor ask me to generate the figures with a minimum resolution
> of 500 dpi. I have tried the *menu-driven method* to save the figures as
> JPEG (100% printed quality), but the results seem not to be very good. I
> have submitted the generated figures twice using the above-mentioned method,
> but the Editor think the resolution is still very low.
>  Finally, i used the Photoshop to check the figure. It seems that its
> resolution for JPEG (100% printed quality) is about 72dpi.
>  *Does anybody know a better method to save a figure with user-defined
> resolution in R software, especially high resolution? Could u please show me
> an example if possible?*
>  I hope to save the figures as TIFF/JPEG format at 1000 dpi.
>  Thanks a lot.

-- 
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] Plotting horizontal dendrograms

2008-06-02 Thread Matthias Kohl

Dear Charles,

the sample code you cite has an additional "as.dendrogram" compared to 
your code. Hence, dend1 is of class dendrogram (class(dend1)) and if you 
call plot(dend1) the method for dendrograms (i.e., plot.dendrogram) is 
executed which has a horiz argument; confer ?plot.dendrogram.
Whereas in your code h is of class hclust (class(hclust)) and therefore 
plot(h) leads to a call of plot.hclust which has no horiz argument; cf. 
?plot.hclust.
So, adding as.dendrogram in your code should remove the warning messages 
and give what you want; e.g.


plot(as.dendrogram(h), horiz = TRUE)

Best,
Matthias

Charles K. Minns wrote:

I am using hclust and plot to produce dendrograms. Using my input data I am
able to complete an analysis and obtain a vertical plot.
I want to be able to plot the dendrogram horizontally.I am using version 2.6
of R and have updated my packages recently.
 
Using the sample script for dendrograms I can produce a horizontal plot

using the instruction horiz = TRUE in plot().
When I use the same instruction in my own script I get a warning message
that horiz, and horizontal, are not recognized commands in plot.
I cannot find any documentation in R on how to change the orientation of
plots and general searches for information on this subject.
Can someone explain why my script does not work.
 
Sample code follows:

---
# Sample code extracted from the Dendrogram documentation in R
#
require(graphics); require(utils)
 
hc <- hclust(dist(USArrests), "ave")

(dend1 <- as.dendrogram(hc)) # "print()" method
str(dend1)  # "str()" method
str(dend1, max = 2) # only the first two sub-levels
 
op <- par(mfrow= c(2,2), mar = c(5,2,1,4))

plot(dend1, horiz = TRUE)
plot(dend1)
#
# My code
#
x <- read.table("Rclust2.data",header=TRUE)
 
m <- data.matrix(x)

d <- as.dist(m)
h <- hclust(d)
plot(h, horiz = TRUE)

--
The three plot commands execute. Plot 1 is horizontal, plot 2 is vertical
and plot 3 is vertical. Plus plot 3
generates the console output:
-
  

#
# My code
#
x <- read.table("Rclust2.data",header=TRUE)

m <- data.matrix(x)
d <- as.dist(m)
h <- hclust(d)
plot(h, horiz = TRUE)


Warning messages:
1: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
2: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
3: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  "horiz" is not a graphical parameter
---
 
I would appreciate help solving this problem. Doubtless there is a simple

answer.

 


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


--
Dr. Matthias Kohl
www.stamats.de

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


Re: [R] Help on Calculating day differences

2008-06-02 Thread Gabor Grothendieck
This was already answered by two people when you posted
it the first time.

On Mon, Jun 2, 2008 at 12:34 PM, Thorsten Muehge <[EMAIL PROTECTED]> wrote:
> Hello R Freaks,
> I calculate the difference in days between two events with the following
> litte R expresseion:
>
> T1a <- strptime(T1,"%m/%d/%y %H:%M:%S");
> T2a <- strptime(T2,"%m/%d/%y %H:%M:%S");
> T1b <- as.Date(T1a);
> T2b <- as.Date(T2a);
> days <- T2b-T1b;
> time <- T2a - T1a;
>
> In the project I would like to calculate only working day.
>
> I the a possibility to count on woring days without weekends?
>
> Is it maybe also possible to skip in addition the national holiday dates?
>
> Thanks a lit for your help
> Thorsten
> Mit freundlichen Grüßen / Best Regards / С наилучшими пожеланиями /
> üdvözlettel
>
> Dr .Th.Mühge,
>
>[[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] High resolution figures for a paper?

2008-06-02 Thread zhijie zhang
Dear Rusers,
  My manuscript has been conditionally accepted recently. The problem to
generate the high  resolution figures in R for the manuscript cannot be
solved by me.
The journal editor ask me to generate the figures with a minimum resolution
of 500 dpi. I have tried the *menu-driven method* to save the figures as
JPEG (100% printed quality), but the results seem not to be very good. I
have submitted the generated figures twice using the above-mentioned method,
but the Editor think the resolution is still very low.
  Finally, i used the Photoshop to check the figure. It seems that its
resolution for JPEG (100% printed quality) is about 72dpi.
  *Does anybody know a better method to save a figure with user-defined
resolution in R software, especially high resolution? Could u please show me
an example if possible?*
 I hope to save the figures as TIFF/JPEG format at 1000 dpi.
 Thanks a lot.


-- 
With Kind Regards,

oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:
[***]
Zhi Jie,Zhang ,PHD
Tel:+86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Address:No. 138 Yi Xue Yuan Road,Shanghai,China
Postcode:200032
Email:[EMAIL PROTECTED] <[EMAIL PROTECTED]>
Website: www.statABC.com
[***]
oooO:
(..):
:\.(:::Oooo::
::\_)::(..)::
:::)./:::
::(_/
:

[[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] LDA and centroids

2008-06-02 Thread Prof Brian Ripley

On Mon, 2 Jun 2008, Dani Valverde wrote:


Hello,
I have carried out an lda analysis using the lda function of MASS package. I 
have plotted the LD1xLD2 to represent the data. Now I would like to get the 
centroids for each group of data and plot it on the LD1xLD2 graph. How can I 
get the centroid value from the lda object?


See the 'Value' section of the help page, and the examples in the book for 
which MASS is support software.



Best,

Dani

--
Daniel Valverde Saubí

Grup de Biologia Molecular de Llevats
Facultat de Veterinària de la Universitat Autònoma de Barcelona
Edifici V, Campus UAB
08193 Cerdanyola del Vallès- SPAIN

Centro de Investigación Biomédica en Red
en Bioingeniería, Biomateriales y
Nanomedicina (CIBER-BBN)

Grup d'Aplicacions Biomèdiques de la RMN
Facultat de Biociències
Universitat Autònoma de Barcelona
Edifici Cs, Campus UAB
08193 Cerdanyola del Vallès- SPAIN
+34 93 5814126

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help on Calculating day differences

2008-06-02 Thread Thorsten Muehge
Hello R Freaks,
I calculate the difference in days between two events with the following 
litte R expresseion:

T1a <- strptime(T1,"%m/%d/%y %H:%M:%S");
T2a <- strptime(T2,"%m/%d/%y %H:%M:%S");
T1b <- as.Date(T1a);
T2b <- as.Date(T2a);
days <- T2b-T1b;
time <- T2a - T1a;

In the project I would like to calculate only working day.

I the a possibility to count on woring days without weekends?

Is it maybe also possible to skip in addition the national holiday dates?

Thanks a lit for your help
Thorsten
Mit freundlichen Grüßen / Best Regards / С наилучшими 
пожеланиями / 
üdvözlettel

Dr .Th.Mühge, 

[[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] = or <-

2008-06-02 Thread Erik Iverson



Sébastien wrote:

Thanks Erik and Gabor for this precision,

I guess that my misunderstanding of these concepts came from some bad 
habits I took during my self-learning experience of R (especially, 
copy/paste of old codes where <- was used for function arguments and did 
not produce error messages).


Well it's not an error necessarily.  There are some situations where it 
might be useful to do an assignment to a variable in an argument list. 
However, this is the exception rather than the rule, especially for 
beginners.


You just have to be mindful of what is going on if you see '<-' in an 
argument list.




Sebastien

Erik Iverson a écrit :



Sébastien wrote:

Dear R-users,

I have written a short VB application to clean and format my R code. 
Everything works fine except one small issue that I did not expected; 
it is related the automatic replacement of assignment signs from "=" 
to "<-". Most functions or arguments seem to accept either = or <-, 
but some don't (e.g.  ls(all=TRUE)). The result is that my supposedly 
clean codes do not run anymore :-(
Is there a way to know the list of arguments/functions that do not 
accept "<-" signs ?


You are surely mixing two concepts here.

When you are doing an assignment of a value to a variable, you may use 
either <- or =.  Example


a <- 2
a = 2

both bind the value of 2 to the symbol "a".

When you call a function, for example ls, you can specify the argument 
names, such as ls(all = TRUE).


If you attempted ls(all <- TRUE), the value of TRUE will be assigned 
to the symbol 'all', and then ls will be evaluated with its first 
argument "names" as TRUE, which produces your error.  You almost 
certainly want ls(all = TRUE).  After the error, try typing 'all' at 
the R prompt.  The 'all' function definition has now been overwritten 
and is simply TRUE, which you probably do not want either.


So, there really is no concept of whether or not a function "accepts 
<- signs".  You want to use = in your function calls, since the '<-' 
method is actually assigning values.


Hope that helps,
Erik




Thanks in advance.

Sebastien

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

2008-06-02 Thread Dieter Menne
François Aucoin  gmail.com> writes:

> 
> I would like to solve the following function in R:
> 
> G <- function(k)  (2*(1 - k)*(1 + 2*k)^.5)/(1+3*k)
> 


G <- function(k)  (2*(1 - k)*(1 + 2*k)^.5)/(1+3*k)
GZero <-function(k,G0) G(k)-G0
plot(1:100,G(1:100))
uniroot(GZero,c(0,100),G=-5)


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] Regression Model with Memory

2008-06-02 Thread Stefan Koenig
Dear all:

I am searching for a regression model (e.g. y=Xb+e) in which dummy-coded events 
(to time point t) on different regressors in X exhibit an effect on subsequent 
responses in the vector y (to time-points t+1, t+2,… t+n). My aim is to 
estimate how long the memory effect is and how strong a certain event 
influences subsequent responses (whether the memory decays e.g. linear or 
exponentially). My first impression is that state-space models are appropriate. 
 However, according to my first understanding in these models regularities in 
the residuals are explained without using the knowledge of the event history. 
Or is a simple linear regression model with time-shifted regressors appropriate?

The response vector y includes misses and the events in X are sampled on 
irregular time points.

Many thanks
Stefan

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 


--

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

2008-06-02 Thread Paul Smith
On Mon, Jun 2, 2008 at 4:31 PM, François Aucoin <[EMAIL PROTECTED]> wrote:
> I would like to solve the following function in R:
>
> G <- function(k)  (2*(1 - k)*(1 + 2*k)^.5)/(1+3*k)
>
> I want to be able to find "k" for a given "G"

Consider G(k)-g. With plot look for intervals where the roots lie in.
Afterwards, use uniroot to get the roots.

Paul

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


[R] R function for Woody Average (Average with alignment)?

2008-06-02 Thread U. Hasson
Dear R users,

I'm looking for a function to align multiple waveforms that contain
random phase shifts.
The "Woody Average" is one such method -- is there any comparable
function already coded for R?
Matlab code for this type of average exists
[http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12459&objectType=FILE]
but I don't speak matlab.

Cheers,
Uri

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: Problemas usando jri0.4-1 y R 2.7.0

2008-06-02 Thread Borja Soto Varela
Hello, this is the first time I send a mail to r-help mailing list.

Mi problema es el siguiente: I'm developing a program in java with calls in
R and I can`t use jri 0.4-1 with R 2.7 or 2.6 .but it runs with 2.4.

The problem that I get when using the latest version of R is as follows:

Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in
java.library.path.

> java.lang.UnsatisfiedLinkError: C:\JRI_0.4-1\JRI\jri.dll: No se encontró >
el proceso especificado
>at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>at java.lang.ClassLoader.loadLibrary0(Unknown Source)
>at java.lang.ClassLoader.loadLibrary(Unknown Source)
>at java.lang.Runtime.loadLibrary0(Unknown Source)
>at java.lang.System.loadLibrary(Unknown Source)
>at org.rosuda.JRI.Rengine.(Rengine.java:9)
>at vista.main.Main.main(Main.java:12)

C:\JRI_0.4-1\JRI\j is included in the system path (in fact, the program runs
fine with R 2.4.0). I wonder if someone also has this problem and how it can
solve.

Any suggestions are highly appreciated,
Thanks,
Borja

[[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] = or <-

2008-06-02 Thread Sébastien

Thanks Erik and Gabor for this precision,

I guess that my misunderstanding of these concepts came from some bad 
habits I took during my self-learning experience of R (especially, 
copy/paste of old codes where <- was used for function arguments and did 
not produce error messages).


Sebastien

Erik Iverson a écrit :



Sébastien wrote:

Dear R-users,

I have written a short VB application to clean and format my R code. 
Everything works fine except one small issue that I did not expected; 
it is related the automatic replacement of assignment signs from "=" 
to "<-". Most functions or arguments seem to accept either = or <-, 
but some don't (e.g.  ls(all=TRUE)). The result is that my supposedly 
clean codes do not run anymore :-(
Is there a way to know the list of arguments/functions that do not 
accept "<-" signs ?


You are surely mixing two concepts here.

When you are doing an assignment of a value to a variable, you may use 
either <- or =.  Example


a <- 2
a = 2

both bind the value of 2 to the symbol "a".

When you call a function, for example ls, you can specify the argument 
names, such as ls(all = TRUE).


If you attempted ls(all <- TRUE), the value of TRUE will be assigned 
to the symbol 'all', and then ls will be evaluated with its first 
argument "names" as TRUE, which produces your error.  You almost 
certainly want ls(all = TRUE).  After the error, try typing 'all' at 
the R prompt.  The 'all' function definition has now been overwritten 
and is simply TRUE, which you probably do not want either.


So, there really is no concept of whether or not a function "accepts 
<- signs".  You want to use = in your function calls, since the '<-' 
method is actually assigning values.


Hope that helps,
Erik




Thanks in advance.

Sebastien

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is variable in one vector part of variable in another

2008-06-02 Thread Bert Gunter
...
Indeed, but note that both %in% and intersect() are essentially wrappers for
match() .

Cheers,
Bert Gunter
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Philipp Pagel
Sent: Saturday, May 31, 2008 2:27 PM
To: r-help@r-project.org
Subject: Re: [R] Is variable in one vector part of variable in another

> I have 2 vectors x & z
> x  has 10 variables in it
> z has 75 variable in it
> 
> I need to check all 75 variables in z and see if they are present in the
> vector x.

In addition to the solution using %in% which has already been suggested,
you may also want to play with something like this:

# make up some data
x = sample(1:8, 10, rep=T)
z = sample(1:25, 75, rep=T)
# find intersection between x and z
intersect(x,z)

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
 
 and
 
Institut für Bioinformatik und Systembiologie / MIPS
Helmholtz Zentrum München -
Deutsches Forschungszentrum für Gesundheit und Umwelt
Ingolstädter Landstrasse 1
85764 Neuherberg, 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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] gsub and multiple replacements

2008-06-02 Thread Ng Stanley
Hi,

I would like to replace "A B" by "A-B" and "AA(DD)" by
"AA" using a single gsub. Is that possible besides using two gsub ?

Thanks
Stanley

[[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] Plotting horizontal dendrograms

2008-06-02 Thread Charles K. Minns
I am using hclust and plot to produce dendrograms. Using my input data I am
able to complete an analysis and obtain a vertical plot.
I want to be able to plot the dendrogram horizontally.I am using version 2.6
of R and have updated my packages recently.
 
Using the sample script for dendrograms I can produce a horizontal plot
using the instruction horiz = TRUE in plot().
When I use the same instruction in my own script I get a warning message
that horiz, and horizontal, are not recognized commands in plot.
I cannot find any documentation in R on how to change the orientation of
plots and general searches for information on this subject.
Can someone explain why my script does not work.
 
Sample code follows:
---
# Sample code extracted from the Dendrogram documentation in R
#
require(graphics); require(utils)
 
hc <- hclust(dist(USArrests), "ave")
(dend1 <- as.dendrogram(hc)) # "print()" method
str(dend1)  # "str()" method
str(dend1, max = 2) # only the first two sub-levels
 
op <- par(mfrow= c(2,2), mar = c(5,2,1,4))
plot(dend1, horiz = TRUE)
plot(dend1)
#
# My code
#
x <- read.table("Rclust2.data",header=TRUE)
 
m <- data.matrix(x)
d <- as.dist(m)
h <- hclust(d)
plot(h, horiz = TRUE)

--
The three plot commands execute. Plot 1 is horizontal, plot 2 is vertical
and plot 3 is vertical. Plus plot 3
generates the console output:
-
> #
> # My code
> #
> x <- read.table("Rclust2.data",header=TRUE)
> 
> m <- data.matrix(x)
> d <- as.dist(m)
> h <- hclust(d)
> plot(h, horiz = TRUE)
Warning messages:
1: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
2: In plot.hclust(h, horiz = TRUE) : "horiz" is not a graphical parameter
3: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  "horiz" is not a graphical parameter
---
 
I would appreciate help solving this problem. Doubtless there is a simple
answer.

 

[[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] LDA and centroids

2008-06-02 Thread Dani Valverde

Hello,
I have carried out an lda analysis using the lda function of MASS 
package. I have plotted the LD1xLD2 to represent the data. Now I would 
like to get the centroids for each group of data and plot it on the 
LD1xLD2 graph. How can I get the centroid value from the lda object?

Best,

Dani

--
Daniel Valverde Saubí

Grup de Biologia Molecular de Llevats
Facultat de Veterinària de la Universitat Autònoma de Barcelona
Edifici V, Campus UAB
08193 Cerdanyola del Vallès- SPAIN

Centro de Investigación Biomédica en Red
en Bioingeniería, Biomateriales y
Nanomedicina (CIBER-BBN)

Grup d'Aplicacions Biomèdiques de la RMN
Facultat de Biociències
Universitat Autònoma de Barcelona
Edifici Cs, Campus UAB
08193 Cerdanyola del Vallès- SPAIN
+34 93 5814126

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

2008-06-02 Thread François Aucoin
I would like to solve the following function in R:

G <- function(k)  (2*(1 - k)*(1 + 2*k)^.5)/(1+3*k)

I want to be able to find "k" for a given "G"

Thanks!

Francois Aucoin

[[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] Ancova: formula with a common intercept

2008-06-02 Thread Daniel Brewer
I have some data with two categorises plus/minus (p53) and a particular
time (Time) and the outcome is a continuous vairable (Result).  I set up
a maximum model.
ancova <- lm(Result~Time*p53)
> summary(ancova)
..
Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.059190.55646   0.1060.916
Time -0.021340.01785  -1.1950.241
p53plus   0.170590.78696   0.2170.830
Time:p53plus  0.118870.02524   4.709 4.62e-05 ***
..

>From a plot of the data and the result of the linear model it looks like
the two categories share the same intercept.  How do I define this?  I
tried this:
> ancova2<-update(ancova,~.-1)
> summary(ancova2)
Call:
lm(formula = Result ~ Time + p53 + Time:p53 - 1)
..
Coefficients:
 Estimate Std. Error t value Pr(>|t|)
Time -0.021340.01785  -1.1950.241
p53minus  0.059190.55646   0.1060.916
p53plus   0.229770.55646   0.4130.682
Time:p53plus  0.118870.02524   4.709 4.62e-05 ***

But I do not think that is doing what I want.

Many thanks
-- 
**
Daniel Brewer, Ph.D.

Institute of Cancer Research
Molecular Carcinogenesis
Email: [EMAIL PROTECTED]
**

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the a...{{dropped:2}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: Aggregation and the meaning of class

2008-06-02 Thread Karl Ove Hufthammer
Chip Barnaby:

> My question is: How does one learn the specifics?  For the case at
> hand, what are the specialized methods associated with class "by"?

The methods for the (S3) generic function 'by':

$ methods(by)
[1] by.data.frame by.default

Functions for objects of class 'by':

$ methods(class="by")
[1] print.by

Note that both of these may be extended by loading additional packages.

-- 
Karl Ove Hufthammer

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


[R] help with RPART

2008-06-02 Thread Terry Therneau
  When using anova method, all of the printed results are scaled by the RSS for 
the top node.  Therefore the relative error measures for the trees already are 
1-R^2.
  
tfit <- rpart(time ~ ., lung)
summary(tfit)

  CP nsplit rel error   xerror  xstd 
1 0.03665178  0 1.000 1.010097 0.1136942
2 0.03310179  1 0.9633482 1.079216 0.1172675
3 0.03029365  2 0.9302464 1.109587 0.1173583
4 0.01963453  3 0.8999528 1.249586 0.1327888
5 0.01627146 11 0.7396726 1.238411 0.1310952
6 0.01507635 12 0.7234012 1.260919 0.1337384
7 0.01031566 13 0.7083248 1.282740 0.1399397
8 0.0100 14 0.6980091 1.296213 0.1396711

Node number 1: 228 observations,complexity param=0.03665178
  mean=305.2325, MSE=44176.93 
  left son=2 (81 obs) right son=3 (147 obs)
  Primary splits:
  pat.karno < 75to the left,  improve=0.03661157, (3 missing)
  ph.ecog   < 1.5   to the right, improve=0.03620793, (1 missing)
  status< 1.5   to the right, improve=0.02930372, (0 missing)
  ph.karno  < 85to the left,  improve=0.02058114, (1 missing)
  sex   < 1.5   to the left,  improve=0.0167, (0 missing)
  Surrogate splits:
  ph.ecog  < 1.5   to the right, agree=0.787, adj=0.392, (3 split)
  ph.karno < 75to the left,  agree=0.751, adj=0.291, (0 split)
  age  < 72.5  to the right, agree=0.680, adj=0.089, (0 split)

Node number 2: 81 observations,complexity param=0.03310179
  mean=251.0247, MSE=34100.99 
  left son=4 (59 obs) right son=5 (22 obs)
  Primary splits:
  wt.loss < 21to the left,  improve=0.12735970, (7 missing)
  status  < 1.5   to the right, improve=0.08060663, (0 missing)
  age < 68.5  to the right, improve=0.04906869, (0 missing)
  inst< 2.5   to the left,  improve=0.04148716, (0 missing)
  sex < 1.5   to the left,  improve=0.02401074, (0 missing)
  Surrogate splits:
  ph.karno < 55to the right, agree=0.743, adj=0.095, (6 split)

etc,

  The first split has R^2 = .0367 = 1-overall fit (top few lines) = the 
improvement measure for the node.
   
   The second split has R^2 = .127 for the obs within that node, it improve the 
R^2 for the model as a whole by .033.
   
Terry T.

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

2008-06-02 Thread Gabor Grothendieck
No function accepts <- in place of =.  In the first
of the 4 examples below we are simply setting
variable b to 10 and then passing it to f as its
first argument. f(b = 10) would be different since
that specifies that we want argument b to take
on the value of 10.

f <- function(a=1, b=2) a-b

# these 5 lines below all give the same result
# except the first 3 also have the side effect
# of creating a variable b
f(b <- 10)
b <- 10; f(b)
f(a = b <- 10)
f(10)
f(a=10)

On Mon, Jun 2, 2008 at 10:05 AM, Sébastien <[EMAIL PROTECTED]> wrote:
> Dear R-users,
>
> I have written a short VB application to clean and format my R code.
> Everything works fine except one small issue that I did not expected; it is
> related the automatic replacement of assignment signs from "=" to "<-". Most
> functions or arguments seem to accept either = or <-, but some don't (e.g.
>  ls(all=TRUE)). The result is that my supposedly clean codes do not run
> anymore :-(
> Is there a way to know the list of arguments/functions that do not accept
> "<-" signs ?
>
> Thanks in advance.
>
> Sebastien
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] non-parametric regression with a convexity constraint

2008-06-02 Thread thierrydb

I would like to know if there's a package in R that enables to get a
non-parametric regression (OLS, not quantile) that would have a positive (or
negative) convexity constraint, as well as monotonicity. 

Right now, I have only found two packages (fdrtool and cir) that enable to
impose only monotonicity.

Thanks,

TDB

-- 
View this message in context: 
http://www.nabble.com/non-parametric-regression-with-a-convexity-constraint-tp17601021p17601021.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] Odp: Aggregation and the meaning of class

2008-06-02 Thread Gabor Grothendieck
To discover the available methods use the methods function, e.g.

example(by) # script creates a variable tmp of class by
class(tmp) # "by"
methods(class = "by") # describe.by print.by

Also try this:

> by # by is S3 generic since it uses UseMethod
function (data, INDICES, FUN, ...)
UseMethod("by")

> methods(by) # by.* methods
[1] by.data.frame by.default

For a generic with a much longer list of methods try methods(print)

On Mon, Jun 2, 2008 at 10:14 AM, Chip Barnaby <[EMAIL PROTECTED]> wrote:
> Hi Petr,
> Thanks for your reply.  See below.
>
> At 05:58 AM 6/2/2008, Petr PIKAL wrote:
>>
>> Hi
>>
>> I did not see any response yet so I try a kick. Each object in R has some
>> attributes which can be revealed by
>>
>> attributes(object)
>>
>> Some of them are useful for methods and tell R how to handle particular
>> object with a method. There are other options how to evaluate your object
>> e.g. str, typeof, mode. If you went through intro manual you could find
>> that there are different types of objects like vectors, matrices,
>> data.frames, arrays, and lists. And probably some others.
>>
>> Output from by is list or array and you can handle such objects in many
>> ways.
>
> I understand all this in general.  I am a C++ programmer with decades of
> experience, so I fully understand object-oriented concepts.
>
> My question is: How does one learn the specifics?  For the case at hand,
> what are the specialized methods associated with class "by"? Are there
> clever things I can do with it?  Is there documentation for class "by"?
>  What are the browsing/exploring approaches one might use to learn about
> that class?
>
> So far, the main approach I have is interactive experimentation, yielding
> slow knowledge accretion.  Is there anything more efficient?  I have a
> moderate pile of R books, they are helpful, but obviously don't cover every
> detail of every situation.
>
>
>> BTW it is hard to tell what is desired result is as we do not have D60.
>
> Agreed and I could supply some example data if you want.
>
> I speculated that experienced users could answer my question on formal
> grounds, but perhaps this speaks to my general issue: questions like this
> aren't easily answered without running experiments.
>
> At the moment, my code "seems to be working."  I don't find that very
> reassuring.  I may have to get used to an "R culture" that is different from
> my prior world.
>
>
>> Eg. when I do
>>
>> > WM = by( D60, D60[ "KeyProfA"], FUN=function(x) weighted.mean( x$IAC,
>> x$Wt))
>> Error in by(D60, D60["KeyProfA"], FUN = function(x) weighted.mean(x$IAC, :
>>
>>  object "D60" not found
>>
>> I get an error.
>>
>> Better then using by is maybe to use ave which retains number of rows, but
>> I am not sure if it can be adopted to weighted mean.
>>
>> Regards
>>
>> Petr
>> [EMAIL PROTECTED]
>> 724008364, 581252140, 581252257
>>
>>
>> [EMAIL PROTECTED] napsal dne 30.05.2008 16:00:50:
>>
>> > Dear R-ers,
>> >
>> > My aggregation saga continues.
>> >
>> > Using the following sequence, I can calculate any statistic for row
>> > groups and merge the result back to all associated rows ...
>> >
>> >  > WM = by( D60, D60[ "KeyProfA"], FUN=function(x) weighted.mean( x$IAC,
>> x$Wt))
>> >
>> >  > D60$IAC.WM = as.numeric( WM[ D60$KeyProfA])
>> >
>> >  > class( WM)
>> > [1] "by"
>> >
>> > Questions ...
>> >
>> > 1) Is this a reasonable way to obtain the desired result?
>> >
>> > 2) What can one glean by knowing the class of WM ("by")?  It appears
>> > to me that class is a pretty shallow attribute in R ... just an
>> > associated string that selects among methods in some contexts.  Is
>> > that really all there is to it?  Is there a way to discover what
>> > generic methods are aware of a given class?  In other words, who
>> > cares if WM is a "by" ... what does that do for me?
>> >
>> > In my traditional universe (C++) I can grep and discover what methods
>> > are virtual, who inherits from whom, etc.  In R, the documentation
>> > appears silent on what is a "by" (correct me if I'm wrong).  In
>> > addition, I have found no way to broadly search code to learn
>> > things.  (Displaying single functions is useful but hardly broad.)
>> >
>> > How does one learn R more efficiently than randomly discovering how
>> > to avoid error messages?  (For example, I now know that a "by" cannot
>> > be coerced into a data.frame (although it seems to me that such a
>> > conversion could be usefully defined), so now I don't hit myself on
>> > the head with that particular hammer.)
>> >
>> > Chip Barnaby
>> >
>> >
>> >
>> >
>> >
>> >
>> > -
>> > Chip Barnaby   [EMAIL PROTECTED]
>> > Vice President of Research
>> > Wrightsoft Corp.   781-862-8719 x118 voice
>> > 131 Hartwell Ave   781-861-2058 fax
>> > Lexington, MA 02421 www.wrightsoft.com
>> >
>> > __
>> > R-help@r-project.org mailing li

Re: [R] = or <-

2008-06-02 Thread Erik Iverson



Sébastien wrote:

Dear R-users,

I have written a short VB application to clean and format my R code. 
Everything works fine except one small issue that I did not expected; it 
is related the automatic replacement of assignment signs from "=" to 
"<-". Most functions or arguments seem to accept either = or <-, but 
some don't (e.g.  ls(all=TRUE)). The result is that my supposedly clean 
codes do not run anymore :-(
Is there a way to know the list of arguments/functions that do not 
accept "<-" signs ?


You are surely mixing two concepts here.

When you are doing an assignment of a value to a variable, you may use 
either <- or =.  Example


a <- 2
a = 2

both bind the value of 2 to the symbol "a".

When you call a function, for example ls, you can specify the argument 
names, such as ls(all = TRUE).


If you attempted ls(all <- TRUE), the value of TRUE will be assigned to 
the symbol 'all', and then ls will be evaluated with its first argument 
"names" as TRUE, which produces your error.  You almost certainly want 
ls(all = TRUE).  After the error, try typing 'all' at the R prompt.  The 
'all' function definition has now been overwritten and is simply TRUE, 
which you probably do not want either.


So, there really is no concept of whether or not a function "accepts <- 
signs".  You want to use = in your function calls, since the '<-' method 
is actually assigning values.


Hope that helps,
Erik




Thanks in advance.

Sebastien

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: Aggregation and the meaning of class

2008-06-02 Thread Chip Barnaby

Hi Petr,
Thanks for your reply.  See below.

At 05:58 AM 6/2/2008, Petr PIKAL wrote:

Hi

I did not see any response yet so I try a kick. Each object in R has some
attributes which can be revealed by

attributes(object)

Some of them are useful for methods and tell R how to handle particular
object with a method. There are other options how to evaluate your object
e.g. str, typeof, mode. If you went through intro manual you could find
that there are different types of objects like vectors, matrices,
data.frames, arrays, and lists. And probably some others.

Output from by is list or array and you can handle such objects in many
ways.


I understand all this in general.  I am a C++ programmer with decades 
of experience, so I fully understand object-oriented concepts.


My question is: How does one learn the specifics?  For the case at 
hand, what are the specialized methods associated with class "by"? 
Are there clever things I can do with it?  Is there documentation for 
class "by"?  What are the browsing/exploring approaches one might use 
to learn about that class?


So far, the main approach I have is interactive experimentation, 
yielding slow knowledge accretion.  Is there anything more 
efficient?  I have a moderate pile of R books, they are helpful, but 
obviously don't cover every detail of every situation.




BTW it is hard to tell what is desired result is as we do not have D60.


Agreed and I could supply some example data if you want.

I speculated that experienced users could answer my question on 
formal grounds, but perhaps this speaks to my general issue: 
questions like this aren't easily answered without running experiments.


At the moment, my code "seems to be working."  I don't find that very 
reassuring.  I may have to get used to an "R culture" that is 
different from my prior world.




Eg. when I do

> WM = by( D60, D60[ "KeyProfA"], FUN=function(x) weighted.mean( x$IAC,
x$Wt))
Error in by(D60, D60["KeyProfA"], FUN = function(x) weighted.mean(x$IAC, :

  object "D60" not found

I get an error.

Better then using by is maybe to use ave which retains number of rows, but
I am not sure if it can be adopted to weighted mean.

Regards

Petr
[EMAIL PROTECTED]
724008364, 581252140, 581252257


[EMAIL PROTECTED] napsal dne 30.05.2008 16:00:50:

> Dear R-ers,
>
> My aggregation saga continues.
>
> Using the following sequence, I can calculate any statistic for row
> groups and merge the result back to all associated rows ...
>
>  > WM = by( D60, D60[ "KeyProfA"], FUN=function(x) weighted.mean( x$IAC,
x$Wt))
>
>  > D60$IAC.WM = as.numeric( WM[ D60$KeyProfA])
>
>  > class( WM)
> [1] "by"
>
> Questions ...
>
> 1) Is this a reasonable way to obtain the desired result?
>
> 2) What can one glean by knowing the class of WM ("by")?  It appears
> to me that class is a pretty shallow attribute in R ... just an
> associated string that selects among methods in some contexts.  Is
> that really all there is to it?  Is there a way to discover what
> generic methods are aware of a given class?  In other words, who
> cares if WM is a "by" ... what does that do for me?
>
> In my traditional universe (C++) I can grep and discover what methods
> are virtual, who inherits from whom, etc.  In R, the documentation
> appears silent on what is a "by" (correct me if I'm wrong).  In
> addition, I have found no way to broadly search code to learn
> things.  (Displaying single functions is useful but hardly broad.)
>
> How does one learn R more efficiently than randomly discovering how
> to avoid error messages?  (For example, I now know that a "by" cannot
> be coerced into a data.frame (although it seems to me that such a
> conversion could be usefully defined), so now I don't hit myself on
> the head with that particular hammer.)
>
> Chip Barnaby
>
>
>
>
>
>
> -
> Chip Barnaby   [EMAIL PROTECTED]
> Vice President of Research
> Wrightsoft Corp.   781-862-8719 x118 voice
> 131 Hartwell Ave   781-861-2058 fax
> Lexington, MA 02421 www.wrightsoft.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.


-
Chip Barnaby   [EMAIL PROTECTED]
Vice President of Research
Wrightsoft Corp.   781-862-8719 x118 voice
131 Hartwell Ave   781-861-2058 fax
Lexington, MA 02421 www.wrightsoft.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] = or <-

2008-06-02 Thread Sébastien

Dear R-users,

I have written a short VB application to clean and format my R code. 
Everything works fine except one small issue that I did not expected; it 
is related the automatic replacement of assignment signs from "=" to 
"<-". Most functions or arguments seem to accept either = or <-, but 
some don't (e.g.  ls(all=TRUE)). The result is that my supposedly clean 
codes do not run anymore :-(
Is there a way to know the list of arguments/functions that do not 
accept "<-" signs ?


Thanks in advance.

Sebastien

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problemas usando jri0.4-1 y R 2.7.0

2008-06-02 Thread Borja Soto Varela
Hola, es la primera vez que mando un correo a cualquiera de las listas de
correo de R y no se si esta consulta se ajusta al próposito de la r-help
list o debería haberlo mandado a otra de las listas que hay.

Mi problema es el siguiente: Estoy desarrollando un programa en java con
llamadas a R y no puedo usar jri 0.4-1 con la version 2.7 o 2.6 de R.
Curiosamente si me funciona si uso jri 0.4 o la propia 0.4-1 con la version
2.4.

El problema que me da al usar la ultima versión de R es el siguiente:

Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in
java.library.path.

> java.lang.UnsatisfiedLinkError: C:\JRI_0.4-1\JRI\jri.dll: No se encontró >
el proceso especificado
>at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>at java.lang.ClassLoader.loadLibrary0(Unknown Source)
>at java.lang.ClassLoader.loadLibrary(Unknown Source)
>at java.lang.Runtime.loadLibrary0(Unknown Source)
>at java.lang.System.loadLibrary(Unknown Source)
>at org.rosuda.JRI.Rengine.(Rengine.java:9)
>at vista.main.Main.main(Main.java:12)

El directorio donde tengo jri.dll lo incluí en el path del sistema en esa
ruta (de hecho con 2.4 funciona sin hacer nada más). Me preguntaba si a
alguien también le ha pasado esto y como se puede solucionar.
Gracias

[[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] Need advise in grab the line number of sorted list in R

2008-06-02 Thread Marc Schwartz

on 06/02/2008 08:45 AM Jason Lee wrote:

Hi,

I have a data frame which format is like below:-

X Y Z
131 22.2 3.4   4.4
150  20.0 12.2 4.5

etc...

And I have sorted the data frame. However, I would like to grab one of these
elements in the data frame. Also, i would like to number these rows so that
when i grab a particular line let say 150, it is able to return me the
position of the row rather than the "150". Let say in this example, when i
grab a value of 150, it gives me 2 rather than 150.


I tried to add anohter extra column of number which is  data$NUMBER =
row.names(data) on the sorted data but it seems not giving what I wanted
which is the "position" of the row 150.

Please advise. Thanks.


Is this what you want?

> DF
   XY   Z
131 22.2  3.4 4.4
150 20.0 12.2 4.5


> which(row.names(DF) == 150)
[1] 2


See ?which

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] Need advise in grab the line number of sorted list in R

2008-06-02 Thread Karl Ove Hufthammer
Jason Lee:

> I have a data frame which format is like below:-
> 
> X     Y     Z
> 131 22.2 3.4   4.4
> 150  20.0 12.2 4.5
> 
> etc...
> 
> And I have sorted the data frame. However, I would like to grab one of
> these elements in the data frame. Also, i would like to number these rows
> so that when i grab a particular line let say 150, it is able to return me
> the position of the row rather than the "150". Let say in this example,
> when i grab a value of 150, it gives me 2 rather than 150.

I'm not sure I understand what you're trying to do. Could you try to explain
using code example of how you 'grab' elements?

One solution could perhaps be to simple renumber the data frame. If the data
frame is named 'dat', you can do it simply by

row.names(dat) = NULL

-- 
Karl Ove Hufthammer

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

2008-06-02 Thread Michael Friendly

I had no on-list replies, so I cobbled up a function for the simplest
method I could think of -- iterative multivariate trimming, following
Gnanadesikan, Kettering & Wilks, assigning 0 weights to observations
based on the Mahalanobis D^2 of residuals.

But I'm getting an error I don't understand, and neither traceback()
nor browser() gives me any insight.  Can anyone tell me what is wrong
with the lm() call in rmlm.GKW below?

> iris.rmod <- rmlm.GKW(cbind(Sepal.Length, Sepal.Width, Petal.Length, 
Petal.Width)~Species, data=iris)
Error in model.frame.default(formula = formula, data = data, subset = 
subset,  :

  invalid type (closure) for variable '(weights)'
>

Here are the functions:

# Mahalanobis Dsq for a matrix of variables
dsq <- function(x, Sigma) {
  if (missing(Sigma)) Sigma <- cov(x, use="complete.obs")
  dev <- scale(x, scale=FALSE)
# DSQ <- dev %*% solve(Sigma) %*% t(dev )
  DSQ <- apply(dev * (dev %*% solve(Sigma)), 1, sum)
  return(DSQ)
}

# robust mlm via multivariate trimming a la Gnanadesikan, Kettering & Wilks
rmlm.GKW <- function(formula, data, subset, weights=NULL, iter=3, 
pvalue=.01) {
  if (missing(weights) | is.null(weights)) { weights <- rep(1, 
nrow(data)) }

  last.weights <- weights
  for (i in 1:iter) {
mod <- lm(formula=formula, data=data, subset=subset, weights=weights)
res <- residuals(mod)
coef <- mod$coefficients
print (coef)
p <- ncol(res)
DSQ <- dsq(res)
prob <- pchisq(DSQ, p, lower.tail=FALSE)
weights <- ifelse( probI'm looking for something in R to fit a multivariate linear model 
robustly, using
an M-estimator or any of the myriad of other robust methods for linear 
models

implemented in robustbase or methods based on MCD or MVE covariance
estimation (package rrcov).

E.g., one can fit an mlm for the iris data as:
iris.mod <- lm(cbind(Sepal.Length, Sepal.Width, Petal.Length, 
Petal.Width) ~ Species, data=iris)


What I'd like is something like rlm() in MASS, but handling an mlm, e.g.,
iris.mod <- rmlm(cbind(Sepal.Length, Sepal.Width, Petal.Length, 
Petal.Width) ~ Species, data=iris)

and returning a vector of observation weights in its result.

There's a burgeoning literature on this topic, but I haven't yet found 
computational methods.

Any pointers or suggestions would be appreciated.

-Michael





--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need advise in grab the line number of sorted list in R

2008-06-02 Thread Jason Lee
Hi,

I have a data frame which format is like below:-

X Y Z
131 22.2 3.4   4.4
150  20.0 12.2 4.5

etc...

And I have sorted the data frame. However, I would like to grab one of these
elements in the data frame. Also, i would like to number these rows so that
when i grab a particular line let say 150, it is able to return me the
position of the row rather than the "150". Let say in this example, when i
grab a value of 150, it gives me 2 rather than 150.


I tried to add anohter extra column of number which is  data$NUMBER =
row.names(data) on the sorted data but it seems not giving what I wanted
which is the "position" of the row 150.

Please advise. 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] R and Openmpi

2008-06-02 Thread Dirk Eddelbuettel
On Mon, Jun 02, 2008 at 12:29:06PM +0200, Marce wrote:
> Hi Dirk, now I'm using R and OpenMPI in a cluster. Could you link me
> some pages of information about this? I'm interesting about the
> installation, all the pages i've seen it's with LAM..
> Really i've just installed R and Rmpi, but I have some problems when I
> spawn nodes in the same vlan.

Rmpi and packages building on top of it have not changed -- we simply
switched the underlying MPI library -- so use whatever documentation
you had before for Rmpi and snow.

Not that you need it unless you plan to rewrite or extend Rmpi, but
for the MPI API, the documentation for LAM is still very good.

As for the Open MPI tools, see the Open MPI website and mailing list.
Jeff just posted some instructional videos that people have commented
on favourably.

Dirk

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

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


Re: [R] exit function in R?

2008-06-02 Thread Hans-Joerg Bibiko


On 2 Jun 2008, at 15:18, Federico Abascal wrote:


Hi,
This is likely an stupid question, but I cannot find the solution.
I am searching for an "exit" function, to end the execution of an R
script if some condition is not filled.
Any clue?



f <- function() {
  ...
  if (1 == 1) return(WHATEVER)
  ...
  ...
  return(ONSUCCESS)
}

--Hans

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

2008-06-02 Thread Markus Schmidberger

try this:

stop("Message")
warning("Message")

Best
Markus

Federico Abascal schrieb:

Hi,
This is likely an stupid question, but I cannot find the solution.
I am searching for an "exit" function, to end the execution of an R
script if some condition is not filled.
Any clue?

Thank you in advance!
Federico

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



--
Dipl.-Tech. Math. Markus Schmidberger

Ludwig-Maximilians-Universität München
IBE - Institut für medizinische Informationsverarbeitung,
Biometrie und Epidemiologie
Marchioninistr. 15, D-81377 Muenchen
URL: http://ibe.web.med.uni-muenchen.de 
Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de

Tel: +49 (089) 7095 - 4599

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

2008-06-02 Thread Marc Schwartz

on 06/02/2008 08:18 AM Federico Abascal wrote:

Hi,
This is likely an stupid question, but I cannot find the solution.
I am searching for an "exit" function, to end the execution of an R
script if some condition is not filled.
Any clue?

Thank you in advance!
Federico


See ?stop and ?stopifnot

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] subject: horizontal text in barplot

2008-06-02 Thread Marc Schwartz

on 06/02/2008 08:00 AM dat wrote:


I have a problem with the ylabs in barplot. When I draw the bars 
horizontal the text for the y axis is not drawn horizontal too.

The text remains vertical. How can I change that. Thank's for your advice.
There is an example below.


##Example
plot.new()
jib <- data.frame(c(1:15),c(11:25),c(15:1),c(25:11))
colnames(jib) <- c("eins","zwei","drei","vier")
rownames(jib) <-  c("AT","BE","DK","FI","FR","DE",   
"GR","IE","IT","LU","NL","PT","ES","SE", "UK" )

jib <- as.matrix(jib)
jib <- t(jib)
barplot(jib,  horiz=TRUE)
jib
## End Example



A lot of what you are doing above with respect to managing/structuring 
the example data is not needed, nor is the plot.new().


Here is your jib:

> jib
 AT BE DK FI FR DE GR IE IT LU NL PT ES SE UK
eins  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
zwei 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
drei 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
vier 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11


Now use:

jib2 <- matrix(c(1:15, 11:25, 15:1, 25:11), nrow = 4, byrow = TRUE)

rownames(jib2) <- c("eins", "zwei", "drei", "vier")

colnames(jib2) <-  c("AT","BE","DK","FI","FR","DE",
 "GR","IE","IT","LU","NL","PT",
 "ES","SE", "UK" )

> jib2
 AT BE DK FI FR DE GR IE IT LU NL PT ES SE UK
eins  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
zwei 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
drei 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
vier 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11


# Now draw the plot, setting 'las' so the labels are
# set to horizontal. See ?par for more information

barplot(jib2,  horiz = TRUE, las = 1)


Data frames are best used when you have columns with differing data 
types (think database table or spreadsheet). When the data is of a 
single type, as in this case, just use a matrix directly.


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.


[R] exit function in R?

2008-06-02 Thread Federico Abascal
Hi,
This is likely an stupid question, but I cannot find the solution.
I am searching for an "exit" function, to end the execution of an R
script if some condition is not filled.
Any clue?

Thank you in advance!
Federico

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


[R] Optimization problem with constraints

2008-06-02 Thread Matthias Graser
I'm trying to da an optimization for the followig function

Zwischenwert <- function (x)
{
lambda<-x[1];
mu<-x[2];
gammal<-x[3];
mud<-x[4];
gammad<-x[5];
Mittelwert <-0;
for(t in 0:(T-1))
{
for(i in 0:(n-1))
{
for(j in i:(n-1))
{
Mittelwert <- Mittelwert +( 
phi[i+1,j+1,t+1]*((j-i)*log(lambda)-log(factorial(j-i))-lambda));
};
if(t>0){Mittelwert <- Mittelwert 
+(phisum[i+1,t+1]*(-0.5*log(2*pi)-0.5*log(t*gammal+i*gammad)-((Y[t+1]-i*mud-t*mu-0.5*t*gammal+lambda*exp(mud+0.5*gammad)-t*lambda)^2
 )/(2*(t*gammal+i*gammad;};
};
};
};


and it's gradient

ZWGrad <- function(x)
{
lambda<-x[1];
mu<-x[2];
gammal<-x[3];
mud<-x[4];
gammad<-x[5];
dlambda<-0;
dmu<-0;
dgamma<-0;
dmud<-0;
dgammad<-0;
for (t in 0:(T-1))
{
for (i in 0:(n-1))
{
for (j in i:(n-1))
{

dlambda<-dlambda-phi[i+1,j+1,t+1]*(-1+(j-i)/lambda);
};
};
};
for (t in 1:(T-1))
{
for (i in 0:(n-1))
{

dlambda<-dlambda+phisum[i+1,t+1]*(t-t*lambda*exp(mud+0.5*gammad))*(Y[t+1]-i*mud-mu*t-0.5*gammal*t+lambda*t*exp(mud+0.5*gammad)-lambda*t)/(2*(gammal*t+gammad*i));

dmu<-dmu+phisum[i+1,t+1]*t*(Y[t+1]-i*mud-t*mu-0.5*gammal*t+lambda*t*exp(mud+0.5*gammad)-lambda*t)/(gammal*t+gammad*i);
dgamma<-dgamma+phisum[i+1,t+1]*( 
t*(0.5*i*gammad+Y[t+1]-i*mud-t*mu+lambda*t*exp(mud+0.5*gammad)-lambda*t)^2/(2*(gammal*t+gammad*i)^2)-t/(2*(gammal*t+gammad*i))-0.125*t);

dmud<-dmud+phisum[i+1,t+1]*(i-lambda*t*exp(mud+0.5*gammad))*(Y[t+1]-i*mud-t*mu-0.5*gammal*t+lambda*t*exp(mud+0.5*gammad)-lambda*t)/(gammal*t+gammad*i);

dgammad<-dgammad+phisum[i+1,t+1]*(Y[t+1]-i*mud-t*mu-0.5*gammal*t+lambda*t*exp(mud+0.5*gammad)-lambda*t)*(i*(Y[t+1]-i*mud-t*mu-0.5*gammal*t-lambda*t)-lambda*t*exp(mud+0.5*gammad)*(gammal*t+gammad*i-i))/(2*(gammal*t+gammad*i)^2);
};
};
GradZW <- c(dlambda,dmu,dgamma,dmud,dgammad);
};


lambda, gammal und gammd need to be larger than 0, so I've tried different 
constrained methods like L-BFGS-B via optim and constrOptim, but both seem to 
have problems with my functions. The standard optim-method works, but sometimes 
it returns negative values for lambda, gammal and gammad. 
Those phi and phisums are known at runtime, n and T can be pretty large, so 
maybe R simple can't handel it.


Many thanks
Matthias


--

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

2008-06-02 Thread Jorge Ivan Velez
Dear dat,

Try this:

barplot(jib,  horiz=TRUE,las=1)

HTH,

Jorge


On Mon, Jun 2, 2008 at 9:00 AM, dat <[EMAIL PROTECTED]> wrote:

>
> I have a problem with the ylabs in barplot. When I draw the bars horizontal
> the text for the y axis is not drawn horizontal too.
> The text remains vertical. How can I change that. Thank's for your advice.
> There is an example below.
>
>
> ##Example
> plot.new()
> jib <- data.frame(c(1:15),c(11:25),c(15:1),c(25:11))
> colnames(jib) <- c("eins","zwei","drei","vier")
> rownames(jib) <-  c("AT","BE","DK","FI","FR","DE",
> "GR","IE","IT","LU","NL","PT","ES","SE", "UK" )
> jib <- as.matrix(jib)
> jib <- t(jib)
> barplot(jib,  horiz=TRUE)
> jib
> ## End Example
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] subject: horizontal text in barplot

2008-06-02 Thread Henrique Dallazuanna
Try this:

bp <- barplot(jib,  horiz=TRUE, yaxt = 'n')
axis(2, at = bp, labels = colnames(jib), tick = FALSE, las = 2)

On Mon, Jun 2, 2008 at 10:00 AM, dat <[EMAIL PROTECTED]> wrote:

>
> I have a problem with the ylabs in barplot. When I draw the bars horizontal
> the text for the y axis is not drawn horizontal too.
> The text remains vertical. How can I change that. Thank's for your advice.
> There is an example below.
>
>
> ##Example
> plot.new()
> jib <- data.frame(c(1:15),c(11:25),c(15:1),c(25:11))
> colnames(jib) <- c("eins","zwei","drei","vier")
> rownames(jib) <-  c("AT","BE","DK","FI","FR","DE",
> "GR","IE","IT","LU","NL","PT","ES","SE", "UK" )
> jib <- as.matrix(jib)
> jib <- t(jib)
> barplot(jib,  horiz=TRUE)
> jib
> ## End Example
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


[R] subject: horizontal text in barplot

2008-06-02 Thread dat


I have a problem with the ylabs in barplot. When I draw the bars 
horizontal the text for the y axis is not drawn horizontal too.

The text remains vertical. How can I change that. Thank's for your advice.
There is an example below.


##Example
plot.new()
jib <- data.frame(c(1:15),c(11:25),c(15:1),c(25:11))
colnames(jib) <- c("eins","zwei","drei","vier")
rownames(jib) <-  c("AT","BE","DK","FI","FR","DE",   
"GR","IE","IT","LU","NL","PT","ES","SE", "UK" )

jib <- as.matrix(jib)
jib <- t(jib)
barplot(jib,  horiz=TRUE)
jib
## End Example

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

2008-06-02 Thread Birgitle

That works perfect.

Thanks a lot Paul!

Greets

Birgit


Paul Smith wrote:
> 
> On Mon, Jun 2, 2008 at 1:04 PM, Birgitle <[EMAIL PROTECTED]>
> wrote:
>>
>> Thanks Paul.
>>
>> I am not sure if I understood well, but when I do it then I have only two
>> columns left:
>>
>>> L3 <- LETTERS[1:3]
>>> (d <- data.frame(cbind(x=1, y=1:10, z=11:20), fac=sample(L3, 10,
>>> replace=TRUE)))
>>   x  y  z fac
>> 1  1  1 11   C
>> 2  1  2 12   B
>> 3  1  3 13   B
>> 4  1  4 14   C
>> 5  1  5 15   C
>> 6  1  6 16   B
>> 7  1  7 17   C
>> 8  1  8 18   C
>> 9  1  9 19   B
>> 10 1 10 20   C
>>> d <- d[,c(2,1)]
>>> d
>>y x
>> 1   1 1
>> 2   2 1
>> 3   3 1
>> 4   4 1
>> 5   5 1
>> 6   6 1
>> 7   7 1
>> 8   8 1
>> 9   9 1
>> 10 10 1
>>
>> But I have more than two columns in my data.frame.
> 
> In your case, it should be
> 
> # Swap the two first columns
> d <- d[,c(2,1,3,4)]
> # Swap column 2 and 3
> d <- d[,c(1,3,2,4)]
> 
> Notice that my data frame had only two columns.
> 
> Paul
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
Bb205Lc

-
The art of living is more like wrestling than dancing.
(Marcus Aurelius)
-- 
View this message in context: 
http://www.nabble.com/Swap-variables-in-data.frame-tp17597476p17600374.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] optim error - repost

2008-06-02 Thread Dieter Menne
  gmail.com> writes:

> 
> Here is a clean version. I did this with nls and  it works (see below), but
> I need to  do it with optim. Keun-Hyung

Great that you got it to work! Just curious if there is any reason why one
should use optim when nls works fine? If this should be on a reviewer's request,
challenge the reviewer.

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] Help : R-packages : Problems loading package fSeries

2008-06-02 Thread Yohan Chalabi
 "CLG" == Celine LE-GOAZIGO <[EMAIL PROTECTED]>
 on Mon, 2 Jun 2008 13:19:35 +0200


   CLG> Hi.
   CLG> 
   CLG> I am trying to load the package fSeries, in order to load
   CLG> the package
   CLG> fGarch after.
   CLG> However, it says the following message.

Dear Celine,

Please make sure that all your Rmetrics packages are up-to-date

update.packages()

and that you have the latest R.

If it does not solve your issue, please post again your question at
the Rmetrics developer mailing list ([EMAIL PROTECTED]). 


regards,
Yohan

-- 
PhD student
Swiss Federal Institute of Technology
Zurich

www.ethz.ch
www.rmetrics.org

NOTE:
Rmetrics Workshop: http://www.rmetrics.org/meielisalp.htm
June 29th - July 3rd Meielisalp, Lake Thune, Switzerland

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