[R] How to use AUC metric in caret

2022-09-05 Thread Neha gupta
Hello everyone

I am using nested resampling in caret (5-fold outer and bootstrap inner
resampling) and by default, it shows the "Accuracy" metric. How can I use
it for the ROC/AUC metric?

My code is:

d=readARFF("apns.arff")
index <- createDataPartition(d$isKilled , p = .70,list = FALSE)
tr <- d[index, ]
ts <- d[-index, ]

boot <- trainControl(method = "boot", number=100, search="random",
classProbs = TRUE, summaryFunction = twoClassSummary)

outer_folds <- createFolds(d$isKilled, k = 5)
boot <- trainControl(method = "boot", number=10)

CV1 <- lapply(outer_folds, function(index){
  tr <- d[-index, ]
  ts <- d[index,]

  cart1 <-train(isKilled ~ ., data = tr,
method = "rpart",

tuneLength = 20,
 metric = "Accuracy",
 preProc = c("center", "scale", "nzv"),
 trControl = boot)

  postResample(predict(cart1, ts), ts$isKilled)
})
sapply(CV1, function(x) x[3]) -> CV_MAE1
CV_MAE1

[[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] How to use contour plot?

2021-11-16 Thread Ivan Krylov
On Tue, 16 Nov 2021 09:45:34 +0100
Luigi Marongiu  wrote:

> contour(df$X, df$Y, df$Z)  

contour() works on matrices (sometimes called "wide format" data). Z
must be a numeric matrix, X must be a numeric vector with length(X) ==
nrow(Z), and Y must be a numeric vector with length(Y) == ncol(Z). This
is described in ?contour.

Since you have a three-column data.frame ("long format" data), you can
use lattice::contourplot instead (e.g. contourplot(Z ~ X + Y, data =
df)) or the appropriate combination of ggplot2 functions.

Alternatively, if your data is already on a grid, you can make a matrix
out of your three-column data.frame, but the procedure is a bit awkward:

ret <- reshape(
 df, direction = "wide", v.names = 'Z', idvar = 'X', timevar = 'Y'
)
contour(
 X <- ret[, 1],
 Y <- attr(ret, "reshapeWide")$times,
 Z <- as.matrix(ret[,-1])
)

(Can be also done with xtabs(); reshape2 and many other contributed
packages also offer some ways of doing that.)

-- 
Best regards,
Ivan

__
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] How to use contour plot?

2021-11-16 Thread Duncan Murdoch

On 16/11/2021 3:45 a.m., Luigi Marongiu wrote:

Hello,
I have a dataframe with 3 values and that I would like to plot with contour:
```

head(df)

Y   X  Z
1 0.0008094667  50 1
2 0.0012360955  50 1
3 0.0016627243  50 1
4 0.0020893531  50 1
5 0.0025159819  50 1
6 0.0029426108  50 1

contour(df$X, df$Y, df$Z)

Error in contour.default(df$X, df$Y, df$Z) :
increasing 'x' and 'y' values expected
```
Y is increasing, whereas X is decreasing. How shall I set the function?
Thank you



Contour needs the Z data in a grid, with the X and Y data corresponding 
to rows and columns.  The interp::interp() function in the interp 
package should be able to convert your data to this format; see its help 
page.  An alternative is the akima::interp() function, which may have 
licensing issues.


Duncan Murdoch

__
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] How to use contour plot?

2021-11-16 Thread Luigi Marongiu
Hello,
I have a dataframe with 3 values and that I would like to plot with contour:
```
> head(df)
   Y   X  Z
1 0.0008094667  50 1
2 0.0012360955  50 1
3 0.0016627243  50 1
4 0.0020893531  50 1
5 0.0025159819  50 1
6 0.0029426108  50 1
> contour(df$X, df$Y, df$Z)
Error in contour.default(df$X, df$Y, df$Z) :
increasing 'x' and 'y' values expected
```
Y is increasing, whereas X is decreasing. How shall I set the function?
Thank you

__
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] How to use ifelse without invoking warnings

2021-10-09 Thread Leonard Mada via R-help

Dear Ravi,


I have uploaded on GitHub a version which handles also constant values 
instead of functions.



Regarding named arguments: this is actually handled automatically as well:

eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, y=2, x)
# [1]  1  4  9 16 25  6 14  8 18 10
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, x=2, x)
# [1]  4  4  4  4  4  2 14  2 18  2
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., list(FUN[[1]], 0, 1), 
y=2, x)

 # [1]  0  0  0  0  0  1 14  1 18  1


But it still needs proper testing and maybe optimization: it is possible 
to run sapply on the filtered sequence (but I did not want to break 
anything now).



Sincerely,


Leonard



On 10/9/2021 9:26 PM, Leonard Mada wrote:

Dear Ravi,


I wrote a small replacement for ifelse() which avoids such unnecessary 
evaluations (it bothered me a few times as well - so I decided to try 
a small replacement).



### Example:
x = 1:10
FUN = list();
FUN[[1]] = function(x, y) x*y;
FUN[[2]] = function(x, y) x^2;
FUN[[3]] = function(x, y) x;
# lets run multiple conditions
# eval.by.formula(conditions, FUN.list, ... (arguments for FUN) );
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, x, x-1)
# Example 2
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, 2, x)


### Disclaimer:
- NOT properly tested;


The code for the function is below. Maybe someone can experiment with 
the code and improve it further. There are a few issues / open 
questions, like:


1.) Best Name: eval.by.formula, ifelse.formula, ...?

2.) Named arguments: not yet;

3.) Fixed values inside FUN.list

4.) Format of expression for conditions:

expression(cond1, cond2, cond3) vs cond1 ~ cond2 ~ cond3 ???

5.) Code efficiency

- some tests on large data sets & optimizations are warranted;


Sincerely,


Leonard

===

The latest code is on Github:

https://github.com/discoleo/R/blob/master/Stat/Tools.Formulas.R

[...]



__
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] How to use ifelse without invoking warnings

2021-10-09 Thread Leonard Mada via R-help

Dear Ravi,


I wrote a small replacement for ifelse() which avoids such unnecessary 
evaluations (it bothered me a few times as well - so I decided to try a 
small replacement).



### Example:
x = 1:10
FUN = list();
FUN[[1]] = function(x, y) x*y;
FUN[[2]] = function(x, y) x^2;
FUN[[3]] = function(x, y) x;
# lets run multiple conditions
# eval.by.formula(conditions, FUN.list, ... (arguments for FUN) );
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, x, x-1)
# Example 2
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, 2, x)


### Disclaimer:
- NOT properly tested;


The code for the function is below. Maybe someone can experiment with 
the code and improve it further. There are a few issues / open 
questions, like:


1.) Best Name: eval.by.formula, ifelse.formula, ...?

2.) Named arguments: not yet;

3.) Fixed values inside FUN.list

4.) Format of expression for conditions:

expression(cond1, cond2, cond3) vs cond1 ~ cond2 ~ cond3 ???

5.) Code efficiency

- some tests on large data sets & optimizations are warranted;


Sincerely,


Leonard

===

The latest code is on Github:

https://github.com/discoleo/R/blob/master/Stat/Tools.Formulas.R


eval.by.formula = function(e, FUN.list, ..., default=NA) {
    tok = split.formula(e);
    if(length(tok) == 0) return();
    FUN = FUN.list;
    # Argument List
    clst = substitute(as.list(...))[-1];
    len  = length(clst);
    clst.all = lapply(clst, eval);
    eval.f = function(idCond) {
    sapply(seq(length(isEval)), function(id) {
        if(isEval[[id]] == FALSE) return(default);
        args.l = lapply(clst.all, function(a) if(length(a) == 1) a 
else a[[id]]);

        do.call(FUN[[idCond]], args.l);
    });
    }
    # eval 1st condition:
    isEval = eval(tok[[1]]);
    rez = eval.f(1);
    if(length(tok) == 1) return(rez);
    # eval remaining conditions
    isEvalAll = isEval;
    for(id in seq(2, length(tok))) {
    if(tok[[id]] == ".") {
        # Remaining conditions: tok == ".";
        # makes sens only on the last position
        if(id < length(tok)) warning("\".\" is not last!");
        isEval = ! isEvalAll;
        rez[isEval] = eval.f(id)[isEval];
        next;
    }
    isEval = rep(FALSE, length(isEval));
    isEval[ ! isEvalAll] = eval(tok[[id]])[ ! isEvalAll];
    isEvalAll[isEval] = isEval[isEval];
    rez[isEval] = eval.f(id)[isEval];
    }
    return(rez);
}


# current code uses the formula format:
# cond1 ~ cond 2 ~ cond3

# tokenizes a formula in its parts delimited by "~"
# Note:
# - tokenization is automatic for ",";
# - but call MUST then use FUN(expression(_conditions_), other_args, ...);
split.formula = function(e) {
    tok = list();
    while(length(e) > 0) {
    if(e[[1]] == "~") {
        if(length(e) == 2) { tok = c(NA, e[[2]], tok); break; }
        tok = c(e[[3]], tok);
        e = e[[2]];
    } else {
        tok = c(e, tok); break;
    }
    }
    return(tok);
}

__
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] How to use ifelse without invoking warnings

2021-10-08 Thread Deepayan Sarkar
On Sat, Oct 9, 2021 at 3:00 AM Ravi Varadhan via R-help
 wrote:
>
> Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but 
> I felt that
> there must be a more principled approach.  While John's solution is what I 
> would prefer,
> I cannot help but wonder why `ifelse' was not constructed to avoid this 
> behavior.

Note that John's approach is mentioned twice in the help page for
ifelse, once in the examples, and once quite early on in the "Warning"
section:

 Sometimes it is better to use a construction such as

   (tmp <- yes; tmp[!test] <- no[!test]; tmp)

 , possibly extended to handle missing values in 'test'.

Best,
-Deepayan

> Thanks & Best regards,
> Ravi
> 
> From: John Fox 
> Sent: Thursday, October 7, 2021 2:00 PM
> To: Ravi Varadhan 
> Cc: R-Help 
> Subject: Re: [R] How to use ifelse without invoking warnings
>
>
>   External Email - Use Caution
>
>
>
> Dear Ravi,
>
> It's already been suggested that you could disable warnings, but that's
> risky in case there's a warning that you didn't anticipate. Here's a
> different approach:
>
>  > kk <- k[k >= -1 & k <= n]
>  > ans <- numeric(length(k))
>  > ans[k > n] <- 1
>  > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
>  > ans
> [1] 0.0 0.006821826 0.254991551 1.0
>
> BTW, I don't think that you mentioned that p = 0.3, but that seems
> apparent from the output you showed.
>
> I hope this helps,
>   John
>
> --
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: 
> https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7gcEEXhM3qFi7n78ZM%3Dreserved=0
>
> On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:
> > Hi,
> > I would like to execute the following vectorized calculation:
> >
> >ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
> > ifelse (k < -1, 0, 1) )
> >
> > For example:
> >
> >
> >> k <- c(-1.2,-0.5, 1.5, 10.4)
> >> n <- 10
> >> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse 
> >> (k < -1, 0, 1) )
> > Warning message:
> > In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> >> print(ans)
> > [1] 0.0 0.006821826 0.254991551 1.0
> >
> > The answer is correct.  However, I would like to eliminate the annoying 
> > warnings.  Is there a better way to do this?
> >
> > Thank you,
> > Ravi
> >
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Dreserved=0
> > PLEASE do read the posting guide 
> > https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=ss2ohzJIY6qj0eAexk4yVzTzbjXxK5VZNors0GpsbA0%3Dreserved=0
> > 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-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] How to use ifelse without invoking warnings

2021-10-08 Thread Jeff Newmiller
I don't think it is avoidable... ifelse cannot figure out which elements will 
exist in the second and third arguments until they are evaluated, so it cannot 
make use of the TRUE/FALSE information until both possible output vectors have 
been evaluated, which is a performance hit and yields warnings or errors.

You, on the other hand, can figure that out and use input validation to limit 
which inputs get fed into the warning- or error- producing algorithm and put 
the results into a final result vector using indexed assignment as Dr Fox 
suggested.


On October 8, 2021 5:21:44 AM PDT, Ravi Varadhan via R-help 
 wrote:
>Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but I 
>felt that there must be a more principled approach.  While John's solution is 
>what I would prefer, I cannot help but wonder why `ifelse' was not constructed 
>to avoid this behavior.
>
>Thanks & Best regards,
>Ravi
>
>From: John Fox 
>Sent: Thursday, October 7, 2021 2:00 PM
>To: Ravi Varadhan 
>Cc: R-Help 
>Subject: Re: [R] How to use ifelse without invoking warnings
>
>
>  External Email - Use Caution
>
>
>
>Dear Ravi,
>
>It's already been suggested that you could disable warnings, but that's
>risky in case there's a warning that you didn't anticipate. Here's a
>different approach:
>
> > kk <- k[k >= -1 & k <= n]
> > ans <- numeric(length(k))
> > ans[k > n] <- 1
> > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
> > ans
>[1] 0.0 0.006821826 0.254991551 1.0
>
>BTW, I don't think that you mentioned that p = 0.3, but that seems
>apparent from the output you showed.
>
>I hope this helps,
>  John
>
>--
>John Fox, Professor Emeritus
>McMaster University
>Hamilton, Ontario, Canada
>web: 
>https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7gcEEXhM3qFi7n78ZM%3Dreserved=0
>
>On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:
>> Hi,
>> I would like to execute the following vectorized calculation:
>>
>>ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
>> ifelse (k < -1, 0, 1) )
>>
>> For example:
>>
>>
>>> k <- c(-1.2,-0.5, 1.5, 10.4)
>>> n <- 10
>>> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse 
>>> (k < -1, 0, 1) )
>> Warning message:
>> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
>>> print(ans)
>> [1] 0.0 0.006821826 0.254991551 1.0
>>
>> The answer is correct.  However, I would like to eliminate the annoying 
>> warnings.  Is there a better way to do this?
>>
>> Thank you,
>> Ravi
>>
>>
>>   [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Dreserved=0
>> PLEASE do read the posting guide 
>> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=ss2ohzJIY6qj0eAexk4yVzTzbjXxK5VZNors0GpsbA0%3Dreserved=0
>> 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.

-- 
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] How to use ifelse without invoking warnings

2021-10-08 Thread Avi Gross via R-help
Ravi,

I have no idea what motivated the people who made ifelse() but there is no
reason they felt the need to program it to meet your precise need. As others
have noted, it probably was built to handle simple cases well and it expects
to return a result that is the same length as the input. If some of the
processing returns an NA or a NaN then that is what it probably should
return. 

What is the alternative? Return a shorter result? Replace it with a zero?
Fail utterly and abort the program?

YOU as the programmer should make such decisions for a non-routine case.

You can create functions with names like wrapperIf() and wrapperElse() and
do your ifelse like this:

result <- ifelse(condition, wrapperIf(args), wrapperElse(args))

Why the wrappers? If your logic is to replace NaN with 0 or NA or 666 or
Inf, then the code for it would invoke your functionality and if tested to
be a NaN it would replace it as you wish. Yes, it would slow things down a
bit but leave the ifelse() routine fairly simple.

If your goal is to remove those entries, you can do it after by manipulating
"result" above such as not keeping any item that matches 666, or even
without the wrappers, something like:

result <- result[!is.nan(result)]

But, of course, warnings are only suppressed if done right. Clearly you can
very selectively suppress warnings in the wrapper functions above without
also suppressing some other more valid warnings. But if the warning is
coming from ifelse() itself then not ever having it see a NaN would suppress
that.

Do note that the implementation of ifelse() is currently a function, not
some internal call. You can copy that and make your own slightly modified
version if you wish. 

(no R) Avi

-Original Message-
From: R-help  On Behalf Of Ravi Varadhan via
R-help
Sent: Friday, October 8, 2021 8:22 AMiu
To: John Fox l
Cc: R-Help 
Subject: Re: [R] How to use ifelse without invoking warnings

Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but
I felt that there must be a more principled approach.  While John's solution
is what I would prefer, I cannot help but wonder why `ifelse' was not
constructed to avoid this behavior.

Thanks & Best regards,
Ravi

From: John Fox 
Sent: Thursday, October 7, 2021 2:00 PM
To: Ravi Varadhan 
Cc: R-Help 
Subject: Re: [R] How to use ifelse without invoking warnings


  External Email - Use Caution



Dear Ravi,

It's already been suggested that you could disable warnings, but that's
risky in case there's a warning that you didn't anticipate. Here's a
different approach:

 > kk <- k[k >= -1 & k <= n]
 > ans <- numeric(length(k))
 > ans[k > n] <- 1
 > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)  >
ans [1] 0.0 0.006821826 0.254991551 1.0

BTW, I don't think that you mentioned that p = 0.3, but that seems apparent
from the output you showed.

I hope this helps,
  John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web:
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialscie
nces.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd88
2e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C63
7692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzI
iLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7g
cEEXhM3qFi7n78ZM%3Dreserved=0

On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:
> Hi,
> I would like to execute the following vectorized calculation:
>
>ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = 
> FALSE), ifelse (k < -1, 0, 1) )
>
> For example:
>
>
>> k <- c(-1.2,-0.5, 1.5, 10.4)
>> n <- 10
>> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), 
>> ifelse (k < -1, 0, 1) )
> Warning message:
> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
>> print(ans)
> [1] 0.0 0.006821826 0.254991551 1.0
>
> The answer is correct.  However, I would like to eliminate the annoying
warnings.  Is there a better way to do this?
>
> Thank you,
> Ravi
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
> .ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadha
> n%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f8
> 6f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWI
> joiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000
> mp;sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Drese
> rved=0 PLEASE do read the posting g

Re: [R] How to use ifelse without invoking warnings

2021-10-08 Thread Ravi Varadhan via R-help
Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but I 
felt that there must be a more principled approach.  While John's solution is 
what I would prefer, I cannot help but wonder why `ifelse' was not constructed 
to avoid this behavior.

Thanks & Best regards,
Ravi

From: John Fox 
Sent: Thursday, October 7, 2021 2:00 PM
To: Ravi Varadhan 
Cc: R-Help 
Subject: Re: [R] How to use ifelse without invoking warnings


  External Email - Use Caution



Dear Ravi,

It's already been suggested that you could disable warnings, but that's
risky in case there's a warning that you didn't anticipate. Here's a
different approach:

 > kk <- k[k >= -1 & k <= n]
 > ans <- numeric(length(k))
 > ans[k > n] <- 1
 > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
 > ans
[1] 0.0 0.006821826 0.254991551 1.0

BTW, I don't think that you mentioned that p = 0.3, but that seems
apparent from the output you showed.

I hope this helps,
  John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: 
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7gcEEXhM3qFi7n78ZM%3Dreserved=0

On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:
> Hi,
> I would like to execute the following vectorized calculation:
>
>ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
> ifelse (k < -1, 0, 1) )
>
> For example:
>
>
>> k <- c(-1.2,-0.5, 1.5, 10.4)
>> n <- 10
>> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse 
>> (k < -1, 0, 1) )
> Warning message:
> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
>> print(ans)
> [1] 0.0 0.006821826 0.254991551 1.0
>
> The answer is correct.  However, I would like to eliminate the annoying 
> warnings.  Is there a better way to do this?
>
> Thank you,
> Ravi
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Dreserved=0
> PLEASE do read the posting guide 
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=ss2ohzJIY6qj0eAexk4yVzTzbjXxK5VZNors0GpsbA0%3Dreserved=0
> 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] How to use ifelse without invoking warnings

2021-10-08 Thread John Fox

Dear Ravi,

On 2021-10-08 8:21 a.m., Ravi Varadhan wrote:
Thank you to Bert, Sarah, and John. I did consider suppressing warnings, 
but I felt that there must be a more principled approach.  While John's 
solution is what I would prefer, I cannot help but wonder why `ifelse' 
was not constructed to avoid this behavior.


The conditional if () else, which works on an individual logical value, 
uses lazy evaluation and so can avoid the problem you encountered. My 
guess is that implementing lazy evaluation for the vectorized ifelse() 
would incur too high a computational overhead for large arguments.


Best,
 John



Thanks & Best regards,
Ravi

*From:* John Fox 
*Sent:* Thursday, October 7, 2021 2:00 PM
*To:* Ravi Varadhan 
*Cc:* R-Help 
*Subject:* Re: [R] How to use ifelse without invoking warnings

   External Email - Use Caution



Dear Ravi,

It's already been suggested that you could disable warnings, but that's
risky in case there's a warning that you didn't anticipate. Here's a
different approach:

  > kk <- k[k >= -1 & k <= n]
  > ans <- numeric(length(k))
  > ans[k > n] <- 1
  > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
  > ans
[1] 0.0 0.006821826 0.254991551 1.0

BTW, I don't think that you mentioned that p = 0.3, but that seems
apparent from the output you showed.

I hope this helps,
   John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: 
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7gcEEXhM3qFi7n78ZM%3Dreserved=0 
<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsocialsciences.mcmaster.ca%2Fjfox%2Fdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160038474%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=Q33yXm36BwEVKUWO72CWFpSUx7gcEEXhM3qFi7n78ZM%3Dreserved=0>


On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:

Hi,
I would like to execute the following vectorized calculation:

    ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
ifelse (k < -1, 0, 1) )

For example:



k <- c(-1.2,-0.5, 1.5, 10.4)
n <- 10
ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < 
-1, 0, 1) )

Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced

print(ans)

[1] 0.0 0.006821826 0.254991551 1.0

The answer is correct.  However, I would like to eliminate the annoying 
warnings.  Is there a better way to do this?

Thank you,
Ravi


   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Dreserved=0 

<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=FXX%2B4zNT0JHBnDFO5dXBDQ484oQF1EK5%2Fa0dG9P%2F4k4%3Dreserved=0>
PLEASE do read the posting guide https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=ss2ohzJIY6qj0eAexk4yVzTzbjXxK5VZNors0GpsbA0%3Dreserved=0 

<https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7Cravi.varadhan%40jhu.edu%7Cfd882e7c4f4349db34e108d989bc6a9f%7C9fa4f438b1e6473b803f86f8aedf0dec%7C0%7C0%7C637692265160048428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000sdata=ss2ohzJIY6qj0eAexk4yVzTzbjXxK5VZNors0GpsbA0%3Dreserved=0>

and provide commented, minimal, self-contained, reproducible code.



Re: [R] How to use ifelse without invoking warnings

2021-10-07 Thread John Fox

Dear Ravi,

It's already been suggested that you could disable warnings, but that's 
risky in case there's a warning that you didn't anticipate. Here's a 
different approach:


> kk <- k[k >= -1 & k <= n]
> ans <- numeric(length(k))
> ans[k > n] <- 1
> ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
> ans
[1] 0.0 0.006821826 0.254991551 1.0

BTW, I don't think that you mentioned that p = 0.3, but that seems 
apparent from the output you showed.


I hope this helps,
 John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2021-10-07 12:29 p.m., Ravi Varadhan via R-help wrote:

Hi,
I would like to execute the following vectorized calculation:

   ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), ifelse 
(k < -1, 0, 1) )

For example:



k <- c(-1.2,-0.5, 1.5, 10.4)
n <- 10
ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < 
-1, 0, 1) )

Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced

print(ans)

[1] 0.0 0.006821826 0.254991551 1.0

The answer is correct.  However, I would like to eliminate the annoying 
warnings.  Is there a better way to do this?

Thank you,
Ravi


[[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] How to use ifelse without invoking warnings

2021-10-07 Thread Sarah Goslee
Bert's approach is much less risky!

On Thu, Oct 7, 2021 at 1:37 PM Bert Gunter  wrote:
>
> ?suppressWarnings
>
> > p <- .05
> > k <- c(-1.2,-0.5, 1.5, 10.4)
> > n <- 10
> >
> > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
> ifelse (k < -1, 0, 1) )
> Warning message:
> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> >
> > suppressWarnings(ans <- ifelse (k >= -1 & k <= n,
> pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < -1, 0, 1) ))
> ## no warnings
>
> 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, Oct 7, 2021 at 10:21 AM Ravi Varadhan via R-help <
> r-help@r-project.org> wrote:
>
> > Hi,
> > I would like to execute the following vectorized calculation:
> >
> >   ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE),
> > ifelse (k < -1, 0, 1) )
> >
> > For example:
> >
> >
> > > k <- c(-1.2,-0.5, 1.5, 10.4)
> > > n <- 10
> > > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
> > ifelse (k < -1, 0, 1) )
> > Warning message:
> > In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> > > print(ans)
> > [1] 0.0 0.006821826 0.254991551 1.0
> >
> > The answer is correct.  However, I would like to eliminate the annoying
> > warnings.  Is there a better way to do this?
> >
> > Thank you,
> > Ravi
> >
> >
> > [[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.



-- 
Sarah Goslee (she/her)
http://www.sarahgoslee.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] How to use ifelse without invoking warnings

2021-10-07 Thread Sarah Goslee
If you are positive the warnings don't matter for your application,
you can disable them: see ?options for details of warn.

But that can be dangerous, so be careful!

Sarah

On Thu, Oct 7, 2021 at 1:21 PM Ravi Varadhan via R-help
 wrote:
>
> Hi,
> I would like to execute the following vectorized calculation:
>
>   ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
> ifelse (k < -1, 0, 1) )
>
> For example:
>
>
> > k <- c(-1.2,-0.5, 1.5, 10.4)
> > n <- 10
> > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse 
> > (k < -1, 0, 1) )
> Warning message:
> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> > print(ans)
> [1] 0.0 0.006821826 0.254991551 1.0
>
> The answer is correct.  However, I would like to eliminate the annoying 
> warnings.  Is there a better way to do this?
>
> Thank you,
> Ravi
>
>
> [[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.



-- 
Sarah Goslee (she/her)
http://www.sarahgoslee.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] How to use ifelse without invoking warnings

2021-10-07 Thread Bert Gunter
?suppressWarnings

> p <- .05
> k <- c(-1.2,-0.5, 1.5, 10.4)
> n <- 10
>
> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
ifelse (k < -1, 0, 1) )
Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
>
> suppressWarnings(ans <- ifelse (k >= -1 & k <= n,
pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k < -1, 0, 1) ))
## no warnings

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, Oct 7, 2021 at 10:21 AM Ravi Varadhan via R-help <
r-help@r-project.org> wrote:

> Hi,
> I would like to execute the following vectorized calculation:
>
>   ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE),
> ifelse (k < -1, 0, 1) )
>
> For example:
>
>
> > k <- c(-1.2,-0.5, 1.5, 10.4)
> > n <- 10
> > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
> ifelse (k < -1, 0, 1) )
> Warning message:
> In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> > print(ans)
> [1] 0.0 0.006821826 0.254991551 1.0
>
> The answer is correct.  However, I would like to eliminate the annoying
> warnings.  Is there a better way to do this?
>
> Thank you,
> Ravi
>
>
> [[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] How to use ifelse without invoking warnings

2021-10-07 Thread Ravi Varadhan via R-help
Hi,
I would like to execute the following vectorized calculation:

  ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE), 
ifelse (k < -1, 0, 1) )

For example:


> k <- c(-1.2,-0.5, 1.5, 10.4)
> n <- 10
> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifelse (k 
> < -1, 0, 1) )
Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
> print(ans)
[1] 0.0 0.006821826 0.254991551 1.0

The answer is correct.  However, I would like to eliminate the annoying 
warnings.  Is there a better way to do this?

Thank you,
Ravi


[[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] How to use R for Speech to text conversion

2020-10-07 Thread Jeff Newmiller
Whether you use RStudio is up to you... the heavy lifting would be done by R 
anyway.

I am not a STT person, but TensorFlow was recently released on CRAN [1] so 
there may be more opportunities for R users to make headway in this area.

[1] https://tensorflow.rstudio.com/installation/

On October 7, 2020 11:31:41 AM PDT, Bert Gunter  wrote:
>Have you checked here:
>https://cran.r-project.org/web/views/NaturalLanguageProcessing.html
>
>Speech to text is a very complex, specialized task requiring, I would
>expect, a lot of IP. It would not surprise
>me if you have to resort to big time, specialized software products
>with or
>without R. "Speech to text with R"
>found some hits, but mostly the google package you refer to. You might
>do
>better with Python.
>
>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 Wed, Oct 7, 2020 at 9:31 AM Gayathri Nagarajan <
>gayathri.nagara...@gmail.com> wrote:
>
>> Hi
>>
>> Iam a newbie to NLP and I would like to get some directions on how to
>> convert speech file to text
>>
>> Google search leads me to using GoogleLanguageR Package and API's but
>these
>> need payments to be made for Google.
>>
>> Can someone suggest ways in which I can do the speech to text
>conversion in
>> R studio ?
>>
>> Thanks for your help and time
>>
>> Regards
>> Gayathri
>>
>> [[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.

-- 
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] How to use R for Speech to text conversion

2020-10-07 Thread Bert Gunter
Have you checked here:
https://cran.r-project.org/web/views/NaturalLanguageProcessing.html

Speech to text is a very complex, specialized task requiring, I would
expect, a lot of IP. It would not surprise
me if you have to resort to big time, specialized software products with or
without R. "Speech to text with R"
found some hits, but mostly the google package you refer to. You might do
better with Python.

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 Wed, Oct 7, 2020 at 9:31 AM Gayathri Nagarajan <
gayathri.nagara...@gmail.com> wrote:

> Hi
>
> Iam a newbie to NLP and I would like to get some directions on how to
> convert speech file to text
>
> Google search leads me to using GoogleLanguageR Package and API's but these
> need payments to be made for Google.
>
> Can someone suggest ways in which I can do the speech to text conversion in
> R studio ?
>
> Thanks for your help and time
>
> Regards
> Gayathri
>
> [[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] How to use R for Speech to text conversion

2020-10-07 Thread Marc Roos
 



I am also interested in this.
Maybe a start:
https://voice.mozilla.org/





-Original Message-
To: r-help@r-project.org
Subject: *SPAM* [R] How to use R for Speech to text conversion

Hi

Iam a newbie to NLP and I would like to get some directions on how to 
convert speech file to text

Google search leads me to using GoogleLanguageR Package and API's but 
these need payments to be made for Google.

Can someone suggest ways in which I can do the speech to text conversion 
in R studio ?

Thanks for your help and time

Regards
Gayathri

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


[R] How to use R for Speech to text conversion

2020-10-07 Thread Gayathri Nagarajan
Hi

Iam a newbie to NLP and I would like to get some directions on how to
convert speech file to text

Google search leads me to using GoogleLanguageR Package and API's but these
need payments to be made for Google.

Can someone suggest ways in which I can do the speech to text conversion in
R studio ?

Thanks for your help and time

Regards
Gayathri

[[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] How to use mle2 function?

2020-07-01 Thread peter dalgaard
The basic problem is that holling() is not a (negative) loglikelihood function. 
nll() _is_ a negative loglikelihood, but it is not clear for what. You appear 
to be very confused as to what a likelihood even is (what is k? apparently your 
response variable? Then how can it be a scalar if X is a vector? etc.), so I 
think you need to read up a bit. 

-pd

> On 30 Jun 2020, at 14:22 , Luigi Marongiu  wrote:
> 
> No, I got the same. I reckon the problem is with X: this was I scalar,
> I was providing a vector with the actual values.
> Ho can mle2 optimize without knowing what are the actual data? and
> what values should I give for X?
> Thank you
> 
> On Tue, Jun 30, 2020 at 2:06 PM Eric Berger  wrote:
>> 
>> I have no problem with the following code:
>> 
>> library(bbmle)
>> holling <- function( a, b, x ) {
>> a*x^2 / (b^2 + x^2)
>> }
>> A=3261
>> B=10
>> X=30
>> foo <- mle2( minuslogl=holling, start=list(a=A,b=B,x=X) )
>> 
>> foo
>> 
>> # Call:
>> # mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
>> 
>> # Coefficients:
>> #a b x
>> # 3.260044e+03  7.315124e+01 -2.332448e-14
>> 
>> # Log-likelihood: 0
>> 
>> 
>> Does this code create a problem for you?
>> 
>> On Tue, Jun 30, 2020 at 3:00 PM Luigi Marongiu  
>> wrote:
>>> 
>>> Sorry for the typo, but I have the same error if using b instead of h:
>>> ```
 O = mle2(minuslogl = holling, start = list(a = A, b = B))
 Error in minuslogl(a = 3261, b = 10) :
>>>  argument "x" is missing, with no default
>>> # let's add x
>>> X = c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,  344,  408,  
>>> 473,
>>>  546,  619,  705,  794,  891,  999, 1096, 1242, 1363, 1506, 1648, 1753,
>>>  1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 2818,
>>>  2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 3152,
>>>  3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
>>> O = mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
>>> Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
>>>  some named arguments in 'start' are not arguments to the specified
>>> log-likelihood function
>>> ```
>>> And even if I use the log-likelihood function:
>>> ```
>>> O = mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720, x = X))
 Error in mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720,  :
>>>  some named arguments in 'start' are not arguments to the specified
>>> log-likelihood function
>>> ```
>>> 
>>> On Tue, Jun 30, 2020 at 12:03 PM Eric Berger  wrote:
 
 Hi Luigi,
 I took a quick look.
 
 First error:
 You wrote
 O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
 
 it should be b=B  (h is not an argument of holling())
 The error message gave very precise information!
 
 Second error:
 You wrote
 O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
 = 5720, k = A))
 but the arguments to nll() are p,n,k. Setting start to values for a
 and h causes the function to complain.
 
 HTH,
 Eric
 
 On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
  wrote:
> 
> Hello,
> I would like to optimize the function:
> ```
> holling = function(a, b, x) {
>  y = (a * x^2) / (b^2 + x^2)
>  return(y)
> }
> ```
> I am trying to use the function mle2 from bbmle, but how do I need to
> feed the data?
> If I give `holling` as function to be optimized, passing the starting
> values for `a`, `b`, and `x`, I get:
> ```
> X = 1:60
> A = 3261
> B = 10
> O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
>> Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
>  some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
> If I pass the negative log-function (assuming a binomial distribution
> of the data, which I am not sure about)
> ```
> nll = function(p, n, k) {
>  # extract parms
>  a = p[1]
>  h = p[2]
>  # calculate probability of attack
>  pred = a/(1+a*h*n)
>  # calc NLL
>  -sum(dbinom(k, prob = pred, size = n, log = TRUE))
> }
> ```
> then I get the same error:
> ```
>> O = mle2(minuslogl = nll, start = list(a = A, h = B),
> +  data = list(n = 5720, k = A))
> Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
> list(n = 5720,  :
>  some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
> but with the disadvantage of working on an assumed function (nll).
> How can I optimize the function `holling` properly?
> Thank you
> 
> 
> 
> 
> --
> Best regards,
> Luigi
> 
> __
> R-help@r-project.org mailing 

Re: [R] How to use mle2 function?

2020-06-30 Thread Luigi Marongiu
Addendum:
the optimization actually got a worse outcome than the original
eyeball estimation:
```
actual <- c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,
344,  408,  473,
  546,  619,  705,  794,  891,  999, 1096, 1242, 1363,
1506, 1648, 1753,
  1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646,
2698, 2727, 2771, 2818,
  2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080,
3102, 3119, 3141, 3152,
  3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239,
3246, 3252, 3261)
# a = 3261, b = 10
raw_estim <- c(32.28713,  125.42308,  269.25688,  449.79310,  652.2,
   863.20588, 1072.40940, 1272.58537,
1459.34254, 1630.5, 1785.43439, 1924.52459, 2048.73234,
2159.31081, 2257.61538, 2344.98876,
2422.69666, 2491.89623, 2553.62473, 2608.8, 2658.22736,
2702.60959, 2742.55803, 2778.60355,
2811.20690, 2840.76804, 2867.63450, 2892.10860, 2914.45377,
2934.9, 2953.64844, 2970.87544,
2986.73591, 3001.36624, 3014.88679, 3027.40401, 3039.01225,
3049.79534, 3059.82788, 3069.17647,
3077.90062, 3086.05365, 3093.68343, 3100.83301, 3107.54118,
3113.84296, 3119.77003, 3125.35108,
3130.61216, 3135.57692, 3140.26694, 3144.70185, 3148.89962,
3152.87666, 3156.64800, 3160.22744,
3163.62765, 3166.86028, 3169.93605, 3172.86486)
# a = 3260.044, b = 73.15124
opt_estim <- c(38.52979,  316.81330,  721.54423, 1388.30154,
1945.64544, 2320.94319,
   2653.48033, 2861.46076,
2987.10641, 3061.17472, 3119.00396, 3158.51140, 3183.89232,
3202.55891, 3215.14235, 3225.31935,
3232.60583, 3238.21701, 3242.65745, 3245.58576, 3248.77411,
3250.68076, 3252.37050, 3253.63342,
3254.37708, 3254.96034, 3255.63152, 3256.09680, 3256.50500,
3256.82832, 3257.08020, 3257.41517,
3257.55425, 3257.64923, 3257.69986, 3257.77366, 3257.84871,
3257.90221, 3257.96386, 3258.00768,
3258.05952, 3258.10037, 3258.13871, 3258.17347, 3258.20611,
3258.23207, 3258.25176, 3258.27676,
3258.28907, 3258.29683, 3258.31112, 3258.32198, 3258.33703,
3258.35083, 3258.36237, 3258.37379,
3258.38203, 3258.38919, 3258.39528, 3258.40437)
plot(1:60, actual, lty = 1 , type = "l", lwd = 2,
 xlab = "Index", ylab = "Values")
points(1:60, raw_estim, lty = 2, type = "l")
points(1:60, opt_estim, lty = 3, type = "l")
legend("bottomright",
   legend = c("Actual values", "Raw estimate", "Optimized values"),
   lty = c(1, 2, 3), lwd = c(2, 1,1))
```

On Tue, Jun 30, 2020 at 2:06 PM Eric Berger  wrote:
>
> I have no problem with the following code:
>
> library(bbmle)
> holling <- function( a, b, x ) {
> a*x^2 / (b^2 + x^2)
> }
> A=3261
> B=10
> X=30
> foo <- mle2( minuslogl=holling, start=list(a=A,b=B,x=X) )
>
> foo
>
> # Call:
> # mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
>
> # Coefficients:
> #a b x
> # 3.260044e+03  7.315124e+01 -2.332448e-14
>
> # Log-likelihood: 0
>
>
> Does this code create a problem for you?
>
> On Tue, Jun 30, 2020 at 3:00 PM Luigi Marongiu  
> wrote:
> >
> > Sorry for the typo, but I have the same error if using b instead of h:
> > ```
> > > O = mle2(minuslogl = holling, start = list(a = A, b = B))
> > > Error in minuslogl(a = 3261, b = 10) :
> >   argument "x" is missing, with no default
> > # let's add x
> > X = c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,  344,  408,  
> > 473,
> >   546,  619,  705,  794,  891,  999, 1096, 1242, 1363, 1506, 1648, 1753,
> >   1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 
> > 2818,
> >   2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 
> > 3152,
> >   3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
> > O = mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
> > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> > And even if I use the log-likelihood function:
> > ```
> > O = mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720, x = X))
> > > Error in mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720,  :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> >
> > On Tue, Jun 30, 2020 at 12:03 PM Eric Berger  wrote:
> > >
> > > Hi Luigi,
> > > I took a quick look.
> > >
> > > First error:
> > > You wrote
> > > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > >
> > > it should be b=B  (h is not an argument of holling())
> > > The error message gave very precise information!
> > >
> > > Second error:
> > > You wrote
> > > O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
> > > = 5720, k = A))
> > > but the arguments to nll() are p,n,k. Setting start to values for a
> > > and h causes the function to complain.
> > >
> > > HTH,
> > > Eric
> > >
> > > On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
> > >  wrote:
> > > >
> > > > Hello,
> > > > I would 

Re: [R] How to use mle2 function?

2020-06-30 Thread Luigi Marongiu
No, I got the same. I reckon the problem is with X: this was I scalar,
I was providing a vector with the actual values.
Ho can mle2 optimize without knowing what are the actual data? and
what values should I give for X?
Thank you

On Tue, Jun 30, 2020 at 2:06 PM Eric Berger  wrote:
>
> I have no problem with the following code:
>
> library(bbmle)
> holling <- function( a, b, x ) {
> a*x^2 / (b^2 + x^2)
> }
> A=3261
> B=10
> X=30
> foo <- mle2( minuslogl=holling, start=list(a=A,b=B,x=X) )
>
> foo
>
> # Call:
> # mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
>
> # Coefficients:
> #a b x
> # 3.260044e+03  7.315124e+01 -2.332448e-14
>
> # Log-likelihood: 0
>
>
> Does this code create a problem for you?
>
> On Tue, Jun 30, 2020 at 3:00 PM Luigi Marongiu  
> wrote:
> >
> > Sorry for the typo, but I have the same error if using b instead of h:
> > ```
> > > O = mle2(minuslogl = holling, start = list(a = A, b = B))
> > > Error in minuslogl(a = 3261, b = 10) :
> >   argument "x" is missing, with no default
> > # let's add x
> > X = c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,  344,  408,  
> > 473,
> >   546,  619,  705,  794,  891,  999, 1096, 1242, 1363, 1506, 1648, 1753,
> >   1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 
> > 2818,
> >   2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 
> > 3152,
> >   3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
> > O = mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
> > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> > And even if I use the log-likelihood function:
> > ```
> > O = mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720, x = X))
> > > Error in mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720,  :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> >
> > On Tue, Jun 30, 2020 at 12:03 PM Eric Berger  wrote:
> > >
> > > Hi Luigi,
> > > I took a quick look.
> > >
> > > First error:
> > > You wrote
> > > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > >
> > > it should be b=B  (h is not an argument of holling())
> > > The error message gave very precise information!
> > >
> > > Second error:
> > > You wrote
> > > O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
> > > = 5720, k = A))
> > > but the arguments to nll() are p,n,k. Setting start to values for a
> > > and h causes the function to complain.
> > >
> > > HTH,
> > > Eric
> > >
> > > On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
> > >  wrote:
> > > >
> > > > Hello,
> > > > I would like to optimize the function:
> > > > ```
> > > > holling = function(a, b, x) {
> > > >   y = (a * x^2) / (b^2 + x^2)
> > > >   return(y)
> > > > }
> > > > ```
> > > > I am trying to use the function mle2 from bbmle, but how do I need to
> > > > feed the data?
> > > > If I give `holling` as function to be optimized, passing the starting
> > > > values for `a`, `b`, and `x`, I get:
> > > > ```
> > > > X = 1:60
> > > > A = 3261
> > > > B = 10
> > > > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > > > > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) 
> > > > > :
> > > >   some named arguments in 'start' are not arguments to the specified
> > > > log-likelihood function
> > > > ```
> > > > If I pass the negative log-function (assuming a binomial distribution
> > > > of the data, which I am not sure about)
> > > > ```
> > > > nll = function(p, n, k) {
> > > >   # extract parms
> > > >   a = p[1]
> > > >   h = p[2]
> > > >   # calculate probability of attack
> > > >   pred = a/(1+a*h*n)
> > > >   # calc NLL
> > > >   -sum(dbinom(k, prob = pred, size = n, log = TRUE))
> > > > }
> > > > ```
> > > > then I get the same error:
> > > > ```
> > > > > O = mle2(minuslogl = nll, start = list(a = A, h = B),
> > > > +  data = list(n = 5720, k = A))
> > > > Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
> > > > list(n = 5720,  :
> > > >   some named arguments in 'start' are not arguments to the specified
> > > > log-likelihood function
> > > > ```
> > > > but with the disadvantage of working on an assumed function (nll).
> > > > How can I optimize the function `holling` properly?
> > > > Thank you
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Best regards,
> > > > Luigi
> > > >
> > > > __
> > > > 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.
> >
> >
> >
> > --
> > Best regards,
> > 

Re: [R] How to use mle2 function?

2020-06-30 Thread Eric Berger
I have no problem with the following code:

library(bbmle)
holling <- function( a, b, x ) {
a*x^2 / (b^2 + x^2)
}
A=3261
B=10
X=30
foo <- mle2( minuslogl=holling, start=list(a=A,b=B,x=X) )

foo

# Call:
# mle2(minuslogl = holling, start = list(a = A, b = B, x = X))

# Coefficients:
#a b x
# 3.260044e+03  7.315124e+01 -2.332448e-14

# Log-likelihood: 0


Does this code create a problem for you?

On Tue, Jun 30, 2020 at 3:00 PM Luigi Marongiu  wrote:
>
> Sorry for the typo, but I have the same error if using b instead of h:
> ```
> > O = mle2(minuslogl = holling, start = list(a = A, b = B))
> > Error in minuslogl(a = 3261, b = 10) :
>   argument "x" is missing, with no default
> # let's add x
> X = c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,  344,  408,  
> 473,
>   546,  619,  705,  794,  891,  999, 1096, 1242, 1363, 1506, 1648, 1753,
>   1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 2818,
>   2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 3152,
>   3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
> O = mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
> Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
>   some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
> And even if I use the log-likelihood function:
> ```
> O = mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720, x = X))
> > Error in mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720,  :
>   some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
>
> On Tue, Jun 30, 2020 at 12:03 PM Eric Berger  wrote:
> >
> > Hi Luigi,
> > I took a quick look.
> >
> > First error:
> > You wrote
> > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> >
> > it should be b=B  (h is not an argument of holling())
> > The error message gave very precise information!
> >
> > Second error:
> > You wrote
> > O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
> > = 5720, k = A))
> > but the arguments to nll() are p,n,k. Setting start to values for a
> > and h causes the function to complain.
> >
> > HTH,
> > Eric
> >
> > On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
> >  wrote:
> > >
> > > Hello,
> > > I would like to optimize the function:
> > > ```
> > > holling = function(a, b, x) {
> > >   y = (a * x^2) / (b^2 + x^2)
> > >   return(y)
> > > }
> > > ```
> > > I am trying to use the function mle2 from bbmle, but how do I need to
> > > feed the data?
> > > If I give `holling` as function to be optimized, passing the starting
> > > values for `a`, `b`, and `x`, I get:
> > > ```
> > > X = 1:60
> > > A = 3261
> > > B = 10
> > > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > > > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
> > >   some named arguments in 'start' are not arguments to the specified
> > > log-likelihood function
> > > ```
> > > If I pass the negative log-function (assuming a binomial distribution
> > > of the data, which I am not sure about)
> > > ```
> > > nll = function(p, n, k) {
> > >   # extract parms
> > >   a = p[1]
> > >   h = p[2]
> > >   # calculate probability of attack
> > >   pred = a/(1+a*h*n)
> > >   # calc NLL
> > >   -sum(dbinom(k, prob = pred, size = n, log = TRUE))
> > > }
> > > ```
> > > then I get the same error:
> > > ```
> > > > O = mle2(minuslogl = nll, start = list(a = A, h = B),
> > > +  data = list(n = 5720, k = A))
> > > Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
> > > list(n = 5720,  :
> > >   some named arguments in 'start' are not arguments to the specified
> > > log-likelihood function
> > > ```
> > > but with the disadvantage of working on an assumed function (nll).
> > > How can I optimize the function `holling` properly?
> > > Thank you
> > >
> > >
> > >
> > >
> > > --
> > > Best regards,
> > > Luigi
> > >
> > > __
> > > 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.
>
>
>
> --
> Best regards,
> Luigi

__
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] How to use mle2 function?

2020-06-30 Thread Luigi Marongiu
Sorry for the typo, but I have the same error if using b instead of h:
```
> O = mle2(minuslogl = holling, start = list(a = A, b = B))
> Error in minuslogl(a = 3261, b = 10) :
  argument "x" is missing, with no default
# let's add x
X = c(8,   24,   39,   63,   89,  115,  153,  196,  242,  287,  344,  408,  473,
  546,  619,  705,  794,  891,  999, 1096, 1242, 1363, 1506, 1648, 1753,
  1851, 1987, 2101, 2219, 2328, 2425, 2575, 2646, 2698, 2727, 2771, 2818,
  2853, 2895, 2926, 2964, 2995, 3025, 3053, 3080, 3102, 3119, 3141, 3152,
  3159, 3172, 3182, 3196, 3209, 3220, 3231, 3239, 3246, 3252, 3261)
O = mle2(minuslogl = holling, start = list(a = A, b = B, x = X))
Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```
And even if I use the log-likelihood function:
```
O = mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720, x = X))
> Error in mle2(minuslogl = nll, start = list(p = c(A, B), n = 5720,  :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```

On Tue, Jun 30, 2020 at 12:03 PM Eric Berger  wrote:
>
> Hi Luigi,
> I took a quick look.
>
> First error:
> You wrote
> O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
>
> it should be b=B  (h is not an argument of holling())
> The error message gave very precise information!
>
> Second error:
> You wrote
> O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
> = 5720, k = A))
> but the arguments to nll() are p,n,k. Setting start to values for a
> and h causes the function to complain.
>
> HTH,
> Eric
>
> On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
>  wrote:
> >
> > Hello,
> > I would like to optimize the function:
> > ```
> > holling = function(a, b, x) {
> >   y = (a * x^2) / (b^2 + x^2)
> >   return(y)
> > }
> > ```
> > I am trying to use the function mle2 from bbmle, but how do I need to
> > feed the data?
> > If I give `holling` as function to be optimized, passing the starting
> > values for `a`, `b`, and `x`, I get:
> > ```
> > X = 1:60
> > A = 3261
> > B = 10
> > O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> > If I pass the negative log-function (assuming a binomial distribution
> > of the data, which I am not sure about)
> > ```
> > nll = function(p, n, k) {
> >   # extract parms
> >   a = p[1]
> >   h = p[2]
> >   # calculate probability of attack
> >   pred = a/(1+a*h*n)
> >   # calc NLL
> >   -sum(dbinom(k, prob = pred, size = n, log = TRUE))
> > }
> > ```
> > then I get the same error:
> > ```
> > > O = mle2(minuslogl = nll, start = list(a = A, h = B),
> > +  data = list(n = 5720, k = A))
> > Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
> > list(n = 5720,  :
> >   some named arguments in 'start' are not arguments to the specified
> > log-likelihood function
> > ```
> > but with the disadvantage of working on an assumed function (nll).
> > How can I optimize the function `holling` properly?
> > Thank you
> >
> >
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > 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.



-- 
Best regards,
Luigi

__
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] How to use mle2 function?

2020-06-30 Thread Eric Berger
Hi Luigi,
I took a quick look.

First error:
You wrote
O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))

it should be b=B  (h is not an argument of holling())
The error message gave very precise information!

Second error:
You wrote
O = mle2(minuslogl = nll, start = list(a = A, h = B),   data = list(n
= 5720, k = A))
but the arguments to nll() are p,n,k. Setting start to values for a
and h causes the function to complain.

HTH,
Eric

On Tue, Jun 30, 2020 at 12:45 PM Luigi Marongiu
 wrote:
>
> Hello,
> I would like to optimize the function:
> ```
> holling = function(a, b, x) {
>   y = (a * x^2) / (b^2 + x^2)
>   return(y)
> }
> ```
> I am trying to use the function mle2 from bbmle, but how do I need to
> feed the data?
> If I give `holling` as function to be optimized, passing the starting
> values for `a`, `b`, and `x`, I get:
> ```
> X = 1:60
> A = 3261
> B = 10
> O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> > Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
>   some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
> If I pass the negative log-function (assuming a binomial distribution
> of the data, which I am not sure about)
> ```
> nll = function(p, n, k) {
>   # extract parms
>   a = p[1]
>   h = p[2]
>   # calculate probability of attack
>   pred = a/(1+a*h*n)
>   # calc NLL
>   -sum(dbinom(k, prob = pred, size = n, log = TRUE))
> }
> ```
> then I get the same error:
> ```
> > O = mle2(minuslogl = nll, start = list(a = A, h = B),
> +  data = list(n = 5720, k = A))
> Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
> list(n = 5720,  :
>   some named arguments in 'start' are not arguments to the specified
> log-likelihood function
> ```
> but with the disadvantage of working on an assumed function (nll).
> How can I optimize the function `holling` properly?
> Thank you
>
>
>
>
> --
> Best regards,
> Luigi
>
> __
> 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.


[R] How to use mle2 function?

2020-06-30 Thread Luigi Marongiu
Hello,
I would like to optimize the function:
```
holling = function(a, b, x) {
  y = (a * x^2) / (b^2 + x^2)
  return(y)
}
```
I am trying to use the function mle2 from bbmle, but how do I need to
feed the data?
If I give `holling` as function to be optimized, passing the starting
values for `a`, `b`, and `x`, I get:
```
X = 1:60
A = 3261
B = 10
O = mle2(minuslogl = holling, start = list(a = A, h = B, x = X))
> Error in mle2(minuslogl = holling, start = list(a = A, b = B, x = X)) :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```
If I pass the negative log-function (assuming a binomial distribution
of the data, which I am not sure about)
```
nll = function(p, n, k) {
  # extract parms
  a = p[1]
  h = p[2]
  # calculate probability of attack
  pred = a/(1+a*h*n)
  # calc NLL
  -sum(dbinom(k, prob = pred, size = n, log = TRUE))
}
```
then I get the same error:
```
> O = mle2(minuslogl = nll, start = list(a = A, h = B),
+  data = list(n = 5720, k = A))
Error in mle2(minuslogl = nll, start = list(a = A, h = B), data =
list(n = 5720,  :
  some named arguments in 'start' are not arguments to the specified
log-likelihood function
```
but with the disadvantage of working on an assumed function (nll).
How can I optimize the function `holling` properly?
Thank you




-- 
Best regards,
Luigi

__
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] How to use msaPrettyPrint in memory efficient mode?

2020-05-28 Thread Luigi Marongiu
Hello,
I have an alignment made with the package MSA. I installed latex on my
ubuntu machine with
`sudo apt-get install texlive-full` but I could not find the package
texshade that is mentioned in the MSA's manual.
When I run msaPrettyPrint I get:
```

Multiple alignment written to temporary file
/tmp/RtmpmW9Nnm/seq12f4d6e21e744.fasta
File aln.tex created
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian)
(preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./aln.tex
LaTeX2e <2020-02-02> patch level 2
L3 programming layer <2020-02-14>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/home/gigiux/R/x86_64-pc-linux-gnu-library/4.0/msa/tex/texshade.sty
Package `texshade', Version 1.24 of 2011/12/01.
(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/dvips.def)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/dvipsnam.def))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
No file aln.aux.
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/tmp/RtmpmW9Nnm/seq12f4d6e21e744.fasta:
! TeX capacity exceeded, sorry [save size=8].
\inf@@get ...@ {#5} \else \def \fourth@ {}
   \fi \fi \def \fifth@ {#5}...
l.25 ...e}{/tmp/RtmpmW9Nnm/seq12f4d6e21e744.fasta}

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on aln.log.
Error in texi2dvi(texfile, quiet = !verbose, pdf = identical(output, "pdf"),  :
  unable to run pdflatex on 'aln.tex'
LaTeX errors:
! TeX capacity exceeded, sorry [save size=8].
\inf@@get ...@ {#5} \else \def \fourth@ {}
   \fi \fi \def \fifth@ {#5}...
l.25 ...e}{/tmp/RtmpmW9Nnm/seq12f4d6e21e744.fasta}

!  ==> Fatal error occurred, no output PDF file produced!

>
```
Looks like texshade has been installed but there is a problem with
memory. How can I set the memory limit for msaPrettyPrint?
-- 
Best regards,
Luigi

__
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] How to use R0 package?

2020-05-22 Thread Jeff Newmiller
Because the dates might not be consecutive.  Or in ISO format.

On May 22, 2020 7:38:17 PM PDT, Jim Lemon  wrote:
>So what if you treat a nuisance as a feature and import your dates as
>factors? as.numeric(dates) would have the correct structure or am I,
>as usual, missing something?
>
>Jim
>
>On Sat, May 23, 2020 at 1:00 AM Jeff Newmiller
> wrote:
>>
>> This is getting off-topic here but R0 is a mathematical parameter
>unrelated to calendar dates. It arises when analyzing case counts
>(integers) as a function of the numerical measure of time since some
>non-trivial number of cases has occurred (conventionally this measure
>is in days)..
>>
>> dta$days <- as.numeric( dta$date - startdate, units="days" )
>>
>> On May 22, 2020 5:31:48 AM PDT, Luigi Marongiu
> wrote:
>> >In theory, it works
>> >```
>> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
>> >methods="EG",pop.size=pop, nsim=N)
>> >>R0
>> >Reproduction number estimate using  Exponential Growth  method.
>> >R :  0.7425278[ 0.7409297 , 0.7441229 ]
>> >```
>> >but I am not happy because 1. I have to use numbers instead of
>> >variables and 2. numbers instead of dates (which are instead
>reported
>> >in
>> >the examples...).
>> >Even if I force to an integer, I still get an error:
>> >```
>> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>> >+ methods="EG",pop.size=pop, nsim=N)
>> >Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>> >time.step,  :
>> >  If both 'begin'= 1  and 'end'= 117  are provided, they must be of
>the
>> >same class (dates, character strings or integers).
>> >> int
>> >Error: object 'int' not found
>> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1,
>> >end=as.integer(length(x1)),
>> >+ methods="EG",pop.size=pop, nsim=N)
>> >Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>> >time.step,  :
>> >  If both 'begin'= 1  and 'end'= 117  are provided, they must be of
>the
>> >same class (dates, character strings or integers).
>> >```
>> >
>> >
>> >
>> >On Fri, May 22, 2020 at 1:51 PM Eric Berger 
>> >wrote:
>> >
>> >> Hi Luigi,
>> >> how about begin=1L (to force it to be integer).
>> >> Also please keep the correspondence on the help list.
>> >>
>> >> Best,
>> >> Eric
>> >>
>> >> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu
>> >
>> >> wrote:
>> >> >
>> >> > Same error:
>> >> > ```
>> >> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>> >> > methods="EG",pop.size=pop, nsim=N)
>> >> >  Error in integrity.checks(epid, t, GT, begin, end,
>date.first.obs,
>> >> time.step,  :
>> >> >   If both 'begin'= 1  and 'end'= 117  are provided, they must be
>of
>> >the
>> >> same class (dates, character strings or integers).
>> >> > > str(length(x1))
>> >> >  int 117
>> >> > ```
>> >> >
>> >> >
>> >> > On Fri, May 22, 2020 at 12:35 PM Eric Berger
>> >
>> >> wrote:
>> >> >>
>> >> >> Hi Luigi,
>> >> >> I am not familiar with the R0 package but I took a quick look.
>> >> >> The example in the documentation sets begin and end to
>integers.
>> >> >> Try setting begin = 1, end = 121 and see if that works.
>> >> >>
>> >> >> HTH,
>> >> >> Eric
>> >> >>
>> >> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
>> >> marongiu.lu...@gmail.com> wrote:
>> >> >> >
>> >> >> > Hello,
>> >> >> > I am trying ot get the R0 from the incidence data from China
>for
>> >the
>> >> >> > COVID-19. I set the following:
>> >> >> > ```
>> >> >> > library("R0")
>> >> >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,
>> >2099,
>> >> 2589,
>> >> >> >  2825,  3235,  3884,  3694,  3143,
>> >> >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090, 
>2641,
>> >2008,
>> >> >> >  2048,  1888,  1749,   391,   889,  823,
>> >> >> > 648,   214,   508,   406,   433,   327,   427,   573,
>> >202,
>> >>  125,
>> >> >> >   119,   139,   143,99,44,
>> >> >> > 40,19,24,15, 8,11,20, 0,
>> >16,
>> >>   13,
>> >> >> >13,34,39,46,39,
>> >> >> > 78,47,67,55,54,45, 0,79,
>> >36,
>> >>   35,
>> >> >> >31,19,30,39,32,
>> >> >> > 0,63,42,46,99,   108,89,46,
>> >46,
>> >> 26,
>> >> >> > 325,27,16,12,11,
>> >> >> > 30,10, 6,12,11, 3, 6,22,
>> >4,
>> >>   12,
>> >> >> > 1, 3, 3, 1, 2,
>> >> >> > 2, 1, 1,14,17, 1, 7, 3,
>> >4,
>> >>  8,
>> >> >> >   6, 7)
>> >> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25",
>"2020-01-26",
>> >> >> > "2020-01-27", "2020-01-28", "2020-01-29",
>> >> >> >"2020-01-30", "2020-01-31", "2020-02-01",
>"2020-02-02",
>> >> >> > "2020-02-03", "2020-02-04", "2020-02-05",
>> >> >> >"2020-02-06", "2020-02-07", "2020-02-08",
>"2020-02-09",
>> >> >> > "2020-02-10", "2020-02-11", "2020-02-12",
>> >> >> >"2020-02-13", "2020-02-14", 

Re: [R] How to use R0 package?

2020-05-22 Thread Jim Lemon
So what if you treat a nuisance as a feature and import your dates as
factors? as.numeric(dates) would have the correct structure or am I,
as usual, missing something?

Jim

On Sat, May 23, 2020 at 1:00 AM Jeff Newmiller  wrote:
>
> This is getting off-topic here but R0 is a mathematical parameter unrelated 
> to calendar dates. It arises when analyzing case counts (integers) as a 
> function of the numerical measure of time since some non-trivial number of 
> cases has occurred (conventionally this measure is in days)..
>
> dta$days <- as.numeric( dta$date - startdate, units="days" )
>
> On May 22, 2020 5:31:48 AM PDT, Luigi Marongiu  
> wrote:
> >In theory, it works
> >```
> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
> >methods="EG",pop.size=pop, nsim=N)
> >>R0
> >Reproduction number estimate using  Exponential Growth  method.
> >R :  0.7425278[ 0.7409297 , 0.7441229 ]
> >```
> >but I am not happy because 1. I have to use numbers instead of
> >variables and 2. numbers instead of dates (which are instead reported
> >in
> >the examples...).
> >Even if I force to an integer, I still get an error:
> >```
> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> >+ methods="EG",pop.size=pop, nsim=N)
> >Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> >time.step,  :
> >  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
> >same class (dates, character strings or integers).
> >> int
> >Error: object 'int' not found
> >> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1,
> >end=as.integer(length(x1)),
> >+ methods="EG",pop.size=pop, nsim=N)
> >Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> >time.step,  :
> >  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
> >same class (dates, character strings or integers).
> >```
> >
> >
> >
> >On Fri, May 22, 2020 at 1:51 PM Eric Berger 
> >wrote:
> >
> >> Hi Luigi,
> >> how about begin=1L (to force it to be integer).
> >> Also please keep the correspondence on the help list.
> >>
> >> Best,
> >> Eric
> >>
> >> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu
> >
> >> wrote:
> >> >
> >> > Same error:
> >> > ```
> >> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> >> > methods="EG",pop.size=pop, nsim=N)
> >> >  Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> >> time.step,  :
> >> >   If both 'begin'= 1  and 'end'= 117  are provided, they must be of
> >the
> >> same class (dates, character strings or integers).
> >> > > str(length(x1))
> >> >  int 117
> >> > ```
> >> >
> >> >
> >> > On Fri, May 22, 2020 at 12:35 PM Eric Berger
> >
> >> wrote:
> >> >>
> >> >> Hi Luigi,
> >> >> I am not familiar with the R0 package but I took a quick look.
> >> >> The example in the documentation sets begin and end to integers.
> >> >> Try setting begin = 1, end = 121 and see if that works.
> >> >>
> >> >> HTH,
> >> >> Eric
> >> >>
> >> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
> >> marongiu.lu...@gmail.com> wrote:
> >> >> >
> >> >> > Hello,
> >> >> > I am trying ot get the R0 from the incidence data from China for
> >the
> >> >> > COVID-19. I set the following:
> >> >> > ```
> >> >> > library("R0")
> >> >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,
> >2099,
> >> 2589,
> >> >> >  2825,  3235,  3884,  3694,  3143,
> >> >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641,
> >2008,
> >> >> >  2048,  1888,  1749,   391,   889,  823,
> >> >> > 648,   214,   508,   406,   433,   327,   427,   573,
> >202,
> >>  125,
> >> >> >   119,   139,   143,99,44,
> >> >> > 40,19,24,15, 8,11,20, 0,
> >16,
> >>   13,
> >> >> >13,34,39,46,39,
> >> >> > 78,47,67,55,54,45, 0,79,
> >36,
> >>   35,
> >> >> >31,19,30,39,32,
> >> >> > 0,63,42,46,99,   108,89,46,
> >46,
> >> 26,
> >> >> > 325,27,16,12,11,
> >> >> > 30,10, 6,12,11, 3, 6,22,
> >4,
> >>   12,
> >> >> > 1, 3, 3, 1, 2,
> >> >> > 2, 1, 1,14,17, 1, 7, 3,
> >4,
> >>  8,
> >> >> >   6, 7)
> >> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
> >> >> > "2020-01-27", "2020-01-28", "2020-01-29",
> >> >> >"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
> >> >> > "2020-02-03", "2020-02-04", "2020-02-05",
> >> >> >"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
> >> >> > "2020-02-10", "2020-02-11", "2020-02-12",
> >> >> >"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
> >> >> > "2020-02-17", "2020-02-18", "2020-02-19",
> >> >> >"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
> >> >> > "2020-02-24", "2020-02-25", "2020-02-26",
> >> >> >"2020-02-27", "2020-02-28", "2020-02-29", 

Re: [R] How to use R0 package?

2020-05-22 Thread Jeff Newmiller
This is getting off-topic here but R0 is a mathematical parameter unrelated to 
calendar dates. It arises when analyzing case counts (integers) as a function 
of the numerical measure of time since some non-trivial number of cases has 
occurred (conventionally this measure is in days)..

dta$days <- as.numeric( dta$date - startdate, units="days" )

On May 22, 2020 5:31:48 AM PDT, Luigi Marongiu  wrote:
>In theory, it works
>```
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
>methods="EG",pop.size=pop, nsim=N)
>>R0
>Reproduction number estimate using  Exponential Growth  method.
>R :  0.7425278[ 0.7409297 , 0.7441229 ]
>```
>but I am not happy because 1. I have to use numbers instead of
>variables and 2. numbers instead of dates (which are instead reported
>in
>the examples...).
>Even if I force to an integer, I still get an error:
>```
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>+ methods="EG",pop.size=pop, nsim=N)
>Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>time.step,  :
>  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
>same class (dates, character strings or integers).
>> int
>Error: object 'int' not found
>> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1,
>end=as.integer(length(x1)),
>+ methods="EG",pop.size=pop, nsim=N)
>Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>time.step,  :
>  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
>same class (dates, character strings or integers).
>```
>
>
>
>On Fri, May 22, 2020 at 1:51 PM Eric Berger 
>wrote:
>
>> Hi Luigi,
>> how about begin=1L (to force it to be integer).
>> Also please keep the correspondence on the help list.
>>
>> Best,
>> Eric
>>
>> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu
>
>> wrote:
>> >
>> > Same error:
>> > ```
>> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>> > methods="EG",pop.size=pop, nsim=N)
>> >  Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
>> time.step,  :
>> >   If both 'begin'= 1  and 'end'= 117  are provided, they must be of
>the
>> same class (dates, character strings or integers).
>> > > str(length(x1))
>> >  int 117
>> > ```
>> >
>> >
>> > On Fri, May 22, 2020 at 12:35 PM Eric Berger
>
>> wrote:
>> >>
>> >> Hi Luigi,
>> >> I am not familiar with the R0 package but I took a quick look.
>> >> The example in the documentation sets begin and end to integers.
>> >> Try setting begin = 1, end = 121 and see if that works.
>> >>
>> >> HTH,
>> >> Eric
>> >>
>> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
>> marongiu.lu...@gmail.com> wrote:
>> >> >
>> >> > Hello,
>> >> > I am trying ot get the R0 from the incidence data from China for
>the
>> >> > COVID-19. I set the following:
>> >> > ```
>> >> > library("R0")
>> >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981, 
>2099,
>> 2589,
>> >> >  2825,  3235,  3884,  3694,  3143,
>> >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641, 
>2008,
>> >> >  2048,  1888,  1749,   391,   889,  823,
>> >> > 648,   214,   508,   406,   433,   327,   427,   573,  
>202,
>>  125,
>> >> >   119,   139,   143,99,44,
>> >> > 40,19,24,15, 8,11,20, 0,   
>16,
>>   13,
>> >> >13,34,39,46,39,
>> >> > 78,47,67,55,54,45, 0,79,   
>36,
>>   35,
>> >> >31,19,30,39,32,
>> >> > 0,63,42,46,99,   108,89,46,   
>46,
>> 26,
>> >> > 325,27,16,12,11,
>> >> > 30,10, 6,12,11, 3, 6,22,
>4,
>>   12,
>> >> > 1, 3, 3, 1, 2,
>> >> > 2, 1, 1,14,17, 1, 7, 3,
>4,
>>  8,
>> >> >   6, 7)
>> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
>> >> > "2020-01-27", "2020-01-28", "2020-01-29",
>> >> >"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
>> >> > "2020-02-03", "2020-02-04", "2020-02-05",
>> >> >"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
>> >> > "2020-02-10", "2020-02-11", "2020-02-12",
>> >> >"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
>> >> > "2020-02-17", "2020-02-18", "2020-02-19",
>> >> >"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
>> >> > "2020-02-24", "2020-02-25", "2020-02-26",
>> >> >"2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
>> >> > "2020-03-02", "2020-03-03", "2020-03-04",
>> >> >"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
>> >> > "2020-03-09", "2020-03-10", "2020-03-11",
>> >> >"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
>> >> > "2020-03-16", "2020-03-17", "2020-03-18",
>> >> >"2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
>> >> > "2020-03-23", "2020-03-24", "2020-03-25",
>> >> >"2020-03-26", "2020-03-27", 

Re: [R] How to use R0 package?

2020-05-22 Thread Olivier Crouzet
Hi,

you should be able to convert your date variables to integers (usually
viewed as the elapse between 1970/01/01 and today) by using date
conversion to integers:

TODAY="2020-05-22"
as.Date(TODAY)
[1] "2020-05-22"
> as.integer(as.Date(TODAY))
[1] 18404

Doing the same with your reference dates should do the job.

Yours.
Olivier.


On Fri, 22 May 2020
14:31:48 +0200 Luigi Marongiu  wrote:

> In theory, it works
> ```
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
> methods="EG",pop.size=pop, nsim=N)
> >R0
> Reproduction number estimate using  Exponential Growth  method.
> R :  0.7425278[ 0.7409297 , 0.7441229 ]
> ```
> but I am not happy because 1. I have to use numbers instead of
> variables and 2. numbers instead of dates (which are instead reported
> in the examples...).
> Even if I force to an integer, I still get an error:
> ```
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> + methods="EG",pop.size=pop, nsim=N)
> Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> time.step,  :
>   If both 'begin'= 1  and 'end'= 117  are provided, they must be of
> the same class (dates, character strings or integers).
> > int
> Error: object 'int' not found
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1,
> > end=as.integer(length(x1)),
> + methods="EG",pop.size=pop, nsim=N)
> Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> time.step,  :
>   If both 'begin'= 1  and 'end'= 117  are provided, they must be of
> the same class (dates, character strings or integers).
> ```
> 
> 
> 
> On Fri, May 22, 2020 at 1:51 PM Eric Berger 
> wrote:
> 
> > Hi Luigi,
> > how about begin=1L (to force it to be integer).
> > Also please keep the correspondence on the help list.
> >
> > Best,
> > Eric
> >
> > On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu
> >  wrote:
> > >
> > > Same error:
> > > ```
> > > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> > > methods="EG",pop.size=pop, nsim=N)
> > >  Error in integrity.checks(epid, t, GT, begin, end,
> > > date.first.obs,
> > time.step,  :
> > >   If both 'begin'= 1  and 'end'= 117  are provided, they must be
> > > of the
> > same class (dates, character strings or integers).
> > > > str(length(x1))
> > >  int 117
> > > ```
> > >
> > >
> > > On Fri, May 22, 2020 at 12:35 PM Eric Berger
> > > 
> > wrote:
> > >>
> > >> Hi Luigi,
> > >> I am not familiar with the R0 package but I took a quick look.
> > >> The example in the documentation sets begin and end to integers.
> > >> Try setting begin = 1, end = 121 and see if that works.
> > >>
> > >> HTH,
> > >> Eric
> > >>
> > >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
> > marongiu.lu...@gmail.com> wrote:
> > >> >
> > >> > Hello,
> > >> > I am trying ot get the R0 from the incidence data from China
> > >> > for the COVID-19. I set the following:
> > >> > ```
> > >> > library("R0")
> > >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,
> > >> > 2099,
> > 2589,
> > >> >  2825,  3235,  3884,  3694,  3143,
> > >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090,
> > >> > 2641,  2008, 2048,  1888,  1749,   391,   889,  823,
> > >> > 648,   214,   508,   406,   433,   327,   427,
> > >> > 573,   202,
> >  125,
> > >> >   119,   139,   143,99,44,
> > >> > 40,19,24,15, 8,11,20,
> > >> > 0,16,
> >   13,
> > >> >13,34,39,46,39,
> > >> > 78,47,67,55,54,45, 0,
> > >> > 79,36,
> >   35,
> > >> >31,19,30,39,32,
> > >> > 0,63,42,46,99,   108,89,46,
> > >> > 46,
> > 26,
> > >> > 325,27,16,12,11,
> > >> > 30,10, 6,12,11, 3, 6,
> > >> > 22, 4,
> >   12,
> > >> > 1, 3, 3, 1, 2,
> > >> > 2, 1, 1,14,17, 1, 7,
> > >> > 3, 4,
> >  8,
> > >> >   6, 7)
> > >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
> > >> > "2020-01-27", "2020-01-28", "2020-01-29",
> > >> >"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
> > >> > "2020-02-03", "2020-02-04", "2020-02-05",
> > >> >"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
> > >> > "2020-02-10", "2020-02-11", "2020-02-12",
> > >> >"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
> > >> > "2020-02-17", "2020-02-18", "2020-02-19",
> > >> >"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
> > >> > "2020-02-24", "2020-02-25", "2020-02-26",
> > >> >"2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
> > >> > "2020-03-02", "2020-03-03", "2020-03-04",
> > >> >"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
> > >> > "2020-03-09", "2020-03-10", "2020-03-11",
> > >> >"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
> > >> > "2020-03-16", "2020-03-17", "2020-03-18",
> > >> >

Re: [R] How to use R0 package?

2020-05-22 Thread Eric Berger
class(length(x1))
"integer"

Your problem is thinking that begin=1 means you are passing begin as
an integer.
class(1)
"numeric"
class(1L)
"integer"

You should pass:  begin=1L, end=length(x1)

Best,
Eric

On Fri, May 22, 2020 at 3:31 PM Luigi Marongiu  wrote:
>
> In theory, it works
> ```
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
> methods="EG",pop.size=pop, nsim=N)
> >R0
> Reproduction number estimate using  Exponential Growth  method.
> R :  0.7425278[ 0.7409297 , 0.7441229 ]
> ```
> but I am not happy because 1. I have to use numbers instead of variables and 
> 2. numbers instead of dates (which are instead reported in the examples...).
> Even if I force to an integer, I still get an error:
> ```
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> + methods="EG",pop.size=pop, nsim=N)
> Error in integrity.checks(epid, t, GT, begin, end, date.first.obs, time.step, 
>  :
>   If both 'begin'= 1  and 'end'= 117  are provided, they must be of the same 
> class (dates, character strings or integers).
> > int
> Error: object 'int' not found
> > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=as.integer(length(x1)),
> + methods="EG",pop.size=pop, nsim=N)
> Error in integrity.checks(epid, t, GT, begin, end, date.first.obs, time.step, 
>  :
>   If both 'begin'= 1  and 'end'= 117  are provided, they must be of the same 
> class (dates, character strings or integers).
> ```
>
>
>
> On Fri, May 22, 2020 at 1:51 PM Eric Berger  wrote:
>>
>> Hi Luigi,
>> how about begin=1L (to force it to be integer).
>> Also please keep the correspondence on the help list.
>>
>> Best,
>> Eric
>>
>> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu  
>> wrote:
>> >
>> > Same error:
>> > ```
>> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
>> > methods="EG",pop.size=pop, nsim=N)
>> >  Error in integrity.checks(epid, t, GT, begin, end, date.first.obs, 
>> > time.step,  :
>> >   If both 'begin'= 1  and 'end'= 117  are provided, they must be of the 
>> > same class (dates, character strings or integers).
>> > > str(length(x1))
>> >  int 117
>> > ```
>> >
>> >
>> > On Fri, May 22, 2020 at 12:35 PM Eric Berger  wrote:
>> >>
>> >> Hi Luigi,
>> >> I am not familiar with the R0 package but I took a quick look.
>> >> The example in the documentation sets begin and end to integers.
>> >> Try setting begin = 1, end = 121 and see if that works.
>> >>
>> >> HTH,
>> >> Eric
>> >>
>> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu  
>> >> wrote:
>> >> >
>> >> > Hello,
>> >> > I am trying ot get the R0 from the incidence data from China for the
>> >> > COVID-19. I set the following:
>> >> > ```
>> >> > library("R0")
>> >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,  2099,  
>> >> > 2589,
>> >> >  2825,  3235,  3884,  3694,  3143,
>> >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641,  2008,
>> >> >  2048,  1888,  1749,   391,   889,  823,
>> >> > 648,   214,   508,   406,   433,   327,   427,   573,   202,   
>> >> > 125,
>> >> >   119,   139,   143,99,44,
>> >> > 40,19,24,15, 8,11,20, 0,16,
>> >> > 13,
>> >> >13,34,39,46,39,
>> >> > 78,47,67,55,54,45, 0,79,36,
>> >> > 35,
>> >> >31,19,30,39,32,
>> >> > 0,63,42,46,99,   108,89,46,46,
>> >> > 26,
>> >> > 325,27,16,12,11,
>> >> > 30,10, 6,12,11, 3, 6,22, 4,
>> >> > 12,
>> >> > 1, 3, 3, 1, 2,
>> >> > 2, 1, 1,14,17, 1, 7, 3, 4, 
>> >> > 8,
>> >> >   6, 7)
>> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
>> >> > "2020-01-27", "2020-01-28", "2020-01-29",
>> >> >"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
>> >> > "2020-02-03", "2020-02-04", "2020-02-05",
>> >> >"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
>> >> > "2020-02-10", "2020-02-11", "2020-02-12",
>> >> >"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
>> >> > "2020-02-17", "2020-02-18", "2020-02-19",
>> >> >"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
>> >> > "2020-02-24", "2020-02-25", "2020-02-26",
>> >> >"2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
>> >> > "2020-03-02", "2020-03-03", "2020-03-04",
>> >> >"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
>> >> > "2020-03-09", "2020-03-10", "2020-03-11",
>> >> >"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
>> >> > "2020-03-16", "2020-03-17", "2020-03-18",
>> >> >"2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
>> >> > "2020-03-23", "2020-03-24", "2020-03-25",
>> >> >"2020-03-26", "2020-03-27", "2020-03-28", "2020-03-29",
>> >> > "2020-03-30", "2020-03-31", "2020-04-01",
>> >> >

Re: [R] How to use R0 package?

2020-05-22 Thread Luigi Marongiu
In theory, it works
```
> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=117,
methods="EG",pop.size=pop, nsim=N)
>R0
Reproduction number estimate using  Exponential Growth  method.
R :  0.7425278[ 0.7409297 , 0.7441229 ]
```
but I am not happy because 1. I have to use numbers instead of
variables and 2. numbers instead of dates (which are instead reported in
the examples...).
Even if I force to an integer, I still get an error:
```
> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
+ methods="EG",pop.size=pop, nsim=N)
Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
time.step,  :
  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
same class (dates, character strings or integers).
> int
Error: object 'int' not found
> R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=as.integer(length(x1)),
+ methods="EG",pop.size=pop, nsim=N)
Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
time.step,  :
  If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
same class (dates, character strings or integers).
```



On Fri, May 22, 2020 at 1:51 PM Eric Berger  wrote:

> Hi Luigi,
> how about begin=1L (to force it to be integer).
> Also please keep the correspondence on the help list.
>
> Best,
> Eric
>
> On Fri, May 22, 2020 at 2:40 PM Luigi Marongiu 
> wrote:
> >
> > Same error:
> > ```
> > > R0 = estimate.R(x1, t=d1, GT=mGT, begin=1, end=length(x1),
> > methods="EG",pop.size=pop, nsim=N)
> >  Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
> time.step,  :
> >   If both 'begin'= 1  and 'end'= 117  are provided, they must be of the
> same class (dates, character strings or integers).
> > > str(length(x1))
> >  int 117
> > ```
> >
> >
> > On Fri, May 22, 2020 at 12:35 PM Eric Berger 
> wrote:
> >>
> >> Hi Luigi,
> >> I am not familiar with the R0 package but I took a quick look.
> >> The example in the documentation sets begin and end to integers.
> >> Try setting begin = 1, end = 121 and see if that works.
> >>
> >> HTH,
> >> Eric
> >>
> >> On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu <
> marongiu.lu...@gmail.com> wrote:
> >> >
> >> > Hello,
> >> > I am trying ot get the R0 from the incidence data from China for the
> >> > COVID-19. I set the following:
> >> > ```
> >> > library("R0")
> >> > x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,  2099,
> 2589,
> >> >  2825,  3235,  3884,  3694,  3143,
> >> > 3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641,  2008,
> >> >  2048,  1888,  1749,   391,   889,  823,
> >> > 648,   214,   508,   406,   433,   327,   427,   573,   202,
>  125,
> >> >   119,   139,   143,99,44,
> >> > 40,19,24,15, 8,11,20, 0,16,
>   13,
> >> >13,34,39,46,39,
> >> > 78,47,67,55,54,45, 0,79,36,
>   35,
> >> >31,19,30,39,32,
> >> > 0,63,42,46,99,   108,89,46,46,
> 26,
> >> > 325,27,16,12,11,
> >> > 30,10, 6,12,11, 3, 6,22, 4,
>   12,
> >> > 1, 3, 3, 1, 2,
> >> > 2, 1, 1,14,17, 1, 7, 3, 4,
>  8,
> >> >   6, 7)
> >> > d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
> >> > "2020-01-27", "2020-01-28", "2020-01-29",
> >> >"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
> >> > "2020-02-03", "2020-02-04", "2020-02-05",
> >> >"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
> >> > "2020-02-10", "2020-02-11", "2020-02-12",
> >> >"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
> >> > "2020-02-17", "2020-02-18", "2020-02-19",
> >> >"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
> >> > "2020-02-24", "2020-02-25", "2020-02-26",
> >> >"2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
> >> > "2020-03-02", "2020-03-03", "2020-03-04",
> >> >"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
> >> > "2020-03-09", "2020-03-10", "2020-03-11",
> >> >"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
> >> > "2020-03-16", "2020-03-17", "2020-03-18",
> >> >"2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
> >> > "2020-03-23", "2020-03-24", "2020-03-25",
> >> >"2020-03-26", "2020-03-27", "2020-03-28", "2020-03-29",
> >> > "2020-03-30", "2020-03-31", "2020-04-01",
> >> >"2020-04-02", "2020-04-03", "2020-04-04", "2020-04-05",
> >> > "2020-04-06", "2020-04-07", "2020-04-08",
> >> >"2020-04-09", "2020-04-10", "2020-04-11", "2020-04-12",
> >> > "2020-04-13", "2020-04-14", "2020-04-15",
> >> >"2020-04-16", "2020-04-17", "2020-04-18", "2020-04-19",
> >> > "2020-04-20", "2020-04-21", "2020-04-22",
> >> >"2020-04-23", "2020-04-24", "2020-04-25", "2020-04-26",
> "2020-04-27"
> >> > ,"2020-04-28", 

Re: [R] How to use R0 package?

2020-05-22 Thread Eric Berger
Hi Luigi,
I am not familiar with the R0 package but I took a quick look.
The example in the documentation sets begin and end to integers.
Try setting begin = 1, end = 121 and see if that works.

HTH,
Eric

On Fri, May 22, 2020 at 1:17 PM Luigi Marongiu  wrote:
>
> Hello,
> I am trying ot get the R0 from the incidence data from China for the
> COVID-19. I set the following:
> ```
> library("R0")
> x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,  2099,  2589,
>  2825,  3235,  3884,  3694,  3143,
> 3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641,  2008,
>  2048,  1888,  1749,   391,   889,  823,
> 648,   214,   508,   406,   433,   327,   427,   573,   202,   125,
>   119,   139,   143,99,44,
> 40,19,24,15, 8,11,20, 0,16,13,
>13,34,39,46,39,
> 78,47,67,55,54,45, 0,79,36,35,
>31,19,30,39,32,
> 0,63,42,46,99,   108,89,46,46,26,
> 325,27,16,12,11,
> 30,10, 6,12,11, 3, 6,22, 4,12,
> 1, 3, 3, 1, 2,
> 2, 1, 1,14,17, 1, 7, 3, 4, 8,
>   6, 7)
> d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
> "2020-01-27", "2020-01-28", "2020-01-29",
>"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
> "2020-02-03", "2020-02-04", "2020-02-05",
>"2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
> "2020-02-10", "2020-02-11", "2020-02-12",
>"2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
> "2020-02-17", "2020-02-18", "2020-02-19",
>"2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
> "2020-02-24", "2020-02-25", "2020-02-26",
>"2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
> "2020-03-02", "2020-03-03", "2020-03-04",
>"2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
> "2020-03-09", "2020-03-10", "2020-03-11",
>"2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
> "2020-03-16", "2020-03-17", "2020-03-18",
>"2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
> "2020-03-23", "2020-03-24", "2020-03-25",
>"2020-03-26", "2020-03-27", "2020-03-28", "2020-03-29",
> "2020-03-30", "2020-03-31", "2020-04-01",
>"2020-04-02", "2020-04-03", "2020-04-04", "2020-04-05",
> "2020-04-06", "2020-04-07", "2020-04-08",
>"2020-04-09", "2020-04-10", "2020-04-11", "2020-04-12",
> "2020-04-13", "2020-04-14", "2020-04-15",
>"2020-04-16", "2020-04-17", "2020-04-18", "2020-04-19",
> "2020-04-20", "2020-04-21", "2020-04-22",
>"2020-04-23", "2020-04-24", "2020-04-25", "2020-04-26", "2020-04-27"
> ,"2020-04-28", "2020-04-29",
>"2020-04-30", "2020-05-01", "2020-05-02", "2020-05-03",
> "2020-05-04", "2020-05-05", "2020-05-06",
>"2020-05-07", "2020-05-08", "2020-05-09", "2020-05-10",
> "2020-05-11", "2020-05-12", "2020-05-13",
>"2020-05-14", "2020-05-15", "2020-05-16", "2020-05-17", "2020-05-18")
> names(x1) <- d1
> pop = 1438443864
> Ts_mean = 5.16
> Ts_sd   = 1.49
> N=1
> TODAY = Sys.Date()
> mGT = generation.time("gamma", c(Ts_mean, Ts_sd))
> R0 = estimate.R(x1, t=d1, GT=mGT, begin=as.Date(d1[1]), end=TODAY,
> methods="EG",pop.size=pop, nsim=N)
> ```
> but when I run I get:
> ```
> Error in if (end.nb <= begin.nb) stop("'begin' and 'end' are not
> consistent.") :
>   argument is of length zero
> > as.Date(d1[1])
> [1] "2020-01-23"
> > TODAY
> [1] "2020-05-22"
> > str(TODAY)
>  Date[1:1], format: "2020-05-22"
> > str(as.Date(d1[1]))
>  Date[1:1], format: "2020-01-23"
> ```
> Since I provided both start and end in the same format, I don't understand
> the error.
> Any tips?
> Thank you
> --
> Best regards,
> Luigi
>
> [[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.


[R] How to use R0 package?

2020-05-22 Thread Luigi Marongiu
Hello,
I am trying ot get the R0 from the incidence data from China for the
COVID-19. I set the following:
```
library("R0")
x1 <- c(259,   457,   688,   769,  1771,  1459,  1737,  1981,  2099,  2589,
 2825,  3235,  3884,  3694,  3143,
3385,  2652,  2973,  2467,  2015, 14108,  5090,  2641,  2008,
 2048,  1888,  1749,   391,   889,  823,
648,   214,   508,   406,   433,   327,   427,   573,   202,   125,
  119,   139,   143,99,44,
40,19,24,15, 8,11,20, 0,16,13,
   13,34,39,46,39,
78,47,67,55,54,45, 0,79,36,35,
   31,19,30,39,32,
0,63,42,46,99,   108,89,46,46,26,
325,27,16,12,11,
30,10, 6,12,11, 3, 6,22, 4,12,
1, 3, 3, 1, 2,
2, 1, 1,14,17, 1, 7, 3, 4, 8,
  6, 7)
d1 = c("2020-01-23", "2020-01-24", "2020-01-25", "2020-01-26",
"2020-01-27", "2020-01-28", "2020-01-29",
   "2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02",
"2020-02-03", "2020-02-04", "2020-02-05",
   "2020-02-06", "2020-02-07", "2020-02-08", "2020-02-09",
"2020-02-10", "2020-02-11", "2020-02-12",
   "2020-02-13", "2020-02-14", "2020-02-15", "2020-02-16",
"2020-02-17", "2020-02-18", "2020-02-19",
   "2020-02-20", "2020-02-21", "2020-02-22", "2020-02-23",
"2020-02-24", "2020-02-25", "2020-02-26",
   "2020-02-27", "2020-02-28", "2020-02-29", "2020-03-01",
"2020-03-02", "2020-03-03", "2020-03-04",
   "2020-03-05", "2020-03-06", "2020-03-07", "2020-03-08",
"2020-03-09", "2020-03-10", "2020-03-11",
   "2020-03-12", "2020-03-13", "2020-03-14", "2020-03-15",
"2020-03-16", "2020-03-17", "2020-03-18",
   "2020-03-19", "2020-03-20", "2020-03-21", "2020-03-22",
"2020-03-23", "2020-03-24", "2020-03-25",
   "2020-03-26", "2020-03-27", "2020-03-28", "2020-03-29",
"2020-03-30", "2020-03-31", "2020-04-01",
   "2020-04-02", "2020-04-03", "2020-04-04", "2020-04-05",
"2020-04-06", "2020-04-07", "2020-04-08",
   "2020-04-09", "2020-04-10", "2020-04-11", "2020-04-12",
"2020-04-13", "2020-04-14", "2020-04-15",
   "2020-04-16", "2020-04-17", "2020-04-18", "2020-04-19",
"2020-04-20", "2020-04-21", "2020-04-22",
   "2020-04-23", "2020-04-24", "2020-04-25", "2020-04-26", "2020-04-27"
,"2020-04-28", "2020-04-29",
   "2020-04-30", "2020-05-01", "2020-05-02", "2020-05-03",
"2020-05-04", "2020-05-05", "2020-05-06",
   "2020-05-07", "2020-05-08", "2020-05-09", "2020-05-10",
"2020-05-11", "2020-05-12", "2020-05-13",
   "2020-05-14", "2020-05-15", "2020-05-16", "2020-05-17", "2020-05-18")
names(x1) <- d1
pop = 1438443864
Ts_mean = 5.16
Ts_sd   = 1.49
N=1
TODAY = Sys.Date()
mGT = generation.time("gamma", c(Ts_mean, Ts_sd))
R0 = estimate.R(x1, t=d1, GT=mGT, begin=as.Date(d1[1]), end=TODAY,
methods="EG",pop.size=pop, nsim=N)
```
but when I run I get:
```
Error in if (end.nb <= begin.nb) stop("'begin' and 'end' are not
consistent.") :
  argument is of length zero
> as.Date(d1[1])
[1] "2020-01-23"
> TODAY
[1] "2020-05-22"
> str(TODAY)
 Date[1:1], format: "2020-05-22"
> str(as.Date(d1[1]))
 Date[1:1], format: "2020-01-23"
```
Since I provided both start and end in the same format, I don't understand
the error.
Any tips?
Thank you
-- 
Best regards,
Luigi

[[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] How to use pakcage R0

2020-05-05 Thread cpolwart




R0 = estimate.R(germany_vect, mGT, begin=germany_vect[1],

end=germany_vect[length(germany_vect)], methods="EG", pop.size=pop_de,
nsim=100)

Error in begin.nb:end.nb : argument of length 0


germany_vect[1]

  1
184

germany_vect[length(germany_vect)]

 57
488

```
What might be the problem here?


begin = germany_vect[1]
So begin = 184

but do you not want begin = 1

and same for end?

__
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] How to use pakcage R0

2020-05-05 Thread Luigi Marongiu
Dear all,
I have been trying to use the package R0
https://www.rdocumentation.org/packages/R0/versions/1.2-6/topics/estimate.R but
the manual is not so rich of words.
The example given is based on the named vector Germany.1918
```
> library("R0")
> data(Germany.1918)
> Germany.1918
1918-09-29 1918-09-30 1918-10-01 1918-10-02 1918-10-03 1918-10-04
1918-10-05
10  4  4 19  6 13
28
1918-10-06 1918-10-07 1918-10-08 1918-10-09 1918-10-10 1918-10-11
1918-10-12
23 35 27 42 51 43
78
1918-10-13 1918-10-14 1918-10-15 1918-10-16 1918-10-17 1918-10-18
1918-10-19
86 80109126126159
 190
[...]
```

Then it creates a gamma function and applied the estimate.R function:
```
mGT<-generation.time("gamma", c(3, 1.5))
estR0<-estimate.R(Germany.1918, mGT, begin=1, end=27, methods=c("EG", "ML",
"TD", "AR", "SB"),
  pop.size=10, nsim=100)
```

I tried with a similar approach for the current epidemics in China:
```
> china_vect
23/01/20 24/01/20 25/01/20 26/01/20 27/01/20 28/01/20 29/01/20 30/01/20
31/01/20
 259  457  688  769 1771 1459 1737 1981
2099
> mGT = generation.time("gamma", c(3, 1.5))   # create distribution
> estR0 = estimate.R(china_vect, mGT, begin=1, end=length(china_vect),
  methods="EG",
  pop.size=pop_ch, nsim=100)
Error in integrity.checks(epid, t, GT, begin, end, date.first.obs,
time.step,  :
  If both 'begin'= 1  and 'end'= 103  are provided, they must be of the
same class (dates, character strings or integers).
```
So I gave the value 103 directly (why it did not accept length, is the
first question?) and it worked:
> estR0 = estimate.R(china_vect, mGT, begin=1, end=103,
+   methods="EG",
+   pop.size=pop_ch, nsim=100)
Waiting for profiling to be done...
> estR0
Reproduction number estimate using  Exponential Growth  method.
R :  0.3359444[ 0.3209695 , 0.3510899 ]
```
I tried another endpoint, 27 as in the example:
```
> estR0 = estimate.R(china_vect, mGT, begin=1, end=27,
+   methods="EG",
+   pop.size=pop_ch, nsim=100)
Waiting for profiling to be done...
Error: no valid set of coefficients has been found: please supply starting
values
In addition: There were 11 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: fitted rates numerically 0 occurred
3: glm.fit: fitted rates numerically 0 occurred
4: glm.fit: fitted rates numerically 0 occurred
5: glm.fit: fitted rates numerically 0 occurred
6: glm.fit: fitted rates numerically 0 occurred
7: glm.fit: fitted rates numerically 0 occurred
8: glm.fit: fitted rates numerically 0 occurred
9: glm.fit: fitted rates numerically 0 occurred
10: glm.fit: fitted rates numerically 0 occurred
11: glm.fit: fitted rates numerically 0 occurred
```
Why these errors?
Is there a better tutorial on how to apply this function?
Thank you

[[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] How to use preProcess in Caret?

2019-12-05 Thread Burak Kaymakci
Hello there,

Yes, I'd tried scale as well. I mean, I could do my preprocessing
separately and it was working fine.
I was just wondering how preProcess argument in train function works. As
far as I know, when preProcess argument is set, it normalizes inputs but
not outputs.

Then I've figured we could also use recipes and that normalizes both
predictors and outcomes as you wish.

Here

you can take a look at the question I've asked on SO.
You can see the use of recipe in comments below by "missuse".

I will read the link you've shared as well.

Thank you,
Burak


William Michels , 4 Ara 2019 Çar, 21:04 tarihinde
şunu yazdı:

> Hello,
>
> Have you tried alternative methods of pre-processing your data, such
> as simply calling scale()? What is the effect on convergence, for both
> the caret package and and the neuralnet package? There's an example
> using scale() with the neuralnet package at the link below:
>
> https://datascienceplus.com/fitting-neural-network-in-r/
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
>
>
> On Sun, Dec 1, 2019 at 10:04 AM Burak Kaymakci 
> wrote:
> >
> > Hello there,
> >
> > I am using caret and neuralnet to train a neural network to predict times
> > table. I am using 'backprop' algorithm for neuralnet to experiment and
> > learn.
> >
> > Before using caret, I've trained a neuralnet without using caret, I've
> > normalized my input & outputs using preProcess with 'range' method. Then
> I
> > predicted my test set, did the multiplication and addition on predictions
> > to get the real values. It gave me good results.
> >
> > What I want to ask is, when I try to train my network using caret, I get
> an
> > error saying algorithm did not converge. I am thinking that I might be
> > doing something wrong with my pre-processing,
> >
> > How would I go about using preProcess in train?
> > Do I pass my not-normalized data set to the train function and train
> > function handles normalization internally?
> >
> > You can find my R gist here
> > 
> >
> > Thank you,
> > Burak
> > __
> > 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] How to use preProcess in Caret?

2019-12-04 Thread William Michels via R-help
Hello,

Have you tried alternative methods of pre-processing your data, such
as simply calling scale()? What is the effect on convergence, for both
the caret package and and the neuralnet package? There's an example
using scale() with the neuralnet package at the link below:

https://datascienceplus.com/fitting-neural-network-in-r/

HTH, Bill.

W. Michels, Ph.D.



On Sun, Dec 1, 2019 at 10:04 AM Burak Kaymakci  wrote:
>
> Hello there,
>
> I am using caret and neuralnet to train a neural network to predict times
> table. I am using 'backprop' algorithm for neuralnet to experiment and
> learn.
>
> Before using caret, I've trained a neuralnet without using caret, I've
> normalized my input & outputs using preProcess with 'range' method. Then I
> predicted my test set, did the multiplication and addition on predictions
> to get the real values. It gave me good results.
>
> What I want to ask is, when I try to train my network using caret, I get an
> error saying algorithm did not converge. I am thinking that I might be
> doing something wrong with my pre-processing,
>
> How would I go about using preProcess in train?
> Do I pass my not-normalized data set to the train function and train
> function handles normalization internally?
>
> You can find my R gist here
> 
>
> Thank you,
> Burak
> __
> 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.


[R] How to use preProcess in Caret?

2019-12-01 Thread Burak Kaymakci
Hello there,

I am using caret and neuralnet to train a neural network to predict times
table. I am using 'backprop' algorithm for neuralnet to experiment and
learn.

Before using caret, I've trained a neuralnet without using caret, I've
normalized my input & outputs using preProcess with 'range' method. Then I
predicted my test set, did the multiplication and addition on predictions
to get the real values. It gave me good results.

What I want to ask is, when I try to train my network using caret, I get an
error saying algorithm did not converge. I am thinking that I might be
doing something wrong with my pre-processing,

How would I go about using preProcess in train?
Do I pass my not-normalized data set to the train function and train
function handles normalization internally?

You can find my R gist here


Thank you,
Burak
__
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] how to use a matrix as an index to another matrix?

2019-10-28 Thread Bert Gunter
No loops necessary. Use array indexing (see ?"[", of course -- the section
on matrices and arrays)

set.seed(123)
 A <- matrix(sample(1:10), nrow = 5)
 B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
## The following could be a 1-liner, but I broke it out for clarity.
 ix <- cbind(as.vector(B), rep(1:2, e=5))
 ix
matrix(A[ix], ncol =2)

Cheers,
Bert


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 Mon, Oct 28, 2019 at 1:48 PM Linus Chen  wrote:

> Hi Jinsong,
>
> In such a case I think explicit loop IS the most elegant solution.
> for(i in 1:2) A[,i] <- A[,i][B[,i]]
>
> Linus
>
> On Fri, 11 Oct 2019 at 11:44, Jinsong Zhao  wrote:
> >
> > Hi there,
> >
> > I have two matrices, A and B. The columns of B is the index of the
> > corresponding columns of A. I hope to rearrange of A by B. A minimal
> > example is following:
> >
> >  > set.seed(123)
> >  > A <- matrix(sample(1:10), nrow = 5)
> >  > B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
> >  > A
> >   [,1] [,2]
> > [1,]39
> > [2,]   101
> > [3,]27
> > [4,]85
> > [5,]64
> >  > B
> >   [,1] [,2]
> > [1,]21
> > [2,]34
> > [3,]15
> > [4,]43
> > [5,]52
> >  > A[,1] <- A[,1][B[,1]]
> >  > A[,2] <- A[,2][B[,2]]
> >  > A
> >   [,1] [,2]
> > [1,]   109
> > [2,]25
> > [3,]34
> > [4,]87
> > [5,]61
> >
> > My question is whether there is any elegant or generalized way to
> replace:
> >
> >  > A[,1] <- A[,1][B[,1]]
> >  > A[,2] <- A[,2][B[,2]]
> >
> > Thanks in advance.
> >
> > PS., I know how to do the above thing by loop.
> >
> > Best,
> > Jinsong
> >
> > __
> > 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.
>

[[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] how to use a matrix as an index to another matrix?

2019-10-28 Thread Linus Chen
Hi Jinsong,

In such a case I think explicit loop IS the most elegant solution.
for(i in 1:2) A[,i] <- A[,i][B[,i]]

Linus

On Fri, 11 Oct 2019 at 11:44, Jinsong Zhao  wrote:
>
> Hi there,
>
> I have two matrices, A and B. The columns of B is the index of the
> corresponding columns of A. I hope to rearrange of A by B. A minimal
> example is following:
>
>  > set.seed(123)
>  > A <- matrix(sample(1:10), nrow = 5)
>  > B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
>  > A
>   [,1] [,2]
> [1,]39
> [2,]   101
> [3,]27
> [4,]85
> [5,]64
>  > B
>   [,1] [,2]
> [1,]21
> [2,]34
> [3,]15
> [4,]43
> [5,]52
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>  > A
>   [,1] [,2]
> [1,]   109
> [2,]25
> [3,]34
> [4,]87
> [5,]61
>
> My question is whether there is any elegant or generalized way to replace:
>
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>
> Thanks in advance.
>
> PS., I know how to do the above thing by loop.
>
> Best,
> Jinsong
>
> __
> 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] how to use a matrix as an index to another matrix?

2019-10-11 Thread Martin Morgan
A matrix can be subset by another 2-column matrix, where the first column is 
the row index and the second column the column index. So

idx = matrix(c(B, col(B)), ncol = 2)
A[] <- A[idx]

Martin Morgan

On 10/11/19, 6:31 AM, "R-help on behalf of Eric Berger" 
 wrote:

Here is one way
A <- sapply(1:ncol(A), function(i) {A[,i][B[,i]]})


On Fri, Oct 11, 2019 at 12:44 PM Jinsong Zhao  wrote:

> Hi there,
>
> I have two matrices, A and B. The columns of B is the index of the
> corresponding columns of A. I hope to rearrange of A by B. A minimal
> example is following:
>
>  > set.seed(123)
>  > A <- matrix(sample(1:10), nrow = 5)
>  > B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
>  > A
>   [,1] [,2]
> [1,]39
> [2,]   101
> [3,]27
> [4,]85
> [5,]64
>  > B
>   [,1] [,2]
> [1,]21
> [2,]34
> [3,]15
> [4,]43
> [5,]52
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>  > A
>   [,1] [,2]
> [1,]   109
> [2,]25
> [3,]34
> [4,]87
> [5,]61
>
> My question is whether there is any elegant or generalized way to replace:
>
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>
> Thanks in advance.
>
> PS., I know how to do the above thing by loop.
>
> Best,
> Jinsong
>
> __
> 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-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] how to use a matrix as an index to another matrix?

2019-10-11 Thread Eric Berger
Here is one way
A <- sapply(1:ncol(A), function(i) {A[,i][B[,i]]})


On Fri, Oct 11, 2019 at 12:44 PM Jinsong Zhao  wrote:

> Hi there,
>
> I have two matrices, A and B. The columns of B is the index of the
> corresponding columns of A. I hope to rearrange of A by B. A minimal
> example is following:
>
>  > set.seed(123)
>  > A <- matrix(sample(1:10), nrow = 5)
>  > B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
>  > A
>   [,1] [,2]
> [1,]39
> [2,]   101
> [3,]27
> [4,]85
> [5,]64
>  > B
>   [,1] [,2]
> [1,]21
> [2,]34
> [3,]15
> [4,]43
> [5,]52
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>  > A
>   [,1] [,2]
> [1,]   109
> [2,]25
> [3,]34
> [4,]87
> [5,]61
>
> My question is whether there is any elegant or generalized way to replace:
>
>  > A[,1] <- A[,1][B[,1]]
>  > A[,2] <- A[,2][B[,2]]
>
> Thanks in advance.
>
> PS., I know how to do the above thing by loop.
>
> Best,
> Jinsong
>
> __
> 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] how to use a matrix as an index to another matrix?

2019-10-11 Thread Jinsong Zhao

Hi there,

I have two matrices, A and B. The columns of B is the index of the 
corresponding columns of A. I hope to rearrange of A by B. A minimal 
example is following:


> set.seed(123)
> A <- matrix(sample(1:10), nrow = 5)
> B <- matrix(c(sample(1:5), sample(1:5)), nrow =5, byrow = FALSE)
> A
 [,1] [,2]
[1,]39
[2,]   101
[3,]27
[4,]85
[5,]64
> B
 [,1] [,2]
[1,]21
[2,]34
[3,]15
[4,]43
[5,]52
> A[,1] <- A[,1][B[,1]]
> A[,2] <- A[,2][B[,2]]
> A
 [,1] [,2]
[1,]   109
[2,]25
[3,]34
[4,]87
[5,]61

My question is whether there is any elegant or generalized way to replace:

> A[,1] <- A[,1][B[,1]]
> A[,2] <- A[,2][B[,2]]

Thanks in advance.

PS., I know how to do the above thing by loop.

Best,
Jinsong

__
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] How to use Conda with R + RStudio Server

2019-10-07 Thread Juan Telleria Ruiz de Aguirre
Solution:

https://github.com/grst/rstudio-server-conda

It works.

[[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] How to use breaks argument in hist() function correctly?

2019-09-18 Thread Stephen Ellison
> When I had breaks = 18, I get total number of cells as 16, which is
> same when I put breaks = 20
>
> In the 2nd case I was expecting total number of cells (i.e. bars) as
> 20 i.e. if I understand the documentation correctly I should expect
> total number of cells (bars) should be same as breaks argument in
> hist() function.

You do not _quite_ understand the documentation correctly.
?hist says
"In the last three cases the number is a suggestion only; as
the breakpoints will be set to 'pretty' values"
That includes specification of a single number of breaks.

> How to make that happen?
Specify a vector of breaks with 20 intervals (21 values). 
For example,
breaks=seq(-450, 350, length.out=21)
This gives a bin width of 4e5. 

S Ellison



***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] How to use breaks argument in hist() function correctly?

2019-09-18 Thread Jim Lemon
Hi Cristofer,
If you just ask for a number of breaks, you will get what "hist"
thinks you should. Try this or something similar:

hist(x,breaks=seq(min(x),max(x),length.out=21))

Jim

On Wed, Sep 18, 2019 at 8:55 PM Christofer Bogaso
 wrote:
>
> Hi,
>
> I have a numerical vector as below
>
> x = c(92958.2014593977, -379826.025677203, 881937.411562002, 25761.5278163719,
> -11837.158273897, 48450.8089746788, -415505.62910869, -168462.98512054,
> 328504.255373387, -298966.051027528, 237133.794811816, -49610.1148173768,
> -92459.1170329526, -261611.557495123, -314388.27876, -432257.362693919,
> -1031328.04402229, 79654.3696754137, 107072.114744956, -43384.1420067487,
> 410881.767122128, 1107540.47690119, -187319.627164858, -363126.966946238,
> 264885.548330589, -127020.002396109, 150315.10537545, 609502.016523236,
> 218679.801620448, 901573.599806465, 8289.59210428538, -860908.637977889,
> 39680.5921457494, -70270.7462533897, 1135442.61429015, 133964.991179536,
> 1603815.51357657, 2509929.42959337, 193680.587201446, -167020.153065672,
> -55258.5415736386, -121185.161514792, -1003115.2769274, 1345368.12703686,
> 91665.388397883, 137350.320344812, 29866.332965572, 558999.444304371,
> 523687.79187, -867194.523170726, -271190.308507375, -423629.796389981,
> 96407.0505512169, 193397.770743584, -1231855.39144784, 324272.89909045,
> -1586859.60653751, 252986.272621096, -1008329.14877038, -24090.2255466315,
> 159815.745712707, 969037.929787668, -586905.922684562, 573133.370665267,
> -285493.361916026, -368392.707593945, -199242.654709143, 151002.480443041,
> -678758.615800119, 467477.65504, -267683.37512503, -1541813.6353232,
> -6723.49019530666, 373.233886695949, 59116.2440402955, -1369030.26511923,
> 1527024.1822942, 63951.299612343, -535128.407281035, 304507.377244809,
> 141771.552178838, 98963.774668207, 10810.9015935012, 1022008.90830883,
> 276804.330003406, -304607.247552493, -15767.6578367545, -204454.923166458,
> 722866.275157944, 137685.886832198, 590201.29119819, 904805.824902981,
> -47417.8588758472, 55097.1936075327, 144426.170076371, 1020559.38779514,
> -7019.11334737329, 488224.043025845, -28272.5766026849, -295384.449673914,
> -93475.8799719289, -367939.725072447, -1244135.36327203, -863835.124327735,
> -1399240.55792133, 241146.794430078, -96612.1109580967, -9159.41140641969,
> -240291.731366074, -7482.02181888149, 71427.8225121907, -228401.89341468,
> 948738.649629141, -327368.940001115, -53374.866091836, 126448.573738739,
> 344962.4459403, 270571.141270723, 746988.197131718, -253220.465177424,
> -362652.833437272, -4385.56796251462, -114398.64639441, 454240.63525686,
> -1239567.92855698, -389939.987378005, -364083.196493484, 24693.1882238397,
> 4635.22406457209, 57992.688805147, -67934.5184434773, 123034.937557127,
> 483909.751375248, -167441.867070132, -382537.019103907, 267584.10264059,
> -188944.743935369, -47062.5409102427, -860201.712919788, -203096.090898701,
> 44317.9727734545, 375924.206160012, 67000.7086638517, 137607.783105903,
> -306430.502044082, -669552.84790218, -72629.0354820569, 251145.827045551,
> -230557.16727732, -112594.52630222, 74052.4425890159, -105774.458850881,
> -241185.430318678, -296663.488112722, 156807.699193046, -520102.742784345,
> -56451.5201730288, -23171.0259034268, -107945.719878344, -158480.929620835,
> -769507.414580615, -83077.050717928, 477248.698330914, 27706.3803488034,
> 70485.7144565997, 302213.341425514, -322119.331851626, -476228.406727923,
> -99453.524756431, -673693.791106482, 38765.0473434452, 63302.3087165867,
> 116619.019966859, -167803.424492692, 82982.1864557734, -262627.809345438,
> 643538.235642472, -90724.2065826313, -435531.286293254, -371820.753318447,
> -224713.223837607, -538987.838068522, -195841.454277966, 13924.6120356087,
> -415252.7309228, 209424.879456433, 485624.048364534, 74317.8482029741,
> 19994.939065553, -460452.302259829, -141374.457424938, -77310.8968822459,
> 56112.3979095014, -150891.122921784, -679395.088755517, -523803.739201696,
> -69888.2239139985, -4463.34352237508, -63616.8025699607, 906704.585396864,
> 1096575.89875834, -382869.397851591, -624324.630106468, -468837.009485095,
> -49963.2943695135, 17038.2753380311, 756286.614911188, -995536.510249994,
> 308899.601761641, -375123.707808525, -113921.428586057, -61573.6957341075,
> 55239.3511454715, -46731.8391379398, 697843.754042485, 265162.29364751,
> 1133747.94683337, -355974.319924194, 30699.0482856455, -19680.791041683,
> -624454.313911307, 94983.7375389124, 744849.080038272, 172732.610815633,
> -120546.157860821, 62579.2205127864, -621204.554941904, 293869.359181081,
> -108505.317455271, 646163.583792489, -502636.630380265, 502413.155645464,
> -49238.362688755, 108812.985894042, -139113.621347874, 1120034.73283877,
> -296008.55142246, -845627.626734492, 116082.364002893, 85096.4224949463,
> -84149.6401610159, 611729.398657364, -783642.839894851, -9788.4825023263,
> -58734.3009729933, -110950.384570162, -53258.3833170316, -20519.0858192393,
> 

[R] How to use breaks argument in hist() function correctly?

2019-09-18 Thread Christofer Bogaso
Hi,

I have a numerical vector as below

x = c(92958.2014593977, -379826.025677203, 881937.411562002, 25761.5278163719,
-11837.158273897, 48450.8089746788, -415505.62910869, -168462.98512054,
328504.255373387, -298966.051027528, 237133.794811816, -49610.1148173768,
-92459.1170329526, -261611.557495123, -314388.27876, -432257.362693919,
-1031328.04402229, 79654.3696754137, 107072.114744956, -43384.1420067487,
410881.767122128, 1107540.47690119, -187319.627164858, -363126.966946238,
264885.548330589, -127020.002396109, 150315.10537545, 609502.016523236,
218679.801620448, 901573.599806465, 8289.59210428538, -860908.637977889,
39680.5921457494, -70270.7462533897, 1135442.61429015, 133964.991179536,
1603815.51357657, 2509929.42959337, 193680.587201446, -167020.153065672,
-55258.5415736386, -121185.161514792, -1003115.2769274, 1345368.12703686,
91665.388397883, 137350.320344812, 29866.332965572, 558999.444304371,
523687.79187, -867194.523170726, -271190.308507375, -423629.796389981,
96407.0505512169, 193397.770743584, -1231855.39144784, 324272.89909045,
-1586859.60653751, 252986.272621096, -1008329.14877038, -24090.2255466315,
159815.745712707, 969037.929787668, -586905.922684562, 573133.370665267,
-285493.361916026, -368392.707593945, -199242.654709143, 151002.480443041,
-678758.615800119, 467477.65504, -267683.37512503, -1541813.6353232,
-6723.49019530666, 373.233886695949, 59116.2440402955, -1369030.26511923,
1527024.1822942, 63951.299612343, -535128.407281035, 304507.377244809,
141771.552178838, 98963.774668207, 10810.9015935012, 1022008.90830883,
276804.330003406, -304607.247552493, -15767.6578367545, -204454.923166458,
722866.275157944, 137685.886832198, 590201.29119819, 904805.824902981,
-47417.8588758472, 55097.1936075327, 144426.170076371, 1020559.38779514,
-7019.11334737329, 488224.043025845, -28272.5766026849, -295384.449673914,
-93475.8799719289, -367939.725072447, -1244135.36327203, -863835.124327735,
-1399240.55792133, 241146.794430078, -96612.1109580967, -9159.41140641969,
-240291.731366074, -7482.02181888149, 71427.8225121907, -228401.89341468,
948738.649629141, -327368.940001115, -53374.866091836, 126448.573738739,
344962.4459403, 270571.141270723, 746988.197131718, -253220.465177424,
-362652.833437272, -4385.56796251462, -114398.64639441, 454240.63525686,
-1239567.92855698, -389939.987378005, -364083.196493484, 24693.1882238397,
4635.22406457209, 57992.688805147, -67934.5184434773, 123034.937557127,
483909.751375248, -167441.867070132, -382537.019103907, 267584.10264059,
-188944.743935369, -47062.5409102427, -860201.712919788, -203096.090898701,
44317.9727734545, 375924.206160012, 67000.7086638517, 137607.783105903,
-306430.502044082, -669552.84790218, -72629.0354820569, 251145.827045551,
-230557.16727732, -112594.52630222, 74052.4425890159, -105774.458850881,
-241185.430318678, -296663.488112722, 156807.699193046, -520102.742784345,
-56451.5201730288, -23171.0259034268, -107945.719878344, -158480.929620835,
-769507.414580615, -83077.050717928, 477248.698330914, 27706.3803488034,
70485.7144565997, 302213.341425514, -322119.331851626, -476228.406727923,
-99453.524756431, -673693.791106482, 38765.0473434452, 63302.3087165867,
116619.019966859, -167803.424492692, 82982.1864557734, -262627.809345438,
643538.235642472, -90724.2065826313, -435531.286293254, -371820.753318447,
-224713.223837607, -538987.838068522, -195841.454277966, 13924.6120356087,
-415252.7309228, 209424.879456433, 485624.048364534, 74317.8482029741,
19994.939065553, -460452.302259829, -141374.457424938, -77310.8968822459,
56112.3979095014, -150891.122921784, -679395.088755517, -523803.739201696,
-69888.2239139985, -4463.34352237508, -63616.8025699607, 906704.585396864,
1096575.89875834, -382869.397851591, -624324.630106468, -468837.009485095,
-49963.2943695135, 17038.2753380311, 756286.614911188, -995536.510249994,
308899.601761641, -375123.707808525, -113921.428586057, -61573.6957341075,
55239.3511454715, -46731.8391379398, 697843.754042485, 265162.29364751,
1133747.94683337, -355974.319924194, 30699.0482856455, -19680.791041683,
-624454.313911307, 94983.7375389124, 744849.080038272, 172732.610815633,
-120546.157860821, 62579.2205127864, -621204.554941904, 293869.359181081,
-108505.317455271, 646163.583792489, -502636.630380265, 502413.155645464,
-49238.362688755, 108812.985894042, -139113.621347874, 1120034.73283877,
-296008.55142246, -845627.626734492, 116082.364002893, 85096.4224949463,
-84149.6401610159, 611729.398657364, -783642.839894851, -9788.4825023263,
-58734.3009729933, -110950.384570162, -53258.3833170316, -20519.0858192393,
456910.655858686, 48830.1071552214, -358333.95721609, 80046.3518406906,
-224193.119044228, 45897.0722281932, -4895.48804178487, 735710.318540904,
183571.602770915, -103173.288434665, 554285.106452708, 536724.819749035,
-38962.2828892764, 26730.2338615816, -267784.282389664, 659763.691652086,
331635.73797362, -305496.497141735, 337703.432388682, 26793.2725583163,
-214055.61511956, 

Re: [R] How to use Conda with R + RStudio Server

2019-09-07 Thread Jeff Newmiller
You may get a response here (including my poorly-informed one) but this is off 
topic (_do read the Posting Guide_) so you are basically barking into the 
darkness here. You should be asking in the RStudio community forum.

As far as I am aware you have to run your RSS in a single environment, so conda 
is a poor match for that IDE. But hey... I could be wrong... go ask an expert.

On September 7, 2019 8:58:19 AM PDT, Juan Telleria Ruiz de Aguirre 
 wrote:
>Dear R-help Mailing List:
>
>For reproducibility, I want to use Conda + R (IRkernel), which will
>allow
>me to have within the same machine different "environments", with
>different
>versions of R installed, and specific package versions:
>
>http://know.continuum.io/rs/387-XNW-688/images/conda-cheatsheet.pdf
>
>As a result, I could execute in my command prompt:
>
>>> conda activate r_environment_A
>
>>> jupyter lab
>
>And develop in a R environment with a fixed set of packages, and anyone
>with my same environment (Can be exported though a `conda env export`
>and
>created though a `conda create`) could reproduce the same analyses in
>their
>machine:
>
>https://docs.anaconda.com/anaconda/user-guide/tasks/using-r-language/
>
>https://richpauloo.github.io/2018-05-16-Installing-the-R-kernel-in-Jupyter-Lab/
>
>
>However, instead of using Jupyter Lab, I would like to use "RStudio
>Server"
>within my conda environment, but this is far more complicated, as I
>have
>not been able to install it in an easy way, so that, changing my conda
>environment, also changes my RStudio Server Environment:
>
>https://www.rstudio.com/products/rstudio/download-server/
>
>Anyone has any gess on how to do it?
>
>Thank you!
>
>Juan Telleria
>
>   [[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.


[R] How to use Conda with R + RStudio Server

2019-09-07 Thread Juan Telleria Ruiz de Aguirre
Dear R-help Mailing List:

For reproducibility, I want to use Conda + R (IRkernel), which will allow
me to have within the same machine different "environments", with different
versions of R installed, and specific package versions:

http://know.continuum.io/rs/387-XNW-688/images/conda-cheatsheet.pdf

As a result, I could execute in my command prompt:

>> conda activate r_environment_A

>> jupyter lab

And develop in a R environment with a fixed set of packages, and anyone
with my same environment (Can be exported though a `conda env export` and
created though a `conda create`) could reproduce the same analyses in their
machine:

https://docs.anaconda.com/anaconda/user-guide/tasks/using-r-language/

https://richpauloo.github.io/2018-05-16-Installing-the-R-kernel-in-Jupyter-Lab/


However, instead of using Jupyter Lab, I would like to use "RStudio Server"
within my conda environment, but this is far more complicated, as I have
not been able to install it in an easy way, so that, changing my conda
environment, also changes my RStudio Server Environment:

https://www.rstudio.com/products/rstudio/download-server/

Anyone has any gess on how to do it?

Thank you!

Juan Telleria

[[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] How to use depmix for HMM with intial parameters

2017-09-20 Thread Ismail SEZEN

> On 20 Sep 2017, at 11:14, niharika singhal  
> wrote:
> 
> Hello,
> 
> I have initial parameters for HMM model and I want to use depmixS4 package.
> The parameters are in the form
> 
> intial_prob_matrix=matrix(c(0.07614213, 0.45177665, 0.47208122), nrow=1,
> ncol=3, byrow = TRUE)
> 
> transition_matrix=matrix(c(0.4667,0.4667,0.0667,
> 0.06741573,0.5617978,0.37078652,
> 0.02173913,0.3478261,0.63043478), nrow = 3, ncol = 3,
> byrow = TRUE)
> 
> meanval_matrix=matrix(c(545.1737,545.1737,803.5235,
>565.7763,673.8019,797.5283,
>733.9332,1006.3571,1383.5395), nrow = 3, ncol = 3,
> byrow = TRUE)
> 
> sigmaval_matrix=matrix(c(82.19592,13.64243,57.07868,
> 65.32724,13.38910,81.66209,
> 97.62573,71.09579,115.55612), nrow = 3, ncol = 3,
> byrow = TRUE)
> 
> coeffval_matrix=matrix(c(0.1295604,0.6464059,0.2240336,
> 0.2091671,0.5267220,0.2641110,
> 0.3430697,0.3350215,0.3219088), nrow = 3, ncol =
> 3, byrow = TRUE)
> 
> emission_matrix=list(meanval_matrix,sigmaval_matrix,coeffval_matrix)
> 
> powerdf is a column from my dataset which look like something = 19.0, 18.0,
> 24.0...it has some 30 thousand rows
> 
> I tried  using the code below and got an error
> 
> mod= depmix( response = power~1, data = powerdf, nstates=3,
>   instart=intial_prob_matrix,
> trstart=transition_matrix, respstart=emission_matrix)
> 
> Error in makeResponseModels(response = response, data = data, nstates =
> nstates,  :
>  'respstart' has incorrect length, it should be 6
> 
> I cannot change my emission matrix, it would always be list of matrix (mean
> , sigma and weighted coefficient mixture)
> 
> I thought to change the response but I am unable to figure out the right
> response
> 
> Can someone guide me how can I solve this problem, by giving the
> parameters defined above?
> 
> Thanks & Regards
> Niharika Singhal

Hello Niharika,

As this is a very specific statistical question, you also should ask this kind 
of a question at [1]. You may get faster response.

1- https://stats.stackexchange.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.


[R] How to use depmix for HMM with intial parameters

2017-09-20 Thread niharika singhal
Hello,

I have initial parameters for HMM model and I want to use depmixS4 package.
The parameters are in the form

intial_prob_matrix=matrix(c(0.07614213, 0.45177665, 0.47208122), nrow=1,
ncol=3, byrow = TRUE)

transition_matrix=matrix(c(0.4667,0.4667,0.0667,
 0.06741573,0.5617978,0.37078652,
 0.02173913,0.3478261,0.63043478), nrow = 3, ncol = 3,
byrow = TRUE)

meanval_matrix=matrix(c(545.1737,545.1737,803.5235,
565.7763,673.8019,797.5283,
733.9332,1006.3571,1383.5395), nrow = 3, ncol = 3,
byrow = TRUE)

sigmaval_matrix=matrix(c(82.19592,13.64243,57.07868,
 65.32724,13.38910,81.66209,
 97.62573,71.09579,115.55612), nrow = 3, ncol = 3,
byrow = TRUE)

coeffval_matrix=matrix(c(0.1295604,0.6464059,0.2240336,
 0.2091671,0.5267220,0.2641110,
 0.3430697,0.3350215,0.3219088), nrow = 3, ncol =
3, byrow = TRUE)

emission_matrix=list(meanval_matrix,sigmaval_matrix,coeffval_matrix)

powerdf is a column from my dataset which look like something = 19.0, 18.0,
24.0...it has some 30 thousand rows

I tried  using the code below and got an error

mod= depmix( response = power~1, data = powerdf, nstates=3,
   instart=intial_prob_matrix,
trstart=transition_matrix, respstart=emission_matrix)

 Error in makeResponseModels(response = response, data = data, nstates =
nstates,  :
  'respstart' has incorrect length, it should be 6

I cannot change my emission matrix, it would always be list of matrix (mean
, sigma and weighted coefficient mixture)

I thought to change the response but I am unable to figure out the right
response

Can someone guide me how can I solve this problem, by giving the
parameters defined above?

Thanks & Regards
Niharika Singhal

[[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] How to use getSymbols() to get annual data

2017-09-02 Thread Duncan Murdoch

On 01/09/2017 7:37 PM, Yingrui Liu wrote:

Dear Sir/Madam,


How to use getSymbols() to get annual data? For example, I need the annual 
stock price of APPLE from the year 2000 to 2016. How to write the command? I 
only know how to get the daily data. It is:


getSymbols("AAPL",from="2000-01-01",to="2016-12-31")




Presumably you'd need to loop over the years:  get all the daily data in 
a year, calculate the overall High and Low, take the Open from the first 
date, the Close from the last one, and repeat.


Duncan Murdoch

__
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] How to use getSymbols() to get annual data

2017-09-01 Thread Bert Gunter
Reading ?getSymbols, why do think you can get yearly data if the src --
"yahoo" by default -- only contains daily data? And if you can get the
daily data, why can't you just pick a day from each year to make it yearly?

Note: I'm not a quantmod user, so apologies if I just don't get it.

Cheers,
Bert





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 Fri, Sep 1, 2017 at 4:37 PM, Yingrui Liu  wrote:

> Dear Sir/Madam,
>
>
> How to use getSymbols() to get annual data? For example, I need the annual
> stock price of APPLE from the year 2000 to 2016. How to write the command?
> I only know how to get the daily data. It is:
>
>
> getSymbols("AAPL",from="2000-01-01",to="2016-12-31")
>
>
> Thank you very much.
>
>
> Have a good week!
>
>
> Best regards,
>
>
> Yingrui Liu
>
>
> [[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] How to use getSymbols() to get annual data

2017-09-01 Thread Jeff Newmiller

I suppose that might depend what you mean by "annual data".

?yearlyReturn

or

###
library(quantmod)
#> Loading required package: xts
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
#> Loading required package: TTR
#> Version 0.4-0 included new data defaults. See ?getSymbols.
getSymbols("AAPL",from="2000-01-01",to="2016-12-31")
#> 'getSymbols' currently uses auto.assign=TRUE by default, but will
#> use auto.assign=FALSE in 0.5-0. You will still be able to use
#> 'loadSymbols' to automatically load data. 
getOption("getSymbols.env")

#> and getOption("getSymbols.auto.assign") will still be checked for
#> alternate defaults.
#>
#> This message is shown once per session and may be disabled by 
setting

#> options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
#>
#> WARNING: There have been significant changes to Yahoo Finance data.
#> Please see the Warning section of '?getSymbols.yahoo' for details.
#>
#> This message is shown once per session and may be disabled by 
setting

#> options("getSymbols.yahoo.warning"=FALSE).
#> [1] "AAPL"
AAPL[ aggregate( index( AAPL )
   , list( Yr = as.POSIXlt( index( AAPL ) )$year + 1900 )
   , FUN=function(d) head(d,1)
   )$x
]
#>AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume
#> 2000-01-03 4.163 4.4664.037   3.997768   133949200
#> 2001-01-02 1.181 1.2111.156   1.062500   113078000
#> 2002-01-02 1.751 1.8501.744   1.664286   132374200
#> 2003-01-02 1.140 1.1851.139   1.05714345357200
#> 2004-01-02 1.711 1.7271.682   1.5236160600
#> 2005-01-03 5.143 5.1694.970   4.520714   172998000
#> 2006-01-0311.49311.870   11.473  10.678572   201808600
#> 2007-01-0313.70213.748   13.005  11.971429   309579900
#> 2008-01-0231.64231.799   30.575  27.834286   269794700
#> 2009-01-0213.63714.456   13.523  12.964286   186503800
#> 2010-01-0433.89134.061   33.724  30.572857   123432400
#> 2011-01-0351.70952.442   51.582  47.081429   111284600
#> 2012-01-0365.00965.501   64.945  58.7471437200
#> 2013-01-0287.16787.353   85.249  78.432854   140129500
#> 2014-01-0285.31785.524   84.755  79.01857058671200
#> 2015-01-02   117.249   117.302  112.997 109.33000253204600
#> 2016-01-04   106.198   109.055  105.567 105.34999867649400
#>AAPL.Adjusted
#> 2000-01-03  3.596616
#> 2001-01-02  0.955884
#> 2002-01-02  1.497285
#> 2003-01-02  0.951065
#> 2004-01-02  1.367477
#> 2005-01-03  4.067089
#> 2006-01-03  9.607041
#> 2007-01-03 10.770167
#> 2008-01-02 25.041281
#> 2009-01-02 11.663397
#> 2010-01-04 27.505054
#> 2011-01-03 42.357094
#> 2012-01-03 52.852215
#> 2013-01-02 71.189217
#> 2014-01-02 73.522530
#> 2015-01-02103.866470
#> 2016-01-04101.790649
###

Please study the Posting Guide (plain text format, etc), and the vignette 
for the reprex package which can help you confirm your example will run 
for us. (quantmod is not a package we all use...)


On Fri, 1 Sep 2017, Yingrui Liu wrote:


Dear Sir/Madam,


How to use getSymbols() to get annual data? For example, I need the annual 
stock price of APPLE from the year 2000 to 2016. How to write the command? I 
only know how to get the daily data. It is:


getSymbols("AAPL",from="2000-01-01",to="2016-12-31")


Thank you very much.


Have a good week!


Best regards,


Yingrui Liu


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



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

__
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] How to use getSymbols() to get annual data

2017-09-01 Thread Yingrui Liu
Dear Sir/Madam,


How to use getSymbols() to get annual data? For example, I need the annual 
stock price of APPLE from the year 2000 to 2016. How to write the command? I 
only know how to get the daily data. It is:


getSymbols("AAPL",from="2000-01-01",to="2016-12-31")


Thank you very much.


Have a good week!


Best regards,


Yingrui Liu


[[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread Mike C
I was using OS X native R editor. I would imagine that editor is as simple and 
native as it gets. But, if it's truly native, why would Gmail think of my code 
chunk so differently.
I'm just throwing it out there! I can always remove format in Gmail after 
pasting as a precaution. :)






On Fri, Feb 24, 2017 at 10:49 PM -0500, "Jeff Newmiller" 
 wrote:










I am pretty sure it is not RStudio that is converting it to html... it is 
Gmail... but many email programs seem to do this these days so that people can 
send Wingdings symbols to their lolz pals, with no thought of the damage done 
to computer code examples. 
-- 
Sent from my phone. Please excuse my brevity.

On February 24, 2017 7:37:45 PM PST, C W  wrote:
>Thanks for letting me know. That line does look familiar.
>
>It's interesting how I simply copy and paste from R editor can result
>in
>HTML format.
>
>On Fri, Feb 24, 2017 at 9:16 PM, Jeff Newmiller
>
>wrote:
>
>> There is a little button near the bottom of the Gmail editing box
>that
>> switches to plain text. We can immediately tell because of the
>>
>> [[alternative HTML version deleted]]
>>
>> line when we receive it, and sometimes it loses all of the line
>breaks or
>> has extra asterisks mixed in. You can look in the archives or replies
>to
>> see what we see.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On February 24, 2017 5:55:15 PM PST, C W  wrote:
>> >I suppose for loop will suffice.
>> >
>> >I simply copy & paste the code from R editor. From my email, it
>looks
>> >plain. Is there a way to tell?
>> >
>> >On Fri, Feb 24, 2017 at 8:50 PM, Jeff Newmiller
>> >
>> >wrote:
>> >
>> >> The apply function is one of many alienate ways to write a loop.
>It
>> >is not
>> >> appreciably more efficient in cpu time than a for loop.
>> >>
>> >> Your example creates the numbers in the loop... does your actual
>data
>> >get
>> >> created in a loop? If so then your original code should be
>perfectly
>> >> serviceable. If not then there might be a better way to do this,
>but
>> >you
>> >> would have to expand your example to illustrate how the data comes
>to
>> >you
>> >> in order to suggest alternatives.
>> >>
>> >> Also post using plain text to prevent your code from being mangled
>on
>> >its
>> >> way to us.
>> >> --
>> >> Sent from my phone. Please excuse my brevity.
>> >>
>> >> On February 24, 2017 5:27:07 PM PST, C W 
>wrote:
>> >> >In theory, I am generating from group 5 groups of random numbers,
>> >each
>> >> >group has 3 samples.
>> >> >
>> >> >Isn't apply() the replacement of loops?
>> >> >
>> >> >On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
>> >> >
>> >> >wrote:
>> >> >
>> >> >> What is wrong with
>> >> >>
>> >> >> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
>> >> >>
>> >> >> ?
>> >> >>
>> >> >> And what is this "no loop drama" you refer to? I use loops
>> >frequently
>> >> >to
>> >> >> loop around large memory gobbling chunks of code.
>> >> >>
>> >> >> --
>> >> >> Sent from my phone. Please excuse my brevity.
>> >> >>
>> >> >> On February 24, 2017 5:02:46 PM PST, C W 
>> >wrote:
>> >> >> >Dear R,
>> >> >> >
>> >> >> >I wanted to simulate a 5 by 3 matrix which fills up by either
>> >rows
>> >> >or
>> >> >> >columns?
>> >> >> >
>> >> >> >I started with the following filling the matrix by rows,
>> >> >> >
>> >> >> >dat <- matrix(NA, nrow=5, ncol = 3)
>> >> >> >
>> >> >> >for(i in 1:5){
>> >> >> >
>> >> >> >dat[i, ] <- rnorm(3)
>> >> >> >
>> >> >> >}
>> >> >> >
>> >> >> >But, R is known for no loop drama. Any suggestions?
>> >> >> >
>> >> >> >Thanks!
>> >> >> >
>> >> >> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread Jeff Newmiller
I am pretty sure it is not RStudio that is converting it to html... it is 
Gmail... but many email programs seem to do this these days so that people can 
send Wingdings symbols to their lolz pals, with no thought of the damage done 
to computer code examples. 
-- 
Sent from my phone. Please excuse my brevity.

On February 24, 2017 7:37:45 PM PST, C W  wrote:
>Thanks for letting me know. That line does look familiar.
>
>It's interesting how I simply copy and paste from R editor can result
>in
>HTML format.
>
>On Fri, Feb 24, 2017 at 9:16 PM, Jeff Newmiller
>
>wrote:
>
>> There is a little button near the bottom of the Gmail editing box
>that
>> switches to plain text. We can immediately tell because of the
>>
>> [[alternative HTML version deleted]]
>>
>> line when we receive it, and sometimes it loses all of the line
>breaks or
>> has extra asterisks mixed in. You can look in the archives or replies
>to
>> see what we see.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On February 24, 2017 5:55:15 PM PST, C W  wrote:
>> >I suppose for loop will suffice.
>> >
>> >I simply copy & paste the code from R editor. From my email, it
>looks
>> >plain. Is there a way to tell?
>> >
>> >On Fri, Feb 24, 2017 at 8:50 PM, Jeff Newmiller
>> >
>> >wrote:
>> >
>> >> The apply function is one of many alienate ways to write a loop.
>It
>> >is not
>> >> appreciably more efficient in cpu time than a for loop.
>> >>
>> >> Your example creates the numbers in the loop... does your actual
>data
>> >get
>> >> created in a loop? If so then your original code should be
>perfectly
>> >> serviceable. If not then there might be a better way to do this,
>but
>> >you
>> >> would have to expand your example to illustrate how the data comes
>to
>> >you
>> >> in order to suggest alternatives.
>> >>
>> >> Also post using plain text to prevent your code from being mangled
>on
>> >its
>> >> way to us.
>> >> --
>> >> Sent from my phone. Please excuse my brevity.
>> >>
>> >> On February 24, 2017 5:27:07 PM PST, C W 
>wrote:
>> >> >In theory, I am generating from group 5 groups of random numbers,
>> >each
>> >> >group has 3 samples.
>> >> >
>> >> >Isn't apply() the replacement of loops?
>> >> >
>> >> >On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
>> >> >
>> >> >wrote:
>> >> >
>> >> >> What is wrong with
>> >> >>
>> >> >> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
>> >> >>
>> >> >> ?
>> >> >>
>> >> >> And what is this "no loop drama" you refer to? I use loops
>> >frequently
>> >> >to
>> >> >> loop around large memory gobbling chunks of code.
>> >> >>
>> >> >> --
>> >> >> Sent from my phone. Please excuse my brevity.
>> >> >>
>> >> >> On February 24, 2017 5:02:46 PM PST, C W 
>> >wrote:
>> >> >> >Dear R,
>> >> >> >
>> >> >> >I wanted to simulate a 5 by 3 matrix which fills up by either
>> >rows
>> >> >or
>> >> >> >columns?
>> >> >> >
>> >> >> >I started with the following filling the matrix by rows,
>> >> >> >
>> >> >> >dat <- matrix(NA, nrow=5, ncol = 3)
>> >> >> >
>> >> >> >for(i in 1:5){
>> >> >> >
>> >> >> >dat[i, ] <- rnorm(3)
>> >> >> >
>> >> >> >}
>> >> >> >
>> >> >> >But, R is known for no loop drama. Any suggestions?
>> >> >> >
>> >> >> >Thanks!
>> >> >> >
>> >> >> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread C W
Thanks for letting me know. That line does look familiar.

It's interesting how I simply copy and paste from R editor can result in
HTML format.

On Fri, Feb 24, 2017 at 9:16 PM, Jeff Newmiller 
wrote:

> There is a little button near the bottom of the Gmail editing box that
> switches to plain text. We can immediately tell because of the
>
> [[alternative HTML version deleted]]
>
> line when we receive it, and sometimes it loses all of the line breaks or
> has extra asterisks mixed in. You can look in the archives or replies to
> see what we see.
> --
> Sent from my phone. Please excuse my brevity.
>
> On February 24, 2017 5:55:15 PM PST, C W  wrote:
> >I suppose for loop will suffice.
> >
> >I simply copy & paste the code from R editor. From my email, it looks
> >plain. Is there a way to tell?
> >
> >On Fri, Feb 24, 2017 at 8:50 PM, Jeff Newmiller
> >
> >wrote:
> >
> >> The apply function is one of many alienate ways to write a loop. It
> >is not
> >> appreciably more efficient in cpu time than a for loop.
> >>
> >> Your example creates the numbers in the loop... does your actual data
> >get
> >> created in a loop? If so then your original code should be perfectly
> >> serviceable. If not then there might be a better way to do this, but
> >you
> >> would have to expand your example to illustrate how the data comes to
> >you
> >> in order to suggest alternatives.
> >>
> >> Also post using plain text to prevent your code from being mangled on
> >its
> >> way to us.
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> On February 24, 2017 5:27:07 PM PST, C W  wrote:
> >> >In theory, I am generating from group 5 groups of random numbers,
> >each
> >> >group has 3 samples.
> >> >
> >> >Isn't apply() the replacement of loops?
> >> >
> >> >On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
> >> >
> >> >wrote:
> >> >
> >> >> What is wrong with
> >> >>
> >> >> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
> >> >>
> >> >> ?
> >> >>
> >> >> And what is this "no loop drama" you refer to? I use loops
> >frequently
> >> >to
> >> >> loop around large memory gobbling chunks of code.
> >> >>
> >> >> --
> >> >> Sent from my phone. Please excuse my brevity.
> >> >>
> >> >> On February 24, 2017 5:02:46 PM PST, C W 
> >wrote:
> >> >> >Dear R,
> >> >> >
> >> >> >I wanted to simulate a 5 by 3 matrix which fills up by either
> >rows
> >> >or
> >> >> >columns?
> >> >> >
> >> >> >I started with the following filling the matrix by rows,
> >> >> >
> >> >> >dat <- matrix(NA, nrow=5, ncol = 3)
> >> >> >
> >> >> >for(i in 1:5){
> >> >> >
> >> >> >dat[i, ] <- rnorm(3)
> >> >> >
> >> >> >}
> >> >> >
> >> >> >But, R is known for no loop drama. Any suggestions?
> >> >> >
> >> >> >Thanks!
> >> >> >
> >> >> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread Jeff Newmiller
There is a little button near the bottom of the Gmail editing box that switches 
to plain text. We can immediately tell because of the

[[alternative HTML version deleted]]

line when we receive it, and sometimes it loses all of the line breaks or has 
extra asterisks mixed in. You can look in the archives or replies to see what 
we see. 
-- 
Sent from my phone. Please excuse my brevity.

On February 24, 2017 5:55:15 PM PST, C W  wrote:
>I suppose for loop will suffice.
>
>I simply copy & paste the code from R editor. From my email, it looks
>plain. Is there a way to tell?
>
>On Fri, Feb 24, 2017 at 8:50 PM, Jeff Newmiller
>
>wrote:
>
>> The apply function is one of many alienate ways to write a loop. It
>is not
>> appreciably more efficient in cpu time than a for loop.
>>
>> Your example creates the numbers in the loop... does your actual data
>get
>> created in a loop? If so then your original code should be perfectly
>> serviceable. If not then there might be a better way to do this, but
>you
>> would have to expand your example to illustrate how the data comes to
>you
>> in order to suggest alternatives.
>>
>> Also post using plain text to prevent your code from being mangled on
>its
>> way to us.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On February 24, 2017 5:27:07 PM PST, C W  wrote:
>> >In theory, I am generating from group 5 groups of random numbers,
>each
>> >group has 3 samples.
>> >
>> >Isn't apply() the replacement of loops?
>> >
>> >On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
>> >
>> >wrote:
>> >
>> >> What is wrong with
>> >>
>> >> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
>> >>
>> >> ?
>> >>
>> >> And what is this "no loop drama" you refer to? I use loops
>frequently
>> >to
>> >> loop around large memory gobbling chunks of code.
>> >>
>> >> --
>> >> Sent from my phone. Please excuse my brevity.
>> >>
>> >> On February 24, 2017 5:02:46 PM PST, C W 
>wrote:
>> >> >Dear R,
>> >> >
>> >> >I wanted to simulate a 5 by 3 matrix which fills up by either
>rows
>> >or
>> >> >columns?
>> >> >
>> >> >I started with the following filling the matrix by rows,
>> >> >
>> >> >dat <- matrix(NA, nrow=5, ncol = 3)
>> >> >
>> >> >for(i in 1:5){
>> >> >
>> >> >dat[i, ] <- rnorm(3)
>> >> >
>> >> >}
>> >> >
>> >> >But, R is known for no loop drama. Any suggestions?
>> >> >
>> >> >Thanks!
>> >> >
>> >> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread C W
I suppose for loop will suffice.

I simply copy & paste the code from R editor. From my email, it looks
plain. Is there a way to tell?

On Fri, Feb 24, 2017 at 8:50 PM, Jeff Newmiller 
wrote:

> The apply function is one of many alienate ways to write a loop. It is not
> appreciably more efficient in cpu time than a for loop.
>
> Your example creates the numbers in the loop... does your actual data get
> created in a loop? If so then your original code should be perfectly
> serviceable. If not then there might be a better way to do this, but you
> would have to expand your example to illustrate how the data comes to you
> in order to suggest alternatives.
>
> Also post using plain text to prevent your code from being mangled on its
> way to us.
> --
> Sent from my phone. Please excuse my brevity.
>
> On February 24, 2017 5:27:07 PM PST, C W  wrote:
> >In theory, I am generating from group 5 groups of random numbers, each
> >group has 3 samples.
> >
> >Isn't apply() the replacement of loops?
> >
> >On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
> >
> >wrote:
> >
> >> What is wrong with
> >>
> >> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
> >>
> >> ?
> >>
> >> And what is this "no loop drama" you refer to? I use loops frequently
> >to
> >> loop around large memory gobbling chunks of code.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> On February 24, 2017 5:02:46 PM PST, C W  wrote:
> >> >Dear R,
> >> >
> >> >I wanted to simulate a 5 by 3 matrix which fills up by either rows
> >or
> >> >columns?
> >> >
> >> >I started with the following filling the matrix by rows,
> >> >
> >> >dat <- matrix(NA, nrow=5, ncol = 3)
> >> >
> >> >for(i in 1:5){
> >> >
> >> >dat[i, ] <- rnorm(3)
> >> >
> >> >}
> >> >
> >> >But, R is known for no loop drama. Any suggestions?
> >> >
> >> >Thanks!
> >> >
> >> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread Jeff Newmiller
The apply function is one of many alienate ways to write a loop. It is not 
appreciably more efficient in cpu time than a for loop.

Your example creates the numbers in the loop... does your actual data get 
created in a loop? If so then your original code should be perfectly 
serviceable. If not then there might be a better way to do this, but you would 
have to expand your example to illustrate how the data comes to you in order to 
suggest alternatives.

Also post using plain text to prevent your code from being mangled on its way 
to us. 
-- 
Sent from my phone. Please excuse my brevity.

On February 24, 2017 5:27:07 PM PST, C W  wrote:
>In theory, I am generating from group 5 groups of random numbers, each
>group has 3 samples.
>
>Isn't apply() the replacement of loops?
>
>On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller
>
>wrote:
>
>> What is wrong with
>>
>> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
>>
>> ?
>>
>> And what is this "no loop drama" you refer to? I use loops frequently
>to
>> loop around large memory gobbling chunks of code.
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On February 24, 2017 5:02:46 PM PST, C W  wrote:
>> >Dear R,
>> >
>> >I wanted to simulate a 5 by 3 matrix which fills up by either rows
>or
>> >columns?
>> >
>> >I started with the following filling the matrix by rows,
>> >
>> >dat <- matrix(NA, nrow=5, ncol = 3)
>> >
>> >for(i in 1:5){
>> >
>> >dat[i, ] <- rnorm(3)
>> >
>> >}
>> >
>> >But, R is known for no loop drama. Any suggestions?
>> >
>> >Thanks!
>> >
>> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread C W
In theory, I am generating from group 5 groups of random numbers, each
group has 3 samples.

Isn't apply() the replacement of loops?

On Fri, Feb 24, 2017 at 8:23 PM, Jeff Newmiller 
wrote:

> What is wrong with
>
> dat <- matrix(rnorm(15), nrow=5, ncol = 3)
>
> ?
>
> And what is this "no loop drama" you refer to? I use loops frequently to
> loop around large memory gobbling chunks of code.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On February 24, 2017 5:02:46 PM PST, C W  wrote:
> >Dear R,
> >
> >I wanted to simulate a 5 by 3 matrix which fills up by either rows or
> >columns?
> >
> >I started with the following filling the matrix by rows,
> >
> >dat <- matrix(NA, nrow=5, ncol = 3)
> >
> >for(i in 1:5){
> >
> >dat[i, ] <- rnorm(3)
> >
> >}
> >
> >But, R is known for no loop drama. Any suggestions?
> >
> >Thanks!
> >
> >   [[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] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread Jeff Newmiller
What is wrong with

dat <- matrix(rnorm(15), nrow=5, ncol = 3)

?

And what is this "no loop drama" you refer to? I use loops frequently to loop 
around large memory gobbling chunks of code. 

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

On February 24, 2017 5:02:46 PM PST, C W  wrote:
>Dear R,
>
>I wanted to simulate a 5 by 3 matrix which fills up by either rows or
>columns?
>
>I started with the following filling the matrix by rows,
>
>dat <- matrix(NA, nrow=5, ncol = 3)
>
>for(i in 1:5){
>
>dat[i, ] <- rnorm(3)
>
>}
>
>But, R is known for no loop drama. Any suggestions?
>
>Thanks!
>
>   [[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.


[R] How to use apply() to fill matrix by rows or columns?

2017-02-24 Thread C W
Dear R,

I wanted to simulate a 5 by 3 matrix which fills up by either rows or
columns?

I started with the following filling the matrix by rows,

dat <- matrix(NA, nrow=5, ncol = 3)

for(i in 1:5){

dat[i, ] <- rnorm(3)

}

But, R is known for no loop drama. Any suggestions?

Thanks!

[[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] how to use vector of values to change row order of a heatmap

2016-11-22 Thread PIKAL Petr
Hi

Heatmap does not work with data frames (at least the version I have)

> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4))
> heatmap(b)
Error in heatmap(b) : 'x' must be a numeric matrix

With matrix, heatmap works as expected.

> b=matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4)
> heatmap(b)

However for row ordering you need to read Details of help page.

compare

> heatmap(b, Rowv=c(3,2,1))

with

> heatmap(b, Rowv=c(10,2,1))

If either is a vector (of ‘weights’) then the appropriate dendrogram is 
reordered according to the supplied values subject to the constraints imposed 
by the dendrogram, by reorder(dd, Rowv), in the row case. If either is
^
missing, as by default, then the ordering of the corresponding dendrogram is by 
the mean value of the rows/columns, i.e., in the case of rows, Rowv <- 
rowMeans(x, na.rm = na.rm). If either is NA, no reordering will be done for the 
corresponding side.

Cheers
Petr



> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Fix Ace via
> R-help
> Sent: Monday, November 21, 2016 9:14 PM
> To: r-help@r-project.org
> Subject: [R] how to use vector of values to change row order of a heatmap
>
> Hello, there,
> R document for heatmap says that Rowv could be a vector of values to
> specify the row order. However, I couldn't figure out how to apply it. A
> simple example here:>
> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4))
> > b
>   V1 V2 V3 V4
> 1  3  8 13 27
> 2  4  9 14 19
> 3  5 10 15 20
> > row.names(b)=c("a","b","c")
> > b
>   V1 V2 V3 V4
> a  3  8 13 27
> b  4  9 14 19
> c  5 10 15 20
> > heatmap(as.matrix(b))
> What I got: "a" stays at the bottom of the heatmap.
>  Now I would like to put row "a" to the top row, how do I do that?I tried
> provide a vector of values (all the possible combination of 1,2,3) to Rowv,  
> "a"
> is always stay at the bottom Any input would be very helpful!
> Thanks.
> Ace
>
>   [[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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender 

[R] how to use vector of values to change row order of a heatmap

2016-11-21 Thread Fix Ace via R-help
Hello, there,
R document for heatmap says that Rowv could be a vector of values to specify 
the row order. However, I couldn't figure out how to apply it. A simple example 
here:> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4))
> b
  V1 V2 V3 V4
1  3  8 13 27
2  4  9 14 19
3  5 10 15 20
> row.names(b)=c("a","b","c")
> b
  V1 V2 V3 V4
a  3  8 13 27
b  4  9 14 19
c  5 10 15 20
> heatmap(as.matrix(b))
What I got: "a" stays at the bottom of the heatmap.
 Now I would like to put row "a" to the top row, how do I do that?I tried 
provide a vector of values (all the possible combination of 1,2,3) to Rowv,  
"a" is always stay at the bottom
Any input would be very helpful!
Thanks.
Ace

[[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] how to use vector of values to change row order of a heatmap

2016-11-21 Thread Fix Ace via R-help
Hello, there,
R document for heatmap says that Rowv could be a vector of values to specify 
the row order. However, I couldn't figure out how to apply it. A simple example 
here:> b=as.data.frame(matrix(c(3,4,5,8,9,10,13,14,15,27,19,20),3,4))
> b
  V1 V2 V3 V4
1  3  8 13 27
2  4  9 14 19
3  5 10 15 20
> row.names(b)=c("a","b","c")
> b
  V1 V2 V3 V4
a  3  8 13 27
b  4  9 14 19
c  5 10 15 20
> heatmap(as.matrix(b))
What I got:
 

Now I would like to put row "a" to the top row, how do I do that?I tried 
provide a vector of values (all the possible combination of 1,2,3) to Rowv,  
"a" is always stay at the bottom
Any input would be very helpful!
Ace
  

   __
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] how to use the fontchooser tcl tk widget ?

2016-11-13 Thread Cleber N.Borges

hello all r users,
somebody has a example how to use fontchooser widget?
I haven't success in my try :-(
Thanks
Cleber


> library( tcltk ) # in R-devel,

> tclVersion()
[1] "8.6.4"

> tclvalue( tcl('tk::fontchooser', 'show', command='' )  )
Error in (function (name, pos = -1L, envir = as.environment(pos), 
all.names = FALSE,  :

  unused argument ("{DejaVu Sans Mono} 26 bold italic")
Error in (function (name, pos = -1L, envir = as.environment(pos), 
all.names = FALSE,  :

  unused argument ("{DejaVu Sans Mono} 26 bold italic")
[1] ""
>


---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

__
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] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread David L Carlson
One additional issue, since you are using logistic regression, you are 
predicting a dichotomy (i.e. 0 and 1 or factor with 2 categories). The value 
returned by predict() is a log odds ratio of belonging in the second category. 
Alternatively if you use the type="response" argument with predict(), you get 
the estimated probability of being in the second category. You can use ifelse() 
to convert the fitted values back to your original categories, but you must 
decide where to break the values (.5 is an obvious choice for the probabilities 
or 0 for the log odds, but these are not always the best). 

There are a number of tutorials on the web that discuss logistic regression. 
You should look at one of them.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Richard M. 
Heiberger
Sent: Thursday, October 20, 2016 8:05 AM
To: mviljamaa
Cc: r-help
Subject: Re: [R] How to use predict() so that one retains the rows that they're 
associated with?

I believe you have missing values and therefore you need to use
the argument
glm(formula, data, na.action=na.exclude, ...)

?na.exclude

The relevant line is

 when 'na.exclude' is used the residuals and
 predictions are padded to the correct length by inserting 'NA's
 for cases omitted by 'na.exclude'.

Rich

On Thu, Oct 20, 2016 at 7:40 AM, mviljamaa <mvilja...@kapsi.fi> wrote:
> I'm using predict() for my glm() logistic model, but I'm having trouble
> relating the predicted results to the rows that produced them.
>
> I want to be able to plot predictions along some categorical variables.
>
> So what can I do in order to get predicted values but also know what
> variable values produced them?
>
> __
> 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.

__
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] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread Richard M. Heiberger
I believe you have missing values and therefore you need to use
the argument
glm(formula, data, na.action=na.exclude, ...)

?na.exclude

The relevant line is

 when 'na.exclude' is used the residuals and
 predictions are padded to the correct length by inserting 'NA's
 for cases omitted by 'na.exclude'.

Rich

On Thu, Oct 20, 2016 at 7:40 AM, mviljamaa  wrote:
> I'm using predict() for my glm() logistic model, but I'm having trouble
> relating the predicted results to the rows that produced them.
>
> I want to be able to plot predictions along some categorical variables.
>
> So what can I do in order to get predicted values but also know what
> variable values produced them?
>
> __
> 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] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread PIKAL Petr
Hi.

I am a bit puzzled. You do not get predicted values from variables but from 
estimated model. AFAIK order of predicted values is the same as order of 
original values.

> x<-1:10
> y<-5*x+3+rnorm(10)
> plot(x,y)
> a<-sample(letters[1:3], 10, replace=T)
> fit<-lm(y~x)
> points(x, predict(fit), col=as.numeric(as.factor(a)), pch=19)
>

Do if you have some categorical variable and want to distinguish result 
according to them, you can use similar approach.

Cheers
Petr



> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of mviljamaa
> Sent: Thursday, October 20, 2016 1:40 PM
> To: r-help@r-project.org
> Subject: [R] How to use predict() so that one retains the rows that they're
> associated with?
>
> I'm using predict() for my glm() logistic model, but I'm having trouble 
> relating
> the predicted results to the rows that produced them.
>
> I want to be able to plot predictions along some categorical variables.
>
> So what can I do in order to get predicted values but also know what variable
> values produced them?
>
> __
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
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] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread Michael Dewey

Some more context would help here but here goes anyway.

You should have a vector of predictions with length equal to the number 
of rows in your original data-set so you can just use cbind. If that is 
not true check the documentation for the correct setting of na.action. 
If you used newdata = in your call to predict then your predictions 
apply to the new data, not the old, so amend my statement as appropriate.


If that does not answer then make a small example data-set, run glm on 
it, run predict, and then show us the data-set, the output from glm, the 
output from predict, and what went wrong when you tried to cbind them.


On 20/10/2016 12:40, mviljamaa wrote:

I'm using predict() for my glm() logistic model, but I'm having trouble
relating the predicted results to the rows that produced them.

I want to be able to plot predictions along some categorical variables.

So what can I do in order to get predicted values but also know what
variable values produced them?

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



--
Michael
http://www.dewey.myzen.co.uk/home.html

__
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] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread mviljamaa
I'm using predict() for my glm() logistic model, but I'm having trouble 
relating the predicted results to the rows that produced them.


I want to be able to plot predictions along some categorical variables.

So what can I do in order to get predicted values but also know what 
variable values produced them?


__
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] how to use 97.5%, 2.5% values of parameters for next calculation

2016-10-06 Thread David Winsemius

> On Oct 6, 2016, at 7:07 AM, abhishek pandey 
>  wrote:
> 
> Sent from RediffmailNG on Android
> 
> From: abhishek pandeyabhishekpandey_1...@rediffmail.com
> Sent:Thu, 06 Oct 2016 13:24:39 +0530
> To: r-help-ow...@r-project.org
> Subject: how to use 97.5%,2.5% values of parameters for next calculation
> Sir 
> I request you to help me for completing my programm.
> SIZE STEPS Age BASEANDSTEPS num.thin num.chain num.iter num.burn ##NUMBER OF 
> ITERATIONS common for cohort model
>> ITER time A1 library(R2WinBUGS)
> Loading required package: boot
> Warning messages:
> 1: package ‘R2WinBUGS’ was built under R version 3.1.3 
> 2: package ‘boot’ was built under R version 3.1.3 
>> A1 J K low up lowl phi.ul  phi.ll =c(18.776362,131.380765,20.367508, 
>> 50.197501,16.199959,1.262005, 1.148303)
>> data parameters inits inits tfrsim tfrsim
>   [[alternative HTML version deleted]]
> 

As you can see, the fact that you (still) have not read the Posting Guide and 
posted in HTML has left this message unreadable. Please _now_ take the time to 
read the Posting Guide.

> __
> 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 \/\/\/\/\/\/\
> and provide commented, minimal, self-contained, reproducible code.

Which mean you need to include data either as a text  attachment(with extension 
'.txt') or inline.

^^
David Winsemius
Alameda, CA, USA

__
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] How to use fuzzy_partition with fuzzy_trapezoid

2016-07-27 Thread Arthur Stilben
Hello, guys!

I tried to do that:

> teste = fuzzy_partition( varnames = c( "a", "b" ), FUN = fuzzy_trapezoid, 
> corners = c( 0, 1, 2, 3), corners = c(4, 5, 6, 7))
Error in FUN(i, ...) :
  argumento formal "corners" corresponde a múltiplos argumentos especificados


So, how can I use fuzzy_partitions to generate multiples trapezoids?

-- 
Arthur Rodrigues Stilben
Geoinformática - LENEP
(22) 2765-6555

__
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] How to use seas()

2016-06-24 Thread T.Riedle
Dear all,

I am trying to run the seas() function. In doing so, I need an object of class 
"ts". I tried to generate an ts object using the ts() function but it does not 
work.
Does anyone have an idea how to generate an ts object. In addition, I get the 
error that there are too many observations in the file. How can I cope with 
that?

library(seasonal)
> data<-Shiller_data[,2]

s<-ts(data,start = c(1871, 01))

> s

Time Series:

Start = 1871

End = 3610

Frequency = 1

   [1]4.444.504.614.744.864.824.734.794.84  
  4.594.644.744.86

  [14]4.885.045.185.185.135.105.044.954.97  
  4.955.075.115.15

  [27]5.115.045.054.984.974.974.594.194.04  
  4.424.664.804.73



> SP <- seas(s)

Error: X-13 run failed



Errors:

- Problem reading 
C:\Users\tr206\AppData\Local\Temp\Rtmp4Qtc08\x1312202a115399/data.dta. Too

  many observations in file.

- Problem reading 
C:\Users\tr206\AppData\Local\Temp\Rtmp4Qtc08\x1312202a115399/data.dta. Check

  your input file and format.

- Time series could not be read due to previously found errors

- Specify series before user-defined adjustments

- Need to specify a series to identify outliers



Thanks for your help.

[[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] how to use AND in grepl

2016-05-02 Thread Tom Wright
Please try to read my earlier comments.
In the absence of a proper example with expected output I think what you
are trying to achieve is:

# create a sample dataframe
df <- data.frame(Command=c("_localize_PD", "_localize_tre_t2",
"_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

# identify which rows in the dataframe set match the patterns
# note, the vectors PD, T2 and PDT2 are booleans indicating if a match was
made
PD <- grepl("pd", df$Command)
T2 <- grepl('t2', df$Command)
PDT2 <- grepl("(.*t2.*pd.*)|(.*pd.*t2.*)", df$Command)

# create the new column to hold the new names
df$new_name <- NA

df[PD,'new_name'] <- 'pd'
df[T2,'new_name'] <- 't2'
df[PDT2,'new_name'] <- 'pdt2'


# note 1: the order of these command is important, if the last command is
run first all matches will be overwritten by the single matches for 't2'
and 'pd'.
# note 2: There is no match for row 1 as "PD" != "pd", as suggested by John
McKown the ignore.case parameter for grepl can be used to change this
behaviour.

On Mon, May 2, 2016 at 11:01 AM,  wrote:

> I just changed all the names in Command to lowercase, then this
> str_extract works fine for "pd" and "t2", but not for "PDT2". Do you have
> any idea how I can bring PDT2  also in str_extract?
>
>
> On Monday, May 2, 2016 9:16 AM, Tom Wright  wrote:
>
>
>
> The first thing I notice here is that your first two subset statements are
> searching in an object named Command, not the column df$Command. I'm not at
> all sure what you are trying to achieve with the str_extract process but it
> is looking for the exact string 'PDT2' the vectors / dataframe formed in
> your previous commands are not being used at all.
> Moving forward I think you need to pay attention to case "PD" != "pd".
> Also the set PDT2 is going to be a subset of both  sets PD and t2, I don't
> think this is what you are after.
>
> On Mon, May 2, 2016, 8:49 AM   wrote:
>
> Yes it works, but let me explain what I am going to do. I extract all the
> names I want and then create a new column out of them for my plot. This is
> he whole thing I do:
> >  PD=subset(df,grepl("pd",Command)) //extract names in Command with only
> "pd"
> >  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
> >  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract
> names which contain both "pd" and "t2"
> >  v1=c('PD','t2','PDT2')// I create a vector with these conditions
> >  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns,
> using stringr library
> >
> >here I see no pattern named PDT2 but there are only PD and t2 patterns.
> >On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
> >
> >
> >
> >Sorry for the missed braces earlier. I was typing on a phone, not the
> best place to conjugate regular expressions.
> >Using the example you provided:
> >
> >> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
> >
> >> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
> >[1] FALSE FALSE FALSE FALSE  TRUE
> >
> >> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
> >  Command
> >5 pd_local_abdomen_t2
> >
> >
> >
> >On Mon, May 2, 2016 at 7:42 AM,  wrote:
> >
> >Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
> >>
> >>
> >>
> >>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
> >>
> >>On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
> >>
> >>> Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
> >>
> >>Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
> >>
> >>
> >>-pd
> >>
> >>> Thanks,
> >>> Elahe
> >>>
> >>>
> >>> On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >>>
> >>>
> >>>
> >>> Actually not sure my previous answer does what you wanted. Using your
> approach:
> >>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> >>> Should work.
> >>> I think the regex pattern you are looking for is:
> >>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >>>
> >>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >>>
> >>> subset(df,grepl("t2|pd",x$Command))
> 
> 
> 
> 
>  On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> 
>  Hi all,
> >
> > I have one factor variable in my df and I want 

Re: [R] how to use AND in grepl

2016-05-02 Thread John McKown
On Mon, May 2, 2016 at 1:01 PM, ch.elahe via R-help 
wrote:

> I just changed all the names in Command to lowercase, then this
> str_extract works fine for "pd" and "t2", but not for "PDT2". Do you have
> any idea how I can bring PDT2  also in str_extract?
>

Looking at ​?grepl, I see the option: ignore.case=TRUE​

 PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$
Command,ignore.case=TRUE)

Perhaps this will do the trick.

-- 
The unfacts, did we have them, are too imprecisely few to warrant our
certitude.

Maranatha! <><
John McKown

[[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] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
I just changed all the names in Command to lowercase, then this str_extract 
works fine for "pd" and "t2", but not for "PDT2". Do you have any idea how I 
can bring PDT2  also in str_extract?  


On Monday, May 2, 2016 9:16 AM, Tom Wright  wrote:



The first thing I notice here is that your first two subset statements are 
searching in an object named Command, not the column df$Command. I'm not at all 
sure what you are trying to achieve with the str_extract process but it is 
looking for the exact string 'PDT2' the vectors / dataframe formed in your 
previous commands are not being used at all. 
Moving forward I think you need to pay attention to case "PD" != "pd". Also the 
set PDT2 is going to be a subset of both  sets PD and t2, I don't think this is 
what you are after.

On Mon, May 2, 2016, 8:49 AM   wrote:

Yes it works, but let me explain what I am going to do. I extract all the names 
I want and then create a new column out of them for my plot. This is he whole 
thing I do:
>  PD=subset(df,grepl("pd",Command)) //extract names in Command with only "pd"
>  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
>  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract 
> names which contain both "pd" and "t2"
>  v1=c('PD','t2','PDT2')// I create a vector with these conditions
>  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns, using 
> stringr library
>
>here I see no pattern named PDT2 but there are only PD and t2 patterns.
>On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
>
>
>
>Sorry for the missed braces earlier. I was typing on a phone, not the best 
>place to conjugate regular expressions.
>Using the example you provided:
>
>> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2", 
>> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
>
>> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
>[1] FALSE FALSE FALSE FALSE  TRUE
>
>> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
>  Command
>5 pd_local_abdomen_t2
>
>
>
>On Mon, May 2, 2016 at 7:42 AM,  wrote:
>
>Thanks Peter, you were right, the exact grepl is 
>grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
>in Command, when I check the size of it by 
>sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
>sure that the size is not 0. It seems that this AND does not work.
>>
>>
>>
>>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>>
>>On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:
>>
>>> Thanks for your reply tom. After using  
>>> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
>>> Argument "x" is missing, with no default. Actually I don't know how to fix 
>>> this. Do you have any idea?
>>
>>Tom's code was missing a ")" but not where you put one. He probably also 
>>didn't intend to capitalize "subset".
>>
>>
>>-pd
>>
>>> Thanks,
>>> Elahe
>>>
>>>
>>> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
>>>
>>>
>>>
>>> Actually not sure my previous answer does what you wanted. Using your 
>>> approach:
>>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
>>> Should work.
>>> I think the regex pattern you are looking for is:
>>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
>>>
>>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
>>>
>>> subset(df,grepl("t2|pd",x$Command))




 On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
  wrote:

 Hi all,
>
> I have one factor variable in my df and I want to extract the names from 
> it which contain both "t2" and "pd":
>
> 'data.frame': 36919 obs. of 162 variables
>  $TE:int 38,41,11,52,48,75,.
>  $TR:int 100,210,548,546,.
>  $Command  :factor W/2229 levels 
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> 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 

Re: [R] how to use AND in grepl

2016-05-02 Thread Tom Wright
The first thing I notice here is that your first two subset statements are
searching in an object named Command, not the column df$Command. I'm not at
all sure what you are trying to achieve with the str_extract process but it
is looking for the exact string 'PDT2' the vectors / dataframe formed in
your previous commands are not being used at all.
Moving forward I think you need to pay attention to case "PD" != "pd". Also
the set PDT2 is going to be a subset of both  sets PD and t2, I don't think
this is what you are after.

On Mon, May 2, 2016, 8:49 AM  wrote:

> Yes it works, but let me explain what I am going to do. I extract all the
> names I want and then create a new column out of them for my plot. This is
> he whole thing I do:
>   PD=subset(df,grepl("pd",Command)) //extract names in Command with only
> "pd"
>   t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
>   PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract
> names which contain both "pd" and "t2"
>   v1=c('PD','t2','PDT2')// I create a vector with these conditions
>   str_extract(df$Command,paste(v1,collaps='|')) //returning patterns,
> using stringr library
>
> here I see no pattern named PDT2 but there are only PD and t2 patterns.
> On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
>
>
>
> Sorry for the missed braces earlier. I was typing on a phone, not the best
> place to conjugate regular expressions.
> Using the example you provided:
>
> > df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
>
> > grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
> [1] FALSE FALSE FALSE FALSE  TRUE
>
> > subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
>   Command
> 5 pd_local_abdomen_t2
>
>
>
> On Mon, May 2, 2016 at 7:42 AM,  wrote:
>
> Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
> >
> >
> >
> >On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
> >
> >On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
> >
> >> Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
> >
> >Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
> >
> >
> >-pd
> >
> >> Thanks,
> >> Elahe
> >>
> >>
> >> On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >>
> >>
> >>
> >> Actually not sure my previous answer does what you wanted. Using your
> approach:
> >> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> >> Should work.
> >> I think the regex pattern you are looking for is:
> >> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >>
> >> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >>
> >> subset(df,grepl("t2|pd",x$Command))
> >>>
> >>>
> >>>
> >>>
> >>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> >>>
> >>> Hi all,
> 
>  I have one factor variable in my df and I want to extract the names
> from it which contain both "t2" and "pd":
> 
>  'data.frame': 36919 obs. of 162 variables
>   $TE:int 38,41,11,52,48,75,.
>   $TR:int 100,210,548,546,.
>   $Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
> 
>  I have tried this but I did not get result:
> 
>  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
> 
> 
>  does anyone know how to apply AND in grepl?
> 
>  Thanks
>  Elahe
> 
>  __
>  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.
> >
> >--
> >Peter Dalgaard, Professor,
> >Center for Statistics, Copenhagen Business School
> >Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >Phone: (+45)38153501

Re: [R] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Yes it works, but let me explain what I am going to do. I extract all the names 
I want and then create a new column out of them for my plot. This is he whole 
thing I do:
  PD=subset(df,grepl("pd",Command)) //extract names in Command with only "pd"
  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract names 
which contain both "pd" and "t2"
  v1=c('PD','t2','PDT2')// I create a vector with these conditions
  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns, using 
stringr library

here I see no pattern named PDT2 but there are only PD and t2 patterns.
On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:



Sorry for the missed braces earlier. I was typing on a phone, not the best 
place to conjugate regular expressions.
Using the example you provided:

> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2", 
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
[1] FALSE FALSE FALSE FALSE  TRUE

> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
  Command
5 pd_local_abdomen_t2



On Mon, May 2, 2016 at 7:42 AM,  wrote:

Thanks Peter, you were right, the exact grepl is 
grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
in Command, when I check the size of it by 
sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
sure that the size is not 0. It seems that this AND does not work.
>
>
>
>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>
>On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:
>
>> Thanks for your reply tom. After using  
>> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
>> Argument "x" is missing, with no default. Actually I don't know how to fix 
>> this. Do you have any idea?
>
>Tom's code was missing a ")" but not where you put one. He probably also 
>didn't intend to capitalize "subset".
>
>
>-pd
>
>> Thanks,
>> Elahe
>>
>>
>> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
>>
>>
>>
>> Actually not sure my previous answer does what you wanted. Using your 
>> approach:
>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
>> Should work.
>> I think the regex pattern you are looking for is:
>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
>>
>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
>>
>> subset(df,grepl("t2|pd",x$Command))
>>>
>>>
>>>
>>>
>>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>>> wrote:
>>>
>>> Hi all,

 I have one factor variable in my df and I want to extract the names from 
 it which contain both "t2" and "pd":

 'data.frame': 36919 obs. of 162 variables
  $TE:int 38,41,11,52,48,75,.
  $TR:int 100,210,548,546,.
  $Command  :factor W/2229 levels 
 "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...

 I have tried this but I did not get result:

 t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))


 does anyone know how to apply AND in grepl?

 Thanks
 Elahe

 __
 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.
>
>--
>Peter Dalgaard, Professor,
>Center for Statistics, Copenhagen Business School
>Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>Phone: (+45)38153501
>Office: A 4.23
>Email: pd@cbs.dk  Priv: pda...@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] how to use AND in grepl

2016-05-02 Thread Tom Wright
Sorry for the missed braces earlier. I was typing on a phone, not the best
place to conjugate regular expressions.
Using the example you provided:

> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
"_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
[1] FALSE FALSE FALSE FALSE  TRUE

> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
  Command
5 pd_local_abdomen_t2


On Mon, May 2, 2016 at 7:42 AM,  wrote:

> Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
>
>
> On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>
> On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
>
> > Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
>
> Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
>
>
> -pd
>
> > Thanks,
> > Elahe
> >
> >
> > On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >
> >
> >
> > Actually not sure my previous answer does what you wanted. Using your
> approach:
> > t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> > Should work.
> > I think the regex pattern you are looking for is:
> > Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >
> > On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >
> > subset(df,grepl("t2|pd",x$Command))
> >>
> >>
> >>
> >>
> >> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> >>
> >> Hi all,
> >>>
> >>> I have one factor variable in my df and I want to extract the names
> from it which contain both "t2" and "pd":
> >>>
> >>> 'data.frame': 36919 obs. of 162 variables
> >>>  $TE:int 38,41,11,52,48,75,.
> >>>  $TR:int 100,210,548,546,.
> >>>  $Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
> >>>
> >>> I have tried this but I did not get result:
> >>>
> >>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
> >>>
> >>>
> >>> does anyone know how to apply AND in grepl?
> >>>
> >>> Thanks
> >>> Elahe
> >>>
> >>> __
> >>> 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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>

[[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] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Thanks Peter, you were right, the exact grepl is 
grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
in Command, when I check the size of it by 
sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
sure that the size is not 0. It seems that this AND does not work.
 

On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:

On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:

> Thanks for your reply tom. After using  
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
> Argument "x" is missing, with no default. Actually I don't know how to fix 
> this. Do you have any idea?

Tom's code was missing a ")" but not where you put one. He probably also didn't 
intend to capitalize "subset".


-pd

> Thanks,
> Elahe 
> 
> 
> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
> 
> 
> 
> Actually not sure my previous answer does what you wanted. Using your 
> approach:
> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> Should work.
> I think the regex pattern you are looking for is:
> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> 
> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> 
> subset(df,grepl("t2|pd",x$Command))
>> 
>> 
>> 
>> 
>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>> wrote:
>> 
>> Hi all,
>>> 
>>> I have one factor variable in my df and I want to extract the names from it 
>>> which contain both "t2" and "pd":
>>> 
>>> 'data.frame': 36919 obs. of 162 variables
>>>  $TE:int 38,41,11,52,48,75,.
>>>  $TR:int 100,210,548,546,.
>>>  $Command  :factor W/2229 levels 
>>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>> 
>>> I have tried this but I did not get result:
>>> 
>>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>> 
>>> 
>>> does anyone know how to apply AND in grepl?
>>> 
>>> Thanks
>>> Elahe
>>> 
>>> __
>>> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@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] how to use AND in grepl

2016-05-02 Thread peter dalgaard

On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:

> Thanks for your reply tom. After using  
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
> Argument "x" is missing, with no default. Actually I don't know how to fix 
> this. Do you have any idea?

Tom's code was missing a ")" but not where you put one. He probably also didn't 
intend to capitalize "subset".

-pd

> Thanks,
> Elahe 
> 
> 
> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
> 
> 
> 
> Actually not sure my previous answer does what you wanted. Using your 
> approach:
> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> Should work.
> I think the regex pattern you are looking for is:
> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> 
> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> 
> subset(df,grepl("t2|pd",x$Command))
>> 
>> 
>> 
>> 
>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>> wrote:
>> 
>> Hi all,
>>> 
>>> I have one factor variable in my df and I want to extract the names from it 
>>> which contain both "t2" and "pd":
>>> 
>>> 'data.frame': 36919 obs. of 162 variables
>>>  $TE:int 38,41,11,52,48,75,.
>>>  $TR:int 100,210,548,546,.
>>>  $Command  :factor W/2229 levels 
>>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>> 
>>> I have tried this but I did not get result:
>>> 
>>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>> 
>>> 
>>> does anyone know how to apply AND in grepl?
>>> 
>>> Thanks
>>> Elahe
>>> 
>>> __
>>> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@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] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Thanks for your reply tom. After using  
Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
Argument "x" is missing, with no default. Actually I don't know how to fix 
this. Do you have any idea?
Thanks,
Elahe 


On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:



Actually not sure my previous answer does what you wanted. Using your approach:
 t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
Should work.
I think the regex pattern you are looking for is:
 Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)

On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:

subset(df,grepl("t2|pd",x$Command))
>
>
>
>
>On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>wrote:
>
>Hi all,
>>
>>I have one factor variable in my df and I want to extract the names from it 
>>which contain both "t2" and "pd":
>>
>>  'data.frame': 36919 obs. of 162 variables
>>   $TE:int 38,41,11,52,48,75,.
>>   $TR:int 100,210,548,546,.
>>   $Command  :factor W/2229 levels 
>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>
>>I have tried this but I did not get result:
>>
>>  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>
>>
>>does anyone know how to apply AND in grepl?
>>
>>Thanks
>>Elahe
>>
>>__
>>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] how to use AND in grepl

2016-04-30 Thread Tom Wright
Actually not sure my previous answer does what you wanted. Using your
approach:

 t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))

Should work.

I think the regex pattern you are looking for is:

 Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)

On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:

> subset(df,grepl("t2|pd",x$Command))
>
>
> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  > wrote:
>
>> Hi all,
>>
>> I have one factor variable in my df and I want to extract the names from
>> it which contain both "t2" and "pd":
>>
>>   'data.frame': 36919 obs. of 162 variables
>>$TE:int 38,41,11,52,48,75,.
>>$TR:int 100,210,548,546,.
>>$Command  :factor W/2229 levels
>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>
>> I have tried this but I did not get result:
>>
>>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>
>>
>> does anyone know how to apply AND in grepl?
>>
>> Thanks
>> Elahe
>>
>> __
>> 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] how to use AND in grepl

2016-04-30 Thread Tom Wright
subset(df,grepl("t2|pd",x$Command))


On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
wrote:

> Hi all,
>
> I have one factor variable in my df and I want to extract the names from
> it which contain both "t2" and "pd":
>
>   'data.frame': 36919 obs. of 162 variables
>$TE:int 38,41,11,52,48,75,.
>$TR:int 100,210,548,546,.
>$Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> 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] how to use AND in grepl

2016-04-30 Thread William Dunlap via R-help
Your code looks fine to me.  What did t2pd look like?

I tried reproducing the problem in R-3.2.4(Revised) and everything worked
(although the output of str() looked a bit different - perhaps you have an
old version of R)

> df <- data.frame(TE=1:10, TR=101:110,
Command=c("pd_local_abdomen_t2","knee_pd_t1_localize","PD_localize_tre_t2","t2_localize_PD")[rep(1:4,len=10)])
> str(df)
'data.frame':   10 obs. of  3 variables:
 $ TE : int  1 2 3 4 5 6 7 8 9 10
 $ TR : int  101 102 103 104 105 106 107 108 109 110
 $ Command: Factor w/ 4 levels "knee_pd_t1_localize",..: 2 1 3 4 2 1 3 4 2 1
> subset(df,grepl("t2",Command) & grepl("pd",Command))
  TE  TR Command
1  1 101 pd_local_abdomen_t2
5  5 105 pd_local_abdomen_t2
9  9 109 pd_local_abdomen_t2
> subset(df,grepl("t2",Command,ignore.case=TRUE) &
grepl("pd",Command,ignore.case=TRUE))
  TE  TR Command
1  1 101 pd_local_abdomen_t2
3  3 103  PD_localize_tre_t2
4  4 104  t2_localize_PD
5  5 105 pd_local_abdomen_t2
7  7 107  PD_localize_tre_t2
8  8 108  t2_localize_PD
9  9 109 pd_local_abdomen_t2


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
wrote:

> Hi all,
>
> I have one factor variable in my df and I want to extract the names from
> it which contain both "t2" and "pd":
>
>   'data.frame': 36919 obs. of 162 variables
>$TE:int 38,41,11,52,48,75,.
>$TR:int 100,210,548,546,.
>$Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
>   t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> 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] how to use AND in grepl

2016-04-30 Thread ch.elahe via R-help
Hi all,

I have one factor variable in my df and I want to extract the names from it 
which contain both "t2" and "pd":

  'data.frame': 36919 obs. of 162 variables 
   $TE:int 38,41,11,52,48,75,. 
   $TR:int 100,210,548,546,. 
   $Command  :factor W/2229 levels 
"_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...

I have tried this but I did not get result: 
   
  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))


does anyone know how to apply AND in grepl?

Thanks
Elahe

__
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] how to use vectorization instead of for loop

2016-03-21 Thread Dalthorp, Daniel
or simpler and faster:

dat[,4] <- sign(dat[,2])/dat[,3] # your original loop

dat <- cbind(dat, dat[,2] == Inf)  # append a new column with indicator for
which rows have dat[,2] = Inf


On Mon, Mar 21, 2016 at 2:45 PM, <ruipbarra...@sapo.pt> wrote:

> Hello,
>
> Use combined ifelses, more or less like the following.
>
> ifelse(dat[, 2] == Inf, do this, ifelse(dat[, 2] > 0, 1 * (1/dat[,3]),
> -1* (1/dat[,3])))
>
> Rui Barradas
>
>
> Citando Stephen HK WONG <hon...@stanford.edu>:
>
> > So much thanks Rui, the code can be so simple and fast.
> >
> > By the way, ifelse is good for two conditions, in my case, either
> > >0, or <0, I found there's a lot of row with value "Inf", I want to
> > keep it in new column, how do I do that using ifelse ?
> >
> > Thanks.
> >
> > 
> > From: ruipbarra...@sapo.pt <ruipbarra...@sapo.pt>
> > Sent: Monday, March 21, 2016 11:50 AM
> > To: Stephen HK WONG
> > Cc: r-help@r-project.org
> > Subject: Re: [R] how to use vectorization instead of for loop
> >
> > Hello,
> >
> > I've renamed your dataframe to 'dat'. Since ?ifelse is vectorized, try
> >
> > dat[, 4] <- ifelse(dat[, 2] > 0, 1 * (1/dat[,3]), -1* (1/dat[,3]))
> >
> > Oh, and why do you multiply by 1 and by -1?
> > It would simply be 1/dat[,3] and -1/dat[,3].
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Quoting Stephen HK WONG <hon...@stanford.edu>:
> >> Dear All,
> >>
> >> I have a dataframe like below but with many thousands rows,
> >>
> >> structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
> >> "0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
> >> "0610010B08Rik,OTTMUSG0016609"), class = "factor"),
> >> log2.fold_change. = c(0.0114463,
> >> -0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
> >> 0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
> >> "NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id",
> "log2.fold_change.",
> >> "p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")
> >>
> >> I want to check if second column is positive or negative value, then
> >> I will do some calculation and put the new value in last column. I
> >> can do this with for loop like below but it is not efficient. Is
> >> there a better way to use a vectorization method instead of loop?
> >> Many thanks!
> >>
> >> for (i in 1:nrow(dataframe)) {
> >>
> >> if dataframe[i, 2]>0 {
> >>
> >> dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{
> >>
> >> dataframe[i, 4] <- -1* (1/dataframe[i,3])}
> >>
> >> }
> >>
> >> ---
> >>
> >> Stephen H.K. WONG, PhD.
> >>
> >> Stanford University
> >>
> >>   [[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.htmland 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.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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] how to use vectorization instead of for loop

2016-03-21 Thread ruipbarradas
Hello,

Use combined ifelses, more or less like the following.

ifelse(dat[, 2] == Inf, do this, ifelse(dat[, 2] > 0, 1 * (1/dat[,3]),  
-1* (1/dat[,3])))

Rui Barradas
 

Citando Stephen HK WONG <hon...@stanford.edu>:

> So much thanks Rui, the code can be so simple and fast.
>
> By the way, ifelse is good for two conditions, in my case, either  
> >0, or <0, I found there's a lot of row with value "Inf", I want to  
> keep it in new column, how do I do that using ifelse ?
>
> Thanks.
>
> 
> From: ruipbarra...@sapo.pt <ruipbarra...@sapo.pt>
> Sent: Monday, March 21, 2016 11:50 AM
> To: Stephen HK WONG
> Cc: r-help@r-project.org
> Subject: Re: [R] how to use vectorization instead of for loop
>
> Hello,
>
> I've renamed your dataframe to 'dat'. Since ?ifelse is vectorized, try
>
> dat[, 4] <- ifelse(dat[, 2] > 0, 1 * (1/dat[,3]), -1* (1/dat[,3]))
>
> Oh, and why do you multiply by 1 and by -1?
> It would simply be 1/dat[,3] and -1/dat[,3].
>
> Hope this helps,
>
> Rui Barradas
>
> Quoting Stephen HK WONG <hon...@stanford.edu>:
>> Dear All,
>>
>> I have a dataframe like below but with many thousands rows,
>>
>> structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
>> "0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
>> "0610010B08Rik,OTTMUSG0016609"), class = "factor"),
>> log2.fold_change. = c(0.0114463,
>> -0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
>> 0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
>> "NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id", "log2.fold_change.",
>> "p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")
>>
>> I want to check if second column is positive or negative value, then
>> I will do some calculation and put the new value in last column. I
>> can do this with for loop like below but it is not efficient. Is
>> there a better way to use a vectorization method instead of loop?
>> Many thanks!
>>
>> for (i in 1:nrow(dataframe)) {
>>
>> if dataframe[i, 2]>0 {
>>
>> dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{
>>
>> dataframe[i, 4] <- -1* (1/dataframe[i,3])}
>>
>> }
>>
>> ---
>>
>> Stephen H.K. WONG, PhD.
>>
>> Stanford University
>>
>>       [[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.htmland 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] how to use vectorization instead of for loop

2016-03-21 Thread Stephen HK WONG
So much thanks Rui, the code can be so simple and fast. 

By the way, ifelse is good for two conditions, in my case, either >0, or <0, I 
found there's a lot of row with value "Inf", I want to keep it in new column, 
how do I do that using ifelse ?

Thanks.


From: ruipbarra...@sapo.pt <ruipbarra...@sapo.pt>
Sent: Monday, March 21, 2016 11:50 AM
To: Stephen HK WONG
Cc: r-help@r-project.org
Subject: Re: [R] how to use vectorization instead of for loop

Hello,

I've renamed your dataframe to 'dat'. Since ?ifelse is vectorized, try

dat[, 4] <- ifelse(dat[, 2] > 0, 1 * (1/dat[,3]), -1* (1/dat[,3]))

Oh, and why do you multiply by 1 and by -1?
It would simply be 1/dat[,3] and -1/dat[,3].

Hope this helps,

Rui Barradas


Quoting Stephen HK WONG <hon...@stanford.edu>:

> Dear All,
>
>
> I have a dataframe like below but with many thousands rows,
>
> structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
> "0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
> "0610010B08Rik,OTTMUSG0016609"), class = "factor"),
> log2.fold_change. = c(0.0114463,
> -0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
> 0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
> "NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id", "log2.fold_change.",
> "p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")
>
>
> I want to check if second column is positive or negative value, then
> I will do some calculation and put the new value in last column. I
> can do this with for loop like below but it is not efficient. Is
> there a better way to use a vectorization method instead of loop?
> Many thanks!
>
>
> for (i in 1:nrow(dataframe)) {
>
> if dataframe[i, 2]>0 {
>
> dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{
>
> dataframe[i, 4] <- -1* (1/dataframe[i,3])}
>
> }
>
>
> ---
>
> Stephen H.K. WONG, PhD.
>
> Stanford University
>
>   [[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.


[R] how to use vectorization instead of for loop

2016-03-21 Thread Stephen HK WONG
Dear All,


I have a dataframe like below but with many thousands rows,

structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
"0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
"0610010B08Rik,OTTMUSG0016609"), class = "factor"), log2.fold_change. = 
c(0.0114463,
-0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
"NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id", "log2.fold_change.",
"p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")


I want to check if second column is positive or negative value, then I will do 
some calculation and put the new value in last column. I can do this with for 
loop like below but it is not efficient. Is there a better way to use a 
vectorization method instead of loop? Many thanks!


for (i in 1:nrow(dataframe)) {

if dataframe[i, 2]>0 {

dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{

dataframe[i, 4] <- -1* (1/dataframe[i,3])}

}


---

Stephen H.K. WONG, PhD.

Stanford University

[[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] how to use vectorization instead of for loop

2016-03-21 Thread ruipbarradas

Hello,

I've renamed your dataframe to 'dat'. Since ?ifelse is vectorized, try

dat[, 4] <- ifelse(dat[, 2] > 0, 1 * (1/dat[,3]), -1* (1/dat[,3]))

Oh, and why do you multiply by 1 and by -1?
It would simply be 1/dat[,3] and -1/dat[,3].

Hope this helps,

Rui Barradas


Quoting Stephen HK WONG :


Dear All,


I have a dataframe like below but with many thousands rows,

structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
"0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
"0610010B08Rik,OTTMUSG0016609"), class = "factor"),  
log2.fold_change. = c(0.0114463,

-0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
"NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id", "log2.fold_change.",
"p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")


I want to check if second column is positive or negative value, then  
I will do some calculation and put the new value in last column. I  
can do this with for loop like below but it is not efficient. Is  
there a better way to use a vectorization method instead of loop?  
Many thanks!



for (i in 1:nrow(dataframe)) {

if dataframe[i, 2]>0 {

dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{

dataframe[i, 4] <- -1* (1/dataframe[i,3])}

}


---

Stephen H.K. WONG, PhD.

Stanford University

[[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] How to use compare.linkage in RecordLinkage package -- unexpected output

2016-01-29 Thread Anders Alexandersson
Problem resolved. I confused the true matching status and the probabilistic
record linkage results.

Anders Alexandersson
andersa...@gmail.com

On Thu, Jan 28, 2016 at 9:48 AM, Anders Alexandersson 
wrote:

> I am using the compare.linkage function in the RecordLinkage package,
> and getting a result I know is wrong, so I know I'm misunderstanding
> something.
> I am using R 3.2.3 for x64 Windows. I am very familar with Stata but not
> so much with R.
> [...]
>

[[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] How to use compare.linkage in RecordLinkage package -- unexpected output

2016-01-28 Thread Anders Alexandersson
I am using the compare.linkage function in the RecordLinkage package,
and getting a result I know is wrong, so I know I'm misunderstanding
something.
I am using R 3.2.3 for x64 Windows. I am very familar with Stata but not so
much with R.

I can create record pairs from the blocking fields but all pairs are
unknown status (NA).
I cannot create matches or non-matches. I want a simple working example of
how to link datasets using the RecordLinkage package. It seems that the
manual and the R Journal Vol. 2/2 only show how to de-duplicate a single
dataset using the compare.dedup function, not how to link two datasets
together using the compare.linkage function. I can reproduce the examples
in the R Journal article, so my R installation is fine.

The example dataset in the manual have 500 and 1 observations on 7
variables, but 1 observation and 2 variables will be enough to show the
problem.
My first comparison pattern loooks like this:
  id1  id2 fname_c1 bm is_match
1  17  3431  1   NA

Instead, I want and expect a comparison pattern that looks like this:
  id1  id2 fname_c1 bm is_match
1  17  3431  1   1

My blocking variable is fname_c1 for first component of first name. My
matching variable is bm for birth month. My understanding is that row 1 in
my example output is the first row where fname_c1 matched in the underlying
datasets. I want and expect is_match to be 1 when the matching variable
bm=1 in both linkage datasets, as in the example.

For more details, this is what I typed and the R output:
> library(RecordLinkage)
> data(RLdata500)
> data(RLdata1)
> RLdata500[17, ]
fname_c1 fname_c2 lname_c1 lname_c2   by bm bd
17 ALEXANDER   MUELLER  1974  9  9
> RLdata1[343, ]
 fname_c1 fname_c2 lname_c1 lname_c2   by bm bd
343 ALEXANDER   BAUMANN  1957  9  7
> rpairs <- compare.linkage(RLdata500,RLdata1,blockfld=c(1),
exclude=c(2:5,7))
> rpairs$pairs[c(1:2), ] # Why is_match=NA? (should be 1)
  id1  id2 fname_c1 bm is_match
1  17  3431  1   NA
2  17 23851  0   NA
> rpairs <- epiWeights(rpairs) # (Weight calculation)
> summary(rpairs) # (0 matches in Linkage Dataset)

Linkage Data Set

500 records in data set 1
1 records in data set 2
47890 record pairs

0 matches
0 non-matches
47890 pairs with unknown status


Weight distribution:
[omitted here to save space]

References:
1. Manual for Package ‘RecordLinkage’
(Available online at
https://cran.r-project.org/web/packages/RecordLinkage/RecordLinkage.pdf)
2. R Journal article Article "The RecordLinkage Package: Detecting Errors
in Data"
(Available online in PDF at
https://journal.r-project.org/archive/2010-2/RJournal_2010-2_Sariyar+Borg.pdf
)

I saw something in the manual and R journal article about identity argument
for true match results, but I guess I only need that for reference ("gold
standard") datasets. There is a non-missing value (bm=1) for the example in
both underlying datasets, so that is not why the result is NA. What am I
missing? How does one link two simple datasets using compare.linkage?

Anders Alexandersson
andersa...@gmail.com
Florida Cancer Data System, University of Miami

[[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] How to use compare.linkage in RecordLinkage package -- unexpected output

2016-01-28 Thread Anders Alexandersson
I am using the compare.linkage function in the RecordLinkage package,
and getting a result I know is wrong, so I know I'm misunderstanding
something.
I am using R 3.2.3 for x64 Windows. I am very familar with Stata but not so
much with R.

I can create record pairs from the blocking fields but all pairs are
unknown status (NA).
I cannot create matches or non-matches. I want a simple working example of
how to link datasets using the RecordLinkage package. It seems that the
manual and the R Journal Vol. 2/2 only show how to de-duplicate a single
dataset using the compare.dedup function, not how to link two datasets
together using the compare.linkage function. I can reproduce the examples
in the R Journal article, so my R installation is fine.

The example dataset in the manual have 500 and 1 observations on 7
variables, but 1 observation and 2 variables will be enough to show the
problem.
My first comparison pattern loooks like this:
  id1  id2 fname_c1 bm is_match
1  17  3431  1   NA

Instead, I want and expect a comparison pattern that looks like this:
  id1  id2 fname_c1 bm is_match
1  17  3431  1   1

My blocking variable is fname_c1 for first component of first name. My
matching variable is bm for birth month. My understanding is that row 1 in
my example output is the first row where fname_c1 matched in the underlying
datasets. I want and expect is_match to be 1 when the matching variable
bm=1 in both linkage datasets, as in the example.

For more details, this is what I typed and the R output:
> library(RecordLinkage)
> data(RLdata500)
> data(RLdata1)
> RLdata500[17, ]
fname_c1 fname_c2 lname_c1 lname_c2   by bm bd
17 ALEXANDER   MUELLER  1974  9  9
> RLdata1[343, ]
 fname_c1 fname_c2 lname_c1 lname_c2   by bm bd
343 ALEXANDER   BAUMANN  1957  9  7
> rpairs <- compare.linkage(RLdata500,RLdata1,blockfld=c(1),
exclude=c(2:5,7))
> rpairs$pairs[c(1:2), ] # Why is_match=NA? (should be 1)
  id1  id2 fname_c1 bm is_match
1  17  3431  1   NA
2  17 23851  0   NA
> rpairs <- epiWeights(rpairs) # (Weight calculation)
> summary(rpairs) # (0 matches in Linkage Dataset)

Linkage Data Set

500 records in data set 1
1 records in data set 2
47890 record pairs

0 matches
0 non-matches
47890 pairs with unknown status


Weight distribution:
[omitted here to save space]

References:
1. Manual for Package ‘RecordLinkage’
(Available online at
https://cran.r-project.org/web/packages/RecordLinkage/RecordLinkage.pdf)
2. R Journal article Article "The RecordLinkage Package: Detecting Errors
in Data"
(Available online in PDF at
https://journal.r-project.org/archive/2010-2/RJournal_2010-2_Sariyar+Borg.pdf
)

I saw something in the manual and R journal article about identity argument
for true match results, but I guess I only need that for reference ("gold
standard") datasets. There is a non-missing value (bm=1) for my example in
both underlying datasets, so that is not why the result is NA. What am I
missing? How does one link two simple datasets using compare.linkage?

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

  1   2   3   4   5   6   >