Re: [R] 3D confidence ellipsoid with ellipse projections onto 2D plane

2012-02-08 Thread baptiste auguie
Hi,

If you read French, you might find the following discussion interesting,

http://www.forum.math.ulg.ac.be/viewthread.html?id=45765

It contains some good suggestions to project an ellipsoid onto a
plane, which as I understand might be related to your question.

HTH,

b.



On 8 February 2012 07:29, Samuel Bazzi  wrote:
> I have a 3xN matrix of parameters obtained from N regressions where the 3
> parameters are jointly statistically significant. I would like to reproduce
> a 3D confidence ellipsoid projecting 2D ellipses onto the XY plane as in
> Figure 5.2 in this
> text
> .
>
> Is this possible using some combination of ellipse3d() and ellipse()? Any
> insights would be greatly appreciated.
>
> Thanks.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

2012-02-08 Thread Martin Maechler
> "R Michael Weylandt "
> 
> on Tue, 7 Feb 2012 20:23:57 -0500 writes:

> Possibly as.character() is what the OP was seeking
> Michael

or   format()   which is closer for numeric data


> On Feb 7, 2012, at 7:15 PM, jim holtman  wrote:

>> ?dump
>> ?dput
>> 
>> 2012/2/7 Ernest Adrogué :
>>> Hi,
>>> 
>>> I was wondering if there's a function in R that is meant to return a
>>> string representation of an object. Basically, it's like print() but
>>> it doesn't print anything, it only returns a string.
>>> 
>>> I know there's a str() function but it's not quite the same. I mean a
>>> function that returns the same string that print() would display.
>>> 
>>> --
>>> Bye, Ernest
>>> 
>>> __ R-help@r-project.org
>>> mailing list https://stat.ethz.ch/mailman/listinfo/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 Data Munger Guru
>> 
>> What is the problem that you are trying to solve?  Tell me what you
>> want to do, not how you want to do it.
>> 
>> __ R-help@r-project.org
>> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
>> read the posting guide http://www.R-project.org/posting-guide.html and
>> provide commented, minimal, self-contained, reproducible code.

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

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

2012-02-08 Thread Bonnett, Laura
Dear David,

Thank you for your input.  I was under the impression that it was not possible 
to obtain survival times using the predict.coxph function.  In a post to the R 
help group I noticed someone had suggested calculating survival times in the 
manner I have used although obviously this is not appropriate.

Are you able to provide any suggestions as to how I might achieve the graph of 
actual vs. Predicted survival times?

Many thanks,
Laura

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: 07 February 2012 16:59
To: Bonnett, Laura
Cc: 'r-help@r-project.org'
Subject: Re: [R] Actual vs. predicted survival times


On Feb 7, 2012, at 10:32 AM, Bonnett, Laura wrote:

> Dear R-help,
>
> I am using R 2.14.1 on Windows 7.
>
> I would like to produce a plot like the attached - although  
> simplified to actual vs. Predicted survival time with distinguishing  
> marks for censored and observed points.  I have a dataset and have  
> fitted a Cox model to it.  In an attempt to visualise how accurate  
> the model is it would be ideal if I could plot the actual survival  
> times against the predicted survival times.
>
> I have been looking on the internet to see if there are ways to do  
> this in R.  The only post I found 
> (https://stat.ethz.ch/pipermail/r-help/2009-February/189888.html 
> ) that seemed directly relevant suggested that I shouldn't be  
> generating survival times at all.  Given that, I was concerned about  
> proceeding but I would like to have access to a plot to make a  
> decision on its usefulness.
>
> I appreciate that there are predict.coxph and predict.cph options  
> available to me.
>
> My first attempt was as follows:
>
> # fit Cox model #
> coxfita = coxph(Surv(tsecond,seccens)~stroke(smess)+rels(smess) 
> +asleep(smess)+eeg1(smess)+eeg2(smess)+ct1(smess)+ct2(smess) 
> +treat(smess),data=smess)
>
> # Find censored and observed groups #
> messcens <- subset(smess,seccens==1)
> messobs <- subset(smess,seccens==0)
>
> # Obtain predicted survival times #
> explp <- exp(predict(coxfita,type="lp"))

That gives you relative risks, not survival times.



> explp2 <- mean(ssmess$tsecond,na.rm=TRUE)*explp

Why are you multiplying times by relative risks? That makes no sense.

-- 
David.
> smess2 <- data.frame(ssmess,explp2)
>
> # Find censored and observed groups #
> smesscens <- subset(smess2,seccens==1)
> smessobs <- subset(smess2,seccens==0)
>
> # Produce plot #
> plot(smesscens$explp2,messcens$tsecond,pch=4,col="blue",ylab="Actual  
> Survival Time",xlab="Predicted Survival Time",main="Survival  
> Times",xlim=c(0,3500),ylim=c(0,3500))
> points(smessobs$explp2,messobs$tsecond,pch=4,col="red")
>
> This leads to the attached plot.  It doesn't seem correct though as  
> the predicted times all start over 500 days.
>
> Any suggestions would be very welcome.
>
> Many thanks,
> Laura
>
>  LJB.pdf>__
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

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


Re: [R] R equivalent of Python str()?

2012-02-08 Thread Ernest Adrogué
 8-02-2012, 09:45 (+0100); Martin Maechler escriu:
> > "R Michael Weylandt "
> > 
> > on Tue, 7 Feb 2012 20:23:57 -0500 writes:
> 
> > Possibly as.character() is what the OP was seeking
> > Michael
> 
> or   format()   which is closer for numeric data
> 

Thanks for the suggestions, but none of these appears to do what I
need. Take a table such as

> a <- as.table(c(A=450,B=12))
> a
  A   B 
450  12 

The string that print() prints is " A B \n450 12 \n". Once you have
the string you can print it with cat() and get the same result as with
print().

> cat("  A   B \n450  12 \n")
  A   B 
450  12 

The function that I was looking for was one that given the table a in
the example would return the string described above. Apparently,
capture.output() can be used for that, although it returns the string
split into lines they can be joined together easily. So, case closed
:)

-- 
Bye, 
Ernest

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

2012-02-08 Thread Ernest Adrogué
 8-02-2012, 04:22 (+); William Dunlap escriu:
> Use
>capture.output(print(yourData))
> to capture would be printed by print as a vector
> of a strings (one per line of printout).  Paste
> together if desired.

This will do it!!

Thanks.

-- 
Cheers,
Ernest

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

2012-02-08 Thread Arnaud Gaboury
> names1<-recode(df$names,"'BO'='BOO';'CL'='CLR';'C'='CC'")
> df1<-data.frame(names1,price)
> df1
  names1 price
1BOO10
2 CC25
3CLR20

TY for the tip.

Any possibility to write this in one single line?

Arnaud Gaboury
 
A2CT2 Ltd.

-Original Message-
From: Berend Hasselman [mailto:b...@xs4all.nl] 
Sent: mardi 7 février 2012 20:46
To: Arnaud Gaboury
Cc: Jorge I Velez; r-help@r-project.org
Subject: Re: [R] replace elements of a data frame


On 07-02-2012, at 20:24, Arnaud Gaboury wrote:

> I did indeed have a look at recode(), and was able to replace, but an error 
> warning :
> 
>> recode(names,"BO","BOO",df)
> Warning message:
> In recode.default(names, "BO", "BOO", df) :
>  Name(s) of vars duplicates with an object outside the dataFrame.
> 
>> df
>  names price
> 1   BOO10
> 2 C25
> 3CL20
> 
> As you can see, "BO" has been replaced by "BOO", but with a warning!

library(car)

 names<-c("BO","C","CL")
price<-c("10","25","20")
df<-data.frame(names,price)
recode(df$names,"'BO'='BOO'; 'CL'='CLO'; 'C'='CR'")

results in

[1] BOO CR  CLO
Levels: BOO CLO CR

Note the single quotes.

Berend

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

2012-02-08 Thread Johannes Radinger
Hi,

I am importing dataframe from an Excel file (xlsx package).
The columns contain acutally measurements for single species and
the column-length is of variable. As it is imported as a dataframe the 
difference to the "longest" column is filled with NA.
To explain it with an example, my dataframe looks like:

A <- seq(1:10)
B <- c(seq(1:5),rep(NA,5))
C <- c(seq(1:7),rep(NA,3))

df <- data.frame(A,B,C)


Now I'd like to transform that to a list of vectors of different length. 
Therefore I need to remove the NAs collectively from the single columns...I 
tried for transforming:

as.list(df)

...but I don't know how can I remove the NAs now? as.list doesn't take 
na.rm=TRUE argument. Is there any ready function to perform such tasks?
Or is there a better way then to assign the data to a list of vectors with 
variable length?

/johannes
--

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

2012-02-08 Thread Dimitris Rizopoulos

Two possibilities are:

lapply(df, function (x) x[!is.na(x)])

and

lapply(df, na.exclude)


I hope it helps.

Best,
Dimitris


On 2/8/2012 11:54 AM, Johannes Radinger wrote:

Hi,

I am importing dataframe from an Excel file (xlsx package).
The columns contain acutally measurements for single species and
the column-length is of variable. As it is imported as a dataframe the difference to the 
"longest" column is filled with NA.
To explain it with an example, my dataframe looks like:

A<- seq(1:10)
B<- c(seq(1:5),rep(NA,5))
C<- c(seq(1:7),rep(NA,3))

df<- data.frame(A,B,C)


Now I'd like to transform that to a list of vectors of different length. 
Therefore I need to remove the NAs collectively from the single columns...I 
tried for transforming:

as.list(df)

...but I don't know how can I remove the NAs now? as.list doesn't take 
na.rm=TRUE argument. Is there any ready function to perform such tasks?
Or is there a better way then to assign the data to a list of vectors with 
variable length?

/johannes
--

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



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

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

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

2012-02-08 Thread Johannes Radinger
Hi,

lapply(df, function (x) x[!is.na(x)])
thats is really great!

Thank you!

 Original-Nachricht 
> Datum: Wed, 08 Feb 2012 12:01:17 +0100
> Von: Dimitris Rizopoulos 
> An: Johannes Radinger 
> CC: R-help@r-project.org
> Betreff: Re: [R] remove NAs from list collectively

> Two possibilities are:
> 
> lapply(df, function (x) x[!is.na(x)])
> 
> and
> 
> lapply(df, na.exclude)
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> On 2/8/2012 11:54 AM, Johannes Radinger wrote:
> > Hi,
> >
> > I am importing dataframe from an Excel file (xlsx package).
> > The columns contain acutally measurements for single species and
> > the column-length is of variable. As it is imported as a dataframe the
> difference to the "longest" column is filled with NA.
> > To explain it with an example, my dataframe looks like:
> >
> > A<- seq(1:10)
> > B<- c(seq(1:5),rep(NA,5))
> > C<- c(seq(1:7),rep(NA,3))
> >
> > df<- data.frame(A,B,C)
> >
> >
> > Now I'd like to transform that to a list of vectors of different length.
> Therefore I need to remove the NAs collectively from the single
> columns...I tried for transforming:
> >
> > as.list(df)
> >
> > ...but I don't know how can I remove the NAs now? as.list doesn't take
> na.rm=TRUE argument. Is there any ready function to perform such tasks?
> > Or is there a better way then to assign the data to a list of vectors
> with variable length?
> >
> > /johannes
> > --
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> -- 
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] optparse::parse_args, using equals sign or not

2012-02-08 Thread Benjamin Tyner

Hi

We've found that when using parse_args(..., positional_arguments=FALSE), 
it is permissible to invoke our script with either "--myfoo=bar" or 
"--myfoo bar"; that is, whether or not the equals sign is present makes 
no difference, and in fact both usage forms are demonstrated in the 
optparse vignette.


However, we've found that when using parse_args(..., 
positional_arguments=TRUE), it is no longer possible to use the equals 
sign; that is, "--myfoo=bar" will show up as a positional argument, with 
"myfoo" set to its default value instead.


Wondering if this is really the intended behavior? Some of our scripts 
use positional arguments and some do not, and we'd like to arrive at a 
standard usage across all scripts.


Many thanks,
Ben
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] check for nearest value in a vector

2012-02-08 Thread Martin Batholdy
Hi,

Is there a way to check which value in a vector is nearest to a given value?

so for example I have vector x:

x <- c(1, 6, 12, 28, 33)

and I would like to get the position of the element of x that is nearest to 14
(in this case the third element).


thanks!
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] check for nearest value in a vector

2012-02-08 Thread Dimitris Rizopoulos

How about this:

x <- c(1, 6, 12, 28, 33)

which.min(abs(x - 14))


I hope it helps.

Best,
Dimitris


On 2/8/2012 1:56 PM, Martin Batholdy wrote:

Hi,

Is there a way to check which value in a vector is nearest to a given value?

so for example I have vector x:

x<- c(1, 6, 12, 28, 33)

and I would like to get the position of the element of x that is nearest to 14
(in this case the third element).


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



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

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] check for nearest value in a vector

2012-02-08 Thread Petr PIKAL
Hi
> 
> Hi,
> 
> Is there a way to check which value in a vector is nearest to a given 
value?
> 
> so for example I have vector x:
> 
> x <- c(1, 6, 12, 28, 33)
> 
> and I would like to get the position of the element of x that is nearest 
to 14
> (in this case the third element).

Easy. Smallest difference between value and target.

which.min(abs(x-14))
[1] 3
which.min((x-14)^2)
[1] 3

Regards
Petr


> 
> 
> thanks!
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] check for nearest value in a vector

2012-02-08 Thread Martin Batholdy
great, thanks!


On 08.02.2012, at 14:00, Dimitris Rizopoulos wrote:

> How about this:
> 
> x <- c(1, 6, 12, 28, 33)
> 
> which.min(abs(x - 14))
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris
> 
> 
> On 2/8/2012 1:56 PM, Martin Batholdy wrote:
>> Hi,
>> 
>> Is there a way to check which value in a vector is nearest to a given value?
>> 
>> so for example I have vector x:
>> 
>> x<- c(1, 6, 12, 28, 33)
>> 
>> and I would like to get the position of the element of x that is nearest to 
>> 14
>> (in this case the third element).
>> 
>> 
>> thanks!
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> -- 
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
> 
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] survfit is too slow! Looking for an alternative

2012-02-08 Thread Terry Therneau
A couple of thoughts.
1. More than 1/2 the work for survfit.coxph is computing standard
errors.  If you don't need them adding se.fit=FALSE will help the speed.

2. Survival curves with time dependent covariates is a complex topic.
To get the "probability of default in each month during next 2 years"
you need to create a scenario that specifies exactly what those time
dependent covariates will do over the next two years.  My book has a
long discussion on this, could I suggest you borrow a copy and read it?

3. For time fixed covariates there is a simple formula to get S(t;x)
from S(t; x0), i.e., if you have the predicted curve for some covariate
choice x0 you can easily derive it for any other chosen x.  That formula
doesn't work in the time dependent variable case (you can't factor
exp(x) out from under an integral of [exp(x) g(t) dt] when x is a
function of t).  Unless you want to learn a lot more math and do custom
programming, I think you are stuck with survfit.

Terry Therneau


-- begin included message 
I found survfit function was very slow for a large
dataset and I am looking for an alternative way to quickly get the
predicted
survival probabilities.
 

My
historical data set is a pool of loans with monthly observed default
status for
24 months. I would like to fit the proportional hazard model with time
varying
covariate such as unemployment rates and time constant variables at loan
application in a counting process format, and then use the model to
predict the
probability of default in each month during next 2 years for a pool of
new
loans.

I have read some posts from other R users. It sounds like using (average
survival
probability)^exp((X-means(X)*Beta) can quickly get the predicted
survival
probabilities. My predictors for the model include both continuous
variables
and categorical variables and my dataset is in counting process format
with
both time varying and time constant predictors. So how should I take the
mean?
I guess it's the mean of training data? And the denominator for the mean
is the
number of observations (i.e, the number of rows of training data in the
counting
process format)? What if the predictor is a categorical variable?

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

2012-02-08 Thread Terry Therneau
Coxph is a regression model, so the coefficient for "x" is the change in
prediction value for each 1 unit change in x.  Just like regression, it
won't matter if you code it as 0/1 or 1/2 or 105 vs 106.  If you code it
as 0 vs 10 the coefficient will be divided by 10 though.
 
  The relative hazard in a coxph model is exp(x beta), so the hazard
ratio for a 0 vs 1 variable is exp(beta); this is shown in the long for
printout given by summary(fit).

  If you want to use factors, e.g.
xfac = factor(x, levels=1:2, labels=c("control", "treatment"))
then the labels will carry forward to the printout, but that is their
only advantage.

Terry T.

--- begin included message -
Hi, in coxph,
coxph(Surv(time, status)~x,data=alm). 
How to encode x? For example, if x has two groups, the treatment group
and
control group. if I encode them as  1 and 2. Is the HR results
treatment/control? What if I encode them as 0 and 1. I am confused with
how
survival package works for HR. What should I do to get a
treatment/control
HR?
Thank you.

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

2012-02-08 Thread Johannes Radinger
Hi,
I want to "melt" my list and get certain deskriptive factors (length of a 
vector etc.) into a dataframe. Best to describe it with an example:

A <- seq(4)
B <- seq(6)
C <- seq(9)

ls <- list(A,B,C) # this is my list with vectors of different length

# thats the dataframe how it should look like:
namelength(x)   length(x[x>5])  length(x[x<5])  
A   4   0   4
B   6   1   4
C   9   4   4

How can that be achieved?


/johannes
--

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

2012-02-08 Thread Terry Therneau
The Cox model predicts two things: the relative hazard (death rate)
associated with each variable, and a predicted survival curve for any
particular variable combination.

   The predicted survival curve will look like a Kaplan-Meier curve:
multiple small steps, and will only rarely go all the way to zero.
There is not a natural way to give "a predicted survival time" for each
subject.  There isn't any program to do what you ask because there isn't
a good answer to "what" it should compute.  This troublesome fact has
led to a lot of work to define some residuals for a Cox model in other
ways: see chapters 4-7 of the book by Therneau and Grambsh for a partial
summary of ideas.  (A little too much to summarize in an email).

Terry Therneau

 begin included message 
I would like to produce a plot like the attached - although simplified
to actual vs. Predicted survival time with distinguishing marks for
censored and observed points.  I have a dataset and have fitted a Cox
model to it.  In an attempt to visualise how accurate the model is it
would be ideal if I could plot the actual survival times against the
predicted survival times.

I have been looking on the internet to see if there are ways to do this
in R.  The only post I found
(https://stat.ethz.ch/pipermail/r-help/2009-February/189888.html) that
seemed directly relevant suggested that I shouldn't be generating
survival times at all.  Given that, I was concerned about proceeding but
I would like to have access to a plot to make a decision on its
usefulness.
 

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


[R] How to start JGR in full window?

2012-02-08 Thread Iurie Malai
I want to start JGR as a full sized/maximized window automatically, but how
to do this? For other applications I can add option "--geometry 1440x900"
to the launch command, but for JGR this do not work. Sugestions?

Iurie Malai
Senior Lecturer
Psychology Department
Ion Creanga Moldova Pedagogical State University

[[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] List to dataframe

2012-02-08 Thread Jorge I Velez
Try

list <- list(1:4, 1:6, 1:9)
t(sapply(list, function(x) c(length(x), sum(x > 5), sum(x < 5

HTH,
Jorge.-


On Wed, Feb 8, 2012 at 8:50 AM, Johannes Radinger <> wrote:

> Hi,
> I want to "melt" my list and get certain deskriptive factors (length of a
> vector etc.) into a dataframe. Best to describe it with an example:
>
> A <- seq(4)
> B <- seq(6)
> C <- seq(9)
>
> ls <- list(A,B,C) # this is my list with vectors of different length
>
> # thats the dataframe how it should look like:
> namelength(x)   length(x[x>5])  length(x[x<5])
> A   4   0   4
> B   6   1   4
> C   9   4   4
>
> How can that be achieved?
>
>
> /johannes
> --
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
Hello,

I have to deal with numbers with a decimal part as quarter, coming from two 
systems with different way to show decimals. I need to tell R these are in fact 
the same number.

On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the other 
side, I have 2.25, 2.50 and 2.75.
All numbers are in fact 2.1/4, 2.1/2, 2.3/4.

How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

TY for any help.

Arnaud Gaboury
 
A2CT2 Ltd.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 3D confidence ellipsoid with ellipse projections onto 2D plane

2012-02-08 Thread Michael Friendly

On 2/7/2012 1:29 PM, Samuel Bazzi wrote:

I have a 3xN matrix of parameters obtained from N regressions where the 3
parameters are jointly statistically significant. I would like to reproduce
a 3D confidence ellipsoid projecting 2D ellipses onto the XY plane as in
Figure 5.2 in this
text
.

Is this possible using some combination of ellipse3d() and ellipse()? Any
insights would be greatly appreciated.



The situation described in Rawlings is for a single regression model, 
with an associated covariance matrix of the parameters which is the 
basis for the ellipsoid.

If all you have are the coefficient estimates, where do you think your
ellipsoid can come from?

Nevertheless, the situation you described -- plotting confidence 
ellipsoids for a model with projections on the XY and other planes

is handled by the p3d package, only on R-Forge
https://r-forge.r-project.org/projects/p3d/
It is in alpha development, and not completely documented.

HTH
-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 StreetWeb:   http://www.datavis.ca
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.


Re: [R] decimal number format as quarter

2012-02-08 Thread jim holtman
will this do it for you:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- (x * 10) %% 10
> # new result
> result <- x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>
>

On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  wrote:
> Hello,
>
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
>
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>
> TY for any help.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] Actual vs. predicted survival times

2012-02-08 Thread alanm (Alan Mitchell)
Have you tried plotting obvserved survival against X*Beta?  I believe the usual 
predictions from a cox model are just monotonic transformations of this.
-Alan

-Original Message-
From: Bonnett, Laura [mailto:l.j.bonn...@liverpool.ac.uk]
Sent: Wed 2/8/2012 1:52 AM
To: 'David Winsemius'
Cc: 'r-help@r-project.org'
Subject: Re: [R] Actual vs. predicted survival times
 
Dear David,

Thank you for your input.  I was under the impression that it was not possible 
to obtain survival times using the predict.coxph function.  In a post to the R 
help group I noticed someone had suggested calculating survival times in the 
manner I have used although obviously this is not appropriate.

Are you able to provide any suggestions as to how I might achieve the graph of 
actual vs. Predicted survival times?

Many thanks,
Laura

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: 07 February 2012 16:59
To: Bonnett, Laura
Cc: 'r-help@r-project.org'
Subject: Re: [R] Actual vs. predicted survival times


On Feb 7, 2012, at 10:32 AM, Bonnett, Laura wrote:

> Dear R-help,
>
> I am using R 2.14.1 on Windows 7.
>
> I would like to produce a plot like the attached - although  
> simplified to actual vs. Predicted survival time with distinguishing  
> marks for censored and observed points.  I have a dataset and have  
> fitted a Cox model to it.  In an attempt to visualise how accurate  
> the model is it would be ideal if I could plot the actual survival  
> times against the predicted survival times.
>
> I have been looking on the internet to see if there are ways to do  
> this in R.  The only post I found 
> (https://stat.ethz.ch/pipermail/r-help/2009-February/189888.html 
> ) that seemed directly relevant suggested that I shouldn't be  
> generating survival times at all.  Given that, I was concerned about  
> proceeding but I would like to have access to a plot to make a  
> decision on its usefulness.
>
> I appreciate that there are predict.coxph and predict.cph options  
> available to me.
>
> My first attempt was as follows:
>
> # fit Cox model #
> coxfita = coxph(Surv(tsecond,seccens)~stroke(smess)+rels(smess) 
> +asleep(smess)+eeg1(smess)+eeg2(smess)+ct1(smess)+ct2(smess) 
> +treat(smess),data=smess)
>
> # Find censored and observed groups #
> messcens <- subset(smess,seccens==1)
> messobs <- subset(smess,seccens==0)
>
> # Obtain predicted survival times #
> explp <- exp(predict(coxfita,type="lp"))

That gives you relative risks, not survival times.



> explp2 <- mean(ssmess$tsecond,na.rm=TRUE)*explp

Why are you multiplying times by relative risks? That makes no sense.

-- 
David.
> smess2 <- data.frame(ssmess,explp2)
>
> # Find censored and observed groups #
> smesscens <- subset(smess2,seccens==1)
> smessobs <- subset(smess2,seccens==0)
>
> # Produce plot #
> plot(smesscens$explp2,messcens$tsecond,pch=4,col="blue",ylab="Actual  
> Survival Time",xlab="Predicted Survival Time",main="Survival  
> Times",xlim=c(0,3500),ylim=c(0,3500))
> points(smessobs$explp2,messobs$tsecond,pch=4,col="red")
>
> This leads to the attached plot.  It doesn't seem correct though as  
> the predicted times all start over 500 days.
>
> Any suggestions would be very welcome.
>
> Many thanks,
> Laura
>
>  LJB.pdf>__
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

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


Re: [R] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com] 
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- (x * 10) %% 10
> # new result
> result <- x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>
>

On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  wrote:
> Hello,
>
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
>
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>
> TY for any help.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] decimal number format as quarter

2012-02-08 Thread David Winsemius


On Feb 8, 2012, at 9:12 AM, Arnaud Gaboury wrote:


Hello,

I have to deal with numbers with a decimal part as quarter, coming  
from two systems with different way to show decimals. I need to tell  
R these are in fact the same number.


On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On  
the other side, I have 2.25, 2.50 and 2.75.

All numbers are in fact 2.1/4, 2.1/2, 2.3/4.

How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?


 vec <- c( 2.2 , 2.4 , 2.6)
 trunc(vec) + (vec-trunc(vec))*(2.5/2)
[1] 2.25 2.50 2.75




TY for any help.

Arnaud Gaboury

A2CT2 Ltd.

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] decimal number format as quarter

2012-02-08 Thread David Reiner
Looks like something priced in eighths; we deal with similar notation for bonds 
and similar instruments.

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> as.integer(x)+10*(x-as.integer(x))/8
[1] 2.25 2.50 2.75 3.25 3.50 3.75

Adjust the 10 and 8 if you have other denominators.
-- David

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Arnaud Gaboury
Sent: Wednesday, February 08, 2012 8:45 AM
To: jim holtman
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury

A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- (x * 10) %% 10
> # new result
> result <- x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>
>

On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  wrote:
> Hello,
>
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
>
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>
> TY for any help.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

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

2012-02-08 Thread jim holtman
Here is a shorter way:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- x %% 1
> result <- x.i + x.f * 1.25
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
> as.integer(x) + (x %% 1) * 1.25
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>

On Wed, Feb 8, 2012 at 9:44 AM, Arnaud Gaboury  wrote:
> TY Jim,
>
> It do the trick.
>
> I was trying to play without success with the format() options.
> No simplest way so?
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
>
> -Original Message-
> From: jim holtman [mailto:jholt...@gmail.com]
> Sent: mercredi 8 février 2012 15:36
> To: Arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] decimal number format as quarter
>
> will this do it for you:
>
>> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
>> # get integer part
>> x.i <- as.integer(x)
>> # get fractional part
>> x.f <- (x * 10) %% 10
>> # new result
>> result <- x.i + ifelse(x.f == 2
> +                     , .25
> +                     , ifelse(x.f == 4
> +                         , .5
> +                         , .75
> +                         )
> +                     )
>> result
> [1] 2.25 2.50 2.75 3.25 3.50 3.75
>>
>>
>
> On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  
> wrote:
>> Hello,
>>
>> I have to deal with numbers with a decimal part as quarter, coming from two 
>> systems with different way to show decimals. I need to tell R these are in 
>> fact the same number.
>>
>> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
>> other side, I have 2.25, 2.50 and 2.75.
>> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>>
>> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>>
>> TY for any help.
>>
>> Arnaud Gaboury
>>
>> A2CT2 Ltd.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
David,

You are not far indeed, as I trade commodities, and prices are the ones from 
grain market: Corn, wheat and Soybeans.

They are quoted in 1/4, and my trading platform displays them in 2,4,6 and my 
statements are in 25,50,75.

TY

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: David Reiner [mailto:david.rei...@xrtrading.com] 
Sent: mercredi 8 février 2012 15:48
To: Arnaud Gaboury; jim holtman
Cc: r-help@r-project.org
Subject: RE: [R] decimal number format as quarter

Looks like something priced in eighths; we deal with similar notation for bonds 
and similar instruments.

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> as.integer(x)+10*(x-as.integer(x))/8
[1] 2.25 2.50 2.75 3.25 3.50 3.75

Adjust the 10 and 8 if you have other denominators.
-- David

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Arnaud Gaboury
Sent: Wednesday, February 08, 2012 8:45 AM
To: jim holtman
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury

A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
> # get integer part
> x.i <- as.integer(x)
> # get fractional part
> x.f <- (x * 10) %% 10
> # new result
> result <- x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
> result
[1] 2.25 2.50 2.75 3.25 3.50 3.75
>
>

On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  wrote:
> Hello,
>
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
>
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>
> TY for any help.
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

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

2012-02-08 Thread peter dalgaard

On Feb 8, 2012, at 15:48 , David Reiner wrote:

> Looks like something priced in eighths; we deal with similar notation for 
> bonds and similar instruments.
> 
>> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
>> as.integer(x)+10*(x-as.integer(x))/8
> [1] 2.25 2.50 2.75 3.25 3.50 3.75
> 
> Adjust the 10 and 8 if you have other denominators.

For the case at hand, I expect that you can even get away with

> ceiling(x*4)/4
[1] 2.25 2.50 2.75 3.25 3.50 3.75


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] List to dataframe

2012-02-08 Thread Johannes Radinger
Hi,

> Try
> 
> list <- list(1:4, 1:6, 1:9)
> t(sapply(list, function(x) c(length(x), sum(x > 5), sum(x < 5
> 

thank you...the sapply approach seems straight forward, although I don't get 
the names into an own column... When the list elements are named the name is 
used for the rownames. I'd like to have them as an own column and no row 
names...

like for the list:
list <- list(A=1:4, B=1:6, C=1:9)
t(sapply(list, function(x) c(length(x), sum(x > 5), sum(x < 5

/Johannes

> HTH,
> Jorge.-
> 
> 
> On Wed, Feb 8, 2012 at 8:50 AM, Johannes Radinger <> wrote:
> 
> > Hi,
> > I want to "melt" my list and get certain deskriptive factors (length of
> a
> > vector etc.) into a dataframe. Best to describe it with an example:
> >
> > A <- seq(4)
> > B <- seq(6)
> > C <- seq(9)
> >
> > ls <- list(A,B,C) # this is my list with vectors of different length
> >
> > # thats the dataframe how it should look like:
> > namelength(x)   length(x[x>5])  length(x[x<5])
> > A   4   0   4
> > B   6   1   4
> > C   9   4   4
> >
> > How can that be achieved?
> >
> >
> > /johannes
> > --
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] decimal number format as quarter

2012-02-08 Thread Gabor Grothendieck
On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury  wrote:
> Hello,
>
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
>
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
>
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?
>

In this solution we break apart the portion before and after the dot
and divide the portion after the dot by 8 (assuming its supposed to
represent the number of eighths):

> library(gsubfn)
> x <- c(2.2, 2.4, 2.6)
> strapply(x, "(\\d+).(\\d+)", ~ as.numeric(x) + as.numeric(y) / 8, simplify = 
> TRUE)
[1] 2.25 2.50 2.75

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
Thanks so much Peter. You are the man.

Easy way and working for me.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: peter dalgaard [mailto:pda...@gmail.com] 
Sent: mercredi 8 février 2012 16:15
To: David Reiner
Cc: Arnaud Gaboury; jim holtman; r-help@r-project.org
Subject: Re: [R] decimal number format as quarter


On Feb 8, 2012, at 15:48 , David Reiner wrote:

> Looks like something priced in eighths; we deal with similar notation for 
> bonds and similar instruments.
> 
>> x <- c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
>> as.integer(x)+10*(x-as.integer(x))/8
> [1] 2.25 2.50 2.75 3.25 3.50 3.75
> 
> Adjust the 10 and 8 if you have other denominators.

For the case at hand, I expect that you can even get away with

> ceiling(x*4)/4
[1] 2.25 2.50 2.75 3.25 3.50 3.75


--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 
Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] decimal number format as quarter

2012-02-08 Thread Petr Savicky
On Wed, Feb 08, 2012 at 03:12:56PM +0100, Arnaud Gaboury wrote:
> Hello,
> 
> I have to deal with numbers with a decimal part as quarter, coming from two 
> systems with different way to show decimals. I need to tell R these are in 
> fact the same number.
> 
> On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
> other side, I have 2.25, 2.50 and 2.75.
> All numbers are in fact 2.1/4, 2.1/2, 2.3/4.
> 
> How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

Hello:

Try the following.

  vec <- c(2, 2.2, 2.4, 2.6, 3, 3.2, 3.4, 3.6)
  round(4*(vec + 0.1))/4

  [1] 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75

Hope this helps.

Petr Savicky.

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

2012-02-08 Thread Anirudh Kondaveeti
Hi

I have a dataset with a few variables but two variables are very important.
One of them is say S1 and other S2. S1 is a numeric variable and S2 is a
categorical variable. Consider two cases of S1-S2 pair like S1 = 70.2, S2 =
A and S1 = 70.21, S2 = B. Assume my dataset has  20 instances of the first
case and 20 instances of the second case.

I have generated a synthetic class and used randomForest for calculating
proximities between the 40 instances described above. The mds plot using
this proximity doesnot seperate the first 20 instances from the next 20
instances.

Any idea of why it doesn't work? What settings can I change in randomForest
to separate these instances? Is there a better way to visualize the results
than mds plots?

I am looking at growing larger trees. How can i control the levels in the
tree. Is nodesize the only parameter in randomForest to control it ?

[[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] List to dataframe

2012-02-08 Thread jim holtman
Does this do what you want:

> list <- list(A=1:4, B=1:6, C=1:9)
> result <- lapply(names(list), function(x){
+ data.frame(name = x
+ , length = length(list[[x]])
+ , gt5 = sum(list[[x]] > 5)
+ , lt5 = sum(list[[x]] < 5)
+ )
+ })
> do.call(rbind, result)
  name length gt5 lt5
1A  4   0   4
2B  6   1   4
3C  9   4   4

On Wed, Feb 8, 2012 at 10:18 AM, Johannes Radinger  wrote:
> Hi,
>
>> Try
>>
>> list <- list(1:4, 1:6, 1:9)
>> t(sapply(list, function(x) c(length(x), sum(x > 5), sum(x < 5
>>
>
> thank you...the sapply approach seems straight forward, although I don't get 
> the names into an own column... When the list elements are named the name is 
> used for the rownames. I'd like to have them as an own column and no row 
> names...
>
> like for the list:
> list <- list(A=1:4, B=1:6, C=1:9)
> t(sapply(list, function(x) c(length(x), sum(x > 5), sum(x < 5
>
> /Johannes
>
>> HTH,
>> Jorge.-
>>
>>
>> On Wed, Feb 8, 2012 at 8:50 AM, Johannes Radinger <> wrote:
>>
>> > Hi,
>> > I want to "melt" my list and get certain deskriptive factors (length of
>> a
>> > vector etc.) into a dataframe. Best to describe it with an example:
>> >
>> > A <- seq(4)
>> > B <- seq(6)
>> > C <- seq(9)
>> >
>> > ls <- list(A,B,C) # this is my list with vectors of different length
>> >
>> > # thats the dataframe how it should look like:
>> > name    length(x)       length(x[x>5])  length(x[x<5])
>> > A       4       0       4
>> > B       6       1       4
>> > C       9       4       4
>> >
>> > How can that be achieved?
>> >
>> >
>> > /johannes
>> > --
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] How to have columns lined up?

2012-02-08 Thread hithit168
Thanks a lot, David. 
Uh...this is not really an R question, but I couldn't find answer nowhere...

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-have-columns-lined-up-tp4367928p4369262.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] library(forecast): Error in SD.test(x, m) : Insufficient data

2012-02-08 Thread Jean Jacques Dureau
I have these R code:

###
time.test.data<-c(2.88645418326693, 2.91546949823027, 2.94130799329234,
  2.93313338038109, 2.89478957915832, 2.86029757243540, 2.78648486664669,
  2.80183167535133, 2.75435512226307, 2.78992352676563, 2.76028433151845,
  2.68741721854305, 2.70691974293828, 2.683833847881, 2.65041551246537,
  2.65169020111254, 2.58837541686517, 2.66549241844080, 2.58451314648945,
  2.60250871080139, 2.61253722876188, 2.59921041087878, 2.71727961060032,
  2.65440192667915, 2.74799149338374, 2.70649994101687, 2.80636027009366,
  2.81801086502298, 2.82555635319454, 2.87133347201997, 2.75746714456392,
  2.7660659236424, 2.71688375522241, 2.72655367231638, 2.72461997828447,
  2.78455790784558, 2.71160702495708, 2.65754456439869, 2.85673280918507,
  2.7053919591233, 2.7532637075718, 2.74272237196766, 2.75893306492199,
  2.62584686181772, 2.75230602278893, 2.82781018027572, 2.80220656652931,
  2.80242587601078, 2.84061953534849, 2.87123514783089, 2.76991605276683,
  2.77796934865900)

library(forecast)
auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
###

I obtain the error message:
Error in SD.test(x, m) : Insufficient data

What is wrong?

jj

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

2012-02-08 Thread J. Augusiak
Dear R list,

I have a package downloaded and looked up a function in there. Now I find
that it uses C code (.C call) to do part of its job.

However, when I wanted to look that part up by using getAnywhere()  I was
told that no object of that name could be found. Then I tried typing C.("
funct.name") which only caused R to crash.

Is there any way to look up the function?

I'm not an expert and don't understand much of the technicalities mentioned
in the  Writing-R-extensions manual. I only would like to see how the
method I think is used is actually implemented.

I use R.2.13.1, Windows 7. The package I'm referring to is adehabitatLT,
function acfang.ltraj -> res <- .C("acfangl",...)

Many thanks in advance!

Jacqueline

[[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] predict.naiveBayes() bug in e1071 package

2012-02-08 Thread David Meyer

Confirmed & fixed upstream.

Thanks,
David

On 2012-02-07 18:43, Ali Tofigh wrote:

Hi,

I'm currently using the R package e1071 to train naive bayes
classifiers and came across a bug: When the posterior probabilities of
all classes are small, the result from the predict.naiveBayes function
become NaNs. This is an issue with the treatment of the
log-transformed probabilities inside the predict.naiveBayes function.
Here is an example to demonstrate the problem (you might need to
increase 'nvar' depending on your machine):

 8<  
N<- 100
nvar<- 60
varnames<- paste("v", 1:nvar, sep="")

dat<- sapply(1:nvar, function(dummy) {c(rnorm(N/2, 0, 1), rnorm(N/2, 10, 1))})
colnames(dat)<- varnames

out<- rep(c("a","b"), each=N/2)
names(dat)<- varnames

nb<- naiveBayes(x=dat, y=out)

new.dat<- t(rnorm(nvar, 5, 0.1))
colnames(new.dat)<- varnames

predict(nb, new.dat, type="raw")
 8<  

the results of the last line is usually NaNs. As for the solution:

To protect agains very small numbers, the e1071:::predict.naiveBayes
function takes the probabilities into log-space and adds instead of
multiplying probabilities. However, when calculating the posterior
probabilities of each class (when type = "raw"), the log of the
probabilities are exponentiated, which defeats the purpose of the
logspace transformation. I suggest the following change to the code:

Towards the end of the predict.naiveBayes function, you currently do:

L<- exp(L)
L / sum(L)   # this is what is returned

you can instead use

sapply(L, function(lp) {1 / sum(exp(L - lp))})

the above comes from the following equality:

x / (x + y + z) = 1 / (1 + exp(log(y) - log(x)) + exp(log(z) - log(x)))

Best wishes,
/Ali Tofigh





--
Priv.-Doz. Dr. David Meyer
Department of Information Systems and Operations

WU
Wirtschaftsuniversität Wien
Vienna University of Economics and Business
Augasse 2-6, 1090 Vienna, Austria
Tel: +43-1-313-36-4393
Fax: +43-1-313-36-90-4393
HP:  http://ec.wu.ac.at/~meyer

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

2012-02-08 Thread summer
Thank you. The factor is useful.
What if I did not factor it,and the x is listed as 2 2 1 1 1 1 2 2  2 and so
on. How would I know the HR for coxph is group2/group1 or group1/group2? I
understand it's just inverse but how can I identify the exact HR?

--
View this message in context: 
http://r.789695.n4.nabble.com/need-help-with-understanding-coxph-encoding-tp4367514p4369604.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] wilderSum

2012-02-08 Thread yuanwei
Hi  Joshua,

Before I found your post here, I have viewed your source code for
'wilderSum' to
figure out how wilderSum works - I re-write a piece of R code to implement
the algorithm as in your source code, but failed to get the right result as
wilderSum function in TTR. Glad to see your explanation here for wilderSum,
but I am still confused by the source code: the initial value(sum) for the
iterator seems to be a simple sum of first (n-1) X's...

   Thanks for your kind help in advance!

yuanwei 

--
View this message in context: 
http://r.789695.n4.nabble.com/wilderSum-tp846599p4368945.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] find a row identical to another

2012-02-08 Thread Francisco

Hello,
I have a dataset with many rows, starting from a row that I choose I 
would like to find the other rows in the dataset which are identical to 
this row (with the same values per each column) and assign them to a 
variable.

How could I do?

Thank you

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


[R] Problems reading tab-delim files using read.table and read.delim

2012-02-08 Thread mails
Hello,

I used read.xlsx to read in Excel files but for large files it turned out to
be not very efficient.
For that reason I use a programme which writes each sheet in an Excel file
into tab-delim txt files.
After that I tried using read.table and read.delim to read in those txt
files. Unfortunately, the results
are not as expected. To show you what I mean I created a tiny Excel sheet
with some rows and columns and
read it in using read.xlsx. I also used my script to write that sheet to a
tab-delim txt file and read that one it with
read.table and read.delim. Here is the R output:



> (test <- read.table(Sheet1.txt, header=TRUE, sep="\t"))
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, 
: 
  line 1 did not have 5 elements

> (test <- read.delim(Sheet1.txt, header=TRUE, sep="\t"))
 c1 c2 c3  X
123 213 NA NA NA
234 asd NA NA NA

> (test <- read.xlsx(file.path(data), "Sheet1"))
   c1   c2  c3   NA. NA..1 NA..2
1 123  213  
2 234  asd  NA  


The last output is what I would expect the file to be read in. Columns 4 to
6 do not have any header rows. in R1C4 I added some white spaces as well as
into R2C5 and R2C6 which a read in correctly by the read.xlsx function.

read.table and read.delim seem not to be able to handle such files. Is there
any workaround for that?


Cheers

--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-reading-tab-delim-files-using-read-table-and-read-delim-tp4369195p4369195.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] library(forecast): Error in SD.test(x, m) : Insufficient data

2012-02-08 Thread Jean Jacques Dureau
 I have these R code:

###
time.test.data<-c(2.88645418326693, 2.91546949823027, 2.94130799329234,
 2.93313338038109, 2.89478957915832, 2.86029757243540, 2.78648486664669,
 2.80183167535133, 2.75435512226307, 2.78992352676563, 2.76028433151845,
 2.68741721854305, 2.70691974293828, 2.683833847881, 2.65041551246537,
 2.65169020111254, 2.58837541686517, 2.66549241844080, 2.58451314648945,
 2.60250871080139, 2.61253722876188, 2.59921041087878, 2.71727961060032,
 2.65440192667915, 2.74799149338374, 2.70649994101687, 2.80636027009366,
 2.81801086502298, 2.82555635319454, 2.87133347201997, 2.75746714456392,
 2.7660659236424, 2.71688375522241, 2.72655367231638, 2.72461997828447,
 2.78455790784558, 2.71160702495708, 2.65754456439869, 2.85673280918507,
 2.7053919591233, 2.7532637075718, 2.74272237196766, 2.75893306492199,
 2.62584686181772, 2.75230602278893, 2.82781018027572, 2.80220656652931,
 2.80242587601078, 2.84061953534849, 2.87123514783089, 2.76991605276683,
 2.77796934865900)

library(forecast)
auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
###

I obtain the error message:
Error in SD.test(x, m) : Insufficient data

What is wrong?



jj

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

2012-02-08 Thread n
Hi,

How can I draw a random sample from a truncated distribution (especially
lognormal)?

I found the functions for truncated normal but not for many other
distributions.

Thanks

Nikhil 

--
View this message in context: 
http://r.789695.n4.nabble.com/Random-sample-from-truncated-distributions-tp4369569p4369569.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] glm.fit and pearson's correlation coefficient

2012-02-08 Thread dzuc
I did a linear correlation of data using glm.fit and stored the output in the
object "f":
f <- glm.fit(x, y, w)
I am intereseted in estimating the quality of the correlation. I am used to
do it using pearson correlation coefficient "r" or "r^2". Can I extract this
coefficient from the output of glm.fit? 
Is there another number in the output of glm.fit that represents the quality
of the correlation?

Here is a printout of the object f:
$coefficients
[1] 95772.92

$residuals
 [1]   -5146.208  -17221.948  -12743.726  -14536.236  -36311.931  -33651.931
 [7]  -75054.063  -73207.873 -136695.506 -142442.126 -268970.512 -260546.762
[13] -281117.024 -247116.5249115.715   64791.715

$fitted.values
 [1]74702.8874702.88   149405.76   149405.76   299769.24   299769.24
 [7]   598580.75   598580.75  1197161.51  1197161.51  2394323.01  2394323.01
[13]  4788646.02  4788646.02 57463752.29 57463752.29

$effects
  
-81641362.05-17217.24-12734.32-14526.83-36293.05   
-33633.05 
  
   -75016.37-73170.18   -136620.11   -142366.73   -268819.73  
-260395.98 

  -280815.45   -246814.95 12734.59 68410.59 

$R
  [,1]
[1,] -852.4472

$rank
[1] 1

$qr
$qr
   [,1]
 [1,] -8.524472e+02
 [2,]  9.150126e-04
 [3,]  1.830025e-03
 [4,]  1.830025e-03
 [5,]  3.671781e-03
 [6,]  3.671781e-03
 [7,]  7.331832e-03
 [8,]  7.331832e-03
 [9,]  1.466366e-02
[10,]  1.466366e-02
[11,]  2.932733e-02
[12,]  2.932733e-02
[13,]  5.865466e-02
[14,]  5.865466e-02
[15,]  7.038559e-01
[16,]  7.038559e-01

$rank
[1] 1

$qraux
[1] 1.000915

$pivot
[1] 1

$tol
[1] 1e-11

attr(,"class")
[1] "qr"

$family

Family: gaussian 
Link function: identity 


$linear.predictors
 [1]74702.8874702.88   149405.76   149405.76   299769.24   299769.24
 [7]   598580.75   598580.75  1197161.51  1197161.51  2394323.01  2394323.01
[13]  4788646.02  4788646.02 57463752.29 57463752.29

$deviance
[1] 337719889404

$aic
[1] 429.7723

$null.deviance
[1] 5.570009e+15

$iter
[1] 2

$weights
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

$prior.weights
 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

$df.residual
[1] 15

$df.null
[1] 15

$y
 [1]69556.6757480.93   136662.03   134869.52   263457.31   266117.31
 [7]   523526.69   525372.88  1060466.00  1054719.38  2125352.50  2133776.25
[13]  4507529.00  4541529.50 57472868.00 57528544.00

$converged
[1] TRUE

$boundary
[1] FALSE

> coefficients(f1)
[1] 95772.92



--
View this message in context: 
http://r.789695.n4.nabble.com/glm-fit-and-pearson-s-correlation-coefficient-tp4369811p4369811.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] earth package question

2012-02-08 Thread luckjiff
I’ve a question on saving a earth object to disk.
Say m is the model then
print(object.size(m), units=”Mb”)
163.8 Mb
and save it off
save(m, “tmp.rda”)
and “tmp.rda” is roughly 171Mb file.

I would like this to be much smaller.
So I try
m$bx<-NULL
then
print(object.size(m), units=”Mb”)
14.9 Mb Great!
however when I save it off
save(m, “tmp.rda”)
and “tmp.rda” is roughly 171Mb file – the same size.

Can you help?  By the way earth is awesome!
Thanks!
Glen


--
View this message in context: 
http://r.789695.n4.nabble.com/earth-package-question-tp4369741p4369741.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] library(forecast): Error in SD.test(x, m) : Insufficient data

2012-02-08 Thread Rainer Hurling

On 08.02.2012 15:35 (UTC+1), Jean Jacques Dureau wrote:

I have these R code:

###
time.test.data<-c(2.88645418326693, 2.91546949823027, 2.94130799329234,
   2.93313338038109, 2.89478957915832, 2.86029757243540, 2.78648486664669,
   2.80183167535133, 2.75435512226307, 2.78992352676563, 2.76028433151845,
   2.68741721854305, 2.70691974293828, 2.683833847881, 2.65041551246537,
   2.65169020111254, 2.58837541686517, 2.66549241844080, 2.58451314648945,
   2.60250871080139, 2.61253722876188, 2.59921041087878, 2.71727961060032,
   2.65440192667915, 2.74799149338374, 2.70649994101687, 2.80636027009366,
   2.81801086502298, 2.82555635319454, 2.87133347201997, 2.75746714456392,
   2.7660659236424, 2.71688375522241, 2.72655367231638, 2.72461997828447,
   2.78455790784558, 2.71160702495708, 2.65754456439869, 2.85673280918507,
   2.7053919591233, 2.7532637075718, 2.74272237196766, 2.75893306492199,
   2.62584686181772, 2.75230602278893, 2.82781018027572, 2.80220656652931,
   2.80242587601078, 2.84061953534849, 2.87123514783089, 2.76991605276683,
   2.77796934865900)

library(forecast)
auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
###


This looks good to me, I got no error:

auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
Series: ts(time.test.data, start = c(2011, 1), frequency = 52)
ARIMA(2,0,2) with non-zero mean

Coefficients:
 ar1  ar2  ma1 ma2  intercept
  1.4540  -0.5762  -1.0235  0.5484 2.7569
s.e.  0.3351   0.3194   0.3240  0.1902 0.0328

sigma^2 estimated as 0.003059:  log likelihood=76.05
AIC=-140.09   AICc=-138.23   BIC=-128.38


So perhaps something is wrong with your data object or with your 
dependend packages?



I obtain the error message:
Error in SD.test(x, m) : Insufficient data

What is wrong?

jj


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


Re: [R] How to have columns lined up?

2012-02-08 Thread David Winsemius


On Feb 8, 2012, at 7:32 AM, hithit168 wrote:


Thanks a lot, David.
Uh...this is not really an R question, but I couldn't find answer  
nowhere...


Questions that relate to how to use editors (and this is especially so  
for Microsoft products) simply do NOT belong on R-help. There must be  
literally thousands of other venues for such questions.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] units for mapproject() function result

2012-02-08 Thread William Stockhausen
Hi Ray,

Thanks for responding! However, it would certainly be very non-intuitive
if you're correct about the units for the projected coordinates.  As I'm
sure you know, in a GIS  geographic coordinates are usually in
degrees--although it's quite possible for these to be in radians instead, I
guess, since it saves converting degrees to radians when computing sines
and cosines--because these are coordinates that locate points on the
surface of a curved surface like a sphere or ellipsoid. Projected
coordinates, on the other hand, are ordinarily in some sort of physical
distance units like km or feet because they represent a projection of
points from the original curved surface onto a flat surface and include
effects due to the local radius of curvature of the surface.  I'd be really
surprised if the projected coordinates were in radians because they are
angular units (independent of the radius of curvature), not distance
units.  Still, it's possible.

My problem is I've got vertices of a polygon in lat/lon coordinates
(degrees) and am trying to find the approximate area of the polygon (in
km^2 or some other physical units, hence the question about the units) by
projecting the coordinates of the vertices to planar coordinates using an
Albers projection and the mapproject function in the mapproj package.  If
you're correct about the units as radians, I guess I'd have to multiply the
area in radians^2 by R^2, where R is the radius of the earth, to get the
area in physical units.

Best regards,

Buck
On Tue, Feb 7, 2012 at 5:29 PM, Ray Brownrigg
wrote:

> On Wed, 08 Feb 2012, William Stockhausen wrote:
> > Does anyone know  what the units are for projected coordinates obtained
> > using mapproj's mapproject function with an Albers projection?  Thanks
> for
> > any and all help!
> >
> > Buck Stockhausen
>
> I don't know for sure, but it looks like radians to me, with some
> unspecified
> origin(depending on the parameters specified).  Certainly the maps package
> data is
> specified in radians internally.
>
> Hope this helps,
> Ray Brownrigg
>

[[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] wilderSum

2012-02-08 Thread Joshua Ulrich
Yuanwei,

You are correct.  The initial seed value is the raw sum, starting with
TTR_0.21-0.

As it says in the TTR/CHANGES file (among other things):
- Changed wilderSum to seed initial value with raw sum. This matches
Wilder's original calculations. Thanks to Mahesh Bp for the report.

HTH,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Wed, Feb 8, 2012 at 3:50 AM, yuanwei  wrote:
> Hi  Joshua,
>
>    Before I found your post here, I have viewed your source code for
> 'wilderSum' to
> figure out how wilderSum works - I re-write a piece of R code to implement
> the algorithm as in your source code, but failed to get the right result as
> wilderSum function in TTR. Glad to see your explanation here for wilderSum,
> but I am still confused by the source code: the initial value(sum) for the
> iterator seems to be a simple sum of first (n-1) X's...
>
>   Thanks for your kind help in advance!
>
> yuanwei
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/wilderSum-tp846599p4368945.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] Problems reading tab-delim files using read.table and read.delim

2012-02-08 Thread Jan van der Laan



I don't know if this completely solves your problem, but here are some  
arguments to read.table/read.delim you might try:

row.names=FALSE
fill=TRUE
The details section also suggests using the colClasses argument as the  
number of columns is determined from the first 5 rows which may not be  
correct.


HTH

Jan



mails  schreef:


Hello,

I used read.xlsx to read in Excel files but for large files it turned out to
be not very efficient.
For that reason I use a programme which writes each sheet in an Excel file
into tab-delim txt files.
After that I tried using read.table and read.delim to read in those txt
files. Unfortunately, the results
are not as expected. To show you what I mean I created a tiny Excel sheet
with some rows and columns and
read it in using read.xlsx. I also used my script to write that sheet to a
tab-delim txt file and read that one it with
read.table and read.delim. Here is the R output:




(test <- read.table(Sheet1.txt, header=TRUE, sep="\t"))

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
:
  line 1 did not have 5 elements


(test <- read.delim(Sheet1.txt, header=TRUE, sep="\t"))

 c1 c2 c3  X
123 213 NA NA NA
234 asd NA NA NA


(test <- read.xlsx(file.path(data), "Sheet1"))

   c1   c2  c3   NA. NA..1 NA..2
1 123  213  
2 234  asd  NA  


The last output is what I would expect the file to be read in. Columns 4 to
6 do not have any header rows. in R1C4 I added some white spaces as well as
into R2C5 and R2C6 which a read in correctly by the read.xlsx function.

read.table and read.delim seem not to be able to handle such files. Is there
any workaround for that?


Cheers

--
View this message in context:  
http://r.789695.n4.nabble.com/Problems-reading-tab-delim-files-using-read-table-and-read-delim-tp4369195p4369195.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] Memory allocation problem (again!)

2012-02-08 Thread Christofer Bogaso
Dear all, I know this problem was discussed many times in forum, however
unfortunately I could not find any way out for my own problem. Here I am
having Memory allocation problem while generating a lot of random number.
Here is my description:

> rnorm(5*6000)
Error: cannot allocate vector of size 2.2 Gb
In addition: Warning messages:
1: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
2: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
3: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
4: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
> memory.size(TRUE)
[1] 15.75
> rnorm(5*6000)
Error: cannot allocate vector of size 2.2 Gb
In addition: Warning messages:
1: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
2: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
3: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)
4: In rnorm(5 * 6000) :
  Reached total allocation of 1535Mb: see help(memory.size)

And the Session info is here:

> sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C

[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.6  zoo_1.7-6

loaded via a namespace (and not attached):
[1] lattice_0.20-0

I am using Windows 7 (home version) with 4 GB of RAM (2.16GB is usable as my
computer reports). So in my case, is it not possible to generate a random
vector with such length? Note that generating such vector is my primary job.
Later I need to do something on that vector. Those Job includes:
1. Create a matrix with 50,000 rows.
2. Get the row sum
3. then report some metrics on that sum values (min. 50,000 elements must be
there).

Can somebody help me with some real solution/suggesting?

Thanks and regards,

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


Re: [R] Problems reading tab-delim files using read.table and read.delim

2012-02-08 Thread Gabor Grothendieck
On Wed, Feb 8, 2012 at 7:09 AM, mails  wrote:
> Hello,
>
> I used read.xlsx to read in Excel files but for large files it turned out to
> be not very efficient.
> For that reason I use a programme which writes each sheet in an Excel file
> into tab-delim txt files.

Note that that is how read.xls in the gdata package works - it uses a
perl program to convert the spreadsheet to a text file and then reads
in the text file.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Memory allocation problem (again!)

2012-02-08 Thread Justin Haynes
32 bit windows has a memory limit of 2GB.  Upgrading to a computer thats
less than 10 years old is the best path.

But short of that, if you're just generating random data, why not do it in
two or more pieces and combine them later?

mat.1 <- matrix(rnorm(5*2000),nrow=5)
mat.2 <- matrix(rnorm(5*2000),nrow=5)
mat.3 <- matrix(rnorm(5*2000),nrow=5)

mat.1.sums <- rowSums(mat.1)
mat.2.sums <- rowSums(mat.2)
mat.3.sums <- rowSums(mat.3)

mat.sums <- c(mat.1.sums,mat.2.sums,mat.3.sums)



On Wed, Feb 8, 2012 at 8:37 AM, Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Dear all, I know this problem was discussed many times in forum, however
> unfortunately I could not find any way out for my own problem. Here I am
> having Memory allocation problem while generating a lot of random number.
> Here is my description:
>
> > rnorm(5*6000)
> Error: cannot allocate vector of size 2.2 Gb
> In addition: Warning messages:
> 1: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 2: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 3: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 4: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> > memory.size(TRUE)
> [1] 15.75
> > rnorm(5*6000)
> Error: cannot allocate vector of size 2.2 Gb
> In addition: Warning messages:
> 1: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 2: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 3: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 4: In rnorm(5 * 6000) :
>  Reached total allocation of 1535Mb: see help(memory.size)
>
> And the Session info is here:
>
> > sessionInfo()
> R version 2.14.0 (2011-10-31)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] graphics  grDevices utils datasets  grid  stats methods
> base
>
> other attached packages:
> [1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.6  zoo_1.7-6
>
> loaded via a namespace (and not attached):
> [1] lattice_0.20-0
>
> I am using Windows 7 (home version) with 4 GB of RAM (2.16GB is usable as
> my
> computer reports). So in my case, is it not possible to generate a random
> vector with such length? Note that generating such vector is my primary
> job.
> Later I need to do something on that vector. Those Job includes:
> 1. Create a matrix with 50,000 rows.
> 2. Get the row sum
> 3. then report some metrics on that sum values (min. 50,000 elements must
> be
> there).
>
> Can somebody help me with some real solution/suggesting?
>
> Thanks and regards,
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Memory allocation problem (again!)

2012-02-08 Thread Ernest Adrogué
 8-02-2012, 22:22 (+0545); Christofer Bogaso escriu:
> And the Session info is here:
> 
> > sessionInfo()
> R version 2.14.0 (2011-10-31)
> Platform: i386-pc-mingw32/i386 (32-bit)

Not an expert, but I think that 32-bit applications can only address
up to 2GB on Windows.

-- 
Bye,
Ernest

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

2012-02-08 Thread oluwole oyebamiji
Hi all,
     I want to do a linear regression with lm package in MASS, my data is 59199 
rows by 29 column.
I got this error message can not allocate a vector of size 1.5Gb.
I have read some of the previous related posting on this but I couldnt still 
got it right.

I have an Ubuntu machine of 64bit and 4Gb ram. 

Any suggestion please.
 
Oyebamiji Oluwole









[[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] search tutorial for function "tt" in cox.zph

2012-02-08 Thread johann . delcourt
Hye,

I am writing to request your help. 

I am working on survival curve analysis with Cox model (cox.zph). After to test 
the proportionality condition for each covariant (independence to the time), 
the time effect is very significant and I must adapt my model, by the addition 
of a function dependent on the time for each time-dependent covoriant. My 
problem is I don’t know how determine this function. It seems there is a 
function “tt” in R which can help to find this function and integrate it in my 
Cox model.

I am searching a good tutorial (or book reference) with example(s) to 
understand and apply the function “tt” in R;

Thanks in advance

Johann Delcourt

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] library(forecast): Error in SD.test(x, m) : Insufficient data

2012-02-08 Thread Jean Jacques Dureau
Hi rainer,
how can I control  dependend packages?

thanks

jj

Il 08 febbraio 2012 17:10, Rainer Hurling  ha scritto:
> On 08.02.2012 15:35 (UTC+1), Jean Jacques Dureau wrote:
>>
>> I have these R code:
>>
>>
>> ###
>> time.test.data<-c(2.88645418326693, 2.91546949823027, 2.94130799329234,
>>   2.93313338038109, 2.89478957915832, 2.86029757243540, 2.78648486664669,
>>   2.80183167535133, 2.75435512226307, 2.78992352676563, 2.76028433151845,
>>   2.68741721854305, 2.70691974293828, 2.683833847881, 2.65041551246537,
>>   2.65169020111254, 2.58837541686517, 2.66549241844080, 2.58451314648945,
>>   2.60250871080139, 2.61253722876188, 2.59921041087878, 2.71727961060032,
>>   2.65440192667915, 2.74799149338374, 2.70649994101687, 2.80636027009366,
>>   2.81801086502298, 2.82555635319454, 2.87133347201997, 2.75746714456392,
>>   2.7660659236424, 2.71688375522241, 2.72655367231638, 2.72461997828447,
>>   2.78455790784558, 2.71160702495708, 2.65754456439869, 2.85673280918507,
>>   2.7053919591233, 2.7532637075718, 2.74272237196766, 2.75893306492199,
>>   2.62584686181772, 2.75230602278893, 2.82781018027572, 2.80220656652931,
>>   2.80242587601078, 2.84061953534849, 2.87123514783089, 2.76991605276683,
>>   2.77796934865900)
>>
>> library(forecast)
>> auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
>>
>> ###
>
>
> This looks good to me, I got no error:
>
> auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
> Series: ts(time.test.data, start = c(2011, 1), frequency = 52)
> ARIMA(2,0,2) with non-zero mean
>
> Coefficients:
>         ar1      ar2      ma1     ma2  intercept
>      1.4540  -0.5762  -1.0235  0.5484     2.7569
> s.e.  0.3351   0.3194   0.3240  0.1902     0.0328
>
> sigma^2 estimated as 0.003059:  log likelihood=76.05
> AIC=-140.09   AICc=-138.23   BIC=-128.38
>
>
> So perhaps something is wrong with your data object or with your dependend
> packages?
>
>
>> I obtain the error message:
>> Error in SD.test(x, m) : Insufficient data
>>
>> What is wrong?
>>
>> jj
>
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find a row identical to another

2012-02-08 Thread Petr Savicky
On Wed, Feb 08, 2012 at 03:36:45PM +0100, Francisco wrote:
> Hello,
> I have a dataset with many rows, starting from a row that I choose I 
> would like to find the other rows in the dataset which are identical to 
> this row (with the same values per each column) and assign them to a 
> variable.
> How could I do?

Hello:

Try the following.

  # prepare a data frame
  df1 <- expand.grid(x=1:2, y=letters[1:2])
  df <- rbind(df1, df1, df1)

  # look for later occurences of df[i, ]
  i <- 6
  ind <- unname(which(rowSums(df == df[rep(i, times=nrow(df)), ]) == ncol(df)))
  ind[ind >= i]

  [1]  6 10

Hope this helps.

See also duplicated(df). This finds all duplicates,
not only duplicates of a given row.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Force printing of excluded axis annotations

2012-02-08 Thread Justin Fincher
Howdy,
   This should be simple, but I am finding that I can't find a simple
solution.  I have a plot to which I am manually adding the annotations
to the y-axis with this command:

axis(2, 
c(-4,-3,-2,-1,0,1,2,3,4,5,6,7),labels=c(-4,-3,-2,-1,0,1,2,3,4,5,6,7),cex.axis=8)

The issue is that, apparently, R doesn't think that the -1 can fit,
even though there is most certainly enough space.  Is there a way to
force R to print all the annotations I give it, regardless of
proximity or to reduce the space it believes it needs? Thank you.

- Fincher

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

2012-02-08 Thread Petr Savicky
On Wed, Feb 08, 2012 at 06:17:40AM -0800, n wrote:
> Hi,
> 
> How can I draw a random sample from a truncated distribution (especially
> lognormal)?
>
> I found the functions for truncated normal but not for many other
> distributions.

Hi.

A variable Y with a log-normal distribution may be obtained as
Y = exp(X), where X has a normal distribution. Since exp() is
monotone, a truncated Y may be generated as exp(X'), where X' has
an appropriate truncated normal distribution.

A general method for continuous distributions uses the inverse of
the distribution function. If p(x) is the distribution function
of some distribution and f(x) is its inverse function, then the
truncated distribution to an interval [a, b] may be obtained as

   f(runif(n, min=p(a), max=p(b)))

Hope this helps.

Petr Savicky.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 in Rd[[which]] : subscript out of bounds

2012-02-08 Thread Ben Ganzfried
Hi--

I googled the above error and found previous postings about this error on
the list.  I was having a little difficulty implementing the advice though.
 The suggestions were to use: traceback() and checkRd().  I'm using R in
the directory in which the .Rd file with the problem is located, but I'm
having difficulty figuring out how to proceed.  I've looked through the
help pages for traceback() and checkRd(), and would greatly appreciate any
advice for how to find the errors and fix them.

The specific error I am getting when trying to check my package is:

* checking Rd files ... WARNING
Error in Rd[[which]] : subscript out of bounds

problem found in ‘curatedData-package.Rd’

Thanks in advance!

Ben

[[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] fixed effects with clustered standard errors

2012-02-08 Thread Millo Giovanni
Dear John,

interesting. There must be a bottleneck somewhere, which possibly went
unnoticed because econometricians seldom use so many data points. In
fact 'plm' wasn't designed to handle "only" 700 Megs of data at a time;
but we're happy to investigate in this direction too. E.g., I was aware
of some efficiency problems if effect="twoways" but I seem to understand
that you are using effect="individual"? --> which takes me to the main
point.

I understand that enclosing the data for a reproducible report, as
requested by the posting guide, is awkward for such a big dataset. Yet
it would be of great help if you at least produced:

- an output of your procedure, in order to see what goes wrong and where
- the output of traceback() called immediately after you got the error
(idem)

and possibly gave it a try with lm() applied to the very same formula
and data, maybe into a system.time( ... ) statement.

Else, the information you provide is way too scant to even make an
educated guess. For example, it isn't clear whether the problem is
related to plm() or to vcovHC.plm etc.

As far as "simple demeaning" is concerned, you might try the following
code, which really does only that. Be aware that **standard errors are
biased** etc. etc., this is not meant to be a proper function but just a
computational test for your data and a quick demonstration of demeaning.
'plm()' is far more structured, for a number of reasons. Please execute
it inside system.time() again.

# test function for within model, BIASED SEs !! #
##
## ## example:
## data(Produc, package="plm")
## mod <- FEmod(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
index=Produc$state, data=Produc)
## summary(mod)
## ## compare with:
## library(plm)
## example(plm)

demean<-function(x,index,lambda=1,na.rm=F) {
 
as.vector(x-lambda*tapply(x,index,mean,na.rm=na.rm)[unclass(as.factor(in
dex))])
  }
FEmod<-function(formula,index,data=ls()) {

  ## fit a model without intercept in any case
  formula<-as.formula(paste(deparse(formula(formula)),"-1",sep=""))
  X<-model.matrix(formula,data=data)
  y<-model.response(model.frame(formula,data=data))
  ## reduce index accordingly
  names(index)<-row.names(data)
  ind<-index[which(names(index)%in%row.names(X))]

  ## within transf.  
  MX<-matrix(NA,ncol=dim(X)[[2]],nrow=dim(X)[[1]])
  for(i in 1:dim(X)[[2]]) {
MX[,i]<-demean(X[,i],index=ind,lambda=1)
}
  My<-demean(y,index=ind,lambda=1)

  ## estimate within model
  femod<-lm(My~MX-1)

  return(femod)
}
### end test function 


Best,
Giovanni

### original message #

--

Message: 28
Date: Tue, 07 Feb 2012 15:35:07 +0100
From: caribou...@gmx.fr
To: r-help@r-project.org
Subject: [R] fixed effects with clustered standard errors
Message-ID: <20120207143507.142...@gmx.com>
Content-Type: text/plain; charset="utf-8"

Dear R-helpers,

I have a very simple question and I really hope that someone could help
me

I would like to estimate a simple fixed effect regression model with
clustered standard errors by individuals.
For those using Stata, the counterpart would be xtreg with the "fe"
option, or areg with the "absorb" option and in both case the clustering
is achieved with "vce(cluster id)"

My question is : how could I do that with R ? An important point is that
I have too many individuals, therefore I cannot include dummies and
should use the demeaning "usual" procedure.
I tried with the plm package with the "within" option, but R quikcly
tells me that the memory limits are attained (I have over 10go ram!)
while the dataset is only 700mo (about 50 000 individuals, highly
unbalanced)
I dont understand... plm do indeed demean the data so the computation
should be fast and light enough... ?!

Are there any other solutions ?
Many thanks in advance ! ;)
John


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

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

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

2012-02-08 Thread R. Michael Weylandt
It's compiled code so you can't view it in R. Download the source from CRAN (in 
your browser, not through R), decompress it, and look through the src/ 
directory with your favorite text editor. 

Michael

On Feb 8, 2012, at 8:51 AM, "J. Augusiak"  wrote:

> Dear R list,
> 
> I have a package downloaded and looked up a function in there. Now I find
> that it uses C code (.C call) to do part of its job.
> 
> However, when I wanted to look that part up by using getAnywhere()  I was
> told that no object of that name could be found. Then I tried typing C.("
> funct.name") which only caused R to crash.
> 
> Is there any way to look up the function?
> 
> I'm not an expert and don't understand much of the technicalities mentioned
> in the  Writing-R-extensions manual. I only would like to see how the
> method I think is used is actually implemented.
> 
> I use R.2.13.1, Windows 7. The package I'm referring to is adehabitatLT,
> function acfang.ltraj -> res <- .C("acfangl",...)
> 
> Many thanks in advance!
> 
> Jacqueline
> 
>[[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] String position character replacement

2012-02-08 Thread Yang, Joy (NIH/NHGRI) [F]
Hi,

Is there a way to efficiently replace specified indices in a string with 
another character? For example, if I had a vector of strings such as

[1] "hellohowareyoudoing"
[2] "imgoodhowareyou"
[3] "goodandyou"
[4] "yesimgoodijusttoldyou"
[5] "ohyesthatsright"

and had a list of positions that I want to replace with the character "-"

[[1]]
[1]  3  9

[[2]]
[1]  3  4

[[3]]
[1]  4  7

[[4]]
[1] 5 6 7 8 9

[[5]]
[1]  2  5  7 12

I would like to get

[1] "he-lohow-reyoudoing"
[2] "im--odhowareyou"
[3] "goo-an-you"
[4] "yesi-ijusttoldyou"
[5] "o-ye-t-atsr-ght"

Is there an easy way to do this? Or would the easiest way be writing a function 
to take substrings of the original vector and pasting in the replacement 
character?

Thanks in advance!
Joy
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: Memory increase

2012-02-08 Thread Uwe Ligges



On 08.02.2012 17:14, oluwole oyebamiji wrote:

Hi all,
  I want to do a linear regression with lm package in MASS, my data is 
59199 rows by 29 column.
I got this error message can not allocate a vector of size 1.5Gb.
I have read some of the previous related posting on this but I couldnt still 
got it right.


Calculate the size of you model matrix. If the 29 columns are numeric, 
this should be a peace of cake, hence you probably model interactions or 
you are dealing with factors with several levels, so that you model 
matrix is huge. We cannot know that.


Uwe Ligges




I have an Ubuntu machine of 64bit and 4Gb ram.

Any suggestion please.

Oyebamiji Oluwole









[[alternative HTML version deleted]]




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


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


Re: [R] String position character replacement

2012-02-08 Thread Jorge I Velez
Hi Joy,

Perhaps not the easiest way, but the following seems to work:

x <- c("hellohowareyoudoing", "imgoodhowareyou", "goodandyou",
"yesimgoodijusttoldyou", "ohyesthatsright")
pos <- list(c(3, 9), c(3,4), c(4,7), 5:9, c(2, 5, 7, 12))

sapply(1:length(pos), function(i){
xx <- strsplit(x, "")[[i]]
xx[pos[[i]]] <- "-"
paste(xx, sep = "", collapse = "")
})

[1] "he-lohow-reyoudoing"   "im--odhowareyou"   "goo-an-you"
[4] "yesi-ijusttoldyou" "o-ye-t-atsr-ght"



On Wed, Feb 8, 2012 at 12:33 PM, Yang, Joy (NIH/NHGRI) [F] <> wrote:

> Hi,
>
> Is there a way to efficiently replace specified indices in a string with
> another character? For example, if I had a vector of strings such as
>
> [1] "hellohowareyoudoing"
> [2] "imgoodhowareyou"
> [3] "goodandyou"
> [4] "yesimgoodijusttoldyou"
> [5] "ohyesthatsright"
>
> and had a list of positions that I want to replace with the character "-"
>
> [[1]]
> [1]  3  9
>
> [[2]]
> [1]  3  4
>
> [[3]]
> [1]  4  7
>
> [[4]]
> [1] 5 6 7 8 9
>
> [[5]]
> [1]  2  5  7 12
>
> I would like to get
>
> [1] "he-lohow-reyoudoing"
> [2] "im--odhowareyou"
> [3] "goo-an-you"
> [4] "yesi-ijusttoldyou"
> [5] "o-ye-t-atsr-ght"
>
> Is there an easy way to do this? Or would the easiest way be writing a
> function to take substrings of the original vector and pasting in the
> replacement character?
>
> Thanks in advance!
> Joy
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] String position character replacement

2012-02-08 Thread Sarah Goslee
And here's an alternative solution:

subchar <- function(string, pos, char="-") {
for(i in pos) {
string <- gsub(paste("^(.{", i-1, "}).", sep=""), "\\1-", string)
}
string
}


> subchar("hellohowareyoudoing", 3)
[1] "he-lohowareyoudoing"

> subchar("hellohowareyoudoing", c(3, 9))
[1] "he-lohow-reyoudoing"

> avec <- c("hellohowareyoudoing", "imgoodhowareyou", "goodandyou", 
> "yesimgoodijusttoldyou", "ohyesthatsright")
> alist <- list(c(3, 9), c(3, 4), c(4, 7), c(5,6,7,8,9), c(2,5,7,12))

> sapply(1:length(avec), function(x)subchar(avec[x], alist[[x]]))
[1] "he-lohow-reyoudoing"   "im--odhowareyou"   "goo-an-you"
[4] "yesi-ijusttoldyou" "o-ye-t-atsr-ght"
>

Sarah


On Wed, Feb 8, 2012 at 12:33 PM, Yang, Joy (NIH/NHGRI) [F]
 wrote:
> Hi,
>
> Is there a way to efficiently replace specified indices in a string with 
> another character? For example, if I had a vector of strings such as
>
> [1] "hellohowareyoudoing"
> [2] "imgoodhowareyou"
> [3] "goodandyou"
> [4] "yesimgoodijusttoldyou"
> [5] "ohyesthatsright"
>
> and had a list of positions that I want to replace with the character "-"
>
> [[1]]
> [1]  3  9
>
> [[2]]
> [1]  3  4
>
> [[3]]
> [1]  4  7
>
> [[4]]
> [1] 5 6 7 8 9
>
> [[5]]
> [1]  2  5  7 12
>
> I would like to get
>
> [1] "he-lohow-reyoudoing"
> [2] "im--odhowareyou"
> [3] "goo-an-you"
> [4] "yesi-ijusttoldyou"
> [5] "o-ye-t-atsr-ght"
>
> Is there an easy way to do this? Or would the easiest way be writing a 
> function to take substrings of the original vector and pasting in the 
> replacement character?
>
> Thanks in advance!
> Joy


-- 
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] String position character replacement

2012-02-08 Thread Gabor Grothendieck
On Wed, Feb 8, 2012 at 12:33 PM, Yang, Joy (NIH/NHGRI) [F]
 wrote:
> Hi,
>
> Is there a way to efficiently replace specified indices in a string with 
> another character? For example, if I had a vector of strings such as
>
> [1] "hellohowareyoudoing"
> [2] "imgoodhowareyou"
> [3] "goodandyou"
> [4] "yesimgoodijusttoldyou"
> [5] "ohyesthatsright"
>
> and had a list of positions that I want to replace with the character "-"
>
> [[1]]
> [1]  3  9
>
> [[2]]
> [1]  3  4
>
> [[3]]
> [1]  4  7
>
> [[4]]
> [1] 5 6 7 8 9
>
> [[5]]
> [1]  2  5  7 12
>
> I would like to get
>
> [1] "he-lohow-reyoudoing"
> [2] "im--odhowareyou"
> [3] "goo-an-you"
> [4] "yesi-ijusttoldyou"
> [5] "o-ye-t-atsr-ght"
>
> Is there an easy way to do this? Or would the easiest way be writing a 
> function to take substrings of the original vector and pasting in the 
> replacement character?
>

Using this input:

pos <- list(c(3, 9), c(3, 4))
s <- c("hellohowareyoudoing", "imgoodhowareyou")

we can use regmatches like this where the lapply on the LHS constructs
a matches list and the lapply on the RHS constructs a list of "-"
characters:

f <- function(p) structure(p, match.length = rep(1, length(p)))
regmatches(s, lapply(pos, f)) <- lapply(pos, function(p) "-")

The resulting s is:

> s
[1] "he-lohow-reyoudoing" "im--odhowareyou"

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] Setting up infile for R CMD BATCH

2012-02-08 Thread ilai
Gang,
Maybe someone here has a different take on things. I'm afraid I have
no more insights on this unless you explain exactly what you are
trying to achieve, or more importantly why? That may help understand
what the problem really is.

Do you want to save an interactive session for future runs? then
?save.image and all your "answers" are in the environment. In this
case consider putting an "if(!exists('type') | length(type)<1 |
is.na(type))" before "type<- readline(...)"  in your script so type
wouldn't be overwritten in subsequent runs.

If your goal is to batch evaluate multiple answer files from users
(why else would you ask questions with readline?), then you should
have enough to go on with my answer and the examples in ?eval.

Elai


On Wed, Feb 8, 2012 at 9:04 AM, Gang Chen  wrote:
> Hi Elai,
>
> Thanks a lot for the suggestions! I really appreciate it...
>
> Your suggestion of using eval() and creating those answers in a list
> would work, but there is no alternative to readline() with which I
> could read the input in batch mode? I'm asking this because I'd like
> to have the program work in both interactive and batch mode.
>
> Thanks again,
> Gang
>
>
> On Wed, Feb 8, 2012 at 12:50 AM, ilai  wrote:
>> Ahh,
>> I think I'm getting it now. Well, readlines() is not going to work for
>> you. The help file ?readline clearly states "In non-interactive use
>> the result is as if the response was RETURN and the value is ‘""’."
>> The implication is you cannot use it to "insert" different answers as
>> if you were really there.
>> How about using eval() instead? You will need to make the answers a
>> named list (or just assigned objects).
>>
>> test <- expression({
>>  if(a>2) print('+')
>>  else print('I got more')
>>  b <- b+3   # reassign b in the environment
>>  print(b)
>>  print(c)
>>  d^2
>> })
>> dump('test',file='myTest.R') ; rm(test)
>>
>> # make the answers.R file:
>>
>> a=5 ; b=2 ; c=2 ; d=3
>> source("myTest.R")
>> eval(test)
>>
>> # Now, from the terminal  R CMD BATCH answers.R out.R
>> # And here is my $ cat out.R
>> ... flushed
>>> a=5 ; b=2 ; c=2 ; d=3
>>> source("myTest.R")
>>> eval(test)
>> [1] "+"
>> [1] 5
>> [1] 2
>> [1] 9
>>>
>>> proc.time()
>>   user  system elapsed
>>  0.640   0.048   0.720
>>
>> Would this work?
>> Elai
>>
>>
>>
>>
>> On Tue, Feb 7, 2012 at 4:05 PM, Gang Chen  wrote:
>>> Suppose I create an R program called myTest.R with only one line like
>>> the following:
>>>
>>> type <- as.integer(readline("input type (1: type1; 2: type2)? "))
>>>
>>> Then I'd like to run myTest.R in batch mode by constructing an input
>>> file called answers.R with the following:
>>>
>>> source("myTest.R")
>>> 1
>>>
>>> When I ran the following at the terminal:
>>>
>>> R CMD BATCH answer.R output.Rout
>>>
>>> it failed to pick up the answer '1' from the 2nd line in answers.R as
>>> shown inside output.Rout:
>>>
 source("myTest.R")
>>> input type (0: quit; 1: type1; 2: type2)?
 1
>>> [1] 1
>>>
>>> What am I missing here?
>>>
>>> Thanks in advance,
>>> Gang

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

2012-02-08 Thread Ron Michael
Dear all, let say I want to write a vector to a CSV file. So I can have 
following syntax:
 
write.csv(rnorm(10), "dat.csv")
 
Now I want to add one more column into that existing file. If I use the same 
code then existing file will be destroyed. Is there any functionality to add 
without destroying the existing file? I have tries with 'append = TRUE' however 
it is not working!
 
Any suggestion will be highly appreciated.

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

2012-02-08 Thread Yang, Joy (NIH/NHGRI) [F]
Thank you both! I was working along the lines of Jorge's method, but was taking 
longer than it should. Sarah's is actually a lot faster.

Thanks again,
Joy


From: Sarah Goslee [sarah.gos...@gmail.com]
Sent: Wednesday, February 08, 2012 1:30 PM
To: Yang, Joy (NIH/NHGRI) [F]
Cc: r-help@R-project.org
Subject: Re: [R] String position character replacement

And here's an alternative solution:

subchar <- function(string, pos, char="-") {
for(i in pos) {
string <- gsub(paste("^(.{", i-1, "}).", sep=""), "\\1-", string)
}
string
}


> subchar("hellohowareyoudoing", 3)
[1] "he-lohowareyoudoing"

> subchar("hellohowareyoudoing", c(3, 9))
[1] "he-lohow-reyoudoing"

> avec <- c("hellohowareyoudoing", "imgoodhowareyou", "goodandyou", 
> "yesimgoodijusttoldyou", "ohyesthatsright")
> alist <- list(c(3, 9), c(3, 4), c(4, 7), c(5,6,7,8,9), c(2,5,7,12))

> sapply(1:length(avec), function(x)subchar(avec[x], alist[[x]]))
[1] "he-lohow-reyoudoing"   "im--odhowareyou"   "goo-an-you"
[4] "yesi-ijusttoldyou" "o-ye-t-atsr-ght"
>

Sarah


On Wed, Feb 8, 2012 at 12:33 PM, Yang, Joy (NIH/NHGRI) [F]
 wrote:
> Hi,
>
> Is there a way to efficiently replace specified indices in a string with 
> another character? For example, if I had a vector of strings such as
>
> [1] "hellohowareyoudoing"
> [2] "imgoodhowareyou"
> [3] "goodandyou"
> [4] "yesimgoodijusttoldyou"
> [5] "ohyesthatsright"
>
> and had a list of positions that I want to replace with the character "-"
>
> [[1]]
> [1]  3  9
>
> [[2]]
> [1]  3  4
>
> [[3]]
> [1]  4  7
>
> [[4]]
> [1] 5 6 7 8 9
>
> [[5]]
> [1]  2  5  7 12
>
> I would like to get
>
> [1] "he-lohow-reyoudoing"
> [2] "im--odhowareyou"
> [3] "goo-an-you"
> [4] "yesi-ijusttoldyou"
> [5] "o-ye-t-atsr-ght"
>
> Is there an easy way to do this? Or would the easiest way be writing a 
> function to take substrings of the original vector and pasting in the 
> replacement character?
>
> Thanks in advance!
> Joy


--
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] R2WinBUGS error message

2012-02-08 Thread Uwe Ligges



On 07.02.2012 15:23, anaraster wrote:

Hi!

I am new to BUGS and running BUGS from R. I am trying to run a regression
model from R, however I have this error message:

Error in file(con, "wb") : cannot open the connection In addition: Warning
messages:

1: In file.create(to[okay]) :   cannot create file 'c:/Program
Files/WinBUGS14//System/Rsrc/Registry_Rsave.odc', reason 'Permission denied'

2: In file(con, "wb") :   cannot open file 'c:/Program
Files/WinBUGS14//System/Rsrc/Registry.odc': Permission denied

Can anyone help me out ?



R2WinBUGS tries to modify the mentioned files. That is not always 
required, hence R2WinBUGS just tries. If it fails, it continues and you 
may get perfect results.


If things won't work, ask your Sysadmin for write permissions on that files.

Uwe  Ligges



I am running R2WinBUGS from a windows 7 machine.

--
View this message in context: 
http://r.789695.n4.nabble.com/R2WinBUGS-error-message-tp4364838p4364838.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] syntax problem with formula / nls

2012-02-08 Thread Journals
I run into a slight syntax proble while using nls that seems to require 
some advice from the R community


I have a nonlinear regression problem where I observe the sum of the  
responses (y) of many individuals (X1  Xn). The properties (x1..xn) 
of these individuals have been measured but since the response is 
nonlinear I cannot use a mean individual to estimate the mean response 
of a population.  But I have reasonable reasons to assume that all 
individuals are responding in the same way.


In other words I want to estimate a function as in the last row of the 
example below. (Note, this is an artificial example and it does not 
converge (appart from having to few observations).


data<-as.data.frame(matrix(c(1,2,3,4,5,6,7,7,9,0,1,2,3,4,6, 9), nrow=4, 
ncol=4))

colnames(data)<-c("y","x1","x2","x3")

nonlin<-nls(y~a*(exp(b*x1)+exp(b*x2)+exp(b*x3))+c, start=list(a=1, b=2, 
c=3),

 data=data)

Now my problem is that I have 500 different x variables (x1  x500) 
for each y variable (and a few thousand of y observations) and I am 
stuck with the syntax problem of how to pass this as a formula to nls. 
Is there any way to define a formula that is passed to nls that would 
take an array of x values.


Cheers Frank

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


Re: [R] na.action in stats::factanal() must be using formula interface and dataframe input to specify na.action?

2012-02-08 Thread Uwe Ligges



On 06.02.2012 18:42, Timothy Bates wrote:

hi,
Does factanal() force the user to use the formula interface if they wish to 
specify an na.action?



Yes, as the help page says:

"na.action: The ‘na.action’ to be used if ‘x’ is used as a formula."

Uwe Ligges



v1<- c(1,1,1,1,1,1,1,1,NA,1,3,3,3,3,3,4,5,6)
v2<- c(1,2,1,1,1,1,2,1,2,1,3,NA,3,3,3,4,6,5)
v3<- c(3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,5,4,6)
v4<- c(3,3,4,NA,3,1,1,2,1,1,1,1,2,NA,1,5,6,4)
v5<- c(1,1,1,1,1,3,3,3,3,3,1,1,1,1,1,6,4,5)
v6<- c(1,1,1,2,1,3,3,3,4,3,1,1,1,2,1,6,5,4)
m1<- data.frame(cbind(v1,v2,v3,v4,v5,v6))
factOut = factanal(m1, factors = 1,scores = "Bartlett", na.action="na.exclude")
factOut = factanal(~v1+v2+v3+v4+v5+v6, data=m1, factors = 1,scores = "Bartlett", 
na.action="na.exclude")

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

2012-02-08 Thread Uwe Ligges



On 08.02.2012 20:14, Ron Michael wrote:

Dear all, let say I want to write a vector to a CSV file. So I can have 
following syntax:

write.csv(rnorm(10), "dat.csv")

Now I want to add one more column into that existing file. If I use the same 
code then existing file will be destroyed. Is there any functionality to add 
without destroying the existing file? I have tries with 'append = TRUE' however 
it is not working!

Any suggestion will be highly appreciated.


Since these text files are written line by line, you cannot add a column 
afterwards, you can just append rows.


Hence read the first column and write a two column data.frame afterwards.

Uwe Ligges



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Error in Rd[[which]] : subscript out of bounds

2012-02-08 Thread Uwe Ligges



On 08.02.2012 18:44, Ben Ganzfried wrote:

Hi--

I googled the above error and found previous postings about this error on
the list.  I was having a little difficulty implementing the advice though.
  The suggestions were to use: traceback() and checkRd().  I'm using R in
the directory in which the .Rd file with the problem is located, but I'm
having difficulty figuring out how to proceed.  I've looked through the
help pages for traceback() and checkRd(), and would greatly appreciate any
advice for how to find the errors and fix them.

The specific error I am getting when trying to check my package is:

* checking Rd files ... WARNING
Error in Rd[[which]] : subscript out of bounds


Which R version (assuming R-2.14.1 or R-devel)? Can you make the file 
available?


Uwe Ligges




problem found in ‘curatedData-package.Rd’

Thanks in advance!

Ben

[[alternative HTML version deleted]]




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


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


Re: [R] syntax problem with formula / nls

2012-02-08 Thread Uwe Ligges



On 08.02.2012 19:32, Journals wrote:

I run into a slight syntax proble while using nls that seems to require
some advice from the R community

I have a nonlinear regression problem where I observe the sum of the
responses (y) of many individuals (X1  Xn). The properties (x1..xn)
of these individuals have been measured but since the response is
nonlinear I cannot use a mean individual to estimate the mean response
of a population. But I have reasonable reasons to assume that all
individuals are responding in the same way.

In other words I want to estimate a function as in the last row of the
example below. (Note, this is an artificial example and it does not
converge (appart from having to few observations).

data<-as.data.frame(matrix(c(1,2,3,4,5,6,7,7,9,0,1,2,3,4,6, 9), nrow=4,
ncol=4))
colnames(data)<-c("y","x1","x2","x3")

nonlin<-nls(y~a*(exp(b*x1)+exp(b*x2)+exp(b*x3))+c, start=list(a=1, b=2,
c=3),
data=data)

Now my problem is that I have 500 different x variables (x1  x500)
for each y variable (and a few thousand of y observations) and I am
stuck with the syntax problem of how to pass this as a formula to nls.
Is there any way to define a formula that is passed to nls that would
take an array of x values.


You can construct a formula programmatically (as.formula on a string 
generated by paste, for example), but I doubt you will manage to 
estimate a nonlinear model with 500 variables easily (!) 


Uwe Ligges




Cheers Frank

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Force printing of excluded axis annotations

2012-02-08 Thread Uwe Ligges



On 08.02.2012 17:43, Justin Fincher wrote:

Howdy,
This should be simple, but I am finding that I can't find a simple
solution.  I have a plot to which I am manually adding the annotations
to the y-axis with this command:

axis(2, 
c(-4,-3,-2,-1,0,1,2,3,4,5,6,7),labels=c(-4,-3,-2,-1,0,1,2,3,4,5,6,7),cex.axis=8)

The issue is that, apparently, R doesn't think that the -1 can fit,
even though there is most certainly enough space.  Is there a way to
force R to print all the annotations I give it, regardless of
proximity or to reduce the space it believes it needs? Thank you.



If you really want to plot all and R thinks it dos not fit although you 
believe it does, you can plot in two sets (first even, then odd numbers, 
for example).


Uwe Ligges



- Fincher

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

2012-02-08 Thread Uwe Ligges
I (and you as well) should have seen that before: use write.table in 
order to append. The reason for that is given in ?write.table / ?write.csv:


 ‘write.csv’ and ‘write.csv2’ provide convenience wrappers for
 writing CSV files.  They set ‘sep’ and ‘dec’ (see below), ‘qmethod
 = "double"’, and ‘col.names’ to ‘NA’ if ‘row.names = TRUE’ (the
 default) and to ‘TRUE’ otherwise.

 ‘write.csv’ uses ‘"."’ for the decimal point and a comma for the
 separator.

 ‘write.csv2’ uses a comma for the decimal point and a semicolon
 for the separator, the Excel convention for CSV files in some
 Western European locales.

 These wrappers are deliberately inflexible: they are designed to
 ensure that the correct conventions are used to write a valid
 file.  Attempts to change ‘append’, ‘col.names’, ‘sep’, ‘dec’ or
 ‘qmethod’ are ignored, with a warning.


Uwe Ligges


On 08.02.2012 20:29, Ron Michael wrote:

Okay, so I understood that appending can only happen row-wise. Therefore I 
tried with following code:


write.csv(matrix(1:5, 1), "dat.csv")
write.csv(matrix(1:5, 1), "dat.csv", append = TRUE)

Warning message:
In write.csv(matrix(1:5, 1), "dat.csv", append = TRUE) :
   attempt to set 'append' ignored

It is destroying my previous file. Where I have done wrong?

Thanks,


- Original Message -
From: Uwe Ligges
To: Ron Michael
Cc: "r-help@r-project.org"
Sent: Thursday, 9 February 2012 1:07 AM
Subject: Re: [R] Wriritng to a CSV file



On 08.02.2012 20:14, Ron Michael wrote:

Dear all, let say I want to write a vector to a CSV file. So I can have 
following syntax:

write.csv(rnorm(10), "dat.csv")

Now I want to add one more column into that existing file. If I use the same 
code then existing file will be destroyed. Is there any functionality to add 
without destroying the existing file? I have tries with 'append = TRUE' however 
it is not working!

Any suggestion will be highly appreciated.


Since these text files are written line by line, you cannot add a column
afterwards, you can just append rows.

Hence read the first column and write a two column data.frame afterwards.

Uwe Ligges



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Setting up infile for R CMD BATCH

2012-02-08 Thread Gang Chen
Sorry Elai for the confusions.

Let me try to reframe my predicament. The main program "myTest.R" has
been written in interactive mode with many readline() lines embedded.
Suppose a user has already run the program once before in interactive
mode with all the answers saved in a text file called answer.R. Now
s/he does not want to go through the interactive again because it's a
tedious process, and would like to run the program but in batch mode
with answer.R. And that's why I tried the following which didn't pan
out:

R CMD BATCH answer.R output.Rout

Of couse I could rewrite a separate program specifically for batch
mode as you suggested previously with eval(), for example. However, is
there an approach to keeping the original program so that the user
could run both interactive and batch mode? That probably requires
modifying the readline() part, but how?

Thanks,
Gang


On Wed, Feb 8, 2012 at 2:08 PM, ilai  wrote:
> Gang,
> Maybe someone here has a different take on things. I'm afraid I have
> no more insights on this unless you explain exactly what you are
> trying to achieve, or more importantly why? That may help understand
> what the problem really is.
>
> Do you want to save an interactive session for future runs? then
> ?save.image and all your "answers" are in the environment. In this
> case consider putting an "if(!exists('type') | length(type)<1 |
> is.na(type))" before "type<- readline(...)"  in your script so type
> wouldn't be overwritten in subsequent runs.
>
> If your goal is to batch evaluate multiple answer files from users
> (why else would you ask questions with readline?), then you should
> have enough to go on with my answer and the examples in ?eval.
>
> Elai
>
>
> On Wed, Feb 8, 2012 at 9:04 AM, Gang Chen  wrote:
>> Hi Elai,
>>
>> Thanks a lot for the suggestions! I really appreciate it...
>>
>> Your suggestion of using eval() and creating those answers in a list
>> would work, but there is no alternative to readline() with which I
>> could read the input in batch mode? I'm asking this because I'd like
>> to have the program work in both interactive and batch mode.
>>
>> Thanks again,
>> Gang
>>
>>
>> On Wed, Feb 8, 2012 at 12:50 AM, ilai  wrote:
>>> Ahh,
>>> I think I'm getting it now. Well, readlines() is not going to work for
>>> you. The help file ?readline clearly states "In non-interactive use
>>> the result is as if the response was RETURN and the value is ‘""’."
>>> The implication is you cannot use it to "insert" different answers as
>>> if you were really there.
>>> How about using eval() instead? You will need to make the answers a
>>> named list (or just assigned objects).
>>>
>>> test <- expression({
>>>  if(a>2) print('+')
>>>  else print('I got more')
>>>  b <- b+3   # reassign b in the environment
>>>  print(b)
>>>  print(c)
>>>  d^2
>>> })
>>> dump('test',file='myTest.R') ; rm(test)
>>>
>>> # make the answers.R file:
>>>
>>> a=5 ; b=2 ; c=2 ; d=3
>>> source("myTest.R")
>>> eval(test)
>>>
>>> # Now, from the terminal  R CMD BATCH answers.R out.R
>>> # And here is my $ cat out.R
>>> ... flushed
 a=5 ; b=2 ; c=2 ; d=3
 source("myTest.R")
 eval(test)
>>> [1] "+"
>>> [1] 5
>>> [1] 2
>>> [1] 9

 proc.time()
>>>   user  system elapsed
>>>  0.640   0.048   0.720
>>>
>>> Would this work?
>>> Elai
>>>
>>>
>>>
>>>
>>> On Tue, Feb 7, 2012 at 4:05 PM, Gang Chen  wrote:
 Suppose I create an R program called myTest.R with only one line like
 the following:

 type <- as.integer(readline("input type (1: type1; 2: type2)? "))

 Then I'd like to run myTest.R in batch mode by constructing an input
 file called answers.R with the following:

 source("myTest.R")
 1

 When I ran the following at the terminal:

 R CMD BATCH answer.R output.Rout

 it failed to pick up the answer '1' from the 2nd line in answers.R as
 shown inside output.Rout:

> source("myTest.R")
 input type (0: quit; 1: type1; 2: type2)?
> 1
 [1] 1

 What am I missing here?

 Thanks in advance,
 Gang

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


Re: [R] using file in hdfs for data mining algorithms in r

2012-02-08 Thread Uwe Ligges



On 06.02.2012 12:29, Karthi KN wrote:

hi all, i am new to r


It is called R - well, everything lower case, shift key is broken?

 , i am trying to run data mining algorithms using map

reduce framework.. *
*i have few basic doubts*

*1. can i give file in hdfs to kmeans( ) ?  ?I tried as

file1 = hdfs.file("testdata/synthetic_control.data")


R> file1 = hdfs.file("testdata/synthetic_control.data")
Error: could not find function "hdfs.file"

???

Uwe Ligges



isf = hdfs.read(lsf,5242880,0)
l = kmeans(isf,2,10)


its not working..  please help

2. How to access the file in hdfs and give as input to algorithms ?

please reply..

Regards,
./T.karthik*
*

[[alternative HTML version deleted]]

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


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


Re: [R] Problem with plotting a square 1 x 3 plot and placement of outer margin text

2012-02-08 Thread Uwe Ligges



On 07.02.2012 16:03, Mark Na wrote:

Dear R-helpers,

Please see the attached plot.

The problem is that I have too much space between the x-axis label
(which is mtext in an outer margin) and the plots.

My par settings for this plot are:


par(mfrow=c(1,3),oma=c(2,2,2,2),mar=c(5.1,4.1,4.1,2.1),pty="s")
#here is the code that produces the three plots, which I have deleted for 
simplicity
mtext("Log Wetland Area",side=1,outer=TRUE)


It works fine (less space between plots and outer margin text)) when I
set pty="m" but then I get very long and skinny rectangular plots. I
would like to keep the square plots.


Then you have to size the device in a way that it is roughly 3 times as 
wide as its height?


Uwe



Any help would be much appreciated!

Many thanks,

Mark



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


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


[R] How to stop a loop for?

2012-02-08 Thread Juan Andres Hernandez
Hi all, I have some time trying to find a way to stop a loop for( ) until the
user presses the enter key or any other one and the loop can continue.
This could
be an example:

 library(MASS)
 data <- data.frame(mvrnorm(1000,rep(0,5),Sigma=diag(1,5)))
 for(i in 1:dim(data)[2]){
  plot(density(data[,i]), main=paste('histogram',i))
 #here something like waituntil command
 }

Thank's in advance
Juan A. Hernandez
Spain.

[[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] Hinton Diagram for a matrix of weights

2012-02-08 Thread Stephen Eglen

>> On 12/08/2011 03:45 AM, Xavier Fernández i Marín wrote:
>> > Hello,
>> >
>> > Although I have used a general search engine, r-seek, and browsed
>> > CRAN for contributed packages and R Gallery, I have not been able
>> > to find an implementation of Hinton Diagrams for representing
>> > weighting matrices using R.
>> >
>> > Does anyone knows a way of plotting weighting matrices in R?
>> >
>> Hi Xavier,
>> The Hinton diagram looks fairly close to an image plot, or the 
>> color2D.matplot function. The difference is that the area of the squares 
>> in the Hinton plot are proportional to some value rather than the color, 
>> which indicates the sign of the value. If you have no luck finding this, 
>> I think I could easily morph color2D.matplot into a Hinton diagram 
>> function.
>
> Just for future reference and searches, the Hinton diagram has been
> implemented in the color2D.matplot function of the plotrix package.
>
> Thank you Jim.

There is a great new book called 'Principles of Computational Modelling
in Neuroscience' which has some examples in R;  in particular in chapter
10 you will find code for 'Hinton plots' (also known as Willshaw
Plots).

http://www.compneuroprinciples.org/code-examples/10

Stephen

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


Re: [R] How to stop a loop for?

2012-02-08 Thread R. Michael Weylandt
A somewhat common idiom is to use readline() with "Please press
 to continue:" as the prompt and not to store the value
anywhere.

Michael

On Wed, Feb 8, 2012 at 2:45 PM, Juan Andres Hernandez
 wrote:
> Hi all, I have some time trying to find a way to stop a loop for( ) until the
> user presses the enter key or any other one and the loop can continue.
> This could
> be an example:
>
>  library(MASS)
>  data <- data.frame(mvrnorm(1000,rep(0,5),Sigma=diag(1,5)))
>  for(i in 1:dim(data)[2]){
>  plot(density(data[,i]), main=paste('histogram',i))
>  #here something like waituntil command
>  }
>
> Thank's in advance
> Juan A. Hernandez
> Spain.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] library(forecast): Error in SD.test(x, m) : Insufficient data

2012-02-08 Thread Rainer Hurling

On 08.02.2012 17:19 (UTC+1), Jean Jacques Dureau wrote:

Hi rainer,
how can I control  dependend packages?


You did not tell us very much about your installation and versions of 
packages you are using.


On my system sessionInfo() gives me the following after loading your 
example:


sessionInfo()
R Under development (unstable) (2012-02-07 r58290)
Platform: amd64-portbld-freebsd10.0 (64-bit)

locale:
[1] 
de_DE.ISO8859-15/de_DE.ISO8859-15/de_DE.ISO8859-15/C/de_DE.ISO8859-15/de_DE.ISO8859-15


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


other attached packages:
[1] forecast_3.17RcppArmadillo_0.2.34 Rcpp_0.9.9 fracdiff_1.4-0
[5] tseries_0.10-27  zoo_1.7-6quadprog_1.5-4

loaded via a namespace (and not attached):
[1] grid_2.15.0lattice_0.20-0


Here you can see, that package forecast uses other packages like 
RcppArmadillo, Rcpp, fracdiff and others. If your dataset 
'time.test.data' is ok, there is a (little) chance, that there are some 
not updated packages used by forecast.


But I am for sure not an expert on this. Perhaps someone else has an idea?

Rainer



thanks

jj

Il 08 febbraio 2012 17:10, Rainer Hurling  ha scritto:

On 08.02.2012 15:35 (UTC+1), Jean Jacques Dureau wrote:


I have these R code:


###
time.test.data<-c(2.88645418326693, 2.91546949823027, 2.94130799329234,
   2.93313338038109, 2.89478957915832, 2.86029757243540, 2.78648486664669,
   2.80183167535133, 2.75435512226307, 2.78992352676563, 2.76028433151845,
   2.68741721854305, 2.70691974293828, 2.683833847881, 2.65041551246537,
   2.65169020111254, 2.58837541686517, 2.66549241844080, 2.58451314648945,
   2.60250871080139, 2.61253722876188, 2.59921041087878, 2.71727961060032,
   2.65440192667915, 2.74799149338374, 2.70649994101687, 2.80636027009366,
   2.81801086502298, 2.82555635319454, 2.87133347201997, 2.75746714456392,
   2.7660659236424, 2.71688375522241, 2.72655367231638, 2.72461997828447,
   2.78455790784558, 2.71160702495708, 2.65754456439869, 2.85673280918507,
   2.7053919591233, 2.7532637075718, 2.74272237196766, 2.75893306492199,
   2.62584686181772, 2.75230602278893, 2.82781018027572, 2.80220656652931,
   2.80242587601078, 2.84061953534849, 2.87123514783089, 2.76991605276683,
   2.77796934865900)

library(forecast)
auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))

###



This looks good to me, I got no error:

auto.arima(ts(time.test.data, start=c(2011,1), frequency=52))
Series: ts(time.test.data, start = c(2011, 1), frequency = 52)
ARIMA(2,0,2) with non-zero mean

Coefficients:
 ar1  ar2  ma1 ma2  intercept
  1.4540  -0.5762  -1.0235  0.5484 2.7569
s.e.  0.3351   0.3194   0.3240  0.1902 0.0328

sigma^2 estimated as 0.003059:  log likelihood=76.05
AIC=-140.09   AICc=-138.23   BIC=-128.38


So perhaps something is wrong with your data object or with your dependend
packages?



I obtain the error message:
Error in SD.test(x, m) : Insufficient data

What is wrong?

jj


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

2012-02-08 Thread array chip
Hi, I am wondering if it is possible to get an estimate of standard error of 
the predicted posterior probability from LDA using lda() from MASS? Logistic 
regression using glm() would generate a standard error for predicted 
probability with se.fit=T argument in predict(), so would it make sense to get 
standard error for posterior probability from lda() and how?

Another question about standard error estimate from glm(): is it ok to 
calculate 95% CI for the predicted probability using the standard error based 
on normal apprximation, i.e. predicted_probability +/- 1.96 * standard_error?

Thanks

John
[[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] Error in Rd[[which]] : subscript out of bounds

2012-02-08 Thread Ben Ganzfried
Hi Uwe,

Thanks for the help.  R version 2.14.0 (2011-10-31).  The file in question
looks like this (w/ a few minor edits for privacy):

\name{curatedData-package}
\alias{curatedData-package}
\alias{curatedData}
\docType{package}
\title{Cancer Gene Expression Analysis}
\description{The curatedData package provides relevant functions and data
for gene expression analysis in cancer patients.}
\details{
\tabular{ll}{
Package: \tab curatedData\cr
Type: \tab Package\cr
Version: \tab 1.0\cr
Date: \tab 2012-2-03\cr
License: \tab Artistic-2.0\cr
Depends: \tab R (>= 2.10.0), affy\cr
}
}
\author{
Benjamin F. Ganzfried, et al.

Department of Biostatistics and Computational Biology, Dana-Farber Cancer
Institute, Harvard School of Public Health

Maintainer: ben.ganzfr...@gmail.com
}
\description{
Please refer to the following key.

For "summarygrade": low = 1, 2, LMP.  High= 3,4,23.

For "summarystage": early = 1,2, 12. late=3,4,23,34.

For "T": Stage (1-4).  If multiple stages given (eg 34), use the highest.

For "substage": substage (abcd).  For cases like ab, bc, use highest given.

For "G": Grade (1-4): If multiple given, ie 12, 23, use highest given.

For "N": N (0/1): degree of spread to regional lymph nodes.

For "M": M (0/1): presence of metastasis.

For "pltx": patient treated with platin.

For "tax": patient treated with taxol.

For "neo": patient treated with neoadjuvant treatment.

For "primary_therapy_outcome_success": response to any kind of therapy
(including radiation only).

For "chemo_response": platinum resistance: refractory=3mo or less,
resistant=6mo or less, sensitive=12mo or higher.

For "inferred_chemo_response": inferred platinum resistance:
refractory=death in 6mo or less, sensitive=survival for 12mo or more.

For "debulking": amount of residual disease (optimal = <1mm,
suboptimal=>1mm).
}




2012/2/8 Uwe Ligges 

>
>
> On 08.02.2012 18:44, Ben Ganzfried wrote:
>
>> Hi--
>>
>> I googled the above error and found previous postings about this error on
>> the list.  I was having a little difficulty implementing the advice
>> though.
>>  The suggestions were to use: traceback() and checkRd().  I'm using R in
>> the directory in which the .Rd file with the problem is located, but I'm
>> having difficulty figuring out how to proceed.  I've looked through the
>> help pages for traceback() and checkRd(), and would greatly appreciate any
>> advice for how to find the errors and fix them.
>>
>> The specific error I am getting when trying to check my package is:
>>
>> * checking Rd files ... WARNING
>> Error in Rd[[which]] : subscript out of bounds
>>
>
> Which R version (assuming R-2.14.1 or R-devel)? Can you make the file
> available?
>
> Uwe Ligges
>
>
>
>> problem found in ‘curatedData-package.Rd’
>>
>> Thanks in advance!
>>
>> Ben
>>
>>[[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] String position character replacement

2012-02-08 Thread Petr Savicky
On Wed, Feb 08, 2012 at 01:30:55PM -0500, Sarah Goslee wrote:
> And here's an alternative solution:
> 
> subchar <- function(string, pos, char="-") {
>   for(i in pos) {
>   string <- gsub(paste("^(.{", i-1, "}).", sep=""), "\\1-", string)
>   }
>   string
> }

Hi.

Try the following modification.

  subchar2 <- function(string, pos) {
for(i in pos) {
substr(string, i, i) <- "-"
}
string
  }

  avec <- c("hellohowareyoudoing", "imgoodhowareyou", "goodandyou", 
"yesimgoodijusttoldyou", "ohyesthatsright")
  alist <- list(c(3, 9), c(3, 4), c(4, 7), c(5,6,7,8,9), c(2,5,7,12))
  sapply(1:length(avec), function(x) subchar2(avec[x], alist[[x]]))

  [1] "he-lohow-reyoudoing"   "im--odhowareyou"   "goo-an-you"   
  [4] "yesi-ijusttoldyou" "o-ye-t-atsr-ght"  

Hope this helps.

Petr Savicky.

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

2012-02-08 Thread Sam Steingold
Suppose I have a vector of strings:
c("A1B2","A3C4","B5","C6A7B8")
[1] "A1B2"   "A3C4"   "B5" "C6A7B8"
where each string is a sequence of  pairs
(fixed width, in this example both value and name are 1 character, in
reality the column name is 6 chars and value is 2 digits).
I need to convert it to a data frame:
data.frame(A=c(1,3,0,7),B=c(2,0,5,8),C=c(0,4,0,6))
  A B C
1 1 2 0
2 3 0 4
3 0 5 0
4 7 8 6

how do I do that?
thanks.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://mideasttruth.com http://jihadwatch.org http://pmw.org.il
http://openvotingconsortium.org http://iris.org.il http://memri.org
What's the difference between Apathy & Ignorance? -I don't know and don't care!

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

2012-02-08 Thread Ron Michael
Okay, so I understood that appending can only happen row-wise. Therefore I 
tried with following code:
 
> write.csv(matrix(1:5, 1), "dat.csv")
> write.csv(matrix(1:5, 1), "dat.csv", append = TRUE)
Warning message:
In write.csv(matrix(1:5, 1), "dat.csv", append = TRUE) :
  attempt to set 'append' ignored

It is destroying my previous file. Where I have done wrong?
 
Thanks,


- Original Message -
From: Uwe Ligges 
To: Ron Michael 
Cc: "r-help@r-project.org" 
Sent: Thursday, 9 February 2012 1:07 AM
Subject: Re: [R] Wriritng to a CSV file



On 08.02.2012 20:14, Ron Michael wrote:
> Dear all, let say I want to write a vector to a CSV file. So I can have 
> following syntax:
>
> write.csv(rnorm(10), "dat.csv")
>
> Now I want to add one more column into that existing file. If I use the same 
> code then existing file will be destroyed. Is there any functionality to add 
> without destroying the existing file? I have tries with 'append = TRUE' 
> however it is not working!
>
> Any suggestion will be highly appreciated.

Since these text files are written line by line, you cannot add a column 
afterwards, you can just append rows.

Hence read the first column and write a two column data.frame afterwards.

Uwe Ligges


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

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


[R] How indices calculated in package "boot"

2012-02-08 Thread Deng Nina
Hi,there,

I am using R package "boot" to bootstrap. I have one question here: does
anybody possibly know how the boot package generates the "indices" which is
used in the statistic function?

I thought "indices = sample(data, replace=TRUE)", but when I replaced
"indices" with this command and used "boot", I got different results.

Specifically, below are the codes for illustration.

(1) The typical way by generating indices in the package:
boot1 <- function (data, indices)
{
 d <- data[indices]
 return(d)
}
AA <- c(1:10)
require(boot)
set.seed(123)
results1 <- boot(data= AA, statistic=boot1, R=100)

(2) The alternative way by calculating "indices" myself:
boot2 <- function (data,indices)
{
 indices <- sample(data, replace=TRUE)
 d <- data[indices]
 return(d)
 }
AA <- c(1:10)
set.seed(123)
results2 <- boot(data= AA, statistic=boot2, R=100)

When I looked up using results1$t and results2$t, I had totoally different
bootstrap samples. I found this even had great impacts on the results in my
study. Does the second approach have any problem? Anyone could provide any
inputs on this? Thank you very much in advance!
Regards
Nina

[[alternative HTML version deleted]]

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


[R] How to store the p value and number of events into a matrix

2012-02-08 Thread summer
Hi, there is p value and number of events from coxph results. How can I keep
record of every p value and number of events automatically if I run 100
times?
Another question is how can I change the true or faulse statment to 1 and 0.
such as w=1<2, I want the value of w to be 1 not true.
Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-store-the-p-value-and-number-of-events-into-a-matrix-tp4370833p4370833.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] "unsparse" a vector

2012-02-08 Thread Sam Steingold
To be clear, I can do that with nested for loops:

v <- c("A1B2","A3C4","B5","C6A7B8")
l <- strsplit(gsub("(.{2})","\\1,",v),",")
d <- data.frame(A=vector(length=4,mode="integer"),
B=vector(length=4,mode="integer"),
C=vector(length=4,mode="integer"))

for (i in 1:length(l)) {
  l1 <- l[[i]]
  for (j in 1:length(l1)) {
d[[substring(l1[j],1,1)]][i] <- as.numeric(substring(l1[j],2,2))
  }
}


but I am afraid that handling 1,000,000 (=length(unlist(l))) strings in
a loop will kill me.


> * Sam Steingold  [2012-02-08 15:34:38 -0500]:
>
> Suppose I have a vector of strings:
> c("A1B2","A3C4","B5","C6A7B8")
> [1] "A1B2"   "A3C4"   "B5" "C6A7B8"
> where each string is a sequence of  pairs
> (fixed width, in this example both value and name are 1 character, in
> reality the column name is 6 chars and value is 2 digits).
> I need to convert it to a data frame:
> data.frame(A=c(1,3,0,7),B=c(2,0,5,8),C=c(0,4,0,6))
>   A B C
> 1 1 2 0
> 2 3 0 4
> 3 0 5 0
> 4 7 8 6
>
> how do I do that?
> thanks.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://palestinefacts.org http://iris.org.il http://camera.org
http://ffii.org http://www.PetitionOnline.com/tap12009/
An elephant is a mouse with an operating system.

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

2012-02-08 Thread David Winsemius


On Feb 8, 2012, at 2:29 PM, Ron Michael wrote:

Okay, so I understood that appending can only happen row-wise.  
Therefore I tried with following code:



write.csv(matrix(1:5, 1), "dat.csv")
write.csv(matrix(1:5, 1), "dat.csv", append = TRUE)

Warning message:
In write.csv(matrix(1:5, 1), "dat.csv", append = TRUE) :
  attempt to set 'append' ignored

It is destroying my previous file. Where I have done wrong?


Failed to read the help page. `write.csv` has some of its setting hard  
coded and will prevent you from changing them. "append" happened to be  
in that list.


Here's the code it's right there for all to see:

Call <- match.call(expand.dots = TRUE)
for (argname in c("append", "col.names", "sep", "dec",  
"qmethod")) if (!is.null(Call[[argname]]))

warning(gettextf("attempt to set '%s' ignored", argname),
domain = NA)
--

David.


Thanks,


- Original Message -
From: Uwe Ligges 
To: Ron Michael 
Cc: "r-help@r-project.org" 
Sent: Thursday, 9 February 2012 1:07 AM
Subject: Re: [R] Wriritng to a CSV file



On 08.02.2012 20:14, Ron Michael wrote:
Dear all, let say I want to write a vector to a CSV file. So I can  
have following syntax:


write.csv(rnorm(10), "dat.csv")

Now I want to add one more column into that existing file. If I use  
the same code then existing file will be destroyed. Is there any  
functionality to add without destroying the existing file? I have  
tries with 'append = TRUE' however it is not working!


Any suggestion will be highly appreciated.


Since these text files are written line by line, you cannot add a  
column

afterwards, you can just append rows.

Hence read the first column and write a two column data.frame  
afterwards.


Uwe Ligges



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


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


David Winsemius, MD
West Hartford, CT

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


Re: [R] units for mapproject() function result

2012-02-08 Thread William Stockhausen
Hi Ray (& all),

Many apologies to Ray--apparently my intuition stinks!!  The projection is
based on the unit sphere (R=1), so the projected coordinates really are
dimensionless--as you said! So to scale up to the earth, just multiply
the projected coordinate values from mapproject by your favorite radius of
the earth.

I did try to track down the source code as listed in the mapproj help but
one link was broken and I wasn't able to find the function listing in
the "Plan 9" c code listings.

Best,

Buck
***
* Dr. William T. Stockhausen  *
***
* Resource Ecology and Fisheries Management   *
* Alaska Fisheries Science Center *
* National Marine Fisheries Service   *
* National Oceanic and Atmospheric Administration *
* 7600 Sand Point Way N.E.*
* Seattle, Washington 98115-6349  *
***
* email: william.stockhau...@noaa.gov *
* voice: 206-526-4241 fax: 206-526-6723   *
* web  : http://www.afsc.noaa.gov *
***
All models are wrong, some are useful.--G.E.P. Box
Beware of geeks bearing equations.--W. Buffett
***
Disclaimer: The opinions expressed above are personal
and do not necessarily reflect official NOAA policy.




On Wed, Feb 8, 2012 at 12:40 PM, Ray Brownrigg
wrote:

> Buck:
>
> [Note this is not sent to the list]
>
> I guess you have two options:
> 1) contact the author of the mapproj package for further information
> 2) read the source :-)
>
> Cheers,
> Ray
>
> On Thu, 09 Feb 2012, William Stockhausen wrote:
> > Hi Ray,
> >
> > Thanks for responding! However, it would certainly be very non-intuitive
> > if you're correct about the units for the projected coordinates.  As I'm
> > sure you know, in a GIS  geographic coordinates are usually in
> > degrees--although it's quite possible for these to be in radians
> instead, I
> > guess, since it saves converting degrees to radians when computing sines
> > and cosines--because these are coordinates that locate points on the
> > surface of a curved surface like a sphere or ellipsoid. Projected
> > coordinates, on the other hand, are ordinarily in some sort of physical
> > distance units like km or feet because they represent a projection of
> > points from the original curved surface onto a flat surface and include
> > effects due to the local radius of curvature of the surface.  I'd be
> really
> > surprised if the projected coordinates were in radians because they are
> > angular units (independent of the radius of curvature), not distance
> > units.  Still, it's possible.
> >
> > My problem is I've got vertices of a polygon in lat/lon coordinates
> > (degrees) and am trying to find the approximate area of the polygon (in
> > km^2 or some other physical units, hence the question about the units) by
> > projecting the coordinates of the vertices to planar coordinates using an
> > Albers projection and the mapproject function in the mapproj package.  If
> > you're correct about the units as radians, I guess I'd have to multiply
> the
> > area in radians^2 by R^2, where R is the radius of the earth, to get the
> > area in physical units.
> >
> > Best regards,
> >
> > Buck
> > On Tue, Feb 7, 2012 at 5:29 PM, Ray Brownrigg
> >
> > wrote:
> > > On Wed, 08 Feb 2012, William Stockhausen wrote:
> > > > Does anyone know  what the units are for projected coordinates
> obtained
> > > > using mapproj's mapproject function with an Albers projection?
>  Thanks
> > >
> > > for
> > >
> > > > any and all help!
> > > >
> > > > Buck Stockhausen
> > >
> > > I don't know for sure, but it looks like radians to me, with some
> > > unspecified
> > > origin(depending on the parameters specified).  Certainly the maps
> > > package data is
> > > specified in radians internally.
> > >
> > > Hope this helps,
> > > Ray Brownrigg
> >
> >   [[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.htmland
> >  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] "unsparse" a vector

2012-02-08 Thread Bert Gunter
I suspect there are cleverer ways to do it, especially using packages
like stringr and gsubfn, but using base tools, you can hack it without
too much effort:

?gregexpr

is the key. To get started (x is your example vector of character strings):

> gregexpr("[[:alpha:]]+[[:digit:]]+",x)
[[1]]
[1] 1 3
attr(,"match.length")
[1] 2 2
attr(,"useBytes")
[1] TRUE

[[2]]
[1] 1 3
attr(,"match.length")
[1] 2 2
attr(,"useBytes")
[1] TRUE

[[3]]
[1] 1
attr(,"match.length")
[1] 2
attr(,"useBytes")
[1] TRUE

[[4]]
[1] 1 3 5
attr(,"match.length")
[1] 2 2 2
attr(,"useBytes")
[1] TRUE

The components of the result give you indices of the start and stop
values for each "entry" in your final matrix/data frame. You can thus
lapply() on this list to get the column name-value pairs substrings
and decode them.

Alternatively, if all your names are really 6 characters and all your
values are really two digits,
?nchar and ?substring will get you the name-value substrings directly.

I leave the niggling details to you (or to other helpeRs -- especially
those who can suggest a more elegant approach).

-- Bert





On Wed, Feb 8, 2012 at 12:34 PM, Sam Steingold  wrote:
> Suppose I have a vector of strings:
> c("A1B2","A3C4","B5","C6A7B8")
> [1] "A1B2"   "A3C4"   "B5"     "C6A7B8"
> where each string is a sequence of  pairs
> (fixed width, in this example both value and name are 1 character, in
> reality the column name is 6 chars and value is 2 digits).
> I need to convert it to a data frame:
> data.frame(A=c(1,3,0,7),B=c(2,0,5,8),C=c(0,4,0,6))
>  A B C
> 1 1 2 0
> 2 3 0 4
> 3 0 5 0
> 4 7 8 6
>
> how do I do that?
> thanks.
>
> --
> Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 
> 11.0.11004000
> http://mideasttruth.com http://jihadwatch.org http://pmw.org.il
> http://openvotingconsortium.org http://iris.org.il http://memri.org
> What's the difference between Apathy & Ignorance? -I don't know and don't 
> care!
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


  1   2   >