Re: [R] Basic misunderstanding, or problem with my installation?

2013-12-31 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Sarah Goslee
> Sent: Tuesday, December 31, 2013 4:55 PM
> To: David Parkhurst
> Cc: r-help@r-project.org
> Subject: Re: [R] Basic misunderstanding, or problem with my
> installation?
> 
> Hi David,
> 
> Your code is showing up here with an arrow symbols. If it's an actual
> cut
> and paste, that's your problem: assignment in R is the two-character <-
> and
> not an arrow symbol.
> 
> Otherwise your code looks fine.
> 
> Sarah
> 
> On Tuesday, December 31, 2013, David Parkhurst wrote:
> 
> > I've just uninstalled and then reinstalled R on my windows 7 machine.
> > To test my understanding of data frames, I'm trying the following
> code.
> > (I plan to do other things with it, if it would only work.)
> > Here's the code, which seems pretty basic to me:
> > ls()
> > nums ← c(1,2,3,4,5)
> > ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> > df1 ← data.frame(nums,ltrs)
> >
> > Here's what happens when I try to run it:
> > > ls()
> > character(0)
> > > nums ← c(1,2,3,4,5)
> > Error: unexpected input in "nums \"
> > > ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> > Error: unexpected input in "ltrs \"
> > > df1 ← data.frame(nums,ltrs)
> > Error: unexpected input in "df1 \"
> > >
> >
> > Am I really misunderstanding the basics, or is there something
> > wrong with my installation?
> > David
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> > posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 

And after you get your assignment operator straightened out, you may need to 
change the quote marks in your character vector.  It looks like they may be 
"smart quotes" from a word processor, rather than the plain single or double 
quote marks that R will accept.

Dan

Daniel J. Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


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

2013-12-31 Thread John Sorkin
Fortune?
Where did lost variables go, with example

Sent from my iPhone

> On Dec 31, 2013, at 7:36 PM, "David Parkhurst " 
>  wrote:
> 
> Thank you.  I've tried what you're suggesting, at an earlier suggestion 
> from another respondent, and I don't find my variable in any of lists 
> ls() through ls(7).
> 
> I'm just going back to using R after being away from statistics for 
> several years.  I'm thinking I might uninstall R, then reinstall it, and 
> redo my work so far (I've kept the commands elsewhere), and avoid using 
> "attach," as someone else has suggested.
> 
> David
>> On 12/31/2013 11:32 AM, Duncan Murdoch wrote:
>>> On 13-12-31 9:48 AM, David Parkhurst wrote:
>>> Two or three respondents asked for an example of my problem.  Here's
>>> what's happening to me now.  I can't reproduce how I got to this point,
>>> though:
>>> 
 ls()
>>> [1] "All8"   "All8Sites"  "A"   "B"  "C"  "i"  "n"  "D"  "F"
 X
>>> Error: object 'X' not found
 attach(All8Sites)
 ls()
>>> [1] "All8"  "All8Sites"  "A"  "B"  "C"  "i"  "n"  "D"  "F"
>>> 
>>> 
>>> "X" is one of the variables in the data frame I attached in the third
>>> command above, but it's not listed by >ls().  If I enter > X now, its
>>> values ARE listed, but it's hiding somewhere.  What is happening here?
>>> How can I get the variables in that data frame listed when I attach it?
>> 
>> Use search() to see the search list.  Your dataframe will likely be in 
>> position 2.  Use ls(2) to see the variables there.
>> 
>> Duncan Murdoch
> 
> 
>[[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.
> 

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

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


Re: [R] Basic misunderstanding, or problem with my installation?

2013-12-31 Thread Sarah Goslee
Hi David,

Your code is showing up here with an arrow symbols. If it's an actual cut
and paste, that's your problem: assignment in R is the two-character <- and
not an arrow symbol.

Otherwise your code looks fine.

Sarah

On Tuesday, December 31, 2013, David Parkhurst wrote:

> I've just uninstalled and then reinstalled R on my windows 7 machine.
> To test my understanding of data frames, I'm trying the following code.
> (I plan to do other things with it, if it would only work.)
> Here's the code, which seems pretty basic to me:
> ls()
> nums ← c(1,2,3,4,5)
> ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> df1 ← data.frame(nums,ltrs)
>
> Here's what happens when I try to run it:
> > ls()
> character(0)
> > nums ← c(1,2,3,4,5)
> Error: unexpected input in "nums \"
> > ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> Error: unexpected input in "ltrs \"
> > df1 ← data.frame(nums,ltrs)
> Error: unexpected input in "df1 \"
> >
>
> Am I really misunderstanding the basics, or is there something
> wrong with my installation?
> David
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[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] Basic misunderstanding, or problem with my installation?

2013-12-31 Thread Gabor Grothendieck
On Tue, Dec 31, 2013 at 6:53 PM, David Parkhurst  wrote:
> I've just uninstalled and then reinstalled R on my windows 7 machine.
> To test my understanding of data frames, I'm trying the following code.
> (I plan to do other things with it, if it would only work.)
> Here's the code, which seems pretty basic to me:
> ls()
> nums ← c(1,2,3,4,5)
> ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> df1 ← data.frame(nums,ltrs)
>
> Here's what happens when I try to run it:
>> ls()
> character(0)
>> nums ← c(1,2,3,4,5)
> Error: unexpected input in "nums \"
>> ltrs ← c(“a”,”b”,”c”,”d”,”e”)
> Error: unexpected input in "ltrs \"
>> df1 ← data.frame(nums,ltrs)
> Error: unexpected input in "df1 \"
>>
>
> Am I really misunderstanding the basics, or is there something
> wrong with my installation?


The assignment operator is TWO characters: a less than sign
immediately followed by a minus sign.  Try copying and pasting this:

x <- 3
x

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


[R] Basic misunderstanding, or problem with my installation?

2013-12-31 Thread David Parkhurst

I've just uninstalled and then reinstalled R on my windows 7 machine.
To test my understanding of data frames, I'm trying the following code.
(I plan to do other things with it, if it would only work.)
Here's the code, which seems pretty basic to me:
ls()
nums ← c(1,2,3,4,5)
ltrs ← c(“a”,”b”,”c”,”d”,”e”)
df1 ← data.frame(nums,ltrs)

Here's what happens when I try to run it:
> ls()
character(0)
> nums ← c(1,2,3,4,5)
Error: unexpected input in "nums \"
> ltrs ← c(“a”,”b”,”c”,”d”,”e”)
Error: unexpected input in "ltrs \"
> df1 ← data.frame(nums,ltrs)
Error: unexpected input in "df1 \"
>

Am I really misunderstanding the basics, or is there something
wrong with my installation?
David

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


Re: [R] cumulative incidence for mstate in Survival package in R

2013-12-31 Thread Jieyue Li
Thanks a lot for the reply!

On Tue, Dec 31, 2013 at 1:59 AM, Göran Broström wrote:

> On 12/30/2013 11:04 PM, Jieyue Li wrote:
>
>> Dear All,
>>
>> I want to have the cumulative incidence curves for 'mstate' data using
>> Survival package in R. But I got some problems:
>> I. Problem 1:
>> 1. If I only use intercept without any covariates, I can have 'right'
>> cumulative incidence curves (2 for 2 competing risks):
>> library(Survival)
>>
>
> That shouldn't work;)

This is from an example from the Survival package...

>
>  fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate") ~
>> 1,data=mgus1, subset=(start==0))
>> plot(fitCI)
>> 2. If I include one variate ('sex'), I get 4 curves (attached; I guess
>> because there are two levels in 'sex' and 2 competing risks):
>> fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate")
>> ~sex,data=mgus1, subset=(start==0))
>> plot(fitCI)
>> However, I want to just have 2 cumulative incidence curves estimated from
>> several covariates (such as 'sex', 'age', 'alb', etc. in mgus1). Could you
>> please help me to do that? Thank you very much!
>>
>
> I suggest that you check the Task Views, under 'Survival' and 'Multistate
> Models', for instance the 'cmprsk' and 'timereg' packages.
>
>
>  II. Problem 2:
>> I try using an example from sourcecode.pdf:
>> fit <- survfit(Surv(time, status, type=’mstate’) ~ sex, data=mine)
>> but where can I have the 'mine' data? Thank you!
>>
>
> Where do you find 'sourcecode.pdf'?
>
It's from
http://stat.ethz.ch/R-manual/R-patched/library/survival/doc/sourcecode.pdf

>
> Göran Broström
>
>
>> Best,
>>
>> Jieyue
>>
>>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Where did lost variables go, with example

2013-12-31 Thread David Parkhurst
Thank you.  I've tried what you're suggesting, at an earlier suggestion 
from another respondent, and I don't find my variable in any of lists 
ls() through ls(7).

I'm just going back to using R after being away from statistics for 
several years.  I'm thinking I might uninstall R, then reinstall it, and 
redo my work so far (I've kept the commands elsewhere), and avoid using 
"attach," as someone else has suggested.

David
On 12/31/2013 11:32 AM, Duncan Murdoch wrote:
> On 13-12-31 9:48 AM, David Parkhurst wrote:
>> Two or three respondents asked for an example of my problem.  Here's
>> what's happening to me now.  I can't reproduce how I got to this point,
>> though:
>>
>>   > ls()
>> [1] "All8"   "All8Sites"  "A"   "B"  "C"  "i"  "n"  "D"  "F"
>>   > X
>> Error: object 'X' not found
>>   > attach(All8Sites)
>>   > ls()
>> [1] "All8"  "All8Sites"  "A"  "B"  "C"  "i"  "n"  "D"  "F"
>>
>>
>> "X" is one of the variables in the data frame I attached in the third
>> command above, but it's not listed by >ls().  If I enter > X now, its
>> values ARE listed, but it's hiding somewhere.  What is happening here?
>> How can I get the variables in that data frame listed when I attach it?
>
> Use search() to see the search list.  Your dataframe will likely be in 
> position 2.  Use ls(2) to see the variables there.
>
> Duncan Murdoch
>


[[alternative HTML version deleted]]

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


Re: [R] seq_len and loops

2013-12-31 Thread Göran Broström
Thanks for the answers from Duncan, Bill, Gabor, and Henrik. You 
convinced me that


1. The solution

if (x > 1){
   for (x in 2:x){
  ...

is the easiest, most effective,  and most easy-to-understand.

2. However, Bill (and Henrik)  raised the question of replacing '1' with 
'1L'; I understand the meaning of that, but does it matter (in practice)?


3. Noone commented upon

i <- 1
while (i < x){
   i <- i + 1
   ...
}

I suppose that it means that it is the best solution.

Thanks, and Happy New Year 2014!

Göran

On 12/22/2013 06:57 PM, William Dunlap wrote:

for (i in seq_len(x - 1) + 1)

should be efficient and safe.


Oops, not safe when x is 0.


Also, the '+ 1' should be '+ 1L' to get the same answer as
seq_len(x)[-1].

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of Duncan Murdoch
Sent: Saturday, December 21, 2013 3:52 PM
To: Göran Broström; R-help@r-project.org
Subject: Re: [R] seq_len and loops

On 13-12-21 6:50 PM, Duncan Murdoch wrote:

On 13-12-21 5:57 PM, Göran Broström wrote:

I was recently reminded on this list that

"Using 1:ncol() is bad practice (seq_len is designed for that purpose)"
(Ripley)

This triggers the following question: What is "good practice" for
2:ncol(x)? (This is not a joke; in a recursive situation it often makes
sense to perform the calculation for the start value i = 1, then
continue with a loop over the rest, "the Fortran way";)

I usually use

if (ncol(x) > 1)
for (i in 2:ncol(x)){
   

but I can think of

for (i in seq_len(x - 1)){
I <- i + 1
   

and

i <- 1
while (i < ncol(x)){
i <- i + 1


What is "good practice" (efficient and safe)?


for (i in seq_len(x - 1) + 1)

should be efficient and safe.


Oops, not safe when x is 0.

  >
A little less efficient, but clearer would be


for (i in seq_len(x)[-1])

Duncan Murdoch



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


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


Re: [R] cumulative incidence for mstate in Survival package in R

2013-12-31 Thread Göran Broström



On 12/31/2013 09:05 PM, Jieyue Li wrote:

Thanks a lot for the reply!

On Tue, Dec 31, 2013 at 1:59 AM, Göran Broström mailto:goran.brost...@umu.se>> wrote:

On 12/30/2013 11:04 PM, Jieyue Li wrote:

Dear All,

I want to have the cumulative incidence curves for 'mstate' data
using
Survival package in R. But I got some problems:
I. Problem 1:
1. If I only use intercept without any covariates, I can have
'right'
cumulative incidence curves (2 for 2 competing risks):
library(Survival)


That shouldn't work;)

This is from an example from the Survival package...


Sorry; the problem is that 'survival' should be with lower-case 's'




fitCI <- survfit(Surv(stop, status*as.numeric(event),
type="mstate") ~
1,data=mgus1, subset=(start==0))
plot(fitCI)
2. If I include one variate ('sex'), I get 4 curves (attached; I
guess
because there are two levels in 'sex' and 2 competing risks):
fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate")
~sex,data=mgus1, subset=(start==0))
plot(fitCI)
However, I want to just have 2 cumulative incidence curves
estimated from
several covariates (such as 'sex', 'age', 'alb', etc. in mgus1).
Could you
please help me to do that? Thank you very much!


I suggest that you check the Task Views, under 'Survival' and
'Multistate Models', for instance the 'cmprsk' and 'timereg' packages.


II. Problem 2:
I try using an example from sourcecode.pdf:
fit <- survfit(Surv(time, status, type=’mstate’) ~ sex, data=mine)
but where can I have the 'mine' data? Thank you!


Where do you find 'sourcecode.pdf'?

It's from
http://stat.ethz.ch/R-manual/R-patched/library/survival/doc/sourcecode.pdf


I see; that is a generic example, I suppose. The data set 'mine' is one 
of your choice! But, as I suggested, look into the packages listed under 
'Multistate models' in 'Survival' under 'Task Views'. What you ask for 
cannot be accomplished with the package 'survival'.


Göran Broström



Göran Broström


Best,

Jieyue



R-help@r-project.org  mailing list
https://stat.ethz.ch/mailman/__listinfo/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] Working with Date

2013-12-31 Thread arun
Hi,
Sorry, a correction:


fun1 <- function(months, Given_date){
 g1 <- format(Given_date, "%b")
 indx1 <- match(months,month.abb)
 indx2 <- match(g1, month.abb)
 yr <- as.numeric(format(Given_date,"%Y"))
if(any(indx1 < indx2)){
 ifelse(indx1 < indx2, paste(months, yr+1,sep="-"), paste(months, yr,sep="-")) 
}
else{
paste(months,yr,sep="-")
}
}

Given_Date2 <- as.Date("2014-01-04")

fun1(Months,Given_Date)
#[1] "Jan-2014" "Dec-2013" "Mar-2014"
 fun1(Months,Given_Date2)
#[1] "Jan-2014" "Dec-2014" "Mar-2014"

A.K.



On , arun  wrote:
Hi,
May be this helps:

fun1 <- function(months, Given_date){
 g1 <- format(Given_date, "%b")
 indx1 <- match(months,month.abb)
 indx2 <- match(g1, month.abb)
 yr <- as.numeric(format(Given_date,"%Y"))
if(any(indx1 < indx2)){
 ifelse(indx1 < indx2, paste(months, yr,sep="-"), paste(months, yr+1,sep="-"))
}

else{
paste(months,yr,sep="-")
} 
}

Given_Date2 <- as.Date("2014-01-04")
fun1(Months,Given_Date)
#[1] "Jan-2013" "Dec-2014" "Mar-2013"
 fun1(Months,Given_Date2)
#[1] "Jan-2014" "Dec-2014" "Mar-2014"
A.K.





On Tuesday, December 31, 2013 4:55 PM, Christofer Bogaso 
 wrote:
Hi again,

Happy new year 2014 to every R gurus and users.

I am struggling with some calculation with dates... Let say I have
following vector of months:

Months <- c("Jan", "Dec", "Mar")

Now I need to assign year with them. This assignment will be based on some
given date. Let say my given date is :

Given_Date <- as.Date("2013-12-23")

So in this case, the modified month will be:

Months_Mod <- c("Jan-2014", "Dec-2013", "Mar-2014")

However if given date is:

Given_Date <- as.Date("2014-01-04")

then the modified months will be:

Months_Mod <- c("Jan-2014", "Dec-2014", "Mar-2014")

My problem is that, I can not extablish some logic around it, so that I can
do it programmatically for any Month-vector and for any Given-date.

Can someone help me to accomplice this?

Thank for your help

    [[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] Working with Date

2013-12-31 Thread arun
Hi,
May be this helps:

fun1 <- function(months, Given_date){
 g1 <- format(Given_date, "%b")
 indx1 <- match(months,month.abb)
 indx2 <- match(g1, month.abb)
 yr <- as.numeric(format(Given_date,"%Y"))
if(any(indx1 < indx2)){
 ifelse(indx1 < indx2, paste(months, yr,sep="-"), paste(months, yr+1,sep="-"))
}

else{
paste(months,yr,sep="-")
} 
}

Given_Date2 <- as.Date("2014-01-04")
fun1(Months,Given_Date)
#[1] "Jan-2013" "Dec-2014" "Mar-2013"
 fun1(Months,Given_Date2)
#[1] "Jan-2014" "Dec-2014" "Mar-2014"
A.K.




On Tuesday, December 31, 2013 4:55 PM, Christofer Bogaso 
 wrote:
Hi again,

Happy new year 2014 to every R gurus and users.

I am struggling with some calculation with dates... Let say I have
following vector of months:

Months <- c("Jan", "Dec", "Mar")

Now I need to assign year with them. This assignment will be based on some
given date. Let say my given date is :

Given_Date <- as.Date("2013-12-23")

So in this case, the modified month will be:

Months_Mod <- c("Jan-2014", "Dec-2013", "Mar-2014")

However if given date is:

Given_Date <- as.Date("2014-01-04")

then the modified months will be:

Months_Mod <- c("Jan-2014", "Dec-2014", "Mar-2014")

My problem is that, I can not extablish some logic around it, so that I can
do it programmatically for any Month-vector and for any Given-date.

Can someone help me to accomplice this?

Thank for your help

    [[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] Working with Date

2013-12-31 Thread Jim Lemon

On 01/01/2014 08:53 AM, Christofer Bogaso wrote:

Hi again,

Happy new year 2014 to every R gurus and users.

I am struggling with some calculation with dates... Let say I have
following vector of months:

Months<- c("Jan", "Dec", "Mar")

Now I need to assign year with them. This assignment will be based on some
given date. Let say my given date is :

Given_Date<- as.Date("2013-12-23")

So in this case, the modified month will be:

  Months_Mod<- c("Jan-2014", "Dec-2013", "Mar-2014")

However if given date is:

Given_Date<- as.Date("2014-01-04")

then the modified months will be:

  Months_Mod<- c("Jan-2014", "Dec-2014", "Mar-2014")

My problem is that, I can not extablish some logic around it, so that I can
do it programmatically for any Month-vector and for any Given-date.

Can someone help me to accomplice this?


Hi Christofer,
I would like to be an accomplice in this, but I can't quite work out 
your logic. I thought that you might want:


IF Given_Date is in the same month as an element of Months

THEN use the year in Given_Date

ELSE use the year in Given_Date plus 1

However, when I programmed it:

assignYear<-function(index_date,months) {
 index_year<-as.numeric(format(index_date,"%Y"))
 index_month<-which(months==format(index_date,"%b"))
 dates<-as.Date(paste(index_year+1,months,"1",sep="-"),"%Y-%b-%d")
 dates[index_month]<-
  as.Date(paste(index_year,months[index_month],"1",sep="-"),"%Y-%b-%d")
 return(format(dates,"%Y-%b"))
}

it didn't work for the second example. Could you give some idea of what 
you want to do?


Jim

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


Re: [R] Working with Date

2013-12-31 Thread Ista Zahn
Use, format() to extract a character string representation of the
year, then paste() it together with Months. Like this:

paste(Months, format(Given_Date, format = "%Y"), sep = "-")

See ?strftime for details.

Best,
Ista

On Tue, Dec 31, 2013 at 4:53 PM, Christofer Bogaso
 wrote:
> Hi again,
>
> Happy new year 2014 to every R gurus and users.
>
> I am struggling with some calculation with dates... Let say I have
> following vector of months:
>
> Months <- c("Jan", "Dec", "Mar")
>
> Now I need to assign year with them. This assignment will be based on some
> given date. Let say my given date is :
>
> Given_Date <- as.Date("2013-12-23")
>
> So in this case, the modified month will be:
>
>  Months_Mod <- c("Jan-2014", "Dec-2013", "Mar-2014")
>
> However if given date is:
>
> Given_Date <- as.Date("2014-01-04")
>
> then the modified months will be:
>
>  Months_Mod <- c("Jan-2014", "Dec-2014", "Mar-2014")
>
> My problem is that, I can not extablish some logic around it, so that I can
> do it programmatically for any Month-vector and for any Given-date.
>
> Can someone help me to accomplice this?
>
> Thank for your help
>
> [[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] cumulative incidence for mstate in Survival package in R

2013-12-31 Thread Terry Therneau

Question 1: How to get just 2 cumulative incidence curves when there are 
multiple covariates.
  I don't understand what you want.  Assume that we have "liver transplant" and "death 
while waiting for a transplant" as my two events.  There are overall curves (2), or one 
can create curves separately for each sex, or for different institutions.  What do you 
mean by "a curve for age"?

  If you want competing risks after Cox model adjustment, see the mstate 
package.

Question 2: "mine" data.  There is no such data.  This was a hypthetical example in the 
document, and I chose a poor name for the data set; "your_data_set" would have been 
better.  I was using "mine" in the sense of "this data set is mine, it belongs to me", and 
now see that it could confuse someone.  The file sourcecode.pdf is intended to document 
the computational algorithms, but not how a user would approach the function.  A vignette 
is planned, someday...


Terry Therneau


On 12/30/2013 04:04 PM, Jieyue Li wrote:

Dear All,

I want to have the cumulative incidence curves for 'mstate' data using Survival 
package in
R. But I got some problems:
I. Problem 1:
1. If I only use intercept without any covariates, I can have 'right' 
cumulative incidence
curves (2 for 2 competing risks):
library(Survival)
fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate") ~ 
1,data=mgus1,
subset=(start==0))
plot(fitCI)
2. If I include one variate ('sex'), I get 4 curves (attached; I guess because 
there are
two levels in 'sex' and 2 competing risks):
fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate") 
~sex,data=mgus1,
subset=(start==0))
plot(fitCI)
However, I want to just have 2 cumulative incidence curves estimated from 
several
covariates (such as 'sex', 'age', 'alb', etc. in mgus1). Could you please help 
me to do
that? Thank you very much!
II. Problem 2:
I try using an example from sourcecode.pdf:
fit <- survfit(Surv(time, status, type=’mstate’) ~ sex, data=mine)
but where can I have the 'mine' data? Thank you!

Best,

Jieyue



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 ask a function to continuously print intermediate results

2013-12-31 Thread Uwe Ligges



On 31.12.2013 20:10, Duncan Murdoch wrote:

On 13-12-31 2:02 PM, Jun Shen wrote:

Dear all,

I have a print command to export some intermediate results from a
user-defined function. It takes a while to run the function and I found I
have to press a key to see the printed results on the screen. How can
I ask
the function to continuously print results on the screen without pressing
any keys? Thanks.


This depends to some extent on which platform you're on.  On Windows in
Rgui, you can disable "buffered output" using Ctrl-W or the entry in the
"Misc" menu.  If you're using a different platform, search for "buffered
output" in its help system.


And see ?flush.console

Best,
Uwe Ligges




Duncan Murdoch

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


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


[R] Working with Date

2013-12-31 Thread Christofer Bogaso
Hi again,

Happy new year 2014 to every R gurus and users.

I am struggling with some calculation with dates... Let say I have
following vector of months:

Months <- c("Jan", "Dec", "Mar")

Now I need to assign year with them. This assignment will be based on some
given date. Let say my given date is :

Given_Date <- as.Date("2013-12-23")

So in this case, the modified month will be:

 Months_Mod <- c("Jan-2014", "Dec-2013", "Mar-2014")

However if given date is:

Given_Date <- as.Date("2014-01-04")

then the modified months will be:

 Months_Mod <- c("Jan-2014", "Dec-2014", "Mar-2014")

My problem is that, I can not extablish some logic around it, so that I can
do it programmatically for any Month-vector and for any Given-date.

Can someone help me to accomplice this?

Thank for your help

[[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] How to ask a function to continuously print intermediate results

2013-12-31 Thread Duncan Murdoch

On 13-12-31 2:02 PM, Jun Shen wrote:

Dear all,

I have a print command to export some intermediate results from a
user-defined function. It takes a while to run the function and I found I
have to press a key to see the printed results on the screen. How can I ask
the function to continuously print results on the screen without pressing
any keys? Thanks.


This depends to some extent on which platform you're on.  On Windows in 
Rgui, you can disable "buffered output" using Ctrl-W or the entry in the 
"Misc" menu.  If you're using a different platform, search for "buffered 
output" in its help system.


Duncan Murdoch

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


[R] How to ask a function to continuously print intermediate results

2013-12-31 Thread Jun Shen
Dear all,

I have a print command to export some intermediate results from a
user-defined function. It takes a while to run the function and I found I
have to press a key to see the printed results on the screen. How can I ask
the function to continuously print results on the screen without pressing
any keys? Thanks.

Jun

[[alternative HTML version deleted]]

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


Re: [R] Where did lost variables go, with example

2013-12-31 Thread Duncan Murdoch

On 13-12-31 11:38 AM, David Parkhurst wrote:

Thank you.  I've tried what you're suggesting, at an earlier suggestion
from another respondent, and I don't find my variable in any of lists
ls() through ls(7).


Are you sure that "X" is really the name of a column in the dataframe? 
names(All8Sites) will tell you all the names that are there.




I'm just going back to using R after being away from statistics for
several years.  I'm thinking I might uninstall R, then reinstall it, and
redo my work so far (I've kept the commands elsewhere), and avoid using
"attach," as someone else has suggested.


It's not likely to be necessary to reinstall R, but it shouldn't hurt.

Duncan Murdoch



David
On 12/31/2013 11:32 AM, Duncan Murdoch wrote:

On 13-12-31 9:48 AM, David Parkhurst wrote:

Two or three respondents asked for an example of my problem.  Here's
what's happening to me now.  I can't reproduce how I got to this point,
though:

  > ls()
[1] "All8"   "All8Sites"  "A"   "B"  "C"  "i"  "n"  "D"  "F"
  > X
Error: object 'X' not found
  > attach(All8Sites)
  > ls()
[1] "All8"  "All8Sites"  "A"  "B"  "C"  "i"  "n"  "D"  "F"


"X" is one of the variables in the data frame I attached in the third
command above, but it's not listed by >ls().  If I enter > X now, its
values ARE listed, but it's hiding somewhere.  What is happening here?
How can I get the variables in that data frame listed when I attach it?


Use search() to see the search list.  Your dataframe will likely be in
position 2.  Use ls(2) to see the variables there.

Duncan Murdoch





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


Re: [R] Problem with http://www.r-project.org/mail.html#instructions

2013-12-31 Thread Uwe Ligges
Thanks for the report, if this is not a temporary problem, we will 
provide an alternative link.


Some search engine suggests that it is mirrored here:
http://linuxgazette.net/no-mime

Best,
Uwe Ligges


On 31.12.2013 16:11, David Parkhurst wrote:

This web page includes this information about turning off HTML in messages:

http://www.r-project.org/mail.html#instructions


 General Instructions

Note that you should configure your e-mail software in such a way as to
send /only plain text/, i.e., *no HTML*. 'html-ified' messages are
usually considerably longer (in bytes!) and harder to filter for spam or
viruses. Many of these (e.g. 'html-only' ones) are currently
spam-filtered or otherwise intercepted completely and without notice to
the sender. For more details and instructions on turning off HTML for
your e-mail software, see here .
Furthermore, most binary e-mail /attachments are not accepted/, i.e.,
they are removed from the posting completely. As an /exception/, we
allow application/pdf, application/postscript, and image/png (and x-tar
and gzip on R-devel). You can use text/plain as well, or simply paste
text into your message instead.

However, when I click on the _here_ link, I get a message that the
server is not available. Perhaps someone can repair that?

Thanks.

David


[[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] Request for help regarding RWeka

2013-12-31 Thread Takatsugu Kobayashi
Hi Rusers,

I am having a hard time understanding/finding a solution to this error
message of RWeka.
I just want to use Xmeans clustering command but when I typed "XMeans" then
I get the following message:

Error value[[3L]](cond) :

  Required Weka package 'XMeans' is not installed.

So I tried to install "XMeans" with WPM (I thought this was a solution like
install.packages()), but when I WPM() then I got this error message:

> WPM("list-packages", "installed")

 Error .jcall("java/lang/System", "V", "setOut", out) :

  java.lang.NoClassDefFoundError: Could not initialize class
org.bounce.net.DefaultAuthenticator

I am not a Java user and have no idea how to solve this issue to use Weka
via R.
That would be appreciated if anyone could help!

Best,

Takatsugu

[[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] Package dependencies in building R packages

2013-12-31 Thread Paul Gilbert
The responses to this seem to be assuming that you want users to have 
access to your tt() function, that is, you export it. Just in case the 
really simple case has been overlooked: if you are only using this 
function internally in your package there should be no problem. Your 
package's namespace ensures that your package's functions find your 
tt(), and if you do not export it then user references to tt() will not 
find your version.


As others have pointed out, if you want users to have access to your 
tt() and they also need access to survival's tt(), then there is a 
problem. You either need to change the name or users will need to be 
explicit about which one they want.


(BTW - this is a question that could be asked on the R-devel list.)

Paul

On 13-12-31 06:00 AM, r-help-requ...@r-project.org wrote:

Date: Mon, 30 Dec 2013 20:01:46 +0100
From: Axel Urbiz
To: Duncan Murdoch
Cc:"R-help@r-project.org"  
Subject: Re: [R] Package dependencies in building R packages
Message-ID:

Content-Type: text/plain

Thanks for your kind response Duncan. To be more specific, I'm using the
function mvrnorm from MASS. The issue is that MASS depends on survival and
I have a function in my package named tt() which conflicts with a function
in survival of the same name. I can think of 2 alternatives solutions to my
problem, but I'm to an expert:

1) Copy mvrnorm into my package, which I thought was not a good idea
2) Rename my tt() function to something else in my package, but this is
painful as I have it all over the place in other functions.

Any suggestions would be much appreciated.

Best,
Axel.


On Mon, Dec 30, 2013 at 7:51 PM, Duncan Murdochwrote:


>On 13-12-30 1:24 PM, Axel Urbiz wrote:
>

>>Dear users,
>>
>>My package {foo} depends on a function "miscFUN" which is on package
>>{foo_depend}. This last package also depends on other packages, say {A, B,
>>C}, but miscFUN is not dependent on A, B, C (only on foo_depend).
>>
>>In my package {foo}, is there a way to only have it depend on the function
>>miscFUN from {foo_depend} without having the user to have installed A, B,
>>C? (as none of those packages are needed for my package to work properly).
>>Also, is this a best practice?
>>

>
>There's no way for your package to tell R to ignore the dependencies
>declared by foo_depend.
>
>If you really only need one function from that package, simply copy the
>source of miscFUN into your package (assuming foo_depend's license permits
>that).  But this is not best practice, unless that function is very simple.
>  Best practice is to declare your dependence by importing that function
>from foo_depend.
>
>Duncan Murdoch
>
>
>

[[alternative HTML version deleted]]



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


Re: [R] Where did lost variables go, with example

2013-12-31 Thread Duncan Murdoch

On 13-12-31 9:48 AM, David Parkhurst wrote:

Two or three respondents asked for an example of my problem.  Here's
what's happening to me now.  I can't reproduce how I got to this point,
though:

  > ls()
[1] "All8"   "All8Sites"  "A"   "B"  "C"  "i"  "n"  "D"  "F"
  > X
Error: object 'X' not found
  > attach(All8Sites)
  > ls()
[1] "All8"  "All8Sites"  "A"  "B"  "C"  "i"  "n"  "D"  "F"


"X" is one of the variables in the data frame I attached in the third
command above, but it's not listed by >ls().  If I enter > X now, its
values ARE listed, but it's hiding somewhere.  What is happening here?
How can I get the variables in that data frame listed when I attach it?


Use search() to see the search list.  Your dataframe will likely be in 
position 2.  Use ls(2) to see the variables there.


Duncan Murdoch

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


[R] Problem with http://www.r-project.org/mail.html#instructions

2013-12-31 Thread David Parkhurst
This web page includes this information about turning off HTML in messages:

http://www.r-project.org/mail.html#instructions


General Instructions

Note that you should configure your e-mail software in such a way as to 
send /only plain text/, i.e., *no HTML*. 'html-ified' messages are 
usually considerably longer (in bytes!) and harder to filter for spam or 
viruses. Many of these (e.g. 'html-only' ones) are currently 
spam-filtered or otherwise intercepted completely and without notice to 
the sender. For more details and instructions on turning off HTML for 
your e-mail software, see here .
Furthermore, most binary e-mail /attachments are not accepted/, i.e., 
they are removed from the posting completely. As an /exception/, we 
allow application/pdf, application/postscript, and image/png (and x-tar 
and gzip on R-devel). You can use text/plain as well, or simply paste 
text into your message instead.

However, when I click on the _here_ link, I get a message that the 
server is not available. Perhaps someone can repair that?

Thanks.

David


[[alternative HTML version deleted]]

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


Re: [R] Where did lost variables go, with example

2013-12-31 Thread David Parkhurst
Two or three respondents asked for an example of my problem.  Here's 
what's happening to me now.  I can't reproduce how I got to this point, 
though:

 > ls()
[1] "All8"   "All8Sites"  "A"   "B"  "C"  "i"  "n"  "D"  "F"
 > X
Error: object 'X' not found
 > attach(All8Sites)
 > ls()
[1] "All8"  "All8Sites"  "A"  "B"  "C"  "i"  "n"  "D"  "F"


"X" is one of the variables in the data frame I attached in the third 
command above, but it's not listed by >ls().  If I enter > X now, its 
values ARE listed, but it's hiding somewhere.  What is happening here?  
How can I get the variables in that data frame listed when I attach it?

Thanks to all.
David


[[alternative HTML version deleted]]

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


Re: [R] Where did lost variables go

2013-12-31 Thread Bert Gunter
Gents:

I would add that:

1) attach() should probably no longer be used in R, for all the
reasons (and more) cited,

2)  The preferred alternative these days is to use lists, including
data frames, as containers and make liberal use of the  ?with and
?within  functions. Environments can also be useful, but are more
complicated as their semantics differ. S4 classes and objects are
probably also relevant.

Comments, criticisms, links, additions, and subtractions welcome, as
this issue comes up regularly here and it would be nice to have
consensus wisdom to refer to.

Cheers,


Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Tue, Dec 31, 2013 at 2:14 AM, Berwin A Turlach
 wrote:
> G'day David,
>
> On Mon, 30 Dec 2013 20:42:53 -0500
> David Parkhurst  wrote:
>
> Some wild guesses in the absence of a reproducible example.
>
>> I have several variables in a data frame that aren't listed by ls()
>> after I attach that data frame.
>
> ls() list the objects in the global environment.  If you attach a data
> frame it is attached to the search path, typically after the global
> environment.
>
> Type 'search()' to see your search path.
>
> ls() list the global environment, the first entry in the list and
> called ".GlobalEnv".  Your data frame should be listed as an object in
> that environment.
>
> Assuming the name of your data frame is 'foo', then there should be the
> name 'foo' somewhere in the list of names returned by 'search()'.
> Assuming 'foo' is listed in the second position, then 'ls(2)' should
> list all the objects found at that location of the search path, i.e.
> all the variables in your data frame.
>
>> Where did they go,
>
> See above.
>
>> and how can I stop the hidden ones from masking the local ones?
>
> Do you mean with "local ones" those in the global environment and by
> "hidden ones" those that you couldn't find?  I.e. is there an object
> "bar" listed by 'ls()' but also an object "bar" listed by 'ls(2)' (i.e.
> your data frame 'foo' contained a variable with name 'bar')?  Then it is
> the other way round, the local ones are hiding the hidden ones.
>
> For that reason attaching data frames has its dangers.  It allows to
> easily access the variables in the data frame, but any changes to a
> variable creates a local copy.  Thus, any change *will* not propagate
> back to the data frame!
>
> Hopefully the commands below will clarify further.
>
> Cheers,
>
> Berwin
>
>
> R> foo <- data.frame(bar=rnorm(2), fubar=runif(2))
> R> ls()
> [1] "foo"
> R> attach(foo)
> R> search()
>  [1] ".GlobalEnv""foo"   "package:stats"
>  [4] "package:graphics"  "package:grDevices" "package:utils"
>  [7] "package:datasets"  "package:methods"   "Autoloads"
> [10] "package:base"
> R> ls(2)
> [1] "bar"   "fubar"
> R> bar
> [1] -0.07741633  1.05804653
> R> fubar
> [1] 0.08516929 0.82718383
> R> bar <- "what now"
> R> ls()
> [1] "bar" "foo"
> R> bar
> [1] "what now"
> R> ls(2)
> [1] "bar"   "fubar"
> R> get("bar", pos=2)
> [1] -0.07741633  1.05804653
> R> foo
>   bar  fubar
> 1 -0.07741633 0.08516929
> 2  1.05804653 0.82718383
> R> detach(2)
> R> bar
> [1] "what now"
> R> fubar
> Error: object 'fubar' not found
> R> foo
>   bar  fubar
> 1 -0.07741633 0.08516929
> 2  1.05804653 0.82718383
> R> attach(foo)
> The following object is masked _by_ .GlobalEnv:
>
> bar
> R> bar
> [1] "what now"
> R> fubar
> [1] 0.08516929 0.82718383
> R> detach(2)
> R> bar
> [1] "what now"
> R> fubar
> Error: object 'fubar' not found
> R> foo
>   bar  fubar
> 1 -0.07741633 0.08516929
> 2  1.05804653 0.82718383
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] format a matrix as fractions?

2013-12-31 Thread Bert Gunter
I find that google is usually a better search engine for R topics

Google on "R fractions".

(I got, e.g.
http://stackoverflow.com/questions/5046026/print-number-as-reduced-fraction-in-r
)

-- Cheers,

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch




On Tue, Dec 31, 2013 at 7:25 AM, Michael Friendly  wrote:
> Is there some way to format a matrix of fractions as fractions?  I think
> I've seen this somewhere,
> but search on Rseek came up empty.
>
> Example:
>
>> outer(1/seq(1:3), 1/seq(1:3))
>   [,1]  [,2]  [,3]
> [1,] 1.000 0.500 0.333
> [2,] 0.500 0.250 0.167
> [3,] 0.333 0.167 0.111
>>
>
> should print as
>
>   1 1/2 1/3
> 1/21/4 1/6
> 1/31/6 1/9
>
> TIA
> -Michael
>
> --
> Michael Friendly Email: friendly AT yorku DOT ca
> Professor, Psychology Dept. & Chair, Quantitative Methods
> York University  Voice: 416 736-2100 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.

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


Re: [R] format a matrix as fractions?

2013-12-31 Thread arun


library(MASS)
 fractions(outer(1/seq(1:3), 1/seq(1:3)))
# [,1] [,2] [,3]
#[1,]   1  1/2  1/3 
#[2,] 1/2  1/4  1/6 
#[3,] 1/3  1/6  1/9 
A.K.


On Tuesday, December 31, 2013 10:27 AM, Michael Friendly  
wrote:
Is there some way to format a matrix of fractions as fractions?  I think 
I've seen this somewhere,
but search on Rseek came up empty.

Example:

> outer(1/seq(1:3), 1/seq(1:3))
           [,1]      [,2]      [,3]
[1,] 1.000 0.500 0.333
[2,] 0.500 0.250 0.167
[3,] 0.333 0.167 0.111
>

should print as

       1     1/2     1/3
     1/2    1/4     1/6
     1/3    1/6     1/9

TIA
-Michael

-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street    Web:  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.


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

2013-12-31 Thread Michael Friendly
Is there some way to format a matrix of fractions as fractions?  I think 
I've seen this somewhere,

but search on Rseek came up empty.

Example:

> outer(1/seq(1:3), 1/seq(1:3))
  [,1]  [,2]  [,3]
[1,] 1.000 0.500 0.333
[2,] 0.500 0.250 0.167
[3,] 0.333 0.167 0.111
>

should print as

  1 1/2 1/3
1/21/4 1/6
1/31/6 1/9

TIA
-Michael

--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University  Voice: 416 736-2100 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] Package dependencies in building R packages

2013-12-31 Thread Hadley Wickham
> Thanks for your kind response Duncan. To be more specific, I'm using the
> function mvrnorm from MASS. The issue is that MASS depends on survival and
> I have a function in my package named tt() which conflicts with a function
> in survival of the same name. I can think of 2 alternatives solutions to my
> problem, but I'm to an expert:
>
> 1) Copy mvrnorm into my package, which I thought was not a good idea
> 2) Rename my tt() function to something else in my package, but this is
> painful as I have it all over the place in other functions.

3) Use namespaces: in your DESCRIPTION add `Import: MASS`, and in your
NAMESPACE add `importFrom(MASS,mvrnorm)`

Then you can access mvrnorm from your package, but it won't be made
available to the user who loads your package, and it won't pull in any
other functions from MASS or survival either.

Hadley


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

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


Re: [R] aes and parameter evaluation problems

2013-12-31 Thread Geoffrey

Thanks A.K. and Jeff, both answers helped me.
(and of course gave me more homework!)

On 31/12/13 16:04, Jeff Newmiller wrote:

A.K. answered your question 1, but since you did say as question 2 that you 
wanted it done right...

library(reshape2)
ex3 <- function() {
   d <- data.frame(x=1:5,a=1:5,b=2:6,c=3:7)
   dl <- melt( d, id.vars="x" )
   ggplot(dl,aes(x=x,y=value,color=variable))+
 geom_line()
}

---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

arun  wrote:


Hi,
Try:

ex2 <- function() {
   d <- data.frame(x=1:5,a=1:5,b=2:6,c=3:7)
   g <- ggplot(d, aes(x))
 for (n in c("a","b","c")) {
 g <- g + geom_line(aes_string(y=n,colour=n))
   }
  return(g)
}

A.K.


On Monday, December 30, 2013 7:49 PM, Geoffrey
 wrote:
I am trying add geom_line's using a loop but the nature of unevaluated
parameters is causing me problems.

This code works:
ex <- function() {
d <- data.frame(x=1:5,a=1:5,b=2:6,c=3:7)
g <- ggplot(d, aes(x))
g <- g +
  geom_line(aes(y=a,colour=a)) +
  geom_line(aes(y=b,colour=b)) +
  geom_line(aes(y=c,colour=c))
return(g)
}

This code (not surprisingly) fails:
ex2 <- function() {
d <- data.frame(x=1:5,a=1:5,b=2:6,c=3:7)
g <- ggplot(d, aes(x))
for (n in c("a","b","c")) {
  g <- g + geom_line(aes(y=n,colour=n))
}
return(g)
}

I believe i want something like the failing code, but done right.

I have two problems (at least in this code):
#1 how do handle the parameter evaluation
#2 is this the right thing to be even doing with geom_line() & aes() ?

Geoff.




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


Re: [R] howto join matrices produced by rcorr()

2013-12-31 Thread Adams, Jean
Alex,

Here's one way to do it, using for() loops.

Jean


library(Hmisc)
# using Swiss Fertility and Socioeconomic Indicators (1888) Data
m <- data.matrix(swiss)
output <- rcorr(m)

varnames <- dimnames(m)[[2]]
nvar <- length(varnames)
# for loops through all possible pairs
for(i in 1:(nvar-1)) {
for(j in (i+1):nvar) {
# get short variables to ease reading
r <- output$r[i, j]
n <- output$n[i, j]
 P <- output$P[i, j]
if(n >= 5 & (r <= -0.5 | r >= 0.5)) {
png(paste0(varnames[i], "_vs_", varnames[j], ".png"))
 plot(m[, i], m[, j], xlab=varnames[i], ylab=varnames[j],
main=paste0("R = ", format(round(r, 2), nsmall=2), ", P = ",
format(round(P, 2), nsmall=4)))
 abline(lsfit(m[, i], m[, j]))
dev.off()
}
 }}



On Mon, Dec 30, 2013 at 10:18 AM, Alexander Schuster  wrote:

> Hi,
>
> i have used rcorr() for calculating pearsons r and according p-values
> for my data, giving me 2 matrices.
>
> Now I would like to print scatterplots for all results with "good"
> correlation values.
>
> So i need a way to extract the row-name and column-name for each item in
> the matrix with "good" r-values, so i can use them in the
> plot()-function on my original dataframe programmatically.
>
> below is what i have got - and now i'm stuck:
>
> --
> incomingData <- read.csv(inputfile, header=TRUE, na="NA")
> datamatrix <- data.matrix(incomingData)
> library(Hmisc)
> output <- rcorr(datamatrix, type="pearson")
>
> # get short variables to ease reading
> r <- output$r
> n <- output$n
> P <- output$P
>
> r[n<5]<-NA # ignore less than five observations
> r[r>-0.5 & r<0.5]<-NA # take only "good" korrelations
> P[is.na(r)]<-NA # delete P values for deleted korrelations
>
> r <- format(round(cbind(rep(-1.11, ncol(r)), r), 2))[,-1] ## trunctuate
> matrix with correlations to 2 decimals
>
> P <- format(round(cbind(rep(-1.11, ncol(P)), P), 4))[,-1] ## trunctuate
> matrix with P-Values to 4 decimals
>
> make_plot <- function(a,b,Rval,Pval,aname,bname) {
> png(paste(aname,'_vs_',bname,'.png', sep=""))
> plot(a,b, main="Rval(p=Pval)")
> fitline <- lm(a~b)
> abline(fitline)
> dev.off()
> }
>
> -
>
> Big Thanks for any ideas on this, Alex
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Where did lost variables go

2013-12-31 Thread Berwin A Turlach
G'day David,

On Mon, 30 Dec 2013 20:42:53 -0500
David Parkhurst  wrote:

Some wild guesses in the absence of a reproducible example.

> I have several variables in a data frame that aren't listed by ls() 
> after I attach that data frame. 

ls() list the objects in the global environment.  If you attach a data
frame it is attached to the search path, typically after the global
environment.  

Type 'search()' to see your search path.

ls() list the global environment, the first entry in the list and
called ".GlobalEnv".  Your data frame should be listed as an object in
that environment.  

Assuming the name of your data frame is 'foo', then there should be the
name 'foo' somewhere in the list of names returned by 'search()'.
Assuming 'foo' is listed in the second position, then 'ls(2)' should
list all the objects found at that location of the search path, i.e.
all the variables in your data frame.

> Where did they go, 

See above.

> and how can I stop the hidden ones from masking the local ones?

Do you mean with "local ones" those in the global environment and by
"hidden ones" those that you couldn't find?  I.e. is there an object
"bar" listed by 'ls()' but also an object "bar" listed by 'ls(2)' (i.e.
your data frame 'foo' contained a variable with name 'bar')?  Then it is
the other way round, the local ones are hiding the hidden ones.  

For that reason attaching data frames has its dangers.  It allows to
easily access the variables in the data frame, but any changes to a
variable creates a local copy.  Thus, any change *will* not propagate
back to the data frame!  

Hopefully the commands below will clarify further.

Cheers,

Berwin


R> foo <- data.frame(bar=rnorm(2), fubar=runif(2))
R> ls()
[1] "foo"
R> attach(foo)
R> search()
 [1] ".GlobalEnv""foo"   "package:stats"
 [4] "package:graphics"  "package:grDevices" "package:utils"
 [7] "package:datasets"  "package:methods"   "Autoloads"
[10] "package:base" 
R> ls(2)
[1] "bar"   "fubar"
R> bar
[1] -0.07741633  1.05804653
R> fubar
[1] 0.08516929 0.82718383
R> bar <- "what now"
R> ls()
[1] "bar" "foo"
R> bar
[1] "what now"
R> ls(2)
[1] "bar"   "fubar"
R> get("bar", pos=2)
[1] -0.07741633  1.05804653
R> foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383
R> detach(2)
R> bar
[1] "what now"
R> fubar
Error: object 'fubar' not found
R> foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383
R> attach(foo)
The following object is masked _by_ .GlobalEnv:

bar
R> bar
[1] "what now"
R> fubar
[1] 0.08516929 0.82718383
R> detach(2)
R> bar
[1] "what now"
R> fubar
Error: object 'fubar' not found
R> foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383

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


Re: [R] cumulative incidence for mstate in Survival package in R

2013-12-31 Thread Göran Broström

On 12/30/2013 11:04 PM, Jieyue Li wrote:

Dear All,

I want to have the cumulative incidence curves for 'mstate' data using
Survival package in R. But I got some problems:
I. Problem 1:
1. If I only use intercept without any covariates, I can have 'right'
cumulative incidence curves (2 for 2 competing risks):
library(Survival)


That shouldn't work;)


fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate") ~
1,data=mgus1, subset=(start==0))
plot(fitCI)
2. If I include one variate ('sex'), I get 4 curves (attached; I guess
because there are two levels in 'sex' and 2 competing risks):
fitCI <- survfit(Surv(stop, status*as.numeric(event), type="mstate")
~sex,data=mgus1, subset=(start==0))
plot(fitCI)
However, I want to just have 2 cumulative incidence curves estimated from
several covariates (such as 'sex', 'age', 'alb', etc. in mgus1). Could you
please help me to do that? Thank you very much!


I suggest that you check the Task Views, under 'Survival' and 
'Multistate Models', for instance the 'cmprsk' and 'timereg' packages.



II. Problem 2:
I try using an example from sourcecode.pdf:
fit <- survfit(Surv(time, status, type=’mstate’) ~ sex, data=mine)
but where can I have the 'mine' data? Thank you!


Where do you find 'sourcecode.pdf'?

Göran Broström



Best,

Jieyue



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


Re: [R] Where did lost variables go

2013-12-31 Thread Simon Zehnder
A reproducible example would do well here David

Best

Simon
On 31 Dec 2013, at 02:42, David Parkhurst  wrote:

> I have several variables in a data frame that aren't listed by ls() 
> after I attach that data frame.  Where did they go, and how can I stop 
> the hidden ones from masking the local ones?
> Thanks for any help.
> David
> 
>   [[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] Package dependencies in building R packages

2013-12-31 Thread Philippe Grosjean

On 30 Dec 2013, at 20:01, Axel Urbiz  wrote:

> Thanks for your kind response Duncan. To be more specific, I'm using the
> function mvrnorm from MASS. The issue is that MASS depends on survival and
> I have a function in my package named tt() which conflicts with a function
> in survival of the same name. I can think of 2 alternatives solutions to my
> problem, but I'm to an expert:

As of version 7.3-29 of MASS, it only depends on R (>= 3.0.0), grDevices, 
graphics, stats and utils. survival appears in the 'Suggests' field, which is 
very different. When you do 'library(MASS)' or 'require(MASS)', it does not 
import survival's NAMESPACE, at least at startup (and if it did, this would not 
cause interferences with your package… precisely the purpose of namespaces). It 
also does not attach survival to the search path, logically… and if it did, 
your package 'foo' would be attached higher on that search path, causing 
survival's tt() function being masked by your foo::tt() function, e.g., from 
the Global Environment with a warning. So, the only inconvenience in this case 
would be for users that need to use tt() from 'survival', and it would be 
better to always indicate explicitly foo::tt() or survival::tt() in order to 
eliminate the ambiguity.

> 1) Copy mvrnorm into my package, which I thought was not a good idea

Absolutely, think about future bug fixes. Moreover, it will not solve the 
problem in case someone attaches the 'survival' package higher in the search 
path than 'foo', e.g., using this in .GlobalEnv:

require(foo)
require(survival)
tt() # This would be survival::tt() that is called!

> 2) Rename my tt() function to something else in my package, but this is
> painful as I have it all over the place in other functions.

Definitely the best solution, providing your package is not on CRAN yet and has 
no other CRAN packages depending on it, and especially on your tt() function. 
Otherwise, you should declare tt() deprecated (see ?.Deprecated), make sure you 
inform maintainers of dependent packages of your changes, and wait long enough 
before removing tt() totally for user to adapt.

Otherwise, choose a good code editor, with regexpr search on all files in a 
directory makes it easy to change calls to tt() all over the places. RStudio, 
Emacs+ESS, Eclipse+StatEt, Komodo+SciViews-K come to me mind first, but there 
are many others.

Best,

Philippe

> Any suggestions would be much appreciated.
> 
> Best,
> Axel.
> 
> 
> On Mon, Dec 30, 2013 at 7:51 PM, Duncan Murdoch 
> wrote:
> 
>> On 13-12-30 1:24 PM, Axel Urbiz wrote:
>> 
>>> Dear users,
>>> 
>>> My package {foo} depends on a function "miscFUN" which is on package
>>> {foo_depend}. This last package also depends on other packages, say {A, B,
>>> C}, but miscFUN is not dependent on A, B, C (only on foo_depend).
>>> 
>>> In my package {foo}, is there a way to only have it depend on the function
>>> miscFUN from {foo_depend} without having the user to have installed A, B,
>>> C? (as none of those packages are needed for my package to work properly).
>>> Also, is this a best practice?
>>> 
>> 
>> There's no way for your package to tell R to ignore the dependencies
>> declared by foo_depend.
>> 
>> If you really only need one function from that package, simply copy the
>> source of miscFUN into your package (assuming foo_depend's license permits
>> that).  But this is not best practice, unless that function is very simple.
>> Best practice is to declare your dependence by importing that function
>> from foo_depend.
>> 
>> Duncan Murdoch
>> 
>> 
>> 
> 
>   [[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] Where did lost variables go

2013-12-31 Thread David Parkhurst
I have several variables in a data frame that aren't listed by ls() 
after I attach that data frame.  Where did they go, and how can I stop 
the hidden ones from masking the local ones?
Thanks for any help.
David

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