Re: [R] Get a copy of a matrix only for TRUE entries of a matching size boolean matrix?

2024-05-03 Thread Marc Girondot via R-help
Is it what you want ?
mat_letters <- matrix(data=c('A', 'B', 'C', 'D'), ncol=2, byrow=TRUE)
mat_bools <- matrix(data=c(FALSE, TRUE, TRUE, FALSE), ncol=2, byrow=TRUE)

ifelse(mat_bools, mat_letters, "")
ifelse(mat_bools, mat_letters, NA)

 > ifelse(mat_bools, mat_letters, "")
  [,1] [,2]
[1,] ""   "B"
[2,] "C"  ""
 > ifelse(mat_bools, mat_letters, NA)
  [,1] [,2]
[1,] NA   "B"
[2,] "C"  NA

Marc



Le 03/05/2024 à 14:47, DynV Montrealer a écrit :
> Is there a way to get a copy of a matrix only for TRUE entries of a
> matching size boolean matrix? For*example*:
>> mat_letters <- matrix(data=c('A', 'B', 'C', 'D'), ncol=2, byrow=TRUE)
>> mat_letters
>   [,1] [,2]
> [1,] "A"  "B"
> [2,] "C"  "D"
>> mat_bools <- matrix(data=c(FALSE, TRUE, TRUE, FALSE), ncol=2, byrow=TRUE)
>> mat_bools
>[,1]  [,2]
> [1,] FALSE  TRUE
> [2,]  TRUE FALSE
> *Reminder:* The following is only an example ; the solution might look very
> different.
> some_command(mat_letters, mat_bools, false=empty)
>   [,1] [,2]
> [1,] ""  "B"
> [2,] "C"  ""
> some_command(mat_letters, mat_bools, false=na)
>   [,1] [,2]
> [1,] NA  "B"
> [2,] "C"  NA


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

2024-02-19 Thread Marc Girondot via R-help
In my package HelpersMG, I have included a function to read in one time 
all the files of a folder and they are stored in a list:


read_folder(
  folder = try(file.choose(), silent = TRUE),
  file = NULL,
  wildcard = "*.*",
  read = read.delim,
  ...
)

In your case, for example:

library("HelpersMG")
data_list <- read_folder(folder=".", file=paste0("data", 
as.character(1:24),".csv"), read=read.csv)

data_df <-   do.call("rbind", data_list)

Marc

Le 19/02/2024 à 04:27, Steven Yen a écrit :

I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, 
24 altogether. That is,

data<-read.csv(“data1.csv”)
…
data<-read.csv(“data24.csv”)
…

Is there a way to do this in a loop? Thank you.

Steven from iPhone
[[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] Try reproduce glmm by hand

2023-12-02 Thread Marc Girondot via R-help

Dear all,

In order to be sure I understand glmm correctly, I try to reproduce by 
hand a simple result. Here is a reproducible code. The questions are in 
_


Of course I have tried to find the solution using internet but I was not 
able to find a solution. I have also tried to follow glmer but it is 
very complicated code!


Thanks for any help.

Marc


# Generate set of df with nb successes and failures
# and ID being A, B or C (the random effect)
# and x being the fixed effect
set.seed(1)
df <- rbind(matrix(data = c(sample(x=5:30, size=40, replace = TRUE), 
rep(10, 40)), ncol=2),
    matrix(data = c(sample(x=10:30, size=40, replace = TRUE), 
rep(10, 40)), ncol=2),
    matrix(data = c(sample(x=20:30, size=40, replace = TRUE), 
rep(10, 40)), ncol=2))

ID <- as.factor(c(rep("A", 40), rep("B", 40), rep("C", 40)))
x <- c(runif(40, min=10, max=30), runif(40, min=20, max=30), runif(40, 
min=40, max=60))

x <- (x-min(x))/(max(x)-min(x))

# In g0, I have the results of the glmm
library(lme4)
g0 <- glmer(formula = df ~ x + (1 | ID), family = 
binomial(link="logit"), nAGQ=1)

-logLik(g0) # 'log Lik.' 268.0188 (df=3)
# I get the fitted parameters
fixep <- fixef(g0)
par <- getME(g0, c("theta","beta"))
# ___
# Question 1: how theta is converted into the specific effect on 
(intercept) for the random effect ?

# Then how a theta parameter is converted into intercepts?
# ___
intercepts <- ranef(g0)$ID

# This part is ok, the predict is correct
pfit <- 1-c(1/(1+exp(fixep["(Intercept)"]+intercepts["A", 
1]+x[ID=="A"]*fixep["x"])),
  1/(1+exp(fixep["(Intercept)"]+intercepts["B", 
1]+x[ID=="B"]*fixep["x"])),

  1/(1+exp(fixep["(Intercept)"]+intercepts["C", 1]+x[ID=="C"]*fixep["x"])))

predict(g0, type = "response")

# ___
# Why I obtain 266.4874 and not 268.0188 as in -logLik(g0)?
# ___
-sum(dbinom(x=df[, 1], size=df[, 1]+df[, 2], prob=pfit, log=TRUE)) # 
266.4874


__
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] creating a time series

2023-10-16 Thread Marc Girondot via R-help

Why did you expect to have 177647 elements ?

I found that 177642 is the correct number:

Marc

baslangic <- as.POSIXct("2017-11-02 13:30:00", tz = "CET")
bitis <- as.POSIXct("2022-11-26 23:45:00", tz = "CET")  #
zaman_seti <- seq.POSIXt(from = baslangic, to = bitis, by = 60 * 15)

y2017_11_02 <- seq(from=as.POSIXct("2017-11-02 13:30:00", tz = "CET"), 
to=as.POSIXct("2017-11-02 23:45:00", tz = "CET"), by = 60 * 15)

# Length 42 - OK
length(y2017_11_02)
y2017_11_12 <- seq(from=as.POSIXct("2017-11-03 00:00:00", tz = "CET"), 
to=as.POSIXct("2017-12-31 23:45:00", tz = "CET"), by = 60 * 15)

# ((30-2)+31)*24*4=5664 - OK
length(y2017_11_12)
y2018 <- seq(from=as.POSIXct("2018-01-01 00:00:00", tz = "CET"), 
to=as.POSIXct("2018-12-31 23:45:00", tz = "CET"), by = 60 * 15)

# (365)*24*4=35040 - OK
length(y2018)
y2019 <- seq(from=as.POSIXct("2019-01-01 00:00:00", tz = "CET"), 
to=as.POSIXct("2019-12-31 23:45:00", tz = "CET"), by = 60 * 15)

# (365)*24*4=35040 - OK
length(y2019)
y2020 <- seq(from=as.POSIXct("2020-01-01 00:00:00", tz = "CET"), 
to=as.POSIXct("2020-12-31 23:45:00", tz = "CET"), by = 60 * 15)

# (366)*24*4=35136 - OK
length(y2020)
y2021 <- seq(from=as.POSIXct("2021-01-01 00:00:00", tz = "CET"), 
to=as.POSIXct("2021-12-31 23:45:00", tz = "CET"), by = 60 * 15)

# (365)*24*4=35040 - OK
length(y2021)
y2022 <- seq(from=as.POSIXct("2022-01-01 00:00:00", tz = "CET"), 
to=as.POSIXct("2022-11-26 23:45:00", tz = "CET"), by = 60 * 15)

# (365-31-4)*24*4=31680 - OK
length(y2022)

length(y2017_11_02)+length(y2017_11_12)+length(y2018)+length(y2019)+length(y2020)+length(y2021)+length(y2022)
length(zaman_seti)


Le 16/10/2023 à 12:12, ahmet varlı a écrit :

Hello everyone,

� had 15 minutes of data from 2017-11-02 13:30:00 to  2022-11-26 23:45:00 and 
number of data is 177647

� would like to ask why my time series are less then my expectation.


baslangic <- as.POSIXct("2017-11-02 13:30:00", tz = "CET")
bitis <- as.POSIXct("2022-11-26 23:45:00", tz = "CET")  #
zaman_seti <- seq.POSIXt(from = baslangic, to = bitis, by = 60 * 15)


length(zaman_seti)
[1] 177642

but it has to be  177647



and secondly � have times in this format ( 2.11.2017 13:30/DD-MM- HH:MM:SS)

su_seviyeleri_data <- as.POSIXct(su_seviyeleri_data$kayit_zaman, format = "%Y-%m-%d 
%H:%M:%S")

I am using this code to change the format but it gives result as Na

How can � solve this problem?

Bests,





[[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] overlay shaded area in base r plot

2023-09-19 Thread Marc Girondot via R-help

Dear Ani,

A solution using my CRAN package HelpersMG; note that yellow is a 
difficult color to manage correct overlay. It is easier to use red.


mean1 <-
c(122.194495954369, 118.955256282505, 115.540991140893, 113.116216840647,
  111.24053267553, 109.827890459103, 108.523652505026, 107.033183023752,
  105.259229707182, 103.124055471975, 100.877524901322, 98.6376579858244,
  96.5156796979913, 94.6968535964952, 93.0502858942909, 91.5977750931902,
  90.2651576455091, 89.0734094965085, 87.9562971122031, 86.9443758094494
)

mean2 <-
c(85.9733226064336, 85.1790888261485, 84.4436873347186, 83.8339820163413,
  83.2527178882373, 82.7270110163027, 82.2807280513966, 81.9025314782845,
  81.4641947900397, 81.0208948190769, 80.5647455355762, 80.0587583244909,
  78.9354501839752, 78.4263183538841, 78.3688690670842, 77.9632850076303,
  77.6888937972956, 77.5689173832678, 77.5860621564674, 77.6375257226031
)

sd1 <-
  c(17.0473968859792, 19.7055838512895, 20.0280169279762, 19.5651973323109,
    19.4292448372276, 19.0540881390057, 18.9295826565011, 18.7039744205801,
    18.688319090752, 18.6946307822843, 18.7427879417687, 18.8069804986113,
    18.8794754969972, 18.9830959093513, 19.0754455885966, 19.1360320444124,
    19.0546404913351, 19.1280788210156, 19.2014747953522, 19.2456454651155
  )

sd2 <-
  c(19.2537538439847, 19.2462114145511, 19.2253213677253, 19.2476344684752,
    19.2494964552016, 19.2871242318276, 19.2695982918065, 19.261879086708,
    19.3410606442566, 19.3257171172684, 19.5029937941038, 19.5286520380856,
    19.472587329424, 19.4815048434245, 19.3056947381611, 19.2193415347369,
    19.1367354761276, 19.062832883228, 19.0123017669597, 18.9504334825052
  )

# Original solution
plot(mean1[1:20],type="l", ylim=c(170,60),las=1,
 xlab="Data",ylab=expression(bold("Val")),cex.axis=1.2,font=2,
cex.lab=1.2,lwd=4)
polygon(c(1:20,20:1),c(mean1[1:20]+sd1[1:20],mean1[20:1]),col="lightblue")
polygon(c(1:20,20:1),c(mean1[1:20]-sd1[1:20],mean1[20:1]),col="lightblue")
polygon(c(1:20,20:1),c(mean2[1:20]+sd2[1:20],mean2[20:1]),col="lightyellow")
polygon(c(1:20,20:1),c(mean2[1:20]-sd2[1:20],mean2[20:1]),col="lightyellow")
lines(mean1,lty=1,lwd=2,col="blue")
lines(mean2,lty=1,lwd=2,col="yellow")

# "my" solution
library(HelpersMG)

plot_errbar(x=1:20, y=mean1, errbar.y = sd1, las = 1, ylim=c(0, 150),
    col="red",
    xlab="Data",ylab=expression(bold("Val")), lwd=4,
    errbar.y.polygon = TRUE, type="l",
    errbar.y.polygon.list = list(border=NA, 
col=adjustcolor("red", alpha = 0.3)))

plot_errbar(x=1:20, y=mean2, errbar.y = sd2, axes=FALSE,
    col="blue",
    xlab="",ylab="", lwd=4,
    errbar.y.polygon = TRUE, type="l",
    errbar.y.polygon.list = list(border=NA,
 col=adjustcolor("blue", alpha 
= 0.3)),

    add=TRUE)

Le 19/09/2023 à 10:21, ani jaya a écrit :

Thank you very much for the help. Turn out I can use 'density' to
differentiate the overlaid area.

On Tue, Sep 19, 2023, 16:16 Ivan Krylov  wrote:


В Tue, 19 Sep 2023 13:21:08 +0900
ani jaya  пишет:

polygon(c(1:20,20:1),c(mean1[1:20]+sd1[1:20],mean1[20:1]),col="lightblue")
polygon(c(1:20,20:1),c(mean1[1:20]-sd1[1:20],mean1[20:1]),col="lightblue")
polygon(c(1:20,20:1),c(mean2[1:20]+sd2[1:20],mean2[20:1]),col="lightyellow")
polygon(c(1:20,20:1),c(mean2[1:20]-sd2[1:20],mean2[20:1]),col="lightyellow")

If you want the areas to overlap, try using a transparent colour. For
example, "lightblue" is rgb(t(col2rgb("lightblue")), max = 255) →
"#ADD8E6", so try setting the alpha (opacity) channel to something less
than FF, e.g., "#ADD8E688".

You can also use rgb(t(col2rgb("lightblue")), alpha = 128, max = 255)
to generate hexadecimal colour strings for a given colour name and
opacity value.

--
Best regards,
Ivan


[[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] only install.packages with type="source" will install packages

2023-09-14 Thread Marc Girondot via R-help

Dear members,

Since #2 weeks I have a problem with install.packages() or 
update.packages():


It seems to work, I have no error, but when I run again 
update.packages(), the same package is proposed again.


Example:

> update.packages()
insight :
 Version 0.19.3 installed in 
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library

 Version 0.19.5 available at https://cran.irsn.fr
Update? (Oui/non/annuler) a
cancelled by user
> install.packages("insight")
essai de l'URL 
'https://cran.irsn.fr/bin/macosx/big-sur-arm64/contrib/4.3/insight_0.19.3.tgz'

Content type 'application/x-gzip' length 2092645 bytes (2.0 MB)
==
downloaded 2.0 MB
Les packages binaires téléchargés sont dans
    /tmp/RtmpDC1kqM/downloaded_packages
> update.packages()
insight :
 Version 0.19.3 installed in 
/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library

 Version 0.19.5 available at https://cran.irsn.fr
Update? (Oui/non/annuler) a
cancelled by user

If I restart R, it gives the same result.

My .libPaths() is "normal":
[1] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library"

The solution is to install with type = "source"

> install.packages("insight", type="source")
essai de l'URL 
'https://pbil.univ-lyon1.fr/CRAN/src/contrib/insight_0.19.5.tar.gz'

Content type 'application/x-gzip' length 935072 bytes (913 KB)
==
downloaded 913 KB

* installing *source* package ‘insight’ ...
** package ‘insight’ correctement décompressé et sommes MD5 vérifiées
** using staged installation
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation 
path

* DONE (insight)

Les packages source téléchargés sont dans
    ‘/private/tmp/RtmpA4I8sr/downloaded_packages’

Then update.packages() does not return insight package.

Have you an idea of what's happened ?

Thanks

Marc

__
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] Count matrix of GSE146049

2023-04-02 Thread Marc Girondot via R-help

Dear Anas Jamshed,

This is a list for R, not for specific genomic question using R.

You will have more chance to have answers using a genomic list.

And when you ask question, it is better to not use abbreviation that 
only people from that field will understand: TMM ?


Marc

Le 02/04/2023 à 17:09, Anas Jamshed a écrit :

I want to get the count matrix of genes from
https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE146049. Is it
possible for GSE146049? After getting counts, I want to do TMM
normalization.

[[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] MLE Estimation of Gamma Distribution Parameters for data with 'zeros'

2023-01-19 Thread Marc Girondot via R-help
Another situation for the presence of 0 is about dosage when 
concentration is below the detection limit. It is not necessary to 
discretize the data. We propose a method here:
Salvat-Leal I, Cortés-Gómez AA, Romero D, Girondot M (2022) New method 
for imputation of unquantifiable values using Bayesian statistics for a 
mixture of censored or truncated distributions: Application to trace 
elements measured in blood of olive ridley sea turtles from mexico. 
Animals 2022: 2919 doi 10.3390/ani12212919

with R code.
If the data has "true" 0, the gamma distribution is not the best choice 
as 0 is impossible with gamma distribution.


Marc

Le 19/01/2023 à 12:49, peter dalgaard a écrit :

Not necessarily homework, Bert. There's a generic issue with MLE and rounded 
data, in that gamma densities may be 0 at the boundary but small numbers are 
represented as 0, making the log-likelihood -Inf.

The cleanest way out is to switch to a discretized distribution in the 
likelihood, so that instead of log(dgamma(0,...)) you use log(pgamma(.005,..) - 
pgamma(0,...)) == pgamma(.005,..., log=TRUE). (For data rounded to nearest .01, 
that is). Cruder techniques would be to just add, like, .0025 to all the zeros.

-pd


On 10 Jan 2023, at 18:42 , Bert Gunter  wrote:

Is this homework? This list has a no-homework policy.


-- Bert

On Tue, Jan 10, 2023 at 8:13 AM Nyasha  wrote:

Please how can one go about this one? I don't know how to go about it.

[[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-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] setting timezone variable permanently...

2022-12-07 Thread Marc Girondot via R-help

You can create a file .Rprofile in your home directory with this command.

Each time you will open R, it will run this command.

https://support.posit.co/hc/en-us/articles/360047157094-Managing-R-with-Rprofile-Renviron-Rprofile-site-Renviron-site-rsession-conf-and-repos-conf

Marc

Le 07/12/2022 à 17:47, akshay kulkarni a écrit :

Dear members,
  I am setting the Time zone environment variable 
by this code:


Sys.setenv(TZ = "Asia/Kolkata")

But I have to run it every time I open a new R session. How do I set it 
permanently?

Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

[[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] Creating NA equivalent

2021-12-20 Thread Marc Girondot via R-help

Dear members,

I work about dosage and some values are bellow the detection limit. I 
would like create new "numbers" like LDL (to represent lower than 
detection limit) and UDL (upper the detection limit) that behave like 
NA, with the possibility to test them using for example is.LDL() or 
is.UDL().


Note that NA is not the same than LDL or UDL: NA represent missing data. 
Here the data is available as LDL or UDL.


NA is built in R language very deep... any option to create new version  
of NA-equivalent ?


Thanks

Marc

__
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] Do not show a "message d'avis" that qbeta reports

2021-10-21 Thread Marc Girondot via R-help
Philippe has convinced me that the translation "Message d'avis" was the 
best based on the constraints in the way R displays messages. I agree 
that Avertissement was much better but it was too long.


Then the solution is to force the console messages to be in English when 
there is something strange:


> warning("Essai")
Message d'avis :
Essai
> Sys.setenv(LANG = "en")
> warning("Essai")
Warning message:
Essai

Thanks a lot to the translation team for their great work.

Marc

Le 21/10/2021 à 07:38, SciViews a écrit :

Martin Maechler wrote:

Currently, the French team is just one person


This is not quite true. The people that contributed to the translation in French are listed 
here: https://github.com/phgrosjean/rfrench <https://github.com/phgrosjean/rfrench>. 
As you can see, there is a total of nine people among which two have actively contributed 
to the update of the translations for R 4.1. The page 
https://developer.r-project.org/TranslationTeams.html 
<https://developer.r-project.org/TranslationTeams.html> only exhibits the name of the 
contact person for each team.

Regarding the translation of “Warning” into “Message d’avis” raised by Marc, I 
gave him an extended explanation offline, that I summarise here. “Warning” was 
finally translated into “avis” after considering “avertissement”, which is 
closer to the meaning in the context. However, we got problems with 
“avertissement” because some sentences became longer than in English. This 
produced sometimes weird display of the whole message, given that there are 
(was?) hard breaks in the middle of some of them.

Finally, it is not “warning” that is translated to “message d’avis”, but it is 
“warning message” in the original sentences. For instance, for R 4.1.0 I, 
base/po/R-fr.po, I got line 1660: “Summary of (a total of %d) warning messages:” I 
don’t think that the translation proposed by Marc is good in that context. It would 
give "Résumé (d’un total de %d) attentions:” Indeed, it is currently Résumé 
(d’un total de %d) messages d’avis:”

All the best,

Philippe Grosjean


On 20 Oct 2021, at 22:11, Martin Maechler  wrote:


Duncan Murdoch
on Wed, 20 Oct 2021 07:17:30 -0400 writes:

Translations are done by the translation teams, listed
here:
<https://developer.r-project.org/TranslationTeams.html>.
If you'd like to offer help, you could contact someone on
that list.
Duncan Murdoch

Indeed.   Currently, the French team is just one person, and
maybe they will be happy to share the workload  or to get
another pair of eyes to look at it...

Martin Maechler



On 20/10/2021 6:47 a.m., Marc Girondot via R-help wrote:

Thanks ! It works.

So "Warnings" has been translated in French by "Message
d'avis :" !  > warning("Essai") Message d'avis : Essai

It is not the best translation...  I would prefer:
"Attention:"

Marc

Le 20/10/2021 à 12:28, Enrico Schumann a écrit :

On Wed, 20 Oct 2021, Marc Girondot via R-help writes:


Dear R-helpers

Do you know how to not show a "message d'avis" that
qbeta reports. suppressMessages and capture.output are
not working.

(PS I Know that qbeta with shape2 being 1e-7 is
"strange"... this is obtained during an optimization
process. Just I don't want see the messages).

Thanks

Marc Girondot

q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797,
shape2 = 0.001) Message d'avis : Dans qbeta(p =
c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| =
0.024997 is not accurate

suppressMessages(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001)) Message d'avis : Dans
qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 =
1e-07) :   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha|
= 0.024997 is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001), type = "message")
character(0) Message d'avis : Dans qbeta(p = c(0.025,
0.975), shape1 = 3.3108797, shape2 = 1e-07) :
qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997
is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001), type = "output")
character(0) Message d'avis : Dans qbeta(p = c(0.025,
0.975), shape1 = 3.3108797, shape2 = 1e-07) :
qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997
is not accurate


Try 'suppressWarnings'.



__
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/list

Re: [R] Do not show a "message d'avis" that qbeta reports

2021-10-20 Thread Marc Girondot via R-help

Thanks ! It works.

So "Warnings" has been translated in French by "Message d'avis :" !
> warning("Essai")
Message d'avis :
Essai

It is not the best translation...
I would prefer: "Attention: "

Marc

Le 20/10/2021 à 12:28, Enrico Schumann a écrit :

On Wed, 20 Oct 2021, Marc Girondot via R-help writes:


Dear R-helpers

Do you know how to not show a "message d'avis" that
qbeta reports. suppressMessages and capture.output are
not working.

(PS I Know that qbeta with shape2 being 1e-7 is
"strange"... this is obtained during an optimization
process. Just I don't want see the messages).

Thanks

Marc Girondot

q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797, shape2 = 0.001)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

suppressMessages(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001))
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001), type = "message")
character(0)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 =
3.3108797, shape2 = 0.001), type = "output")
character(0)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
   qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate


Try 'suppressWarnings'.




__
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] Do not show a "message d'avis" that qbeta reports

2021-10-20 Thread Marc Girondot via R-help

Dear R-helpers

Do you know how to not show a "message d'avis" that qbeta reports. 
suppressMessages and capture.output are not working.


(PS I Know that qbeta with shape2 being 1e-7 is "strange"... this is 
obtained during an optimization process. Just I don't want see the 
messages).


Thanks

Marc Girondot

q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797, shape2 = 0.001)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
  qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

suppressMessages(q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797, 
shape2 = 0.001))

Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
  qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797, shape2 
= 0.001), type = "message")

character(0)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
  qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

capture.output(q <- qbeta(p=c(0.025, 0.975), shape1 = 3.3108797, shape2 
= 0.001), type = "output")

character(0)
Message d'avis :
Dans qbeta(p = c(0.025, 0.975), shape1 = 3.3108797, shape2 = 1e-07) :
  qbeta(a, *) =: x0 with |pbeta(x0,*) - alpha| = 0.024997 is not accurate

__
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] Good practice for database with utf-8 string in package

2021-09-16 Thread Marc Girondot via R-help
Hello everyone,

I am a little bit stucked on the problem to include a database with 
utf-8 string in a package. When I submit it to CRAN, it reports NOTES 
for several Unix system and I try to find a solution (if it exists) to 
not have these NOTES.

The database has references and some names have non ASCII characters.

* First I don't agree at all with the solution proposed here:

https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Encoding-issues

"First, consider carefully if you really need non-ASCIItext."

If a language has non ASCII characters, it is not just to make the 
writting nicer of more complex, it is because it changes the prononciation.

* Then I try to find solution to not have these NOTES.

For example, here is a reference with utf-8 characters

> DatabaseTSD$Reference[211]
[1] Hernández-Montoya, V., Páez, V.P. & Ceballos, C.P. (2017) Effects of 
temperature on sex determination and embryonic development in the 
red-footed tortoise, Chelonoidis carbonarius. Chelonian Conservation and 
Biology 16, 164-171.

When I convert the characters into unicode, I get indeed only ASCII 
characters. Perfect.

>  iconv(DatabaseTSD$Reference[211], "UTF-8", "ASCII", "Unicode")
[1] "Hernndez-Montoya, V., Pez, V.P. & Ceballos, C.P. 
(2017) Effects of temperature on sex determination and embryonic 
development in the red-footed tortoise, Chelonoidis carbonarius. 
Chelonian Conservation and Biology 16, 164-171."

Then I have no NOTES when I checked the package with database in UNIX... 
but how can I print the reference back with original characters ?

Thanks a lot to point me to best practices to include databases with 
non-ASCII characters and not have NOTES while submitted package to CRAN.

Marc


[[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] Plot histogram and lognormal fit on the same time

2021-01-21 Thread Marc Girondot via R-help
Two solutions not exactly equivalent ;

data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)

f <- fitdistr(data, "lognormal")

f$estimate

lines(x=seq(from=0, to=50, by=0.1),
 � y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog = 
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)

library(HelpersMG)

m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
 � meanlog = f$estimate["meanlog"], sdlog = 
f$estimate["sdlog"], sum = 100)

points(m$x, m$y, pch=19, col="red")

Marc Girondot

Le 21/01/2021 � 12:54, Eric Leroy a �crit�:
> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal 
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write 
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a 
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
>
> __
> 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] Error in optim with method L-BFGS-B when hessian is TRUE

2020-08-23 Thread Marc Girondot via R-help

Sorry... it is already stated in the help, at the hessian section:

hessian
Only if argument hessian is true. A symmetric matrix giving an estimate 
of the Hessian at the solution found. Note that this is the Hessian of 
the unconstrained problem even if the box constraints are active.


So no problem...

Marc

Le 23/08/2020 ?? 11:19, Marc Girondot via R-help a ??crit??:

Dear members,

I fought for several days against an error I was getting with optim in 
L-BFGS-B. The error was produced because some parameters were outside 
the limits defined by upper and lower.
After investigation, the error is not produced during the optimization 
itself but during the calculation of the Hessian matrix which does not 
take into account the upper and lower bounds.
It would be nice if this was stated in the optim help within the 
L-BFGS-B method section.


Marc Girondot

__
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] Error in optim with method L-BFGS-B when hessian is TRUE

2020-08-23 Thread Marc Girondot via R-help

Dear members,

I fought for several days against an error I was getting with optim in 
L-BFGS-B. The error was produced because some parameters were outside 
the limits defined by upper and lower.
After investigation, the error is not produced during the optimization 
itself but during the calculation of the Hessian matrix which does not 
take into account the upper and lower bounds.
It would be nice if this was stated in the optim help within the 
L-BFGS-B method section.


Marc Girondot

__
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] Having problems with the ifelse and negative numbers

2019-12-10 Thread Marc Girondot via R-help
Here is a test of the different proposed solutions and a new one faster. 
In conclusion, ifelse much be used with caution:


Aini =  runif(100, min=-1,max=1)
library(microbenchmark)
A <- Aini
microbenchmark({B1 <- ifelse( A < 0, sqrt(-A), A )})
# mean = 77.1
A <- Aini
microbenchmark({B2 <- ifelse( A < 0, suppressWarnings(sqrt(-A)), A )})
# mean = 76.53762
A <- Aini
microbenchmark({B3 <- ifelse( A < 0, sqrt(abs(A)), A )})
# mean = 75.26712
A <- Aini
microbenchmark({A[A < 0] <- sqrt(-A[A < 0]);B4 <- A})
# mean = 17.71883

Marc

Le 09/12/2019 à 19:25, Richard M. Heiberger a écrit :

or even simpler
sqrt(abs(A))

On Mon, Dec 9, 2019 at 8:45 AM Eric Berger  wrote:

Hi Bob,
You wrote "the following error message" -
when in fact it is a Warning and not an error message. I think your
code does what you hoped it would do, in the sense it successfully
calculates the sqrt(abs(negativeNumber)), where appropriate.

If you want to run the code without seeing this warning message you can run

ifelse( A < 0, suppressWarnings(sqrt(-A)), A )

and you should be fine.

HTH,
Eric

On Mon, Dec 9, 2019 at 3:18 PM Kevin Thorpe  wrote:

The sqrt(-A) is evaluated for all A. The result returned is conditional on the 
first argument but the other two arguments are evaluated on the entire vector.

Kevin

--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016


On 2019-12-09, 7:58 AM, "R-help on behalf of rsherry8" 
 wrote:

 Please consider the following two R statements:
  A =  runif(20, min=-1,max=1)
  ifelse( A < 0, sqrt(-A), A )

 The second statement produces the following error message:
  rt(-A) : NaNs produced

 I understand that you cannot take the square root of a negative number
 but I thought the condition A < 0
 would take care of that issue. It appears not to be.

 What am I missing?

 Thanks,
 Bob

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

__
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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Marc Girondot via R-help
Le 09/12/2019 à 16:45, Bert Gunter a écrit :
> In addition, as John's included output shows, only 1 parameter, the 
> intercept, is fit. As he also said, the sd is estimated from the 
> residual deviance -- it is not a model parameter.
>
> Suggest you spend some time with a glm tutorial/text.

I tried ! But I miss this point. I understand now this point. Thanks a  
lot... big progress for me.

But still I don't understand why AIC calculation uses 2 parameters if 
the SD is estimated from the residual deviance.

 > y=rnorm(100)
 > gnul <- glm(y ~ 1)
 > logLik(gnul)
'log Lik.' -136.4343 (df=2)
 > AIC(gnul)
[1] 276.8687
 > -2*logLik(gnul)+2*2
'log Lik.' 276.8687 (df=2)

This is not intuitive when to count SD as a parameter (in AIC) or not in 
df.resuidual !


>
> Bert
>
> On Mon, Dec 9, 2019 at 7:17 AM Marc Girondot via R-help 
> mailto:r-help@r-project.org>> wrote:
>
> Let do a simple glm:
>
>  > y=rnorm(100)
>  > gnul <- glm(y ~ 1)
>  > gnul$coefficients
> (Intercept)
>    0.1399966
>
> The logLik shows the fit of two parameters (DF=2) (intercept) and sd
>
>  > logLik(gnul)
> 'log Lik.' -138.7902 (df=2)
>
> But where is the sd term in the glm object?
>
> If I do the same with optim, I can have its value
>
>  > dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"],
> sd=x["sd"], log = TRUE))}
>  > parg <- c(mean=0, sd=1)
>  > o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
>  > o0$value/1E9
> [1] 138.7902
>  > o0$par
>   mean    sd
>
> 0.1399966 0.9694405
>
> But I would like have the value in the glm.
>
> (and in the meantime, I don't understand why gnul$df.residual
> returned
> 99... for me it should be 98=100 - number of observations) -1 (for
> mean)
> - 1 (for sd); but it is statistical question... I have asked it in
> crossvalidated [no answer still] !)
>
> Thanks
>
> Marc
>
> __
> R-help@r-project.org <mailto: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] Where is the SD in output of glm with Gaussian distribution

2019-12-09 Thread Marc Girondot via R-help

Let do a simple glm:

> y=rnorm(100)
> gnul <- glm(y ~ 1)
> gnul$coefficients
(Intercept)
  0.1399966

The logLik shows the fit of two parameters (DF=2) (intercept) and sd

> logLik(gnul)
'log Lik.' -138.7902 (df=2)

But where is the sd term in the glm object?

If I do the same with optim, I can have its value

> dnormx <- function(x, data) {1E9*-sum(dnorm(data, mean=x["mean"], 
sd=x["sd"], log = TRUE))}

> parg <- c(mean=0, sd=1)
> o0 <- optim(par = parg, fn=dnormx, data=y, method="BFGS")
> o0$value/1E9
[1] 138.7902
> o0$par
 mean    sd

0.1399966 0.9694405

But I would like have the value in the glm.

(and in the meantime, I don't understand why gnul$df.residual returned 
99... for me it should be 98=100 - number of observations) -1 (for mean) 
- 1 (for sd); but it is statistical question... I have asked it in 
crossvalidated [no answer still] !)


Thanks

Marc

__
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 prevent update of a package

2019-12-06 Thread Marc Girondot via R-help
Thanks for your answer. I try this trick:

mkdir packages
sudo chmod -R a+w packages
ls -al
drwxrwxrwx��� 2 marcgirondot staff� 64� 6 d�c 17:20 packages

Now in R

 > require(devtools)
 >
 > install_version("raster", version = "2.5-8", repos 
="http://cran.us.r-project.org";,
 ��� lib="/Users/marcgirondot/ Here the full path /packages")

And I get:
Erreur : Failed to install 'unknown package' from URL:
 � (converti depuis l'avis) 'lib = 
"/Users/marcgirondot/Documents/Espace_de_travail_R/packages
"' is not writable

Not sure were I do something wrong.

Thanks if you have an idea.

Marc


Le 06/12/2019 � 08:42, Amit Mittal a �crit�:
> Just install Older R from the project R archives in a separate directory
>
> Best Regards
>
> Please excuse the brevity of the message. This message was sent from a 
> mobile device.
> ------------
> *From:* R-help  on behalf of Marc 
> Girondot via R-help 
> *Sent:* Friday, December 6, 2019 1:09 PM
> *To:* R-help Mailing List
> *Subject:* [R] How prevent update of a package
> I use R 3.6.1 in macOSX 10.15.1 (Catalina).
>
> I cannot install the last version (3.0-7) of the package raster from
> source or from binary. In both cases I get
>
> ??*** caught segfault ***
> address 0x31, cause 'memory not mapped'
>
> when I try to load it.
>
> Same occurs when I use the development version using:
>
> library(devtools)
> install_github("rspatial/raster")
>
> This is the same bug as described here:
> https://github.com/rspatial/raster/issues/63
>
> The last working version for me is the 2.5-8
>
> require(devtools)
> install_version("raster", version = "2.5-8", repos =
> "http://cran.us.r-project.org";)
>
> However, each time that I use update.packages(), raster wants to be 
> updated.
>
> So here my three questions:
>
> - Does someone has a solution to have raster 3.0-7 working in MacOSX ?
>
> - Do others have raster 3.0-7 working in R 3.6.1 and Catalina MacOSX ?
>
> - How to prevent raster package to be updated ?
>
> Thanks a lot
>
> Marc
>
> __
> 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 prevent update of a package

2019-12-05 Thread Marc Girondot via R-help

I use R 3.6.1 in macOSX 10.15.1 (Catalina).

I cannot install the last version (3.0-7) of the package raster from 
source or from binary. In both cases I get


??*** caught segfault ***
address 0x31, cause 'memory not mapped'

when I try to load it.

Same occurs when I use the development version using:

library(devtools)
install_github("rspatial/raster")

This is the same bug as described here: 
https://github.com/rspatial/raster/issues/63


The last working version for me is the 2.5-8

require(devtools)
install_version("raster", version = "2.5-8", repos = 
"http://cran.us.r-project.org";)


However, each time that I use update.packages(), raster wants to be updated.

So here my three questions:

- Does someone has a solution to have raster 3.0-7 working in MacOSX ?

- Do others have raster 3.0-7 working in R 3.6.1 and Catalina MacOSX ?

- How to prevent raster package to be updated ?

Thanks a lot

Marc

__
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] Raster package crash with segmentation fault

2019-09-27 Thread Marc Girondot via R-help

Dear members,

When I load raster 3.0-7 package installed or from source or from binary 
in r 3.6.1 (macosX 10.14.6), I get a segmentation fault crash:


(see below)

As someone the same problem and a solution ? Thanks

(I have posted this question in R-Sig_GEO list without answer still)

> library("raster")
Le chargement a n??cessit?? le package : sp

??*** caught segfault ***
address 0x31, cause 'memory not mapped'

Traceback:
??1: Module(module, mustStart = TRUE, where = env)
??2: doTryCatch(return(expr), name, parentenv, handler)
??3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
??4: tryCatchList(expr, classes, parentenv, handlers)
??5: tryCatch(Module(module, mustStart = TRUE, where = env), error = 
function(e) e)

??6: loadModule(module = "spmod", what = TRUE, env = ns, loadNow = TRUE)
??7: (function (ns) loadModule(module = "spmod", what = TRUE, env = ns, 
loadNow = TRUE))()

??8: doTryCatch(return(expr), name, parentenv, handler)
??9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch((function (ns) loadModule(module = "spmod", what = TRUE, 
env = ns, loadNow = TRUE))(), error = function(e) e)
12: eval(substitute(tryCatch(FUN(WHERE), error = function(e) e), 
list(FUN = f, WHERE = where)), where)
13: eval(substitute(tryCatch(FUN(WHERE), error = function(e) e), 
list(FUN = f, WHERE = where)), where)

14: .doLoadActions(where, attach)
15: methods::cacheMetaData(ns, TRUE, ns)
16: loadNamespace(package, lib.loc)
17: doTryCatch(return(expr), name, parentenv, handler)
18: tryCatchOne(expr, names, parentenv, handlers[[1L]])
19: tryCatchList(expr, classes, parentenv, handlers)
20: tryCatch({?? attr(package, "LibPath") <- which.lib.loc ns <- 
loadNamespace(package, lib.loc)?? env <- attachNamespace(ns, pos = 
pos, deps, exclude, include.only)}, error = function(e) {?? P <- if 
(!is.null(cc <- conditionCall(e))) paste(" in", 
deparse(cc)[1L])?? else ""?? msg <- gettextf("package or 
namespace load failed for %s%s:\n %s", sQuote(package), 
P, conditionMessage(e)) if (logical.return) 
message(paste("Error:", msg), domain = NA)?? else stop(msg, call. = 
FALSE, domain = NA)})

21: library("raster")

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

__
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] Bug (?): file.copy() erases 'from' file if the "to" file already exists and is a symlinked file

2019-09-13 Thread Marc Girondot via R-help
If file.copy() is used to replace a symlinked file, it erases the 
original file and does not copy the file. The original file is lost.


> version
 _
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status Patched
major?? 3
minor?? 6.1
year 2019
month?? 09
day?? 06
svn rev?? 77160
language R
version.string R version 3.6.1 Patched (2019-09-06 r77160)
nickname Action of the Toes

#

Here is a reproducible example:

A <- 10
save(A, file="A.Rdata")
file.symlink(from="A.Rdata", to="B.Rdata")
rm(A)

load(file="B.Rdata")
print(A)?? # Perfect

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
A.Rdata

file.copy(from="A.Rdata", to="B.Rdata", overwrite = TRUE)

system("ls -l")
## -rw-r--r--?? 1 marcgirondot?? staff 0 13 sep 11:44 A.Rdata
## lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:44 B.Rdata -> 
A.Rdata

###

A.Rdata becomes empty: 0B
The content of A.Rdata is lost


In terminal the problem does not occur


marcgirondot$ ls
A.Rdata
marcgirondot$ ln -s A.Rdata B.Rdata
marcgirondot$ ls -l
-rw-r--r--?? 1 marcgirondot?? staff?? 70 13 sep 11:38 A.Rdata
lrwxr-xr-x?? 1 marcgirondot?? staff 7 13 sep 11:38 B.Rdata -> 
A.Rdata
marcgirondot$ cp A.Rdata B.Rdata
cp: B.Rdata and A.Rdata are identical (not copied).

__
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] Loading aliased file in MacOSX

2019-09-11 Thread Marc Girondot via R-help
If I try to load data from an alias file made using Cmd+Ctrl+A in finder 
for MacOSX, I get an error. Symbolic links are working well but 
sometimes, it is easier to use finder rather than terminal.


Has someone a solution to help R to read the original aliased file ?

Thanks

Here is a reproducible example:

A <- 10
save(A, file="A.Rdata")
rm(A)

# Make hard link
system(paste("ln A.Rdata B.Rdata"))
load(file="B.Rdata")
# It works
print(A)

rm(A)

# Make symbolic link
system(paste("ln -s A.Rdata C.Rdata"))
load(file="C.Rdata")
# It works
print(A)

rm(A)

# Make an alias of the A.Rdata file in finder using Cmd+Ctrl+A; the name 
of the new file is "A.Rdata alias"

load(file="A.Rdata alias")

It failed with this error:

Error in load(file = "A.Rdata alias") :
?? mauvais num??ro magique de restauration de fichier (le fichier est 
peut ??tre corrompu) -- aucune donn??e charg??e

De plus : Warning message:
?? file ???A.Rdata alias??? has magic number 'book'
Use of save versions prior to 2 is deprecated

__
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] knitr error for small text in pdf (bug)

2019-08-09 Thread Marc Girondot via R-help

Let try this minimal Rmarkdown file

---
title: "cex in Rmarkdown"
output: word_document
---

```{r}
knitr::opts_chunk$set(dev='pdf')
```


```{r}
plot((0:160)/4, 0:160, type="n")
text(x=20, y=70, labels =expression(alpha), cex=1e-7)
```

When knitr-red from Rstudio (with r 3.6.1 on MacosX with knitr 1.24), it 
produced an error with this message ("Information of metric non 
available for this family") [translation from French because of my 
system configuration]


However,

text(x=20, y=70, labels =expression(alpha), cex=0)

and

text(x=20, y=70, labels =expression(alpha), cex=0.1)

work.

Also text(x=20, y=70, labels ="a", cex=1e-7) works.

The error does not occur when dev='png' is used but it occurs also for 
dev='postscript'


I don't know where I should report the bug.

Thanks

__
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] SE for all fixed factor effect in GLMM

2018-12-29 Thread Marc Girondot via R-help

Dear members,

Let do a example of simple GLMM with x and G as fixed factors and R as 
random factor:


(note that question is the same with GLM or even LM):

x <- rnorm(100)
y <- rnorm(100)
G <- as.factor(sample(c("A", "B", "C", "D"), 100, replace = TRUE))
R <- as.factor(rep(1:25, 4))

library(lme4)

m <- lmer(y ~ x + G + (1 | R))
summary(m)$coefficients

I get the fixed effect fit and their SE

> summary(m)$coefficients
   Estimate Std. Error    t value
(Intercept)  0.07264454  0.1952380  0.3720820
x   -0.02519892  0.1238621 -0.2034433
GB   0.10969225  0.3118371  0.3517614
GC  -0.09771555  0.2705523 -0.3611706
GD  -0.12944760  0.2740012 -0.4724344

The estimate for GA is not shown as it is fixed to 0. Normal, it is the 
reference level.


But is there a way to get SE for GA of is-it non-sense question because 
GA is fixed to 0 ?


__

I propose here a solution but I don't know if it is correct. It is based 
on reordering levels and averaging se for all reordering:


G <- relevel(G, "A")
m <- lmer(y ~ x + G + (1 | R))
sA <- summary(m)$coefficients

G <- relevel(G, "B")
m <- lmer(y ~ x + G + (1 | R))
sB <- summary(m)$coefficients

G <- relevel(G, "C")
m <- lmer(y ~ x + G + (1 | R))
sC <- summary(m)$coefficients

G <- relevel(G, "D")
m <- lmer(y ~ x + G + (1 | R))
sD <- summary(m)$coefficients

seA <- mean(sB["GA", "Std. Error"], sC["GA", "Std. Error"], sD["GA", 
"Std. Error"])
seB <- mean(sA["GB", "Std. Error"], sC["GB", "Std. Error"], sD["GB", 
"Std. Error"])
seC <- mean(sA["GC", "Std. Error"], sB["GC", "Std. Error"], sD["GC", 
"Std. Error"])
seD <- mean(sA["GD", "Std. Error"], sB["GD", "Std. Error"], sC["GD", 
"Std. Error"])


seA; seB; seC; seD


Thanks,

Marc

__
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] Webshot failed to take snapshot in Ubuntu machine

2018-12-18 Thread Marc Girondot via R-help

Hi Christofer,
I just try on MacOSX and ubuntu and it works on both:

For ubuntu:
> Sys.info()
  sysname
  "Linux"
  release
  "4.15.0-42-generic"
  version
"#45-Ubuntu SMP Thu Nov 15 19:32:57 UTC 2018"
 nodename
   "lepidochelys"
  machine
 "x86_64"

Not sure what to do...

Marc

Le 18/12/2018 à 13:37, Christofer Bogaso a écrit :

Hi,

I was using webshot package to take snapshot of a webpage as below:

library(webshot)
webshot('
https://www.bseindia.com/stock-share-price/asian-paints-ltd/asianpaint/500820/',
'bb.pdf')

However what I see is a Blank PDF file is saved.

However if I use the same code in my windows machine it is able to produce
correct snapshot.

Below is my system information

Sys.info()

sysname
"Linux"
release
"4.4.0-139-generic"
version
"#165-Ubuntu SMP Wed Oct 24 10:58:50 UTC 2018"
   nodename
   "ubuntu-s-2vcpu-4gb-blr1-01"
machine
   "x86_64"
  login
 "root"
   user
 "root"
 effective_user
 "root"

Any idea what went wrong would be highly helpful.

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] High dimensional optimization in R

2018-11-30 Thread Marc Girondot via R-help
I fit also model with many variables (>100) and I get good result when I 
mix several method iteratively, for example: 500 iterations of 
Nelder-Mead followed by 500 iterations of BFGS followed by 500 
iterations of Nelder-Mead followed by 500 iterations of BFGS etc. until 
it stabilized. It can take several days.

I use or several rounds of optimx or simply succession of optim.

Marc


Le 28/11/2018 à 09:29, Ruben a écrit :

Hi,

Sarah Goslee (jn reply to  Basic optimization question (I'm a 
rookie)):  "R is quite good at optimization."


I wonder what is the experience of the R user community with high 
dimensional problems, various objective functions and various 
numerical methods in R.


In my experience with my package CatDyn (which depends on optimx), I 
have fitted nonlinear models with nearly 50 free parameters using 
normal, lognormal, gamma, Poisson and negative binomial exact 
loglikelihoods, and adjusted profile normal and adjusted profile 
lognormal approximate loglikelihoods.


Most numerical methods crash, but CG and spg often, and BFGS, bobyqa, 
newuoa and Nelder-Mead sometimes, do yield good results (all numerical 
gradients less than 1)  after 1 day or more running in a normal 64 bit 
PC with Ubuntu 16.04 or Windows 7.


Ruben



__
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] Should package be reinstalled when exterbal library is changed

2018-10-30 Thread Marc Girondot via R-help

Dear R-experts,

Some packages need external libraries to be installed. For example ncdf4 
needs netcdf library or flextable need pandoc.


When there is new version of external library, should the R package be 
installed again to use the new external version, or do the package finds 
itself the new version? Perhaps the answer is "It depends on the 
package", and so how to know if it requires new compilation or not ?


Thanks

Marc

__
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] studio server on High SIerra

2018-10-21 Thread Marc Girondot via R-help

I post long time ago a post on my blog about this:
https://max2.ese.u-psud.fr/epc/conservation/Girondot/Publications/Blog_r/Entrees/2014/8/3_Install_RStudio_server_on_Marverick_MacOSX.html

You could try using this base.

Marc

Le 21/10/2018 à 05:12, Fuchs Ira a écrit :

Can I run Rstudio Server on OSX 10.13 (High Sierra). If so, can someone
please point me to install directions? I found an old post that talks about
using homebrew but I can't find the rstudio-server brew to install.

__
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] Set attributes for object known by name

2018-10-10 Thread Marc Girondot via R-help

Hello everybody,

Has someone the solution to set attribute when variable is known by name ?

Thanks a lot

Marc

Let see this exemple:

# The variable name is stored as characters.

varname <- "myvarname"
assign(x = varname, data.frame(A=1:5, B=2:6))
attributes(myvarname)

$names
[1] "A" "B"
$class
[1] "data.frame"
$row.names
[1] 1 2 3 4 5

# perfect

attributes(get(varname))

# It works also

$names
[1] "A" "B"
$class
[1] "data.frame"

$row.names
[1] 1 2 3 4 5

attributes(myvarname)$NewAtt <- "MyAtt"

# It works

attributes(get(varname))$NewAtt2 <- "MyAtt2"
Error in attributes(get(varname))$NewAtt2 <- "MyAtt2" :
  impossible de trouver la fonction "get<-"

# Error...

__
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] Strange result for strptime with %p

2018-10-02 Thread Marc Girondot via R-help

Dear members... are these results normal ?

For the first one, no problem. I expected this:

> strptime("05/01/18 01:00:00 AM", format = ("%m/%d/%y %I:%M:%S %p"), 
tz="Asia/Jayapura")

[1] "2018-05-01 01:00:00 WIT"

For this one, it is ok also:

> strptime("05/01/18 01:00:00 AM", format = ("%m/%d/%y %I:%M:%S %p"), 
tz="Asia/Jayapura")-1

[1] "2018-05-01 00:59:59 WIT"

But how to explain this ???

> strptime("05/01/18 00:59:59 AM", format = ("%m/%d/%y %I:%M:%S %p"), 
tz="Asia/Jayapura")

[1] NA

Thanks for your advices
Marc
__

R 3.5.1 on MacOS 10.14

> version
   _
platform   x86_64-apple-darwin15.6.0
arch   x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major  3
minor  5.1
year   2018
month  07
day    02
svn rev    74947
language   R
version.string R version 3.5.1 (2018-07-02)
nickname   Feather Spray

__
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] sub/grep question: extract year

2018-08-09 Thread Marc Girondot via R-help

I answer myself to the third point:
This pattern is better to get a year:

pattern.year <- ".*\\b(18|19|20)([0-9][0-9])\\b.*"

subtext <- "bla 1880 bla"
sub(pattern.year, "\\1\\2", subtext) # return 1880
subtext <- "bla 1980 bla"
sub(pattern.year, "\\1\\2", subtext) # return 1980
subtext <- "bla 2010 bla"
sub(pattern.year, "\\1\\2", subtext) # return 2010
subtext <- "bla 1010 bla"
sub(pattern.year, "\\1\\2", subtext) # return bla 1010 bla
subtext <- "bla 3010 bla"
sub(pattern.year, "\\1\\2", subtext) # return bla 3010 bla

Marc


Le 09/08/2018 à 09:57, Marc Girondot via R-help a écrit :

Hi everybody,

I have some questions about the way that sub is working. I hope that 
someone has the answer:


1/ Why the second example does not return an empty string ? There is 
no match.


subtext <- "-1980-"
sub(".*(1980).*", "\\1", subtext) # return 1980
sub(".*(1981).*", "\\1", subtext) # return -1980-

2/ Based on sub documentation, it replaces the first occurence of a 
pattern: why it does not return 1980 ?


subtext <- " 1980 1981 "
sub(".*(198[01]).*", "\\1", subtext) # return 1981

3/ I want extract year from text; I use:

subtext <- "bla 1980 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) 
# return 1980

subtext <- "bla 2010 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) 
# return 2010


but

subtext <- "bla 1010 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) 
# return 1010


I would like exclude the case 1010 and other like this.

The solution would be:

18[0-9][0-9] or 19[0-9][0-9] or 200[0-9] or 201[0-9]

Is there a solution to write such a pattern in grep ?

Thanks a lot

Marc

__
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] sub/grep question: extract year

2018-08-09 Thread Marc Girondot via R-help

Hi everybody,

I have some questions about the way that sub is working. I hope that 
someone has the answer:


1/ Why the second example does not return an empty string ? There is no 
match.


subtext <- "-1980-"
sub(".*(1980).*", "\\1", subtext) # return 1980
sub(".*(1981).*", "\\1", subtext) # return -1980-

2/ Based on sub documentation, it replaces the first occurence of a 
pattern: why it does not return 1980 ?


subtext <- " 1980 1981 "
sub(".*(198[01]).*", "\\1", subtext) # return 1981

3/ I want extract year from text; I use:

subtext <- "bla 1980 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) # 
return 1980

subtext <- "bla 2010 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) # 
return 2010


but

subtext <- "bla 1010 bla"
sub(".*[ \\.\\(-]([12][01289][0-9][0-9])[ \\.\\)-].*", "\\1", subtext) # 
return 1010


I would like exclude the case 1010 and other like this.

The solution would be:

18[0-9][0-9] or 19[0-9][0-9] or 200[0-9] or 201[0-9]

Is there a solution to write such a pattern in grep ?

Thanks a lot

Marc

__
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] progress of a function...

2018-07-06 Thread Marc Girondot via R-help

Take a look at the pbmcapply package. It does what you need.

Marc

Le 06/07/2018 à 11:37, akshay kulkarni a écrit :

dear members,
 I want to use svMisc package in R to check how my 
function is progressing.
It has the following syntax:

f <- function(x){ for (i in 1:1000){
   progress (i)
   s[i] <- sqrt(i)
  }
  return(i)
}

This gives me the progress of the function as i moves.

But what if I have mclapply function instead of the for loop? How do we get the progress 
of an ongoing "apply" family of functions?

Very many thanks for your time and effort...
yours sincerely,
AKSHAY M KULKARNI

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

2018-04-15 Thread Marc Girondot via R-help

Le 15/04/2018 à 17:56, alireza daneshvar a écrit :

break-down point


Can you explain more what you plan to do and give an example of what you 
have tried to do until now to do a "break down point" in R. Perhaps a 
"break down point" is common in your field, but I have no idea about 
what it is !


https://en.wikipedia.org/wiki/Breakdown_(1997_film)

Sincerely

Marc

__
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] Bivariate Normal Distribution Plots

2018-04-13 Thread Marc Girondot via R-help

Try this code:

# Standard deviations and correlation
sig_x <- 1
sig_y <- 2
rho_xy <- 0.7

# Covariance between X and Y
sig_xy <- rho_xy * sig_x *sig_y

# Covariance matrix
Sigma_xy <- matrix(c(sig_x ^ 2, sig_xy, sig_xy, sig_y ^ 2), nrow = 2, 
ncol = 2)


# Load the mvtnorm package
library("mvtnorm")

# Means
mu_x <- 0
mu_y <- 0

# Simulate 1000 observations
set.seed(12345)  # for reproducibility
xy_vals <- rmvnorm(1000, mean = c(mu_x, mu_y), sigma = Sigma_xy)

# Have a look at the first observations
head(xy_vals)

# Create scatterplot
# plot(xy_vals[, 1], xy_vals[, 2], pch = 16, cex = 2, col = "blue",
#  main = "Bivariate normal: rho = 0.0", xlab = "x", ylab = "y")

library(graphics)

x <- xy_vals[, 1]
y <- xy_vals[, 2]

par(mar=c(4, 4, 2, 6)+0.4)

smoothScatter(x, y, asp=1,
  main = paste("Bivariate normal: rho = ", rho_xy),
  xlab = "x", ylab = "y")


# Add lines
abline(h = mu_y, v = mu_x)

library(fields)

n <- matrix(0, ncol=128, nrow=128)

xrange <- range(x)
yrange <- range(y)

for (i in 1:length(x)) {
  posx <- 1+floor(127*(x[i]-xrange[1])/(xrange[2]-xrange[1]))
  posy <- 1+floor(127*(y[i]-yrange[1])/(yrange[2]-yrange[1]))
  n[posx, posy] <- n[posx, posy]+1
}

image.plot( legend.only=TRUE,
    zlim= c(0, max(n)), nlevel=128,
    col=colorRampPalette(c("white", blues9))(128))


Hope it helps,

Marc

Le 12/04/2018 à 16:59, JEFFERY REICHMAN a écrit :

R-Help

I am attempting to create a series of bivariate normal distributions.  So using 
the mvtnorm library I have created the following code ...

# Standard deviations and correlation
sig_x <- 1
sig_y <- 1
rho_xy <- 0.0

# Covariance between X and Y
sig_xy <- rho_xy * sig_x *sig_y

# Covariance matrix
Sigma_xy <- matrix(c(sig_x ^ 2, sig_xy, sig_xy, sig_y ^ 2), nrow = 2, ncol = 2)

# Load the mvtnorm package
library("mvtnorm")

# Means
mu_x <- 0
mu_y <- 0

# Simulate 1000 observations
set.seed(12345)  # for reproducibility
xy_vals <- rmvnorm(1000, mean = c(mu_x, mu_y), sigma = Sigma_xy)

# Have a look at the first observations
head(xy_vals)

# Create scatterplot
plot(xy_vals[, 1], xy_vals[, 2], pch = 16, cex = 2, col = "blue",
  main = "Bivariate normal: rho = 0.0", xlab = "x", ylab = "y")

# Add lines
abline(h = mu_y, v = mu_x)

Problem is this results in sigma(x) = sigma(y), rho=0 and I need or what 
2sigma(x)=sigma(y), rho=0 or 2sigma(y)=sigma(x), rho=0 to elongate the 
distribution.  What I have created creates a circle.  Can I do that within the 
mvtnorm package?

Jeff Reichman

__
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] Fail to save an object using name as string

2018-04-09 Thread Marc Girondot via R-help

Dear list member,

I think that I have detected a strange behavior of the save() command:

> year <- "2000"
> assign(paste0("Var_", year), list(A=10, B=20))
> get(paste0("Var_", year))
$A
[1] 10

$B
[1] 20

# At this point all is ok, I have created a list of name Var_2000

> save(paste0("Var_", year), file=paste0("Var_", year, ".Rdata"))
Error in save(paste0("Var_", year), file = paste0("Var_", year, 
".Rdata")) :

  objet ‘paste0("Var_", year)’ introuvable

(introuvable=cannot be found)

but

> save("Var_2000", file=paste0("Var_", year, ".Rdata"))

When I read the help for save: ?save

...    the names of the objects to be saved (as symbols or character 
strings).


I checked if paste0("Var_", year) produced a character string:

> str("Var_2000")
 chr "Var_2000"
> str(paste0("Var_", year))
 chr "Var_2000"

The solution was to include the name in the list argument:

> save(list=paste0("Var_", year), file=paste0("Var_", year, ".Rdata"))

But I don't understand what is the difference between "Var_2000" and 
paste0("Var_", year) as both produced the same output.


Thanks for your help,

Marc


R Under development (unstable) (2018-03-23 r74448) -- "Unsuffered 
Consequences"

Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

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


Re: [R] R 3.4.4, internet access fails on Windows XP

2018-03-21 Thread Marc Girondot via R-help
To solve similar problem, I just install Lubuntu 17.10 on an old PC 
(i686) and I am astonished by the reactivity of the computer... it has a 
second life.
The main problem is that Rstudio Desktop 32 bits is no more supported 
for Ubuntu 32bits computers but the solution using Rstudio Server 32 
bits works very well.

Marc


Le 21/03/2018 à 16:58, Duncan Murdoch a écrit :

On 21/03/2018 8:27 AM, Holger Taschenberger wrote:
I can install and run R 3.4.4 on Windows XP (32bit). However, calling 
"Update Packages..." or "Html help" from the RGui.exe main menu fails 
with a Windows MessageBox saying:


"The procedure entry point IdnToAscii could not be located in the 
dynamic link library KERNEL32.dll"


and the following text printed to the RGui console window:

"...
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
   unable to load shared object 
'C:/R/R-3.4.4/modules/i386/internet.dll':

   LoadLibrary failure:  The specified procedure could not be found."

"IdnToAscii" is exported from "C:\WINDOWS\system32\normaliz.dll" on 
Windows XP. But apparently RGui cannot locate this procedure on 
Windows XP.


Any advice? (except for "switch to a more recent windows version")



The Windows FAQ 2.2 says, "Windows XP is no longer supported", so I 
think you're out of luck.  XP went past "end-of-life" in 2014.


Other than switching to a more recent Windows version, your choices 
are switching to a completely different OS, or switching to an older 
version of R.


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-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] Warning for LC_CTYPE when R is ran through ssh

2018-03-14 Thread Marc Girondot via R-help

Dear member,

When I run a code on a computer B from a computer A through shh using 
for example:


system("ssh login@IPadress \"R -e 'print(1)'\"")
[Note that I don't need indicate password because ~/.ssh/authorized_keys 
is used]


I get a warning:
During startup - Warning message:
Setting LC_CTYPE failed, using "C"

The code is working (it prints 1) but I don't like get a warning.

R 3.4.3 is installed on the IPadress computer under Ubuntu 16.04

In this computer, I tried to add in .Rprofile this line:
Sys.setlocale(category = "LC_CTYPE", locale = "en_US.UTF-8")

it is recognized but I get always the same warning when the code is ran 
through ssh:


> system("ssh login@IPadress \"R -e 'print(1)'\"")

R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

 some messages are removed for simplicity

[1] "en_US.UTF-8"
[Previously saved workspace restored]

During startup - Warning message:
Setting LC_CTYPE failed, using "C"
> print(1)
[1] 1

If I run the same in the local terminal, I don't get the warning:

~$ R -e "print(1)"

R version 3.4.3 (2017-11-30) -- "Kite-Eating Tree"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

 some messages are removed for simplicity


[1] "en_US.UTF-8"
[Previously saved workspace restored]

> print(1)
[1] 1


Has someone a solution to not get this warning when a code is ran 
through ssh ?


Thanks

Marc Girondot

__
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] Names of variables needed in newdata for predict.glm

2018-03-07 Thread Marc Girondot via R-help

Hi,

Some try:
> names(mi$xlevels)
[1] "f"
> all.vars(mi$formula)
[1] "D" "x" "f" "Y"
> names(mx$xlevels)
[1] "f"
> all.vars(mx$formula)
[1] "D" "x" "f"

When offset is indicated out of the formula, it does not work...

Marc

Le 07/03/2018 à 06:20, Bendix Carstensen a écrit :

I would like to extract the names, modes [numeric/factor] and levels
of variables needed in a data frame supplied as newdata= argument to
predict.glm()

Here is a small example illustrating my troubles; what I want from
(both of) the glm objects is the vector c("x","f","Y") and an
indication that f is a factor:

library( splines )
dd <- data.frame( D = sample(0:1,200,rep=T),
   x = abs(rnorm(200)),
   f = factor(sample(letters[1:4],200,rep=T)),
   Y = runif(200,0.5,10) )
mx <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) , offset=log(Y) , 
family=poisson, data=dd)
mi <- glm( D ~ ns(x,knots=1:2,Bo=c(0,5)) + f:I(x^2) + offset(log(Y)), 
family=poisson, data=dd)

attr(mx$terms,"dataClasses")
attr(mi$terms,"dataClasses")
mi$xlevels
mx$xlevels

...so far not quite there.

Regards,

Bendix Carstensen

Senior Statistician
Steno Diabetes Center
Clinical Epidemiology
Niels Steensens Vej 2-4
DK-2820 Gentofte, Denmark
b...@bxc.dk
bendix.carsten...@regionh.dk
http://BendixCarstensen.com




Denne e-mail indeholder fortrolig information. Hvis du ikke er den rette 
modtager af denne e-mail eller hvis du modtager den ved en fejltagelse, beder 
vi dig venligst informere afsender om fejlen ved at bruge svarfunktionen. 
Samtidig bedes du slette e-mailen med det samme uden at videresende eller 
kopiere den.

__
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] [FORGED] Re: SE for all levels (including reference) of a factor atfer a GLM

2018-02-16 Thread Marc Girondot via R-help

Le 16/02/2018 à 10:24, Peter Dalgaard a écrit :

To give a short answer to the original question:


On 16 Feb 2018, at 05:02 , Rolf Turner  wrote:

In order to ascribe unique values to the parameters, one must apply a "constraint".  With 
the "treatment contrasts" the constraint is that
beta_1 = 0.

...and consequently, being a constant, has an s.e. of 0.



It makes sense !

Thanks for the precision !

Marc

__
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] SE for all levels (including reference) of a factor atfer a GLM

2018-02-15 Thread Marc Girondot via R-help

Dear R-er,

I try to get the standard error of fitted parameters for factors with a 
glm, even the reference one:


a <- runif(100)
b <- sample(x=c("0", "1", "2"), size=100, replace = TRUE)
df <- data.frame(A=a, B=b, stringsAsFactors = FALSE)

g <- glm(a ~ b, data=df)
summary(g)$coefficients

# I don't get SE for the reference factor, here 0:

  Estimate Std. Error    t value Pr(>|t|)
(Intercept)  0.50384827 0.05616631  8.9706490 2.236684e-14
b1  -0.03598386 0.07496151 -0.4800311 6.322860e-01
b2   0.03208039 0.07063113  0.4541962 6.507023e-01

# Then I try to change the order of factors, for example:

df$B[df$B=="0"] <- "3"
g <- glm(a ~ b, data=df)
summary(g)$coefficients

By I get the same...

Any idea ?

Thanks

Marc

__
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] format integer numbers with leading 0

2018-01-04 Thread Marc Girondot via R-help

Dear R-er,

I would like format integer number as characters with leading 0 for a 
fixed width, for example:


1 shoud be "01"
2 shoud be "02"
20 should be "20"

Now I use:

x <- c(1, 2, 20)

gsub(" ", "0", format(x, width=2))

But I suspect more elegant way could be done directly with format 
options, but I don't find.


Thanks a lot

Marc

__
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] format integer numbers with leading 0

2018-01-04 Thread Marc Girondot via R-help

Dear R-er,

I would like format integer number as characters with leading 0 for a 
fixed width, for example:


1 shoud be "01"
2 shoud be "02"
20 should be "20"

Now I use:

x <- c(1, 2, 20)

gsub(" ", "0", format(x, width=2))

But I suspect more elegant way could be done directly with format 
options, but I don't find.


Thanks a lot

Marc

__
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] Order of methods for optimx

2017-12-31 Thread Marc Girondot via R-help

Dear R-er,

For a non-linear optimisation, I used optim() with BFGS method but it 
stopped regularly before to reach a true mimimum. It was not a problem 
with limit of iterations, just a local minimum. I was able sometimes to 
reach better minimum using several rounds of optim().


Then I moved to optimx() to do the different optim rounds automatically 
using "Nelder-Mead" and "BFGS" methods


I find a huge time difference using system.time() based on the order of 
these both methods:


> snb # "Nelder-Mead" and "BFGS"
    user   system  elapsed
1021.656    0.200 1021.695
> sbn # "BFGS" and "Nelder-Mead"
    user   system  elapsed
3140.096    0.384 3139.728

But optimx() with "Nelder-Mead" and "BFGS" stops in local minimum:

> o_mu2p1$value
[1] 2297.557

whereas "BFGS" and "Nelder-Mead" stops in better model (not sure if it 
is a global minimum, but it is better):


> o_mu2p1$value
[1] 2297.305



My questions are:

Are my findings common and documented (order of methods giving non 
consistant results) or are they specific to the model I try to fit ?


If it is known problem, where I can find the best advice about order of 
methods ?




To reproduce what I said:

install.packages("http://www.ese.u-psud.fr/epc/conservation/CRAN/HelpersMG.tar.gz";, 
repos=NULL, type="source")
install.packages("http://www.ese.u-psud.fr/epc/conservation/CRAN/phenology.tar.gz";, 
repos=NULL, type="source")


library("phenology")
library("car")
library("optimx")
library("numDeriv")

ECFOCF_2002 <- TableECFOCF(MarineTurtles_2002)
snb <- system.time(
  o_mu2p1_nb <- fitCF(par = structure(c(0.244863062899293,
   43.5578630363601,
   4.94764539004454,
   129.606771856887,
   -0.323749593604171,
   1.37326091618759),
 .Names = c("mu1", "size1", "mu2",
    "size2", "p", "OTN")),
 method = c("Nelder-Mead", "BFGS"),
 data=ECFOCF_2002, hessian = TRUE)
)
sbn <- system.time(
  o_mu2p1_bn <- fitCF(par = structure(c(0.244863062899293,
 43.5578630363601,
 4.94764539004454,
 129.606771856887,
 -0.323749593604171,
 1.37326091618759),
   .Names = c("mu1", "size1", "mu2",
   "size2", "p", "OTN")),
   method = c("BFGS", "Nelder-Mead"),
   data=ECFOCF_2002, hessian = TRUE)
)

snb
o_mu2p1_nb$value

sbn
o_mu2p1_bn$value

__
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] Draw Overlapping Circles with shaded tracks

2017-12-31 Thread Marc Girondot via R-help
Another solution:

library("HelpersMG") plot(0:10,type="n",axes=FALSE,xlab="",ylab="", 
asp=1) ellipse(center.x = 3, center.y = 5, radius.x = 5, radius.y = 5, 
lwd=10, col=NA, border=rgb(red = 1, green = 0, blue=0, alpha = 0.5)) 
ellipse(center.x = 8, center.y = 5, radius.x = 5, radius.y = 5, lwd=10, 
col=NA, border=rgb(red = 0, green = 1, blue=0, alpha = 0.5))


(Without the graphic example, it is difficult to know what tit was 
supposed to do !)

Marc

Le 31/12/2017 à 14:10, John Kane via R-help a écrit :
> That code nees the plotrix package:
> library(plotrix)
> pdf("circles.pdf")
> plot(0:10,type="n",axes=FALSE,xlab="",ylab="")
> draw.circle(4,5,radius=3,border="#ffaa",lwd=10)
> draw.circle(6,5,radius=3,border="#ffaa",lwd=10)
> dev.off()
>
>
>   
>
>  On Friday, December 29, 2017, 6:06:32 PM EST, Jim Lemon 
>  wrote:
>   
>   Hi Abou,
> Without an illustration it's hard to work out what you want. here is a
> simple example of two circles using semi-transparency. Is this any
> help?
>
> pdf("circles.pdf")
> plot(0:10,type="n",axes=FALSE,xlab="",ylab="")
> draw.circle(4,5,radius=3,border="#ffaa",lwd=10)
> draw.circle(6,5,radius=3,border="#ffaa",lwd=10)
> dev.off()
>
> Jim
>
> On Fri, Dec 29, 2017 at 9:45 PM, AbouEl-Makarim Aboueissa
>  wrote:
>> Dear All:
>>
>>
>> I am wondering if there is a way in R to draw these two circles with shaded
>> tracks in both circles using R, and make both circles uncovered. I am
>> trying to make it in MS words, but I could not. Your help will be highly
>> appreciated.
>>
>>
>> In my previous post I added the image of the two circles, but the post
>> never published. I just thought to resent the post again without the image.
>>
>> with many thanks
>> abou
>> __
>>
>>
>> *AbouEl-Makarim Aboueissa, PhD*
>>
>> *Professor of Statistics*
>>
>> *Department of Mathematics and Statistics*
>> *University of Southern Maine*
>>
>>          [[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.
>
>   [[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] Help with dates

2017-12-28 Thread Marc Girondot via R-help

Le 28/12/2017 à 18:13, Ramesh YAPALPARVI a écrit :

Hi all,

I’m struggling to get the dates in proper format.
I have dates as factors and is in the form 02/27/34( 34 means 1934). If I use


Try this

x <- "02/27/34"
x2 <- paste0(substr(x, 1, 6), "19", substr(x, 7, 8))
as.Date(x2, format="%m/%d/%Y")
[1] "1934-02-27"

or

x2 <- gsub("(../../)(..)", "\\119\\2", x)

Marc


as.Date with format %d%m%y it gets converted to 2034-02-27. I tried changing 
the origin in the as.Date command but nothing worked. Any help is appreciated.

Thanks,
Ramesh
__
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.



--
__
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.giron...@u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot

__
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] chi-square distribution table

2017-12-19 Thread Marc Girondot via R-help

Le 18/12/2017 à 15:41, HATMZAHARNA via R-help a écrit :
Please could you tell me how to make code to make chi-square 
distribution table?


Please help

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

To help you to begin to do a code that we could enhance, here are some 
functions that will be usefull for you:


> qchisq(p=1-0.05, df=1)
[1] 3.841459

Then, using a range of df, from example 1 to 10:

> qchisq(p=1-0.05, df=1:10)
 [1]  3.841459  5.991465  7.814728  9.487729 11.070498 12.591587 
14.067140 15.507313 16.918978 18.307038


To help to present a nice table:

> X <- qchisq(p=1-0.05, df=1)
> format(X, digits = 4+log10(X), width = 10)
[1] " 3.841"

Or use the xtable package

Sincerely

Marc

__
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] Shiny App inside R Package

2017-09-17 Thread Marc Girondot via R-help

I have this working in my package embryogrowth available in CRAN.

I have a function to call the shiny app:
web.tsd <- function() {

  if (!requireNamespace("shiny", quietly = TRUE)) {
    stop("shiny package is absent; Please install it first")
  }

getFromNamespace("runApp", ns="shiny")(appDir = system.file("shiny", 
package="embryogrowth"),

   launch.browser =TRUE)

}

I have a folder inst and inside a folder shiny.
Within this folder inst/shiny/ I copy the two files server.R and ui.R

Marc

Le 17/09/2017 à 19:31, Axel Urbiz a écrit :

Dear List,

I have a wrapper function that creates a Shiny App, as illustrated below.

I'd like to include the function myApp() inside a package. I'd appreciate
your guidance here, as I could not find good instructions on this online.


myApp <- function(x) {
   require(shiny)
   shinyApp(
 ui = fluidPage(
   sidebarLayout(
 sidebarPanel(sliderInput("n", "Bins", 5, 100, 20)),
 mainPanel(plotOutput("hist"))
   )
 ),
 server = function(input, output) {
   output$hist <- renderPlot(
 hist(x, breaks = input$n,
  col = "skyblue", border = "white")
   )
 }
   )
}

myApp(rnorm(100))

Regards,
Axel.

[[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] please let me unsubscribe or remove me from mailing list.

2017-09-12 Thread Marc Girondot via R-help

Le 12/09/2017 à 16:57, Where's YK a écrit :

Thank you.

from cabi...@gmail.com


Google R-help@r-project.org unsubscribe

bring you to:

https://www.r-project.org/mail.html

Sincerely

Marc

__
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] Rounding of problem with sum command in R

2017-08-23 Thread Marc Girondot via R-help

Le 22/08/2017 à 16:26, niharika singhal a écrit :

Hello I have a vector
v=c(0.0886,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027)
when i do
sum(v)
or
0.0886+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027
i am getting output as 1
But if i add them manually i get
1.0026
I do not want to round of my value since it effect my code further
Can anyone suggest how can i avoid this.

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.


> print(sum(v), digits = 12)
[1] 1.0016

__
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] [FORGED] Re: axis() after image.plot() does not work except if points() is inserted between

2017-07-30 Thread Marc Girondot via R-help

Le 28/07/2017 à 05:32, Paul Murrell a écrit :

plot(1:10)
mtext("margin-label", side=2, at=9, las=1, line=1, adj=0)
par(mfg=c(1,1))
## Only the text within the plot region is drawn
mtext("margin-label", side=2, at=9, las=1, line=1, adj=0, col="red")


It works also for axis(). Thanks a lot.

Marc

__
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] axis() after image.plot() does not work except if points() is inserted between

2017-07-26 Thread Marc Girondot via R-help
Thanks... I agree that the problem was explained in the documentation 
but I can't find a way to have axis() working even manipulating 
par("plt") or with graphics.reset = TRUE:

- adding graphics.reset=TRUE does not allow axis() to be shown;
- I see that par()$plt is involved but it is the not sufficient to 
explain why axis() works because if it is changed by hand, axes are not 
shown.


Thanks for the trick about range(). I didn't notice that it has also a 
na.rm option. It is more elegant.


Here is the code showing the various propositions and checks:


library(fields)
D <- matrix(c(10, 20, 25, 30, 12, 22, 32, 35, 13, 25, 38, 40), nrow=3)
(pplt <- par()$plt)
 [1] 0.08844944 0.95469663 0.14253275 0.88541485

# original problem. Axis() not shown

image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=range(D, na.rm=TRUE),
   las=1, axes=FALSE)
# Check the value of par()$plt; it is indeed modified
par()$plt
 [1] 0.08844944 0.86408989 0.14253275 0.88541485
# axis() does not work
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, 
cex.axis=0.5)


# I restore par("plt") to it original value
par(plt=pplt)

# graphics.reset = TRUE. Axis() not shown

par()$plt
### [1] 0.08844944 0.95469663 0.14253275 0.88541485
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=range(D, na.rm=TRUE),
   las=1, axes=FALSE, graphics.reset = TRUE)
# Check an effect on par()$plt. Indeed with graphics.reset = TRUE 
par()$plt is restored

par()$plt
### [1] 0.08844944 0.95469663 0.14253275 0.88541485
# But the axes at not shown
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, 
cex.axis=0.5)


# Check an effect of points() on par()$plt
# There is an effect
# axes are shown

par()$plt
### [1] 0.08844944 0.95469663 0.14253275 0.88541485
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=range(D, na.rm=TRUE),
   las=1, axes=FALSE)
points(1.5, 1.5, type="p")
par()$plt
### [1] 0.08844944 0.86408989 0.14253275 0.88541485
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, 
cex.axis=0.5)


# Try to reproduce the effect of points() on par()$plt
# axes are not shown. Then points() is doing something else !

image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=range(D, na.rm=TRUE),
   las=1, axes=FALSE)
par(plt=c(0.08844944, 0.86408989, 0.14253275, 0.88541485))
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, 
cex.axis=0.5)

# check that par("plt") is correctly setup
par()$plt
### [1] 0.08844944 0.86408989 0.14253275 0.88541485

I think that it will remain a mystery !
At least the trick with points() is working.

Thanks
Marc


Le 25/07/2017 à 13:03, Martin Maechler a écrit :

Marc Girondot via R-help 
 on Mon, 24 Jul 2017 09:35:06 +0200 writes:

 > Thanks for the proposition. As you see bellow, par("usr") is the same
 > before and after the points() (the full code is bellow):
 > 
 >> par("usr")
 > [1] -0.250  1.250 -0.167  1.167
 >> # if you remove this points() function, axis will show nothing.
 >>
 >> points(1.5, 1.5, type="p")
 >> p2 <- par(no.readonly=TRUE)
 >> par("usr")
 > [1] -0.250  1.250 -0.167  1.167
 > ...

 > I can reproduce it in Ubuntu and MacosX R Gui and Rstudio (R 3.4.1).

 > Marc

 > Here is the code:
 > library(fields)
 > par(mar=c(5,4.5,4,7))
 > D <- matrix(c(10, 20, 25, 30, 12, 22, 32, 35, 13, 25, 38, 40), nrow=3)

 > p0 <- par(no.readonly=TRUE)
 > image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
 >   ylab="Columns", cex.lab = 0.5,
 >   zlim=c(min(D, na.rm=TRUE),max(D, na.rm=TRUE)),
 >   las=1, axes=FALSE)
 > p1 <- par(no.readonly=TRUE)

 > par("usr")
 > par("xpd")

 > # if you remove this points() function, axis will show nothing.

 > points(1.5, 1.5, type="p")
 > p2 <- par(no.readonly=TRUE)
 > par("usr")
 > par("xpd")

 > ##
 > axis(1, at=seq(from=0, to=1, length=nrow(D)), l

Re: [R] axis() after image.plot() does not work except if points() is inserted between

2017-07-24 Thread Marc Girondot via R-help
Thanks for the proposition. As you see bellow, par("usr") is the same 
before and after the points() (the full code is bellow):


> par("usr")
[1] -0.250  1.250 -0.167  1.167
> # if you remove this points() function, axis will show nothing.
>
> points(1.5, 1.5, type="p")
> p2 <- par(no.readonly=TRUE)
> par("usr")
[1] -0.250  1.250 -0.167  1.167
...

I can reproduce it in Ubuntu and MacosX R Gui and Rstudio (R 3.4.1).

Marc

Here is the code:
library(fields)
par(mar=c(5,4.5,4,7))
D <- matrix(c(10, 20, 25, 30, 12, 22, 32, 35, 13, 25, 38, 40), nrow=3)

p0 <- par(no.readonly=TRUE)
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D,
na.rm=TRUE)),
   las=1, axes=FALSE)
p1 <- par(no.readonly=TRUE)

par("usr")
par("xpd")

# if you remove this points() function, axis will show nothing.

points(1.5, 1.5, type="p")
p2 <- par(no.readonly=TRUE)
par("usr")
par("xpd")

##
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1,
 cex.axis=0.5)

identical(p1, p2)




Le 24/07/2017 à 05:17, Jim Lemon a écrit :

Hi marc,
Try:

par("usr")

before and after the call to points and see if it changes.

Jim


On Sat, Jul 22, 2017 at 12:05 AM, Marc Girondot via R-help
 wrote:

It is known (several discussions on internet) that axis() cannot be used
after fields:::image.plot() (axis() shows nothing).

However, if points(1.5, 1.5, type="p") is inserted before the axis()
finctions, it works.

I have investigated what points(1.5, 1.5, type="p") is doing to allow axis
to work and I don't find a solution. par() options are identical (p1 and p2
are identical).

Has someone a solution ?

Thanks

Marc

library(fields)
p0 <- par(no.readonly=TRUE)
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
ylab="Columns", cex.lab = 0.5, zlim=c(min(D, na.rm=TRUE),max(D,
na.rm=TRUE)),
las=1, axes=FALSE)
p1 <- par(no.readonly=TRUE)

# if you remove this points() function, axis will show nothing.

points(1.5, 1.5, type="p")
p2 <- par(no.readonly=TRUE)

##
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1,
cex.axis=0.5)

identical(p1, p2)

__
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] axis() after image.plot() does not work except if points() is inserted between

2017-07-21 Thread Marc Girondot via R-help
It is known (several discussions on internet) that axis() cannot be used 
after fields:::image.plot() (axis() shows nothing).


However, if points(1.5, 1.5, type="p") is inserted before the axis() 
finctions, it works.


I have investigated what points(1.5, 1.5, type="p") is doing to allow 
axis to work and I don't find a solution. par() options are identical 
(p1 and p2 are identical).


Has someone a solution ?

Thanks

Marc

library(fields)
p0 <- par(no.readonly=TRUE)
image.plot(D, col=rev(heat.colors(128)),bty="n", xlab="Lines",
   ylab="Columns", cex.lab = 0.5, zlim=c(min(D, 
na.rm=TRUE),max(D, na.rm=TRUE)),

   las=1, axes=FALSE)
p1 <- par(no.readonly=TRUE)

# if you remove this points() function, axis will show nothing.

points(1.5, 1.5, type="p")
p2 <- par(no.readonly=TRUE)

##
axis(1, at=seq(from=0, to=1, length=nrow(D)), labels=0:2, cex.axis=0.5)
axis(2, at=seq(from=0, to=1, length=ncol(D)), labels=0:3, las=1, 
cex.axis=0.5)


identical(p1, p2)

__
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] optim() has a non-consistent way to send parameter for different methods

2017-06-23 Thread Marc Girondot via R-help
When optim() is used with method="BFGS", the name of parameters within 
the vector are transmitted (see below, first example).


When method="Brent", the name of parameter (only one parameter can be 
fitted with Brent method) is not transmitted. As there is only one, of 
course, we know which parameter it is, but it makes things 
non-consistent between methods.


It would be better that same convention is used for different method.

Marc

Tested in R-3.4.0

For example, here:

@@@
Method BFGS
@@@

# The names of values in par are transmitted
fitnorm_meansd<-function(par, val) {
  print(par)
  -sum(dnorm(x=val, mean=par["mean"], sd=par["sd"], log = TRUE))
}

val <- rnorm(100, mean=20, sd=2)
p<-c(mean=20, sd=2)
result<-optim(par=p, fn=fitnorm_meansd, val=val, method="BFGS")

The print(par) shows the named vector:
> result<-optim(par=p, fn=fitnorm_meansd, val=val, method="BFGS")
mean   sd
  202
  mean sd
20.001  2.000
  mean sd
19.999  2.000
  mean sd
20.000  2.001
etc...

@@@
Method Brent
@@@

# The name of value in par is not transmitted

fitnorm_mean<-function(par, val) {
  print(par)
  -sum(dnorm(x=val, mean=par, sd=2, log = TRUE))
}

val <- rnorm(100, mean=20, sd=2)
p<-c(mean=20)
result<-optim(par=p, fn=fitnorm_mean, val=val, method="Brent", lower=10, 
upper=30)



The print(par) does not show named vector:
> result<-optim(par=p, fn=fitnorm_mean, val=val, method="Brent", 
lower=10, upper=30)

[1] 17.63932
[1] 22.36068

__
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] stepAIC() that can use new extractAIC() function implementing AICc

2017-06-08 Thread Marc Girondot via R-help

I have found the problem and a solution.

The problem comes from the functions addterm.glm() and dropterm.glm() 
from MASS package. They use extractAIC() without transmitting the ... 
argument:


aic <- aic + (extractAIC(object, k = k)[2L] - aic[1L])

I replace the call with:
aic <- aic + (extractAIC(object, k = k, ...)[2L] - aic[1L])

and I create dropterm.glm() and addterm.glm() in global environnement.
I add:
dropterm <- dropterm.lm <- dropterm.glm
addterm <- addterm.lm <- addterm.glm

I copy also stepAIC from MASS package to global environnement.
I detach MASS package, and it works:

> stepAIC(G1, criteria="AICc", steps = 1)
Start:  AIC=70.06
x ~ A + B

   Df DevianceAIC
- A 1   48.506 68.355
  47.548 70.055
- B 1   57.350 70.867

Now stepAIC can use AICc

Marc

__
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] stepAIC() that can use new extractAIC() function implementing AICc

2017-06-07 Thread Marc Girondot via R-help
I would like test AICc as a criteria for model selection for a glm using 
stepAIC() from MASS package.


Based on various information available in WEB, stepAIC() use 
extractAIC() to get the criteria used for model selection.


I have created a new extractAIC() function (and extractAIC.glm() and 
extractAIC.lm() ones) that use a new parameter criteria that can be AIC, 
BIC or AICc.


It works as expected using extractAIC() but when I run stepAIC(), the 
first AIC shown in the result is correct, but after it still shows the 
original AIC:


For example (the full code is below) the "Start:  AIC=70.06" is indeed 
the AICc but after, "  47.548 67.874" is the AIC.


> stepAIC(G1, criteria="AICc")
Start:  AIC=70.06
x ~ A + B

   Df DevianceAIC
- A 1   48.506 66.173
  47.548 67.874
- B 1   57.350 68.685

Thanks if you can help me that stepAIC() use always the new extractAIC() 
function.


Marc




library("MASS")
set.seed(1)

df <- data.frame(x=rnorm(15, 15, 2))
for (i in 1:10) {
  df <- cbind(df, matrix(data = rnorm(15, 15, 2), ncol=1, 
dimnames=list(NULL, LETTERS[i])))

}

G1 <- glm(formula = x ~ A + B,
  data=df, family = gaussian(link = "identity"))

extractAIC(G1)
stepAIC(G1)

extractAIC.glm <- function(fit, scale, k = 2, criteria = c("AIC", 
"AICc", "BIC"), ...) {

  criteria <- match.arg(arg=criteria, choice=c("AIC", "AICc", "BIC"))
  AIC <- fit$aic
  edf <- length(fit$coefficients)
  n <- nobs(fit, use.fallback = TRUE)
  if (criteria == "AICc") return(c(edf, AIC + (2*edf*(edf+1))/(n - edf 
-1)))

  if (criteria == "AIC")  return(c(edf, AIC-2*edf + k*edf))
  if (criteria == "BIC")  return(c(edf, AIC -2*edf + log(n)*edf))
}

extractAIC <- extractAIC.lm <- extractAIC.glm

extractAIC(G1, criteria="AIC")
extractAIC(G1, k=log(15))
extractAIC(G1, criteria="BIC")
stats:::extractAIC.glm(G1, k=log(15))
extractAIC(G1, criteria="AICc")

stepAIC(G1)
stepAIC(G1, criteria="AICc")

__
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] glm and stepAIC selects too many effects

2017-06-05 Thread Marc Girondot via R-help

This is a question at the border between stats and r.

When I do a glm with many potential effects, and select a model using 
stepAIC, many independent variables are selected even if there are no 
relationship between dependent variable and the effects (all are random 
numbers).


Do someone has a solution to prevent this effect ? Is it related to 
Bonferoni correction ?


Is there is a ratio of independent vs number of observations that is 
safe for stepAIC ?


Thanks

Marc

Example of code. When 2 independent variables are included, no effect is 
selected, when 11 are included, 7 to 8 are selected.


x <- rnorm(15, 15, 2)
A <- rnorm(15, 20, 5)
B <- rnorm(15, 20, 5)
C <- rnorm(15, 20, 5)
D <- rnorm(15, 20, 5)
E <- rnorm(15, 20, 5)
F <- rnorm(15, 20, 5)
G <- rnorm(15, 20, 5)
H <- rnorm(15, 20, 5)
I <- rnorm(15, 20, 5)
J <- rnorm(15, 20, 5)
K <- rnorm(15, 20, 5)

df <- data.frame(x=x, A=A, B=B, C=C, D=D,
 E=E, F=F, G=G, H=H, I=I, J=J,
 K=K)

G1 <- glm(formula = x ~ A + B,
 data=df, family = gaussian(link = "identity"))

g1 <- stepAIC(G1)

summary(g1)

G2 <- glm(formula = x ~ A + B + C + D + E + F + G + H + I + J + K,
 data=df, family = gaussian(link = "identity"))

g2 <- stepAIC(G2)

summary(g2)

__
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] optimx and follow.on=TRUE... does not follow

2017-05-17 Thread Marc Girondot via R-help

Hi,

I would like to know if some of you have a solution for this problem:

I use optimx (from package optimx) to fit the parameters of a model 
(complex model based on several imbricated exponential functions).


I use the two methods : method = c("Nelder-Mead", "BFGS") with the options:

control=list(dowarn=FALSE, follow.on=TRUE, kkt=FALSE, trace=1, 
REPORT=100, maxit=1000)


For some situations, it works as expected, but not for others.

The problem occurs at the transition between the two methods:

For example at the end of the Nelder-Mead method the value is 47.55839 
but at the beginning of the BFGS it drops again at 47.62xxx and at the 
end of the BFGS it is "only" 47.56198, so a local minimum (see below a 
result).


 DHA  DHH T12Hvalue fevals gevals niter 
convcode kkt1 kkt2  xtimes


Nelder-Mead 46.93154 39.94028 318.4949 47.55839409 NA NA   
10   NA   NA 156.896
BFGS45.29744 36.80026 321.5996 47.56198 54  5 NA
0   NA   NA  32.604


After investigations, it seems that when parameters are transmitted from 
one method to the next, the values is truncated at the 5th digit. And as 
my model has several exponential functions imbricated, it is very 
sensitive to the precision of the parameters. It does not change the 
main conclusion, but I would prefer not have such a problem.


Does someone has a solution ?

I would prefer continue to use optimx.

Thanks a lot.

Marc

__
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] Different output for "if else" and "ifelse" that I don't understand

2017-04-28 Thread Marc Girondot via R-help

Dear list-members,

During the test phase of a function, I run it interactively (in Rstudio) 
and the ... produces an error. Then I use this to read it:


if (class(try(list(...), silent=TRUE))=="try-error") p3p <- list() else 
p3p <- list(...)


It works fine; interactively I will get

> if (class(try(list(...), silent=TRUE))=="try-error") p3p <- list() 
else p3p <- list(...)

> p3p
list()

and within a function I will get a list with the ... value. Perfect.

I wanted to simplify the line by doing:

p3p <- ifelse(class(try(list(...), silent=TRUE))=="try-error", list(), 
list(...))


In interactive mode, it works but within a function, I don't get the 
names of the parameters. I don't understand the logic behind this 
difference. Have you an idea ?


Thanks

Marc


> Try1 <- function(...) {
+   if (class(try(list(...), silent=TRUE))=="try-error") p3p <- list() 
else p3p <- list(...)

+   return(p3p)
+ }
> Try1(k=100)
$k
[1] 100

> Try1()
list()
> Try2 <- function(...) {
+   p3p <- ifelse(class(try(list(...), silent=TRUE))=="try-error", 
list(), list(...))

+   return(p3p)
+ }
> Try2(k=100)
[[1]]
[1] 100

> Try2()
[[1]]
NULL

__
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] "found 4 marked UTF-8 strings" during check of package... but where !

2017-03-10 Thread Marc Girondot via R-help

Thanks Duncan and Michael,

Indeed I have data file with utf-8 characters inside. In the 
DESCRIPTION, I have the line Encoding: UTF-8

but it seems to not be sufficient.
In each R page for these data, I have also :
#' @docType data
#' @encoding UTF-8

But I still have the notes during check when I try to submit the package 
in CRAN (not in local --as-cran check).


How I could "say" that these data have utf-8 characters inside?

Thanks
Marc


Le 10/03/2017 à 15:24, Duncan Murdoch a écrit :

On 10/03/2017 2:52 AM, Marc Girondot via R-help wrote:

Dear members,

I want submit to CRAN a new version of a package that I maintain. When I
check locally "as-cran" no note or error are reported but the link after
submission reports several notes and one warning:

For example:

using R Under development (unstable) (2017-03-05 r72309)
using platform: x86_64-apple-darwin16.4.0 (64-bit)
using session charset: UTF-8
...
checking extension type ... Package
this is package ‘embryogrowth’ version ‘6.4’
package encoding: UTF-8
...
checking data for non-ASCII characters ... NOTE
   Note: found 4 marked UTF-8 strings

I have the same with
using R version 3.3.0 (2016-05-03)
using platform: x86_64-apple-darwin13.4.0 (64-bit)

but not with some others such as r-devel-linux-x86_64-debian-gcc

Based on the message, "Note: found 4 marked UTF-8 strings", it seems
that "4 marked UTF-8 strings" are present in the package and it is a
problem...

Is there any solution to know in which file?


It's one containing an object coming from your data directory.

R won't give more detail than that, but if you still can't guess, you 
could get some idea by debugging the check code:


debug(tools:::.check_package_datasets)
tools:::.check_package_datasets(pkg)

where pkg contains the path to the package source code.  That function 
does the checking one variable at a time.


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] "found 4 marked UTF-8 strings" during check of package... but where !

2017-03-10 Thread Marc Girondot via R-help

Dear members,

I want submit to CRAN a new version of a package that I maintain. When I 
check locally "as-cran" no note or error are reported but the link after 
submission reports several notes and one warning:


For example:

using R Under development (unstable) (2017-03-05 r72309)
using platform: x86_64-apple-darwin16.4.0 (64-bit)
using session charset: UTF-8
...
checking extension type ... Package
this is package ‘embryogrowth’ version ‘6.4’
package encoding: UTF-8
...
checking data for non-ASCII characters ... NOTE
  Note: found 4 marked UTF-8 strings

I have the same with
using R version 3.3.0 (2016-05-03)
using platform: x86_64-apple-darwin13.4.0 (64-bit)

but not with some others such as r-devel-linux-x86_64-debian-gcc

Based on the message, "Note: found 4 marked UTF-8 strings", it seems 
that "4 marked UTF-8 strings" are present in the package and it is a 
problem...


Is there any solution to know in which file?

Thanks
Marc

__
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] roxygen2 v6.0.0

2017-02-06 Thread Marc Girondot via R-help

Le 06/02/2017 à 17:14, Yihui Xie a écrit :

If your package source is version controlled (meaning you are free to
regret any time), I'd recommend you to delete the three files
NAMESPACE, chr.Rd, and essai-package.Rd. Then try to roxygenize again.
Basically the warnings you saw indicates that roxygen2 failed to find
the line

% Generated by roxygen2: do not edit by hand

in your NAMESPACE and .Rd files, so it thinks these files were
probably not previously generated by roxygen2. I think the cause is
package.skeleton(), which generated the Rd files. Seriously, friends
don't let friends use package.skeleton()... (it is 2017 now)
Thanks ! It works perfectly after removing the /man/ folder and the 
NAMESPACE file.

I didn't know that package.skeleton() was out-of-age !
That's true that it is easy to generate the skeleton manually.

Marc


Regards,
Yihui
--
Yihui Xie 
Web: http://yihui.name


On Mon, Feb 6, 2017 at 9:46 AM, Marc Girondot via R-help
 wrote:

Hi,

I used roxygen2 v5.0.1 to document my package, and all was ok. I have just
updated to roxygen2 v6.0.0 and my script is broken and I can't find why.

I have done a simple version of a package folder as a test with 3 files:
chr.R, essai-package.R and DESCRIPTION.

Previously, I did:

package.skeleton("essai",code_files=c('chr.R',"essai-package.R"))
roxygenize("essai")
system(paste0("R CMD build '", getwd(), "/essai'"))
install.packages(file.path(getwd(), "essai_1.0.tar.gz"), repos = NULL,
type="source")

And it worked well.

Now I get an error at the second line: roxygenize("essai")


roxygenize("essai")

First time using roxygen2. Upgrading automatically...
Updating roxygen version in
/Users/marcgirondot/Documents/Espace_de_travail_R/Package_Essai/essai/DESCRIPTION
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, and
will not be overwritten.
Warning: The existing 'chr.Rd' file was not generated by roxygen2, and will
not be overwritten.
Warning: The existing 'essai-package.Rd' file was not generated by roxygen2,
and will not be overwritten.

And of course it fails after.

Are you aware of this situation ? And do you have a solution ?

Thanks a lot

Marc


A file DESCRIPTION:

Package: essai
Type: Package
Title: Package Used For Try
Version: 1.0
Date: 2017-02-06
Author: Marc Girondot 
Maintainer: Marc Girondot 
Description: Trying package.
Depends: R (>= 2.14.2)
License: GPL-2
LazyData: yes
LazyLoad: yes
Encoding: UTF-8
RoxygenNote: 6.0.0

A file essai-package.R (essai=try in French):

#' Trying package
#'
#' \tabular{ll}{
#'  Package: \tab essai\cr
#'  Type: \tab Package\cr
#'  Version: \tab 1.0 - build 1\cr
#'  Date: \tab 2017-02-06\cr
#'  License: \tab GPL (>= 2)\cr
#'  LazyLoad: \tab yes\cr
#'  }
#' @title The package essai
#' @author Marc Girondot \email{marc.girondot@@u-psud.fr}
#' @docType package
#' @name essai-package

NULL

A file chr.R:

#' chr returns the characters defined by the codes
#' @title Return the characters defined by the codes
#' @author Based on this blog:
http://datadebrief.blogspot.com/2011/03/ascii-code-table-in-r.html
#' @return A string with characters defined by the codes
#' @param n The vector with codes
#' @description Return a string with characters defined by the codes.
J'essaye avec un code utf-8: ê.
#' @examples
#' chr(65:75)
#' chr(unlist(tapply(144:175, 144:175, function(x) {c(208, x)})))
#' @encoding UTF-8
#' @export


chr <- function(n) {
 rawToChar(as.raw(n))
 }

__
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] roxygen2 v6.0.0

2017-02-06 Thread Marc Girondot via R-help

Hi,

I used roxygen2 v5.0.1 to document my package, and all was ok. I have 
just updated to roxygen2 v6.0.0 and my script is broken and I can't find 
why.


I have done a simple version of a package folder as a test with 3 files: 
chr.R, essai-package.R and DESCRIPTION.


Previously, I did:

package.skeleton("essai",code_files=c('chr.R',"essai-package.R"))
roxygenize("essai")
system(paste0("R CMD build '", getwd(), "/essai'"))
install.packages(file.path(getwd(), "essai_1.0.tar.gz"), repos = NULL, 
type="source")


And it worked well.

Now I get an error at the second line: roxygenize("essai")

> roxygenize("essai")
First time using roxygen2. Upgrading automatically...
Updating roxygen version in 
/Users/marcgirondot/Documents/Espace_de_travail_R/Package_Essai/essai/DESCRIPTION
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, 
and will not be overwritten.
Warning: The existing 'chr.Rd' file was not generated by roxygen2, and 
will not be overwritten.
Warning: The existing 'essai-package.Rd' file was not generated by 
roxygen2, and will not be overwritten.


And of course it fails after.

Are you aware of this situation ? And do you have a solution ?

Thanks a lot

Marc


A file DESCRIPTION:

Package: essai
Type: Package
Title: Package Used For Try
Version: 1.0
Date: 2017-02-06
Author: Marc Girondot 
Maintainer: Marc Girondot 
Description: Trying package.
Depends: R (>= 2.14.2)
License: GPL-2
LazyData: yes
LazyLoad: yes
Encoding: UTF-8
RoxygenNote: 6.0.0

A file essai-package.R (essai=try in French):

#' Trying package
#'
#' \tabular{ll}{
#'  Package: \tab essai\cr
#'  Type: \tab Package\cr
#'  Version: \tab 1.0 - build 1\cr
#'  Date: \tab 2017-02-06\cr
#'  License: \tab GPL (>= 2)\cr
#'  LazyLoad: \tab yes\cr
#'  }
#' @title The package essai
#' @author Marc Girondot \email{marc.girondot@@u-psud.fr}
#' @docType package
#' @name essai-package

NULL

A file chr.R:

#' chr returns the characters defined by the codes
#' @title Return the characters defined by the codes
#' @author Based on this blog: 
http://datadebrief.blogspot.com/2011/03/ascii-code-table-in-r.html

#' @return A string with characters defined by the codes
#' @param n The vector with codes
#' @description Return a string with characters defined by the codes. 
J'essaye avec un code utf-8: ê.

#' @examples
#' chr(65:75)
#' chr(unlist(tapply(144:175, 144:175, function(x) {c(208, x)})))
#' @encoding UTF-8
#' @export


chr <- function(n) {
rawToChar(as.raw(n))
}

__
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] Function that works within a package and not when copied in global environment. Why?

2017-02-02 Thread Marc Girondot via R-help

Thanks Bert for the explanation about identical.

For the vectorize.args, note that vectorize.args is not a function but 
an variable that is unknown in the namespace nlWaldTest.


> nlWaldTest::vectorize.args
Erreur : 'vectorize.args' n'est pas un objet exporté depuis 
'namespace:nlWaldTest'



Furthermore, if the function is created from a copy of the original one:

smartsub <- getFromNamespace(".smartsub", ns="nlWaldTest")

or if it is created manually: by copy-paste of the code:

smartsub2 <- function (pat, repl, x)
 {
 args <- lapply(as.list(match.call())[-1L], eval, parent.frame())
 names <- if (is.null(names(args)))
 character(length(args))
 else names(args)
 dovec <- names %in% vectorize.args
 do.call("mapply", c(FUN = FUN, args[dovec], MoreArgs = 
list(args[!dovec]),

 SIMPLIFY = SIMPLIFY, USE.NAMES = USE.NAMES))
 }

Both are defined in the global env, but the first one works and not the 
second one.


I am surprised and don't understand how it is possible.

Sincerely

Marc Girondot


2. You need to review how namespaces work. From the "Writing R
extensions" manual:

"The namespace controls the search strategy for variables used by
**functions in the package**. If not found locally, R searches the
package namespace first, then the imports, then the base namespace and
then the normal search path."

So if vectorize.args() is among the package functions, it will be
found by package functions but not by those you write unless
specifically qualified by :: or ::: depending on whether it is
exported.

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 Thu, Feb 2, 2017 at 6:30 AM, Marc Girondot via R-help
 wrote:

Dear experts,

In the package nlWaldTest, there is an hidden function : .smartsub

I can use it, for example:


getFromNamespace(".smartsub", ns="nlWaldTest")(pat="x", repl="b" ,

x="essai(b[1], b[2], x[1])")
[1] "essai(b[1], b[2], b[1])"

Now I try to create this function in my global environment:
smartsub <- getFromNamespace(".smartsub", ns="nlWaldTest")

It works also:

smartsub(pat="x", repl="b" , x="essai(b[1], b[2], x[1])")

[1] "essai(b[1], b[2], b[1])"

But if I create the function manually:

smartsub2 <- function (pat, repl, x)

  {
  args <- lapply(as.list(match.call())[-1L], eval, parent.frame())
  names <- if (is.null(names(args)))
  character(length(args))
  else names(args)
  dovec <- names %in% vectorize.args
  do.call("mapply", c(FUN = FUN, args[dovec], MoreArgs =
list(args[!dovec]),
  SIMPLIFY = SIMPLIFY, USE.NAMES = USE.NAMES))
  }

smartsub2(pat="x", repl="b" , x="essai(b[1], b[2], x[1])")

Error in names %in% vectorize.args : objet 'vectorize.args' introuvable

It fails because vectorize.args is unknown

Indeed smartsub2 is different from smartsub.

identical(smartsub, smartsub2)

[1] FALSE

1/ Why are they different? They are just a copy of each other.

2/ Second question, vectorize.args is indeed not defined before to be used
in the function. Why no error is produced in original function?

Thanks a lot

Marc


--

__
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.giron...@u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot

__
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] Function that works within a package and not when copied in global environment. Why?

2017-02-02 Thread Marc Girondot via R-help

Dear experts,

In the package nlWaldTest, there is an hidden function : .smartsub

I can use it, for example:

> getFromNamespace(".smartsub", ns="nlWaldTest")(pat="x", repl="b" ,
x="essai(b[1], b[2], x[1])")
[1] "essai(b[1], b[2], b[1])"

Now I try to create this function in my global environment:
smartsub <- getFromNamespace(".smartsub", ns="nlWaldTest")

It works also:
> smartsub(pat="x", repl="b" , x="essai(b[1], b[2], x[1])")
[1] "essai(b[1], b[2], b[1])"

But if I create the function manually:
> smartsub2 <- function (pat, repl, x)
 {
 args <- lapply(as.list(match.call())[-1L], eval, parent.frame())
 names <- if (is.null(names(args)))
 character(length(args))
 else names(args)
 dovec <- names %in% vectorize.args
 do.call("mapply", c(FUN = FUN, args[dovec], MoreArgs = 
list(args[!dovec]),

 SIMPLIFY = SIMPLIFY, USE.NAMES = USE.NAMES))
 }
> smartsub2(pat="x", repl="b" , x="essai(b[1], b[2], x[1])")
Error in names %in% vectorize.args : objet 'vectorize.args' introuvable

It fails because vectorize.args is unknown

Indeed smartsub2 is different from smartsub.
> identical(smartsub, smartsub2)
[1] FALSE

1/ Why are they different? They are just a copy of each other.

2/ Second question, vectorize.args is indeed not defined before to be 
used in the function. Why no error is produced in original function?


Thanks a lot

Marc


--

__
Marc Girondot, Pr

Laboratoire Ecologie, Systématique et Evolution
Equipe de Conservation des Populations et des Communautés
CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079
Bâtiment 362
91405 Orsay Cedex, France

Tel:  33 1 (0)1.69.15.72.30   Fax: 33 1 (0)1.69.15.73.53
e-mail: marc.giron...@u-psud.fr
Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html
Skype: girondot

__
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] g parameter for deltaMethod() as a function

2017-01-31 Thread Marc Girondot via R-help

Dear John and list members,

I have found a solution using the package nlWaldTest. I post the 
solution in case someone else will have this problem.


Here is a summary of the problem:
I would like use the delta method for a function for which no derivative 
using D() can be calculated. I would like rather use numerical derivative.


Here is the solution. In the two first examples, symbolic derivative is 
used.


library(car)
m1 <- lm(time ~ t1 + t2, data = Transact)
deltaMethod(coef(m1), "t1/t2", vcov.=vcov(m1))

library("nlWaldTest")
nlConfint(obj = NULL, texts="b[2]/b[3]", level = 0.95, coeff = coef(m1),
  Vcov = vcov(m1), df2 = TRUE, x = NULL)

# Now numerical derivative is used. The result is the same.

try_g <- function(...) {
  par <- list(...)
  return(par[[1]]/par[[2]])
}

nlConfint(obj = NULL, texts="try_g(b[2], b[3])", level = 0.95, coeff = 
coef(m1),

  Vcov = vcov(m1), df2 = TRUE, x = NULL)

Marc

__
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] g parameter for deltaMethod() as a function

2017-01-30 Thread Marc Girondot via R-help
Le 30/01/2017 � 19:04, Fox, John a �crit :
>> Hi everyone,
>>
>> I try to use the Default S3 method DeltaMethod() from car package, but I
>> have some problems when I try to use a function as the "g" parameter. I
>> don't know if it is possible anyway. I hope that you could tell me:
> I don't see how that would work. From ?deltaMethod: "g [the second argument]: 
> A quoted string that is the function of the parameter estimates to be 
> evaluated; see the details below."
>
> A possible solution would be to write a wrapper function that prepares a 
> proper call to deltaMethod().

Hi John,

This is exactly what I try to do: a wrapper (I forget that name in 
English !).

I have made some progress to do a wrapper function:

try_g <- function(...) {
   par <- list(...)
   return(par$t1/par$t2)
}

try_g(t1=1, t2=2)
deltaMethod(coef(m1), "try_g(t1, t2)", vcov.=vcov(m1))

The wrapper function try_g is accepted now, but I get an error because 
deltaMethod() tried to do symbolic derivative:

 > deltaMethod(coef(m1), "try_g(t1, t2)", vcov.=vcov(m1))
Error in D(g, names(para)[i]) :
   La fonction 'try_g' n'est pas dans la table des d�riv�es 
(translation: The function 'try_g' is not in the table of derivative 
functions).

I was hopping that numeric approximation of derivative (example 
numDeriv::grad() or deriv() ) could be used, but it is not the case.

Thanks

Marc


[[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] g parameter for deltaMethod() as a function

2017-01-30 Thread Marc Girondot via R-help

Hi everyone,

I try to use the Default S3 method DeltaMethod() from car package, but I 
have some problems when I try to use a function as the "g" parameter. I 
don't know if it is possible anyway. I hope that you could tell me:


Here an example from the help of deltaMethod(). It works and I 
understand well (I think at least !).


library(car)
m1 <- lm(time ~ t1 + t2, data = Transact)
deltaMethod(coef(m1), "t1/t2", vcov.=vcov(m1))

###

I would like do the same with a function instead of "t1/t2":

try_g <- function(...) {
  par <- list(...)
  return(par$t1/par$t2)
}

try_g(t1=1, t2=2)
deltaMethod(coef(m1), "try_g", vcov.=vcov(m1))

But I get an error:

Error in as.data.frame.default(x[[i]], optional = TRUE) :
  cannot coerce class ""function"" to a data.frame

If someone could give me the solution... or tell me if it is impossible !

Thanks

Marc

PS. In fine I would like using deltaMethod() to produce a confidence 
interval after fitting a model using ML with optim.


__
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] \n and italic() in legend()

2016-12-29 Thread Marc Girondot via R-help

Hi,
Thanks a lot to Duncan Mackay for the trick using atop() [but the 
legends are centered and not left aligned] and also for the suggestion 
of William Michels to use simply ",". However this last solution 
prevents to use several legends.


Here is a solution to allow both return within a legend and several legends:
plot(1, 1)
v1 <- c(expression(italic("p")*"-value"), expression("based on 
"*italic("t")*"-test"))
v2 <- c(expression(italic("w")*"-value for A"), expression("and B 
identical models"))
legend("topright", legend=c(v1, v2), lty=c(1, 0, 1, 0), y.intersp = 1, 
bty="n", col=c("black", "", "red", ""))


Thanks again

Marc


Le 29/12/2016 à 10:54, Duncan Mackay a écrit :

Hi Marc

Try atop

plot(1, 1)
v1 <- expression(atop(italic("p")*"-value","based on "*italic("t")*"-test"))
legend("topright", legend=v1, y.intersp = 3, bty="n")


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc
Girondot via R-help
Sent: Thursday, 29 December 2016 20:35
To: R-help Mailing List
Subject: [R] \n and italic() in legend()

Hi everyone,

Could someone help me to get both \n (return) and italic() in a legend.
Here is a little example showing what I would like (but without the
italic) and second what I get:

plot(1, 1)
v1 <- "p-value\nbased on t-test"
legend("topright", legend=v1, y.intersp = 3, bty="n")

plot(1, 1)
v1 <- expression(italic("p")*"-value\nbased on "*italic("t")*"-test")
legend("topright", legend=v1, y.intersp = 3, bty="n")

The second one shows :

-value
pbased on t-test

rather than the expected:

p-value
based on t-test

Thanks a lot,

Marc

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


[R] \n and italic() in legend()

2016-12-29 Thread Marc Girondot via R-help

Hi everyone,

Could someone help me to get both \n (return) and italic() in a legend. 
Here is a little example showing what I would like (but without the 
italic) and second what I get:


plot(1, 1)
v1 <- "p-value\nbased on t-test"
legend("topright", legend=v1, y.intersp = 3, bty="n")

plot(1, 1)
v1 <- expression(italic("p")*"-value\nbased on "*italic("t")*"-test")
legend("topright", legend=v1, y.intersp = 3, bty="n")

The second one shows :

-value
pbased on t-test

rather than the expected:

p-value
based on t-test

Thanks a lot,

Marc

__
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] MC_CORES and mc.cores for parallel package

2016-12-07 Thread Marc Girondot via R-help

Hi,

From the documentation of ?options

Options set in package parallel
These will be set when package parallel (or its namespace) is loaded if 
not already set.


mc.cores:
a integer giving the maximum allowed number of additional R processes 
allowed to be run in parallel to the current R process. Defaults to the 
setting of the environment variable MC_CORES if set. Most applications 
which use this assume a limit of 2 if it is unset.


Then I try:
> getOption("mc.cores")
NULL

I suspect that my environment variable MC_CORES is not set. I test and 
that's right:

> Sys.getenv("MC_CORES")
[1] ""

Then I do:
> Sys.setenv(MC_CORES=4)
> Sys.getenv("MC_CORES")
[1] "4"

But when I try again getOption("mc.cores"); it does not change:
> getOption("mc.cores")
NULL

Probably I do something wrong but I don't see what !

Thanks

Marc

__
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] Limit the y-axis line with ggplot2 (not the axis itself, but the line used at the left of the graph)

2016-10-24 Thread Marc Girondot via R-help

Hello everybody,

Using ggplot2 package, is there a way to force to stop the y-axis line 
at a specified point ? (not using ylim because I want that some text 
written using annotate() at the top of the graph is still shown).


Bellow is a simple example to show what I would like do:

Thanks a lot

Marc





library("ggplot2")

g <- ggplot()+
  geom_point(aes(x=c(20, 29, 32), y=c(0, 0.4, 1)))+
  scale_y_continuous(breaks=c(0, 0.25, 0.5, 0.75, 1))+
  labs(x="Label for x axis")+
  labs(y="Label for y axis") +
  annotate("text", x = 25 , y=1.2, label="Text 1")+
  annotate("text", x = 22 , y=1.0, label="How to stop the y-axis line 
here !")+

  geom_segment(aes(x=25, xend=25, y=0, yend=1.1), linetype=2)+
  # This part is just to make it more nice
  theme(panel.background = element_rect(fill = 'white'),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(0.5, 1, 0.5, 0.5), "cm"),
axis.text.x=element_text(size=14),
axis.text.y=element_text(size=14),
axis.title.x=element_text(size=18),
axis.title.y=element_text(size=18),
axis.ticks.length=unit(0.3,"cm"),
panel.border = element_blank(),
axis.line.x = element_line(),
axis.line.y = element_line())
g

__
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] ggplot() and annotation_custom()

2016-10-15 Thread Marc Girondot via R-help
Until now I was using plot() and I check the possibility to shift to 
ggplot2.


All is OK until now except to write text out of the plotting region 
[equivalent of par(xpd=TRUE); text(x, y, labels)].


I have found using google recommendation to use annotation_custom() but 
I still failed to print text out of the plotting region:


library("ggplot2")

df <- data.frame(x = 1:10, y = 1:10)
ggplot(data=df, mapping=aes(x, y))+
  geom_line(color="black") +
  annotation_custom(
  grob = textGrob(label="essai"), xmin=2.5, xmax=5, ymin=10, ymax=11
) + theme(plot.margin = unit(c(1.5, 1, 0.5, 0.5), "cm"))

If someone has the solution, I could continue to explore ggplot2 !

Thanks a lot,

Marc

__
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] bquote in list to be used with do.plot()

2016-10-08 Thread Marc Girondot via R-help

Dear members,

Has someone have a solution to include a bquote() statement in a list to 
be used with do.call() ?


Here is an exemple:
scaleY <- 1
plot(x=1, y=1, ylab=bquote(.(format(scaleY), scientific=FALSE)^"-1"))

Like that, it works.

Now he same in a list:
L <- list(x=1, y=1, ylab=bquote(.(format(scaleY), 
scientific=FALSE)^"-1"))

do.call(plot, L)
Error in "1"^"-1" : argument non numérique pour un 
opérateur binaire


It produces an error.

Any solution?

(I tries also with substitute() and expression() but I fail also)

Thanks

Marc

__
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] Problem Mixstock in R

2016-09-21 Thread Marc Girondot via R-help

Le 19/09/2016 à 10:53, FIORAVANTI TATIANA a écrit :

Dear members of the R-project

I am doing a mixed stock analysis with the Mixstock Package in R, at the end of the analysis I 
would summarize all my results (mean, standard deviation, median, percentile, etc...) using the 
mysum(x, name=NULL) function, but I don't understand which is the correct manner to set up it, what 
"x" and "name"are? ..Can you help me? Thank you very much,

Tatiana


Dear Tatiana,

First: I don't find the Mixstock package in CRAN. You should indicate 
how to install it.
Second: I don't find anywhere a function mysum(). Is it part of the 
Mixstock package?
Third: Send a reproducible exemple to show what you tried to use the 
function.


Finaly you should read the posting guide in this list to have more 
chance to have answers.


Sincerely,

Marc

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


Re: [R] R Shiny convert into Java

2016-08-19 Thread Marc Girondot via R-help

You should try these:
http://www.renjin.org
https://github.com/allr/purdue-fastr

which are two R interpreters in Java. But I am not sure that shiny can 
work on these.


Sincerely

Marc

Le 16/08/2016 à 15:11, Venky a écrit :

Hi,

How to run Shiny (Server,UI) into JAVA?

I am running R Shiny app using R
But i want to run those functions in Java without dependent of R
Please help me on this anyone


Thanks and Regards
Venkatesan

[[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] about netcdf files

2016-08-02 Thread Marc Girondot via R-help

You can find many tutorials in internet. For example, I did one here:
http://max2.ese.u-psud.fr/epc/conservation/Girondot/Publications/Blog_r/Entrees/2014/4/27_Comparison_between_packages_RnetCDF%2C_ncdf4_and_ncdf.html
Without any reproducibl example, it is impossible to help you further.

Sincerely

Marc

__
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] error.crosses

2016-05-07 Thread Marc Girondot via R-help
Following the message of Bert Gunter, you should explain better what you 
have done (not everyone know that describeBy is a function of psych 
package) and what you want. You said "error bars"... but what "error 
bar"? (I don't like the term "error bars". Most often they are not 
errors but dispersion bar; if you read French, you can check this ppt 
from a conference I gave : Myths and legends in statistics : 
http://max2.ese.u-psud.fr/epc/conservation/Publi/Mythes.pdf


Here is a reproducible example, and it works:
> library("psych")
> df <- data.frame(A=rnorm(10, 10, 2), B=rnorm(10, 9, 3), 
C=sample(c("G", "H"), 10, replace=TRUE))

> d <- describeBy(df[, c("A", "B")], group=df$C)
> error.crosses(d$G, d$H)

Sincerely

Marc Girondot


Le 27/04/2016 20:54, Marlin Keith Cox a écrit :

Hello all, I have used describeBy to generate the following summary
statistics.  I simply need x and y error bars on a plot that has CQN
(xaxis) and Price (yaxis).  There should be four total points on the graph
(one for each supplier).

Using "error.crosses(desc$CQN, desc$Price)" does not work.



group: a
   vars  n  meansd median trimmed   mad   min   max range skew
CQN  1 65 48.22 11.12  49.61   47.86 13.79 31.30 72.71 41.41  0.1
Price2 65  6.65  0.06   6.696.66  0.01  6.48  6.70  0.22 -1.2
Supplier*3 65   NaNNA NA NaNNA   Inf  -Inf  -Inf   NA
   kurtosis   se
CQN  -1.01 1.38
Price 0.70 0.01
Supplier*   NA   NA

group: b
   vars n  mean sd median trimmed mad   min   max range skew
kurtosis se
CQN  1 1 91.93 NA  91.93   91.93   0 91.93 91.93 0   NA
NA NA
Price2 1  6.95 NA   6.956.95   0  6.95  6.95 0   NA
NA NA
Supplier*3 1   NaN NA NA NaN  NA   Inf  -Inf  -Inf   NA
NA NA

group: c
   vars n  mean   sd median trimmed  mad   min   max range skew
kurtosis
CQN  1 6 63.11 2.58  62.04   63.11 1.53 60.66 67.19  6.53 0.55
  -1.68
Price2 6  8.92 0.00   8.928.92 0.00  8.92  8.92  0.00  NaN
  NaN
Supplier*3 6   NaN   NA NA NaN   NA   Inf  -Inf  -Inf   NA
   NA
 se
CQN   1.05
Price 0.00
Supplier*   NA

group: d
   vars n  mean  sd median trimmed  mad   min   max range skew
kurtosis
CQN  1 6 47.20 5.7  46.31   47.20 7.17 39.52 54.45 14.93 0.08
  -1.79
Price2 6  7.17 0.0   7.177.17 0.00  7.17  7.17  0.00  NaN
  NaN
Supplier*3 6   NaN  NA NA NaN   NA   Inf  -Inf  -Inf   NA
NA
 se
CQN   2.33
Price 0.00
Supplier*   NA

M. Keith Cox, Ph.D.
Principal
MKConsulting
17415 Christine Ave.
Juneau, AK 99801
U.S. 907.957.4606

[[alternative HTML version deleted]]

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



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


Re: [R] R logo size in package information

2016-03-29 Thread Marc Girondot via R-help

Le 30/03/2016 06:18, Jeff Newmiller a écrit :
You are not clarifying yet. If this requires RStudio to reproduce then 
this question doesn't belong here. I am not yet convinced that RStudio 
IS required, but every time you mention it the water gets muddier.

I try to be shorter:

There is bad interaction between Rlogo.svg installed by R and Rstudio:
So there are two solutions. Or Rstudio changes the way they scale 
Rlogo.svg, or Rlogo.svg is differently scaled during R install. Here is 
a Rlogo.svg correctly scaled to replace the original version hat is 
located at 
/Library/Frameworks/R.framework/Versions/3.3/Resources/doc/html/Rlogo.svg for 
R 3.3 MacOSX version:

http://www.ese.u-psud.fr/epc/conservation/CRAN/Rlogo.svg

Marc

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

Re: [R] R logo size in package information tab of Rstudio

2016-03-29 Thread Marc Girondot via R-help

Here are my R session information:
> sessionInfo()
R version 3.3.0 alpha (2016-03-24 r70373)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

If the help is displayed within the R gui using:
help(package='packrat')

The Rlogo.svg is scaled correctly.

However if the help is shown within Rstudio, the Rlogo.svg is not scaled 
corrected and is shown at huge size.


The choice of logo displayed in the help comes from the file in folder 
html within each package. For example for package numDeriv, within the 
file: 
/Library/Frameworks/R.framework/Versions/3.3/Resources/library/numDeriv/html/00Index.html


There is this link:

 Accurate Numerical Derivatives



Whereas for packrat package, within the file
/Library/Frameworks/R.framework/Versions/3.3/Resources/library/packrat/html/00Index.html

The link is this one:

 A Dependency Management System for Projects and their R Package
Dependencies



And the Rlogo.svg is badly scaled in Rstudio Version 0.99.1119 (beta) or 
in public 0.99.893 version.


So there are two solutions. Or Rstudio changes the way they scale 
Rlogo.svg, or Rlogo.svg is correctly scaled during R install. Here is a 
Rlogo.svg correctly scaled to replace the original version:

http://www.ese.u-psud.fr/epc/conservation/CRAN/Rlogo.svg

Sincerely,

Marc


Le 30/03/2016 00:44, Duncan Murdoch a écrit :

On 29/03/2016 3:42 PM, Marc Girondot via R-help wrote:

Two different sizes of R logo are shown in Rstudio in the Help at the
package level.

For example, numderiv shows a nice discreet logo located at (in MacosX):
/Library/Frameworks/R.framework/Versions/3.3/Resources/doc/html/logo.jpg
whereas packrat shows a huge logo located at:
/Library/Frameworks/R.framework/Versions/3.3/Resources/doc/html/Rlogo.svg 



The choice between both depends on the path indicated in the file
Index.html located in html folder for each package.

It would be better to have svg version of Rlogo.svg of the same size
than logo.jpg (I have converted the Rlogo.svg into the same size than
logo.jpg and it looks much better whit the new version).



What versions are you talking about?  I'd guess your packages were 
built with different versions of R if they ended up with different 
links to the logo.


Why is RStudio relevant here?  I don't think RStudio does anything 
with the R help files other than to display them in its built-in browser.




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] R logo size in package information tab of Rstudio

2016-03-29 Thread Marc Girondot via R-help
Two different sizes of R logo are shown in Rstudio in the Help at the 
package level.


For example, numderiv shows a nice discreet logo located at (in MacosX):
/Library/Frameworks/R.framework/Versions/3.3/Resources/doc/html/logo.jpg
whereas packrat shows a huge logo located at:
/Library/Frameworks/R.framework/Versions/3.3/Resources/doc/html/Rlogo.svg

The choice between both depends on the path indicated in the file 
Index.html located in html folder for each package.


It would be better to have svg version of Rlogo.svg of the same size 
than logo.jpg (I have converted the Rlogo.svg into the same size than 
logo.jpg and it looks much better whit the new version).


Sincerely

Marc




__
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] help in maximum likelihood estimation

2016-03-29 Thread Marc Girondot via R-help

Le 28/03/2016 22:19, heba eldeeb via R-help a écrit :

  Dear AllI'm trying to find the maximum likelihood estimator  of a certain 
distribution using nlm command but I receive an error as:
  non-finite value supplied by 'nlm'
can't figure out what is wrong in my function
Any help?
Thank you in advance



Hi,

Whitout rproducible example, it will be impossible to help you 
efficiently. See https://www.r-project.org/posting-guide.html
Anyway, this error means that your function returns NA or error for some 
combination of parameters.


Marc

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