Re: [R] R grep question

2021-05-27 Thread Jim Lemon
Hi Kai,
You may find %in% easier than grep when multiple matches are needed:

match_strings<-c("MLH1","MSH2")
CRC<-data.frame(gene.all=c("MLH1","MSL1","MSH2","MCC3"))
CRC$MMR.gene<-ifelse(CRC$gene.all %in% match_strings,"Yes","No")

Composing your match strings before applying %in% may be more flexible
if you have more than one selection to make.

On Fri, May 28, 2021 at 1:57 AM Marc Schwartz via R-help
 wrote:
>
> Hi,
>
> A quick clarification:
>
> The regular expression is a single quoted character vector, not a
> character vector on either side of the | operator:
>
> "MLH1|MSH2"
>
> not:
>
> "MLH1"|"MSH2"
>
> The | is treated as a special character within the regular expression.
> See ?regex.
>
> grep(), when value = FALSE, returns the index of the match within the
> source vector, while when value = TRUE, returns the found character
> entries themselves.
>
> Thus, you need to be sure that your ifelse() incantation is matching the
> correct values.
>
> In the case of grepl(), it returns TRUE or FALSE, as Rui noted, thus:
>
>CRC$MMR.gene <- ifelse(grepl("MLH1|MSH2",CRC$gene.all), "Yes", "No")
>
> should work.
>
> Regards,
>
> Marc Schwartz
>
>
> Kai Yang via R-help wrote on 5/27/21 11:23 AM:
> >   Hi Rui,thank you for your suggestion.
> > but when I try the solution, I got message below:
> >
> > Error in "MLH1" | "MSH2" :   operations are possible only for numeric, 
> > logical or complex types
> >
> > does it mean, grepl can not work on character field?
> > Thanks,KaiOn Thursday, May 27, 2021, 01:37:58 AM PDT, Rui Barradas 
> >  wrote:
> >
> >   Hello,
> >
> > ifelse needs a logical condition, not the value. Try grepl.
> >
> >
> > CRC$MMR.gene <- ifelse(grepl("MLH1"|"MSH2",CRC$gene.all), "Yes", "No")
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 05:29 de 27/05/21, Kai Yang via R-help escreveu:
> >> Hi List,
> >> I wrote the code to create a new variable:
> >> CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")
> >>
> >>
> >> I need to create MMR.gene column in CRC data frame, ifgene.all column 
> >> contenes MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No
> >>
> >> But, the code doesn't work for me. Can anyone tell how to fix the code?
> >>
> >> Thank you,
> >>
> >> Kai
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Testing optimization solvers with equality constraints

2021-05-27 Thread Gabor Grothendieck
In case it is of interest this problem can be solved with an
unconstrained optimizer,
here optim, like this:

proj <- function(x) x / sqrt(sum(x * x))
opt <- optim(c(0, 0, 1), function(x) f(proj(x)))
proj(opt$par)
## [1] 5.388907e-09 7.071068e-01 7.071068e-01

On Fri, May 21, 2021 at 11:01 AM Hans W  wrote:
>
> Just by chance I came across the following example of minimizing
> a simple function
>
> (x,y,z) --> 2 (x^2 - y z)
>
> on the unit sphere, the only constraint present.
> I tried it with two starting points, x1 = (1,0,0) and x2 = (0,0,1).
>
> #-- Problem definition in R
> f = function(x)  2 * (x[1]^2 - x[2]*x[3])   # (x,y,z) |-> 2(x^2 -yz)
> g = function(x)  c(4*x[1], 2*x[3], 2*x[2])  # its gradient
>
> x0 = c(1, 0, 0); x1 = c(0, 0, 1)# starting points
> xmin = c(0, 1/sqrt(2), 1/sqrt(2))   # true minimum -1
>
> heq = function(x)  1-x[1]^2-x[2]^2-x[3]^2   # staying on the sphere
> conf = function(x) {# constraint function
> fun = x[1]^2 + x[2]^2 + x[3]^2 - 1
> return(list(ceq = fun, c = NULL))
> }
>
> I tried all the nonlinear optimization solvers in R packages that
> allow for equality constraints: 'auglag()' in alabama, 'solnl()' in
> NlcOptim, 'auglag()' in nloptr, 'solnp()' in Rsolnp, or even 'donlp2()'
> from the Rdonlp2 package (on R-Forge).
>
> None of them worked from both starting points:
>
> # alabama
> alabama::auglag(x0, fn = f, gr = g, heq = heq)  # right (inaccurate)
> alabama::auglag(x1, fn = f, gr = g, heq = heq)  # wrong
>
> # NlcOptim
> NlcOptim::solnl(x0, objfun = f, confun = conf)  # wrong
> NlcOptim::solnl(x1, objfun = f, confun = conf)  # right
>
> # nloptr
> nloptr::auglag(x0, fn = f, heq = heq)   # wrong
> # nloptr::auglag(x1, fn = f, heq = heq) # not returning
>
> # Rsolnp
> Rsolnp::solnp(x0, fun = f, eqfun = heq) # wrong
> Rsolnp::solnp(x1, fun = f, eqfun = heq) # wrong
>
> # Rdonlp2
> Rdonlp2::donlp2(x0, fn = f, nlin = list(heq),   # wrong
>nlin.lower = 0, nlin.upper = 0)
> Rdonlp2::donlp2(x1, fn = f, nlin = list(heq),   # right
>nlin.lower = 0, nlin.upper = 0)  # (fast and exact)
>
> The problem with starting point x0 appears to be that the gradient at
> that point, projected onto the unit sphere, is zero. Only alabama is
> able to handle this somehow.
>
> I do not know what problem most solvers have with starting point x1.
> The fact that Rdonlp2 is the fastest and most accurate is no surprise.
>
> If anyone with more experience with one or more of these packages can
> give a hint of what I made wrong, or how to change calling the solver
> to make it run correctly, please let me know.
>
> Thanks  -- HW
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] multilabel classification XGBoost and hyperparameter tuning

2021-05-27 Thread Carlos Ortega
Hello Agnes,

Yes, it is true, "xgboost" is not oriented for a "multi-label"
classification. "xgboost" can handle "multi-class" but not "multi-label".

Bue in "mlr", you can handle "multi-class" problems although not with
"xgboost" a base learner algorithm. You can see here how you can handle
that with "mlr":


   - https://mlr.mlr-org.com/articles/tutorial/multilabel.html


Besides that, you can see if these other alternatives could work for your
problem:

   - "utiml" was one of them but now it's not avaialble on CRAN (
   https://github.com/rivolli/utiml).
   - And this other one "mldr" could help you out:
   https://cran.r-project.org/web/packages/mldr/vignettes/mldr.pdf.

Thanks,
Carlos.

On Thu, May 27, 2021 at 7:30 PM Agnes g2g  wrote:

> Thank you for your reply.
> As far as I can see xgboost package does not provide multilabel
> classification.
> The mlr package uses a wrapper for xgboost, so I have used the package
> xgboost. But I still have the problem with the hyperparameter tuning.
>
> Did I understand you correctly?
> Do you have any other suggestion?
>
> Bye,
> Agnes
>
> 
> Van: Bert Gunter 
> Verzonden: donderdag 27 mei 2021 16:44
> Aan: Agnes g2g 
> CC: r-help@r-project.org 
> Onderwerp: Re: [R] multilabel classification XGBoost and hyperparameter
> tuning
>
> 1. A web search on "xgboost R" brought up R package "xgboost" which you
> did not mention. Did you not first try a web search or did you find that it
> did not meet your needs?
>
> 2. Have you looked here:
> https://cran.r-project.org/web/views/Cluster.html
> or here: https://cran.r-project.org/web/views/MachineLearning.html
>
> Cran's "task views" are a useful resource for such "does R have...?"
> questions.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, May 27, 2021 at 7:29 AM Agnes g2g  agnes...@hotmail.com>> wrote:
> Hi all,
>
> I want to do multilabel classification with XGBoost and tune
> hyperparameters.
> With the mlr package this does not seem possible, see
> https://stackoverflow.com/questions/67640953/feature-names-stored-in-object-and-newdata-are-different-using-mlr-package?noredirect=1#comment119651508_67640953
>
> Any ideas how to solve this?
>
> What other packages support multilabel classification for XGBoost and has
> the possibility to tune hyperparameters?
>
> Thanks in advance!
>
> Bye,
> Agnes
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] foreign package read.spss() and NA levels

2021-05-27 Thread Allen, Justin
Hi All,

Wanted to report what may be a bug or possibly an oversight, but I am unsure, 
in the "foreign" packages in the read.spss() command, 
https://cran.r-project.org/web/packages/foreign/index.html. When running the 
following code,

input <- read.spss("[.sav file location]", to.data.frame = TRUE)
str(input)

The read.spss() seems to be applying addNA() to factors so NA is being set as a 
level, and there seems to be no way to get read.spss() to bring factors in 
without doing this. This seems to be a recent change as read.spss() was not 
doing this as of a few months ago. None of the arguments in read.spss() seem to 
also stop this behaviour. I am currently on the most recent version of both R 
and the package, as of 27/05/21, and am using RStudio Version 1.4.1106.

Any thoughts?

Many Thanks,

Justin Allen

p.s. your continued maintenance and additions to R and its packages have been 
infinitely useful in my work and life and thank for that.

Justin Allen
Housing Consultant, BRE
T: 07807122647


Follow BRE on Twitter: @BRE_Group

Privileged and confidential information and/or copyright material may be 
contained in this e-mail. If you are not the intended addressee you may not 
copy or deliver it to anyone else or use it in any unauthorised manner. To do 
so is prohibited and may be unlawful. If you have received this e-mail by 
mistake, please advise the sender immediately by return e-mail and destroy all 
copies. Thank you.

Building Research Establishment Ltd, Registered under number 3319324 in England 
and Wales. VAT Registration No GB 689 9499 27 
www.bregroup.com
BRE Global Limited, Registered under number 8961297 in England and Wales. 
www.breglobal.com
Building Research Establishment and BRE Global are subsidiaries of the BRE 
Trust.
BRE Trust is a company limited by guarantee, Registered under number 3282856 in 
England and Wales, and registered as a charity in England (no. 1092193) and in 
Scotland (no. SC039320). www.bretrust.org.uk
Registered Offices: Bucknalls Lane, Garston, Watford, Hertfordshire WD25 9XX - 
Travelling to BRE: see 
www.bregroup.com/contact/directions/


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] multilabel classification XGBoost and hyperparameter tuning

2021-05-27 Thread Agnes g2g
Thank you for your reply.
As far as I can see xgboost package does not provide multilabel classification.
The mlr package uses a wrapper for xgboost, so I have used the package xgboost. 
But I still have the problem with the hyperparameter tuning.

Did I understand you correctly?
Do you have any other suggestion?

Bye,
Agnes


Van: Bert Gunter 
Verzonden: donderdag 27 mei 2021 16:44
Aan: Agnes g2g 
CC: r-help@r-project.org 
Onderwerp: Re: [R] multilabel classification XGBoost and hyperparameter tuning

1. A web search on "xgboost R" brought up R package "xgboost" which you did not 
mention. Did you not first try a web search or did you find that it did not 
meet your needs?

2. Have you looked here:  https://cran.r-project.org/web/views/Cluster.html
or here: https://cran.r-project.org/web/views/MachineLearning.html

Cran's "task views" are a useful resource for such "does R have...?" questions.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and 
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, May 27, 2021 at 7:29 AM Agnes g2g 
mailto:agnes...@hotmail.com>> wrote:
Hi all,

I want to do multilabel classification with XGBoost and tune hyperparameters.
With the mlr package this does not seem possible, see 
https://stackoverflow.com/questions/67640953/feature-names-stored-in-object-and-newdata-are-different-using-mlr-package?noredirect=1#comment119651508_67640953

Any ideas how to solve this?

What other packages support multilabel classification for XGBoost and has the 
possibility to tune hyperparameters?

Thanks in advance!

Bye,
Agnes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] multilabel classification XGBoost and hyperparameter tuning

2021-05-27 Thread Bert Gunter
One other suggestion. Per the posting guide linked below, statistical
issues such as your query on "hyperparameter tuning" are off topic on this
list, as are questions about specific nonstandard packages. You might try
posting on stats.stackexchange.com instead for help on such matters.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, May 27, 2021 at 7:51 AM Agnes g2g  wrote:

> Thank you for your reply.
> As far as I can see xgboost package does not provide multilabel
> classification.
> The mlr package uses a wrapper for xgboost, so I have used the package
> xgboost. But I still have the problem with the hyperparameter tuning.
>
> Did I understand you correctly?
> Do you have any other suggestion?
>
> Bye,
> Agnes
>
> --
> *Van:* Bert Gunter 
> *Verzonden:* donderdag 27 mei 2021 16:44
> *Aan:* Agnes g2g 
> *CC:* r-help@r-project.org 
> *Onderwerp:* Re: [R] multilabel classification XGBoost and hyperparameter
> tuning
>
> 1. A web search on "xgboost R" brought up R package "xgboost" which you
> did not mention. Did you not first try a web search or did you find that it
> did not meet your needs?
>
> 2. Have you looked here:
> https://cran.r-project.org/web/views/Cluster.html
> or here: https://cran.r-project.org/web/views/MachineLearning.html
>
> Cran's "task views" are a useful resource for such "does R have...?"
> questions.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, May 27, 2021 at 7:29 AM Agnes g2g  wrote:
>
> Hi all,
>
> I want to do multilabel classification with XGBoost and tune
> hyperparameters.
> With the mlr package this does not seem possible, see
> https://stackoverflow.com/questions/67640953/feature-names-stored-in-object-and-newdata-are-different-using-mlr-package?noredirect=1#comment119651508_67640953
>
> Any ideas how to solve this?
>
> What other packages support multilabel classification for XGBoost and has
> the possibility to tune hyperparameters?
>
> Thanks in advance!
>
> Bye,
> Agnes
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 grep question

2021-05-27 Thread Marc Schwartz via R-help

Hi,

A quick clarification:

The regular expression is a single quoted character vector, not a 
character vector on either side of the | operator:


"MLH1|MSH2"

not:

"MLH1"|"MSH2"

The | is treated as a special character within the regular expression. 
See ?regex.


grep(), when value = FALSE, returns the index of the match within the 
source vector, while when value = TRUE, returns the found character 
entries themselves.


Thus, you need to be sure that your ifelse() incantation is matching the 
correct values.


In the case of grepl(), it returns TRUE or FALSE, as Rui noted, thus:

  CRC$MMR.gene <- ifelse(grepl("MLH1|MSH2",CRC$gene.all), "Yes", "No")

should work.

Regards,

Marc Schwartz


Kai Yang via R-help wrote on 5/27/21 11:23 AM:

  Hi Rui,thank you for your suggestion.
but when I try the solution, I got message below:

Error in "MLH1" | "MSH2" :   operations are possible only for numeric, logical 
or complex types

does it mean, grepl can not work on character field?
Thanks,KaiOn Thursday, May 27, 2021, 01:37:58 AM PDT, Rui Barradas 
 wrote:
  
  Hello,


ifelse needs a logical condition, not the value. Try grepl.


CRC$MMR.gene <- ifelse(grepl("MLH1"|"MSH2",CRC$gene.all), "Yes", "No")


Hope this helps,

Rui Barradas

Às 05:29 de 27/05/21, Kai Yang via R-help escreveu:

Hi List,
I wrote the code to create a new variable:
CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")
   


I need to create MMR.gene column in CRC data frame, ifgene.all column contenes 
MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No

But, the code doesn't work for me. Can anyone tell how to fix the code?

Thank you,

Kai


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 grep question

2021-05-27 Thread Kai Yang via R-help
 Hi Rui,thank you for your suggestion. 
but when I try the solution, I got message below:

Error in "MLH1" | "MSH2" :   operations are possible only for numeric, logical 
or complex types

does it mean, grepl can not work on character field?
Thanks,KaiOn Thursday, May 27, 2021, 01:37:58 AM PDT, Rui Barradas 
 wrote:  
 
 Hello,

ifelse needs a logical condition, not the value. Try grepl.


CRC$MMR.gene <- ifelse(grepl("MLH1"|"MSH2",CRC$gene.all), "Yes", "No")


Hope this helps,

Rui Barradas

Às 05:29 de 27/05/21, Kai Yang via R-help escreveu:
> Hi List,
> I wrote the code to create a new variable:
> CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")
>  
> 
> I need to create MMR.gene column in CRC data frame, ifgene.all column 
> contenes MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No
> 
> But, the code doesn't work for me. Can anyone tell how to fix the code?
> 
> Thank you,
> 
> Kai
>     [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] multilabel classification XGBoost and hyperparameter tuning

2021-05-27 Thread Bert Gunter
1. A web search on "xgboost R" brought up R package "xgboost" which you did
not mention. Did you not first try a web search or did you find that it did
not meet your needs?

2. Have you looked here:  https://cran.r-project.org/web/views/Cluster.html
or here: https://cran.r-project.org/web/views/MachineLearning.html

Cran's "task views" are a useful resource for such "does R have...?"
questions.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, May 27, 2021 at 7:29 AM Agnes g2g  wrote:

> Hi all,
>
> I want to do multilabel classification with XGBoost and tune
> hyperparameters.
> With the mlr package this does not seem possible, see
> https://stackoverflow.com/questions/67640953/feature-names-stored-in-object-and-newdata-are-different-using-mlr-package?noredirect=1#comment119651508_67640953
>
> Any ideas how to solve this?
>
> What other packages support multilabel classification for XGBoost and has
> the possibility to tune hyperparameters?
>
> Thanks in advance!
>
> Bye,
> Agnes
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] multilabel classification XGBoost and hyperparameter tuning

2021-05-27 Thread Agnes g2g
Hi all,

I want to do multilabel classification with XGBoost and tune hyperparameters.
With the mlr package this does not seem possible, see 
https://stackoverflow.com/questions/67640953/feature-names-stored-in-object-and-newdata-are-different-using-mlr-package?noredirect=1#comment119651508_67640953

Any ideas how to solve this?

What other packages support multilabel classification for XGBoost and has the 
possibility to tune hyperparameters?

Thanks in advance!

Bye,
Agnes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Decompose df1 into another df2 based on values in df1

2021-05-27 Thread Eik Vettorazzi

A tidyverse-ish solution would be

library(dplyr)
library(tidyr)
library(tibble)

# max cols to split values into
seps<-max(stringr::str_count(unlist(d1),"[/|]"))+1

d1 %>% pivot_longer(S1:S5, names_to="S") %>% 
mutate(value=na_if(value,"w")) %>% separate(value,"[/|]", 
into=LETTERS[1:seps], fill="right") %>% pivot_longer(-S, names_to=NULL, 
values_to="rownames") %>% filter(!is.na(rownames)) %>% 
mutate(index=1L)%>%pivot_wider(names_from=S, values_from=index) %>% 
mutate_all(replace_na,0L) %>% column_to_rownames(var = "rownames")


Best, Eik

Am 26.05.2021 um 23:16 schrieb Adrian Johnson:

Hello,

I am trying to convert a df (given below as d1) into df2 (given below as
res).

  I tried using loops for each row. I cannot get it right.  Moreover the df
is 25 x 500 in dimension and I cannot get it to work.

Could anyone help me here please.

Thanks.
Adrian.

d1 <-
structure(list(S1 = c("a1|a2", "b1|b3", "w"), S2 = c("w", "b1",
"c2"), S3 = c("a2", "b3|b4|b1", "c1|c4"), S4 = c("w", "b4", "c4"
), S5 = c("a2/a3", "w", "w")), class = "data.frame", row.names = c("A",
"B", "C"))

res <-
structure(list(S1 = c(1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L),
 S2 = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L), S3 = c(0L,
 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L), S4 = c(0L, 0L, 0L, 0L,
 0L, 0L, 1L, 0L, 0L, 1L), S5 = c(0L, 1L, 1L, 0L, 0L, 0L, 0L,
 0L, 0L, 0L)), class = "data.frame", row.names = c("a1", "a2",
"a3", "b1", "b2", "b3", "b4", "c1", "c2", "c4"))

[[alternative HTML version deleted]]

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






--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Joachim Prölß, 
Prof. Dr. Blanche Schwappach-Pignataro, Marya Verdel
_

SAVE PAPER - THINK BEFORE PRINTING
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 grep question

2021-05-27 Thread Rui Barradas

Hello,

ifelse needs a logical condition, not the value. Try grepl.


CRC$MMR.gene <- ifelse(grepl("MLH1"|"MSH2",CRC$gene.all), "Yes", "No")


Hope this helps,

Rui Barradas

Às 05:29 de 27/05/21, Kai Yang via R-help escreveu:

Hi List,
I wrote the code to create a new variable:
CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")
  


I need to create MMR.gene column in CRC data frame, ifgene.all column contenes 
MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No

But, the code doesn't work for me. Can anyone tell how to fix the code?

Thank you,

Kai
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 grep question

2021-05-27 Thread Jeff Newmiller
Post in plain text

Use grepl

On May 26, 2021 9:29:10 PM PDT, Kai Yang via R-help  
wrote:
>Hi List,
>I wrote the code to create a new variable:
>CRC$MMR.gene<-ifelse(grep("MLH1"|"MSH2",CRC$gene.all,value=T),"Yes","No")
> 
>
>I need to create MMR.gene column in CRC data frame, ifgene.all column
>contenes MLH1 or MSH2, then the MMR.gene=Yes, if not,MMR.gene=No
>
>But, the code doesn't work for me. Can anyone tell how to fix the code?
>
>Thank you,
>
>Kai
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Testing optimization solvers with equality constraints

2021-05-27 Thread Abby Spurdle
I meant:
x0 = c (1, 1e-3, 0)

Not:
x0 = c (1, 1e6, 0)

So, large intentional error may work too.
Possibly, better...?

On Thu, May 27, 2021 at 6:00 PM Abby Spurdle  wrote:
>
> If I can re-answer the original post:
> There's a relatively simple solution.
> (For these problems, at least).
>
> #wrong
> x0 = c (1, 0, 0)
> NlcOptim::solnl(x0, objfun = f, confun = conf)$par
> Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), nlin.lower = 0,
> nlin.upper = 0)$par
>
> #right
> x0 = c (1, 1e6, 0)
> NlcOptim::solnl(x0, objfun = f, confun = conf)$par
> Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), nlin.lower = 0,
> nlin.upper = 0)$par
>
> So, problems with the starting point, appear to be very *specific*.
> Hence, a small amount of intentional error resolves the problem.
>
> Presumably, there are more efficient solutions, that the package
> maintainers may (or may not) want to address.
>
>
> On Thu, May 27, 2021 at 3:27 PM Abby Spurdle  wrote:
> >
> > I need to retract my previous post.
> > (Except the part that the R has extremely good numerical capabilities).
> >
> > I ran some of the examples, and Hans W was correct.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Testing optimization solvers with equality constraints

2021-05-27 Thread Abby Spurdle
If I can re-answer the original post:
There's a relatively simple solution.
(For these problems, at least).

#wrong
x0 = c (1, 0, 0)
NlcOptim::solnl(x0, objfun = f, confun = conf)$par
Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), nlin.lower = 0,
nlin.upper = 0)$par

#right
x0 = c (1, 1e6, 0)
NlcOptim::solnl(x0, objfun = f, confun = conf)$par
Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), nlin.lower = 0,
nlin.upper = 0)$par

So, problems with the starting point, appear to be very *specific*.
Hence, a small amount of intentional error resolves the problem.

Presumably, there are more efficient solutions, that the package
maintainers may (or may not) want to address.


On Thu, May 27, 2021 at 3:27 PM Abby Spurdle  wrote:
>
> I need to retract my previous post.
> (Except the part that the R has extremely good numerical capabilities).
>
> I ran some of the examples, and Hans W was correct.

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