[R] CCA no scores for some constraining variables

2014-02-01 Thread Paresys, Lise
Dear all,

I am performing a CCA using vegan package, function cca.
Data loaded are fine (presence-absence data) but when using cca function it 
seems some constraining variables are not taken into account.
While asking for the summary of the CCA:
- they appear in call:cca(formula = etc.).
- but their scores are not shown in Biplot scores for constraining variables
- and they cannot be plotted.
If they are considered alone i.e. without other constraining variables in the 
CCA, their scores appear and they can be plotted.
How can it be? May someone help me to be sure they are taken into account in 
the CCA with all other constraining variables, and to get their scores? Or to 
understand why they are disregarded and others taken into account?

Regards,
Lise.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Avoid using eval in a neat way

2014-02-01 Thread Hai Qian
I know using eval is not optimal and maybe bad, but how to avoid using eval
in the following example

func1 - function(dat, eval.this) {
eval(parse(text = paste0(with(dat, , eval.this, 
}

dat - data.frame(x = 1:2, y = 2:3)

func1(dat, x*2+y)

func1(dat, sin(x)*cos(y))

Here eval.this is a string that contains whatever the user wants to
evaluate. I wonder whether there is a neat way to avoid using eval in this
case? So far I have not figured out a way to do this.

[[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] Avoid using eval in a neat way

2014-02-01 Thread Ista Zahn
This has been discussed extensively, on this list as well as
elsewhere. I suggest doing a web search, read up on the issue, and
post back here only if you have specific questions that are not
answered already.

Best,
Ista

On Sat, Feb 1, 2014 at 11:40 AM, Hai Qian hq...@gopivotal.com wrote:
 I know using eval is not optimal and maybe bad, but how to avoid using eval
 in the following example

 func1 - function(dat, eval.this) {
 eval(parse(text = paste0(with(dat, , eval.this, 
 }

 dat - data.frame(x = 1:2, y = 2:3)

 func1(dat, x*2+y)

 func1(dat, sin(x)*cos(y))

 Here eval.this is a string that contains whatever the user wants to
 evaluate. I wonder whether there is a neat way to avoid using eval in this
 case? So far I have not figured out a way to do this.

 [[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] Avoid using eval in a neat way

2014-02-01 Thread Hai Qian
I have been searching around for some time, but with no luck for this
particular problem.

--
*Pivotal http://www.gopivotal.com/*
A new platform for a new era


On Sat, Feb 1, 2014 at 9:02 AM, Ista Zahn istaz...@gmail.com wrote:

 This has been discussed extensively, on this list as well as
 elsewhere. I suggest doing a web search, read up on the issue, and
 post back here only if you have specific questions that are not
 answered already.

 Best,
 Ista

 On Sat, Feb 1, 2014 at 11:40 AM, Hai Qian hq...@gopivotal.com wrote:
  I know using eval is not optimal and maybe bad, but how to avoid using
 eval
  in the following example
 
  func1 - function(dat, eval.this) {
  eval(parse(text = paste0(with(dat, , eval.this, 
  }
 
  dat - data.frame(x = 1:2, y = 2:3)
 
  func1(dat, x*2+y)
 
  func1(dat, sin(x)*cos(y))
 
  Here eval.this is a string that contains whatever the user wants to
  evaluate. I wonder whether there is a neat way to avoid using eval in
 this
  case? So far I have not figured out a way to do this.
 
  [[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] Avoid using eval in a neat way

2014-02-01 Thread Jeff Newmiller
You have set up your criteria for success to be that your user has full freedom 
to specify code in strings to evaluate. Then you ask how to achieve this goal 
without evaluating that code. Are you thinking objectively at all about your 
question?

The advice to not use eval has a number of justifications that you should be 
able to find yourself online (unnecessary obfuscation and program security are 
two). Implementing an interpreter is not where this advice applies.

At the core of this problem, as long as you accept that your user is working 
within the R interpreter then they can provide your code with functions that 
access data on their own. You don't need to assume so much responsibility as 
your question assumes you have to.

Doctor, my head hurts!
Then stop banging it against the wall.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  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.

On February 1, 2014 8:40:47 AM PST, Hai Qian hq...@gopivotal.com wrote:
I know using eval is not optimal and maybe bad, but how to avoid using
eval
in the following example

func1 - function(dat, eval.this) {
eval(parse(text = paste0(with(dat, , eval.this, 
}

dat - data.frame(x = 1:2, y = 2:3)

func1(dat, x*2+y)

func1(dat, sin(x)*cos(y))

Here eval.this is a string that contains whatever the user wants to
evaluate. I wonder whether there is a neat way to avoid using eval in
this
case? So far I have not figured out a way to do this.

   [[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] Avoid using eval in a neat way

2014-02-01 Thread Duncan Murdoch

On 14-02-01 11:40 AM, Hai Qian wrote:

I know using eval is not optimal and maybe bad, but how to avoid using eval
in the following example

func1 - function(dat, eval.this) {
 eval(parse(text = paste0(with(dat, , eval.this, 
}

dat - data.frame(x = 1:2, y = 2:3)

func1(dat, x*2+y)

func1(dat, sin(x)*cos(y))

Here eval.this is a string that contains whatever the user wants to
evaluate. I wonder whether there is a neat way to avoid using eval in this
case? So far I have not figured out a way to do this.


You're asking how to parse some text and evaluate it without using eval. 
Sounds impossible to me.


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] Avoid using eval in a neat way

2014-02-01 Thread Hai Qian
Hi Jeff,

Your answer is good. It makes me think that maybe I should revise some of
my designs.

Now I know that it is impossible to do this under my settings.

Thanks


On Sat, Feb 1, 2014 at 9:55 AM, Jeff Newmiller jdnew...@dcn.davis.ca.uswrote:

 You have set up your criteria for success to be that your user has full
 freedom to specify code in strings to evaluate. Then you ask how to achieve
 this goal without evaluating that code. Are you thinking objectively at all
 about your question?

 The advice to not use eval has a number of justifications that you should
 be able to find yourself online (unnecessary obfuscation and program
 security are two). Implementing an interpreter is not where this advice
 applies.

 At the core of this problem, as long as you accept that your user is
 working within the R interpreter then they can provide your code with
 functions that access data on their own. You don't need to assume so much
 responsibility as your question assumes you have to.

 Doctor, my head hurts!
 Then stop banging it against the wall.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  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.

 On February 1, 2014 8:40:47 AM PST, Hai Qian hq...@gopivotal.com wrote:
 I know using eval is not optimal and maybe bad, but how to avoid using
 eval
 in the following example
 
 func1 - function(dat, eval.this) {
 eval(parse(text = paste0(with(dat, , eval.this, 
 }
 
 dat - data.frame(x = 1:2, y = 2:3)
 
 func1(dat, x*2+y)
 
 func1(dat, sin(x)*cos(y))
 
 Here eval.this is a string that contains whatever the user wants to
 evaluate. I wonder whether there is a neat way to avoid using eval in
 this
 case? So far I have not figured out a way to do this.
 
[[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] Avoid using eval in a neat way

2014-02-01 Thread Gabor Grothendieck
On Sat, Feb 1, 2014 at 11:40 AM, Hai Qian hq...@gopivotal.com wrote:

 I know using eval is not optimal and maybe bad, but how to avoid using eval
 in the following example

 func1 - function(dat, eval.this) {
 eval(parse(text = paste0(with(dat, , eval.this, 
 }

 dat - data.frame(x = 1:2, y = 2:3)

 func1(dat, x*2+y)

 func1(dat, sin(x)*cos(y))

 Here eval.this is a string that contains whatever the user wants to
 evaluate. I wonder whether there is a neat way to avoid using eval in this
 case? So far I have not figured out a way to do this.


Since the string is arbitrary R code ultimately it will have to be pushed
through the R interpreter but we can avoid the superficial act of calling
'eval' by punting to some other function which in turn invokes 'eval' like
this:

   func2 - function(dat, s) do.call(with, list(dat, parse(text = s)))

'func2' can be run like this:

 func2(dat, x*2+y)
[1] 4 7
 func2(dat, sin(x)*cos(y))
[1] -0.3501755 -0.9001976

Note that 'with' dispatches to 'with.default' which in turn invokes `eval`:

 with.default
function (data, expr, ...)
eval(substitute(expr), data, enclos = parent.frame())
bytecode: 0x05db6790
environment: namespace:base

[[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] predicted values

2014-02-01 Thread Felipe Carrillo
Consider this dummy dataset.
My real dataset with over 1000 records has
scatter large and small values.
I want to predict for values with NA but I
get negative predictions. Is this a normal
behaviour or I am missing a gam argument
to force the model to predict positive values.
library(mgcv)
test - data.frame(iddate=seq(as.Date(2014-01-01),
    as.Date(2014-01-12), by=days),
    value=c(300,29,22,NA,128,24,15,1,3,30,NA,2))
test
str(test)
mod - gam(value ~ s(as.numeric(iddate)),data=test)
# Predict for values with NA's
test$pred - with(test,ifelse(is.na(value),predict(mod,test),value))
test
[[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] meta data on infert data set

2014-02-01 Thread Aziz, Muhammad Fayez
Hi,



I wanted to know what the following columns mean in the infert dataset:



parity  count
matched set number  1-83
stratum number  1-63



Thank you,

Fayez

Urbana, IL, USA

[[alternative HTML version deleted]]

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


Re: [R] meta data on infert data set

2014-02-01 Thread Jeff Newmiller
They appear to be technical terms relevant to fertility. You should probably 
ask someone with a background in medicine... or Google for these terms in 
conjunction with the word fertility.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  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.

On February 1, 2014 5:57:37 PM PST, Aziz, Muhammad Fayez az...@illinois.edu 
wrote:
Hi,



I wanted to know what the following columns mean in the infert
dataset:



parity  count
matched set number  1-83
stratum number  1-63



Thank you,

Fayez

Urbana, IL, USA

   [[alternative HTML version deleted]]

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

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

2014-02-01 Thread Joshua Wiley
Dear Felipe,

That is a normal behavior --- The prediction for that simple model
decreases over time, and ends up negative.  If the outcome cannot take
on negative values, treating it as a continuous gaussian may not be
optimal --- perhaps some transformation, like using a log link so that
the expoentiated values are always positive would be better?
Alternately, if the predictions are going negative, not because the
data is over all, but say there is a quick decrease in values in the
first part of time but later on it slows, but if you have an overly
simplisitic time model, it may just keep decreasing.  Using a smoother
with a higher basis dimensions may help more accurately model the
function over the span of time in your dataset and then not have
predicted values.

I do not think that there would be any straight forward 'force' the
model to be positive only.

Best,

Joshua


On Sat, Feb 1, 2014 at 5:05 PM, Felipe Carrillo
mazatlanmex...@yahoo.com wrote:
 Consider this dummy dataset.
 My real dataset with over 1000 records has
 scatter large and small values.
 I want to predict for values with NA but I
 get negative predictions. Is this a normal
 behaviour or I am missing a gam argument
 to force the model to predict positive values.
 library(mgcv)
 test - data.frame(iddate=seq(as.Date(2014-01-01),
 as.Date(2014-01-12), by=days),
 value=c(300,29,22,NA,128,24,15,1,3,30,NA,2))
 test
 str(test)
 mod - gam(value ~ s(as.numeric(iddate)),data=test)
 # Predict for values with NA's
 test$pred - with(test,ifelse(is.na(value),predict(mod,test),value))
 test
 [[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://joshuawiley.com/
Senior Analyst - Elkhart Group Ltd.
http://elkhartgroup.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] meta data on infert data set

2014-02-01 Thread David Winsemius

On Feb 1, 2014, at 6:32 PM, Jeff Newmiller wrote:

 They appear to be technical terms relevant to fertility. You should probably 
 ask someone with a background in medicine... or Google for these terms in 
 conjunction with the word fertility.

Parity is the only technical term and its easy enough to look up in a 
dictionary. (Or if you do a Google search and choose the first hit you see it 
accurately defined at least for its biologic meaning. The other two relate to 
the study design and that why the author put in a citation, which unsurprising 
brings up the orignal paper as the first hit with a Google search.

So, Aziz, please use a bit more initiative.

-- 
David Winsemius


 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  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.
 
 On February 1, 2014 5:57:37 PM PST, Aziz, Muhammad Fayez 
 az...@illinois.edu wrote:
 Hi,
 
 
 
 I wanted to know what the following columns mean in the infert
 dataset:
 
 
 
 parity  count
 matched set number  1-83
 stratum number  1-63
 
 
 
 Thank you,
 
 Fayez
 
 Urbana, IL, USA
 
  [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
Alameda, CA, USA

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


Re: [R] Defining function help

2014-02-01 Thread Mathew Nagendran
ah, I see! Thanks you for the assistance! I can see how I went wrong.

From: arun smartpink...@yahoo.com
Sent: Friday, January 31, 2014 2:59 PM
To: r-help@r-project.org
Cc: Mathew Nagendran
Subject: Re: [R] Defining function help

Hi,
Not sure if this is what you wanted:
t.control=function(m, a){(1-exp(-a*m)*((1-(1/30))*m))}
  t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*((1-(1/30))*m))}
t.control(2,2)
#[1] 0.9645898
t.sham(2,2,0.1)
#[1] 0.9471741
A.K.




On Friday, January 31, 2014 12:29 PM, Mathew Nagendran 
mathew.nagend...@mail.utoronto.ca wrote:
Hello everyone. I am quite new to R and I would appreciate some help in 
figuring out what I am doing wrong.

For the following code:

 #with cost

 m.control=c(1.45,9.40,9.96,4.2,1.86,0.2)
 m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09)

 t.control=function(m, a){(1-exp(-a*m)*(1-(1/30)*m))}
 t.sham=function(m, a, d){(1-exp(-a*(1-d)*m)*(1-(1/30)*m))}

 t.sham(2, 2, 0.1)
[1] 0.9744979
 t.control(2, 2)
[1] 0.9829054

 #without cost

 m.control=c(1.45,9.40,9.96,4.2,1.86,0.2)
 m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09)

 t.control=function(m, a){(1-exp(-a*m))}
 t.sham=function(m, a, d){(1-exp(-a*(1-d)*m))}

 t.sham(2, 2, 0.1)
[1] 0.9726763
 t.control(2, 2)
[1] 0.9816844

As you can see the values I am getting for t.control and t.sham are larger in 
the with cost scenario and this shouldn't be the case. (the cost is 
1-1/30*m). Is there something wrong I did when defining t.sham and t.control in 
the with cost section that I am failing to see?

[[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] (no subject)

2014-02-01 Thread mohammad javad Azadchehr
Hi
I want R code for bayesian CIF competing risks.
best 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] (no subject)

2014-02-01 Thread Rolf Turner

On 02/02/14 15:37, mohammad javad Azadchehr wrote:

Hi
I want R code for bayesian CIF competing risks.
best regards


I want wealth, wisdom, good looks, and to play full forward for the 
Sydney Swans.


cheers,

Rolf Turner

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

2014-02-01 Thread Jim Lemon

On 02/02/2014 01:37 PM, mohammad javad Azadchehr wrote:

Hi
I want R code for bayesian CIF competing risks.
best regards


Hi mohammad,
Have a look at the SemiCompRisks package.

Jim

PS - You deserved Rolf's reply.

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

2014-02-01 Thread Norm Matloff
I'm about halfway finished writing a book titled, Parallel Computation
for Data Science:  with Examples in R and Beyond, to be published later
this year by Chapman and Hall.

I'm making a rough draft of the first half of the book available on the Web:

http://heather.cs.ucdavis.edu/paralleldatasci.pdf

Your comments and suggestions are welcome, in fact very much hoped-for.
I took this approach when I wrote my R programming book, and found it
very helpful to me, and of much value to people who downloaded it.
Hopefully the same will be true here.

Norm Matloff

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