Re: [R] Data frame organization

2019-08-27 Thread Arnaud Mosnier
Aaaah finally !!! Thanks a lot !!!

Arnaud

Le lun. 26 août 2019 18 h 28, Jim Lemon  a écrit :

> Hi Arnaud,
> The reason I wrote the following function is that it always takes me
> half a dozen tries with "reshape" before I get the syntax right:
>
> amdf<-read.table(text="A   10
> B   5
> C   9
> A   5
> B   15
> C   20")
> library(prettyR)
> stretch_df(amdf,"V1","V2")
>  V1 V2_1 V2_2
> 1  A   105
> 2  B5   15
> 3  C9   20
>
> Jim
>
> On Tue, Aug 27, 2019 at 4:06 AM Arnaud Mosnier 
> wrote:
> >
> > Hi,
> >
> > I have a really simple question.
> > I need to convert a data.frame with the following format
> >
> > A   10
> > B   5
> > C   9
> > A   5
> > B   15
> > C   20
> >
> > in this format
> >
> > A   10   5
> > B   515
> > C   920
> >
> > Thanks !!!
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Data frame organization

2019-08-26 Thread Arnaud Mosnier
Hi,

I have a really simple question.
I need to convert a data.frame with the following format

A   10
B   5
C   9
A   5
B   15
C   20

in this format

A   10   5
B   515
C   920

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] file connection when using parallel

2016-05-24 Thread Arnaud Mosnier
Dear UserRs,

I have a little problem creating a file connection when working in parallel
(see the reproducable script below).
I am sure this is something obvious,
Can you enlighten me ?

Thanks,

Arnaud



# This part works
#
cat("This is a test file" , file={f <- tempfile()})
con <- file(f, "rt")


# Doing what I think is the same thing gives an error message when executed
in parallel
#--

library(parallel)
cl <- makeCluster(2)

## Exporting the object f into the cluster

  clusterExport(cl, "f")
  clusterEvalQ(cl[1], con <- file(f[[1]], "rt"))
   #Error in checkForRemoteErrors(lapply(cl, recvResult)) :
   # one node produced an error: cannot open the connection


## Creating the object f into the cluster

  clusterEvalQ(cl[1],cat("This is a test file" , file={f <- tempfile()}))
  clusterEvalQ(cl[1],con <- file(f, "rt"))
   #Error in checkForRemoteErrors(lapply(cl, recvResult)) :
   # one node produced an error: cannot open the connection

[[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] Clean method to convert date and time between time zones keeping it in POSIXct format

2016-05-09 Thread Arnaud Mosnier
Dear UseRs,

I know two ways to convert dates and time from on time zone to another but
I am pretty sure that there is a better (cleaner) way to do that.


Here are the methods I know:


## The longest way ...

T1 <- as.POSIXct("2016-05-09 10:00:00", format="%Y-%m-%d %H:%M:%S",
tz="America/New_York")

print(T1)

T2 <- as.POSIXct(format(T1, tz="UTC"), tz="UTC") # format convert it to
character, so I have to convert it back to POSIXct afterward.

print(T2)



## The shortest but probably not the cleanest ...

attributes(T1)$tzone <- "UTC"

print(T1)

[[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] Reading some csv files from different folders and add the name of each files to the first column of files

2015-07-26 Thread Arnaud Mosnier
Hi Lida,

You can try this:

d- choose.dir() # choose the folder with the subdirectories containing the
csv files
f - list.files(d, full.names = TRUE, recursive = TRUE)

# Here the example for the sing files
selsing - grep(sing,f) #Select the files notaining the word sing

allsing - data.frame() #Create an empty data frame

# Loop among the selected files
for (i in 1:length(f[selsing])){
  dat - read.csv(file=f[selsing][i])  # suppose that the csv files have a
header
  allsing - rbind(allsing,data.frame(FileID =
gsub(EA_sing_|.txt,,basename(f[selsing][i])), dat)) #Combine the file
ID with the other columns and add the result to the all sing object
}

Now, you just have to do it for the other cases and save your final object.

Hope this help !

Arnaud

###

Date: Sat, 25 Jul 2015 15:03:21 -0500
From: Lida Zeighami lid.z...@gmail.com
To: r-help@r-project.org
Subject: [R] Reading some csv files from different folders and add the
name of each files to the first column of files
Message-ID:
CAMqbV1CXN0=r+hxmays40smymgdbhdqk1v+n5bhmbpgbr3m...@mail.gmail.com
Content-Type: text/plain; charset=UTF-8

I have 600 folders in which there are 3 csv files. The name of folders are
as follows: EA_aa, EA_bb, EA_cc, EA_dd,

In each folder there are 3 csv files:
in folder EA_aa there are:
  EA_sing_aa.csvqwerty
  EA_ska_aa.csv
  EA_tat_aa.csv

In folder EA_bb:
  EA_sing_bb.csv
  EA_ska_bb.csv
  EA_tat_bb.csv
...

I need to read all the same kind of files (for example sing files) in one
dataframe but before that I should add a column to each files with the name
of file as a row names!

So in output I should have just 3 csv files such as
EA_sing.csv: (rbind all EA_sing_*.csv file)
EA_ska.csv: (rbind all EA_ska_*.csv files)
EA_tat.csv: (rbind all EA_tat_*.csv files)

And in each file the first column should be added as row names which
containing the file name! So the format will be as follow:
EA_sing.csv:
1st column   2nd column  3rd column
   aayhhhghj
   aa k ki   Fyh
   bb k ki   vgd
   bb k gki  Fyh
   bbk reci  Fyh
   cc k hcd  hyd
   dd lmb Fyh

EA_ska.csv:
1st column   2nd column  3rd column
   aayhhhghj
   aa k ki   Fyh
   bb k ki   Fyh
   cc k gki  Fyh
   cc k reci  oki
   cc k hcd  Fyh
   dd lmb dsf

EA_tat.csv:
1st column   2nd column  3rd column
   aayhhhghj
   aa k ki   Fyh
   bb k ki   Fyh
   cc k gki  Fyh
   cc k reci  oki
   dd k hcd  Fyh
   dd lmb dsf

Would you please help me how to can I do that?
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] Comparing gam models fitted using ti()

2015-02-16 Thread Arnaud Mosnier
Dear R-Help list,

I want to compare gam models including interaction with simpler models.
For interaction models, I used gam(Y~ti(X1) + ti(X2) + ti(X1,X2))
removing the interaction, the models end as Y~ti(X1) + ti(X2)

How those models compare with models with the form Y ~ s(X1) + s(X2)

In my case, the former (i.e. ti() ) have a better AIC value than those with
s().

Should I keep the ti() form or use only the s() form when I have no
interaction ?

Thanks for your help !

Arnaud

[[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] Submodel selection using dredge and gam (mgcv)

2014-11-12 Thread Arnaud Mosnier
Hi Kamil,

Thanks for your answer. In fact, I already tried something with operators
in such a way you advise, but it seems more complicated due to the use of
the s() and ti() operators.

Can you provide a solution for the following example ?

library(mgcv)
set.seed(2)
dat - gamSim(1,n=400,dist=normal,scale=2)

bt - gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method=ML)

library(MuMIn)

# this does not work
dredge(bt, subset = (!(x0,x1) | (x0  x1)))
dredge(bt, subset = (!ti(x0,x1) | (s(x0)  s(x1

Cheers,

Arnaud


2014-11-11 4:11 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl:

 Hi Arnaud,
 your question has in fact nothing to do with gam or model selection. What
 you are asking is: what is the logical expression that yields True when AB
 is False or both A and B are True. Now replace the words with operators
 (!AB | (A  B)) and voilà.

 See also:
 help(Logic, base)
 fortunes::fortune(350)

 best,
 kamil



 On 2014-11-10 21:26, Arnaud Mosnier wrote:

 Hi,

 I want to use dredge to test several gam submodels including interactions.
 I tried to find a way in order to keep models with interaction only if
 the single variables occurring in the interaction are also included.

 i.e.: for
   y~s(x0)+s(x1)+ti(x0, x1)

 I want to keep
 y ~ s(x0)
 y ~ s(x1)
 y ~ s(x0) + s(x1)
 y ~ s(x0) + s(x1) + ti(x0,x1)

 and I want to remove

 y ~ s(x0) + ti(x0,x1)
 y ~ s(x1) + ti(x0,x1)
 y ~ ti(x0,x1)


 I know that I should use the subset option of the dredge function.
 However, I can not find the correct matrix / expression to obtain what I
 need !


 Here a small example.

 

 # Create some data (use mgcv example)
 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,scale=2)

 # Create the global gam model
 # Here a model with interaction. Note the use of ti()
 bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+ti(x1,x2), data=dat,method=ML)

 # Use dredge to test sub-models
 library(MuMIn)
 print(modstab - dredge(bt))

 # Here the 11th model include the interaction but do not include the
 single variables x1 and x2
 # ... I want to avoid that kind of model.
 get.models(modstab, subset = 11)

 


 Any help would be appreciated !

 Arnaud




[[alternative HTML version deleted]]

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


Re: [R] Submodel selection using dredge and gam (mgcv)

2014-11-12 Thread Arnaud Mosnier
Argh ! Ok ... my fault ... the use of back-ticks was the solution !!!
Thanks,

Arnaud

2014-11-12 14:19 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl:

 Hi Arnaud,
 please read ?dredge - Details - Subsetting, where this is explained.


 On 2014-11-12 15:19, Arnaud Mosnier wrote:

 Hi Kamil,

 Thanks for your answer. In fact, I already tried something with
 operators in such a way you advise, but it seems more complicated due to
 the use of the s() and ti() operators.

 Can you provide a solution for the following example ?

 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,scale=2)

 bt - gam(y~s(x0)+s(x1)+ti(x0,x1), data=dat,method=ML)

 library(MuMIn)

 # this does not work
 dredge(bt, subset = (!(x0,x1) | (x0  x1)))
 dredge(bt, subset = (!ti(x0,x1) | (s(x0)  s(x1

 Cheers,

 Arnaud


 2014-11-11 4:11 GMT-05:00 Kamil Bartoń kamil.bar...@o2.pl
 mailto:kamil.bar...@o2.pl:


 Hi Arnaud,
 your question has in fact nothing to do with gam or model selection.
 What you are asking is: what is the logical expression that yields
 True when AB is False or both A and B are True. Now replace the
 words with operators (!AB | (A  B)) and voilà.

 See also:
 help(Logic, base)
 fortunes::fortune(350)

 best,
 kamil



 On 2014-11-10 21:26, Arnaud Mosnier wrote:

 Hi,

 I want to use dredge to test several gam submodels including
 interactions.
 I tried to find a way in order to keep models with interaction
 only if
 the single variables occurring in the interaction are also
 included.

 i.e.: for
y~s(x0)+s(x1)+ti(x0, x1)

 I want to keep
 y ~ s(x0)
 y ~ s(x1)
 y ~ s(x0) + s(x1)
 y ~ s(x0) + s(x1) + ti(x0,x1)

 and I want to remove

 y ~ s(x0) + ti(x0,x1)
 y ~ s(x1) + ti(x0,x1)
 y ~ ti(x0,x1)


 I know that I should use the subset option of the dredge
 function.
 However, I can not find the correct matrix / expression to
 obtain what I
 need !


 Here a small example.

 

 # Create some data (use mgcv example)
 library(mgcv)
 set.seed(2)
 dat - gamSim(1,n=400,dist=normal,__scale=2)

 # Create the global gam model
 # Here a model with interaction. Note the use of ti()
 bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+__ti(x1,x2),
 data=dat,method=ML)

 # Use dredge to test sub-models
 library(MuMIn)
 print(modstab - dredge(bt))

 # Here the 11th model include the interaction but do not include
 the
 single variables x1 and x2
 # ... I want to avoid that kind of model.
 get.models(modstab, subset = 11)

 


 Any help would be appreciated !

 Arnaud






[[alternative HTML version deleted]]

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


[R] Submodel selection using dredge and gam (mgcv)

2014-11-10 Thread Arnaud Mosnier
Hi,

I want to use dredge to test several gam submodels including interactions.
I tried to find a way in order to keep models with interaction only if the
single variables occurring in the interaction are also included.

i.e.: for
 y~s(x0)+s(x1)+ti(x0, x1)

I want to keep
y ~ s(x0)
y ~ s(x1)
y ~ s(x0) + s(x1)
y ~ s(x0) + s(x1) + ti(x0,x1)

and I want to remove

y ~ s(x0) + ti(x0,x1)
y ~ s(x1) + ti(x0,x1)
y ~ ti(x0,x1)


I know that I should use the subset option of the dredge function.
However, I can not find the correct matrix / expression to obtain what I
need !


Here a small example.



# Create some data (use mgcv example)
library(mgcv)
set.seed(2)
dat - gamSim(1,n=400,dist=normal,scale=2)

# Create the global gam model
# Here a model with interaction. Note the use of ti()
bt - gam(y~s(x0)+s(x1)+s(x2)+s(x3)+ti(x1,x2), data=dat,method=ML)

# Use dredge to test sub-models
library(MuMIn)
print(modstab - dredge(bt))

# Here the 11th model include the interaction but do not include the single
variables x1 and x2
# ... I want to avoid that kind of model.
get.models(modstab, subset = 11)




Any help would be appreciated !

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] speed of makeCluster (package parallel)

2013-10-29 Thread Arnaud Mosnier
Thanks Brian, I thought that forking clusters was better ... but as you
mentioned, it is not available on windows.
Unfortunately, you do not always choose the OS used by your company !

Arnaud



Date: Mon, 28 Oct 2013 17:59:10 +
From: Prof Brian Ripley rip...@stats.ox.ac.uk
To: r-help@r-project.org
Subject: Re: [R] speed of makeCluster (package parallel)
Message-ID: 526ea5ee.9060...@stats.ox.ac.uk
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 28/10/2013 16:19, Arnaud Mosnier wrote:
 Hi all,

 I am quite new in the world of parallelization and I wonder if there is a
 way to increase the speed of creation of a parallel socket cluster. The
 time spend to include threads increase exponentially with the number of

It increases linearly in my tests (or a decent OS).  But really if
parallel computing is worthwhile you will be doing minutes of work on
each worker process and the startup time will not be signifcant.

 thread considered and I use of computer with two 8 cores CPU and thus
 showing a total of 32 threads in windows 7.

The first way to speed things up: use a decent OS:  forking clusters is
much faster.

 Currently, I use the default parameters (type = PSOCK), but is there any
 fine tuning parameters that I can use to take advantage of this system ?

 Thanks in advance for your help !

 Arnaud

 R version 3.0.1 (2013-05-16)
 Platform: x86_64-w64-mingw32/x64 (64-bit)

   [[alternative HTML version deleted]]


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

[[alternative HTML version deleted]]

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


[R] speed of makeCluster (package parallel)

2013-10-28 Thread Arnaud Mosnier
Hi all,

I am quite new in the world of parallelization and I wonder if there is a
way to increase the speed of creation of a parallel socket cluster. The
time spend to include threads increase exponentially with the number of
thread considered and I use of computer with two 8 cores CPU and thus
showing a total of 32 threads in windows 7.
Currently, I use the default parameters (type = PSOCK), but is there any
fine tuning parameters that I can use to take advantage of this system ?

Thanks in advance for your help !

Arnaud

R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

[[alternative HTML version deleted]]

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


Re: [R] speed of makeCluster (package parallel)

2013-10-28 Thread Arnaud Mosnier
Thanks Simon,

I already read the parallel vignette but I did not found what I wanted.
May be you can be more specific on a part of the document that can provide
me hints !

Arnaud


2013/10/28 Simon Zehnder szehn...@uni-bonn.de

 See library(help = parallel”)


 On 28 Oct 2013, at 17:19, Arnaud Mosnier a.mosn...@gmail.com wrote:

  Hi all,
 
  I am quite new in the world of parallelization and I wonder if there is a
  way to increase the speed of creation of a parallel socket cluster. The
  time spend to include threads increase exponentially with the number of
  thread considered and I use of computer with two 8 cores CPU and thus
  showing a total of 32 threads in windows 7.
  Currently, I use the default parameters (type = PSOCK), but is there
 any
  fine tuning parameters that I can use to take advantage of this system ?
 
  Thanks in advance for your help !
 
  Arnaud
 
  R version 3.0.1 (2013-05-16)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
 
[[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



[[alternative HTML version deleted]]

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


Re: [R] speed of makeCluster (package parallel)

2013-10-28 Thread Arnaud Mosnier
Thanks a lot Simon, that's useful.
I will take a look at this process-pinning things.

Arnaud


2013/10/28 Simon Zehnder szehn...@uni-bonn.de

 First,

 use only the number of cores as a number of thread - i.e. I would not use
 hyper threading, etc.. Each core has its own caches and it is always
 fortunate if a process has enough memory; hyper threads use all the same
 cache on the core they are running on. detectCores() gives me for example 4
 - I know I have 2. I would therefore call makeCluster() with nnode = 2.
 mcaffinity() lets you perform a technique called process-pinning (see
 process affinity) and is only possible if the OS supports it. It makes
 sometimes sense to assign certain processes to certain CPUs such that each
 process has enough memory in caches (e.g. for a 16 Core machine using 8
 processes on CPUs 1, 3, 5, 7, 9, 11, 13 and 15; so each process has the
 cache of two CPUs).
 A lot of functions though are not available for Windows.

 At first it comes always the problem you want to solve and then you look
 how much memory will be used in a process and how much you have (more often
 the memory bandwidth is the bottleneck and not the computing power). Look
 at the architecture of your chips (how much L1 Cache, how much L2 cache).
 Then you decide how many cores to use and if it makes sense to pin
 processes to certain cores.

 There are no general recipes for parallel computing - each problem is
 different. Some problems are even not scalable.

 Simon


 On 28 Oct 2013, at 17:51, Arnaud Mosnier a.mosn...@gmail.com wrote:

  Thanks Simon,
 
  I already read the parallel vignette but I did not found what I wanted.
  May be you can be more specific on a part of the document that can
 provide me hints !
 
  Arnaud
 
 
  2013/10/28 Simon Zehnder szehn...@uni-bonn.de
  See library(help = parallel”)
 
 
  On 28 Oct 2013, at 17:19, Arnaud Mosnier a.mosn...@gmail.com wrote:
 
   Hi all,
  
   I am quite new in the world of parallelization and I wonder if there
 is a
   way to increase the speed of creation of a parallel socket cluster. The
   time spend to include threads increase exponentially with the number of
   thread considered and I use of computer with two 8 cores CPU and thus
   showing a total of 32 threads in windows 7.
   Currently, I use the default parameters (type = PSOCK), but is there
 any
   fine tuning parameters that I can use to take advantage of this system
 ?
  
   Thanks in advance for your help !
  
   Arnaud
  
   R version 3.0.1 (2013-05-16)
   Platform: x86_64-w64-mingw32/x64 (64-bit)
  
 [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
 
 



[[alternative HTML version deleted]]

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


Re: [R] lowercase and uppercase greek letters

2013-09-18 Thread Arnaud Mosnier
You're right! QFMFT!
:-)

Thanks


2013/9/17 Rolf Turner rolf.tur...@xtra.co.nz

 On 09/18/13 07:26, Arnaud Mosnier wrote:

 Hi all,

 I want to present a figure including the uppercase and lowercase version
 of
 the greek letter phi.

 I know that I can use expression to have the symbol like in:

 plot(1~1, main = expression(phi))

 But, is there somewhere things like upper(phi) or lower(phi) ?

 Thanks for your help !


 RTFM.  From ?plotmath:

 alpha -- omega Greek symbols
 Alpha -- Omega uppercase Greek symbols

 cheers,

 Rolf Turner


[[alternative HTML version deleted]]

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


Re: [R] lowercase and uppercase greek letters

2013-09-18 Thread Arnaud Mosnier
Thanks Murdoch. I tried PHI but not Phi.

Arnaud


2013/9/17 Duncan Murdoch murdoch.dun...@gmail.com

 On 17/09/2013 3:26 PM, Arnaud Mosnier wrote:

 Hi all,

 I want to present a figure including the uppercase and lowercase version
 of
 the greek letter phi.

 I know that I can use expression to have the symbol like in:

 plot(1~1, main = expression(phi))

 But, is there somewhere things like upper(phi) or lower(phi) ?


 No functions for that.  You just need to give the letters in lowercase or
 uppercase:  lowercase is phi, uppercase is Phi.  Run
 demo(plotmath) for more hints.

 Duncan Murdoch



[[alternative HTML version deleted]]

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


[R] lowercase and uppercase greek letters

2013-09-17 Thread Arnaud Mosnier
Hi all,

I want to present a figure including the uppercase and lowercase version of
the greek letter phi.

I know that I can use expression to have the symbol like in:

plot(1~1, main = expression(phi))

But, is there somewhere things like upper(phi) or lower(phi) ?

Thanks for your help !

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] column width in .dbf files using write.dbf ... to be continued

2013-05-22 Thread Arnaud Mosnier
Thanks Bastien,
I completely forgot that I asked this question.
I learned a lot since then ... actually, now I know how to do it, but it
was not the case in 2009 :-)

Arnaud


2013/5/22 bastien.ferland-raym...@mrn.gouv.qc.ca


 Hello Arnaud,

 You posted this question a long long time ago, however I found your answer
 so I decided to post it anyway in case somebody else have the same problem
 as you and me.

 You were actually very close in finding your solution.  The function
 DoWritedbf is an internal function from the foreign package.  To access it
 outside of the package just do:

 foreign:::DoWritedbf

 so in your line:

 invisible(.Call(foreign:::DoWritedbf, as.character(file), dataframe,
   as.integer(precision), as.integer(scale), as.character(DataTypes)))

 It is explain here:
 http://stackoverflow.com/questions/2165342/r-calling-a-function-from-a-namespace

 Sorry for the delay in my answer...

 Bastien Ferland-Raymond, M.Sc. Stat., M.Sc. Biol.
 Division des orientations et projets spéciaux
 Direction des inventaires forestiers
 Ministère des Ressources naturelles

 In reply to :
 #
 Dear UseRs,
 I did not have any answer to my previous message (Is there a way to
 define manually columns width when using write.dbf function from the
 library foreign ?), so I tried to modify write.dbf function to do what I
 want.
 Here is my modified version :
 write.dbfMODIF - function (dataframe, file, factor2char = TRUE, max_nchar
 = 254, width = d)
 {
 allowed_classes - c(logical, integer, numeric, character,
 factor, Date)
 if (!is.data.frame(dataframe))
 dataframe - as.data.frame(dataframe) if
 (any(sapply(dataframe, function(x) !is.null(dim(x)
 stop(cannot handle matrix/array columns) cl -
 sapply(dataframe, function(x) class(x[1L])) asis - cl == AsIs
 cl[asis  sapply(dataframe, mode) == character] - character
 if (length(cl0 - setdiff(cl, allowed_classes)))
 stop(data frame contains columns of unsupported class(es) ,
 paste(cl0, collapse = ,))

 m - ncol(dataframe)
 DataTypes - c(logical = L, integer = N, numeric = F,
 character = C, factor = if (factor2char) C else N,
 Date = D)[cl]
 for (i in seq_len(m)) {
 x - dataframe[[i]]
 if (is.factor(x))
 dataframe[[i]] - if (factor2char)
 as.character(x)
 else as.integer(x)
 else if (inherits(x, Date))
 dataframe[[i]] - format(x, %Y%m%d)
 }
 precision - integer(m)
 scale - integer(m)
 dfnames - names(dataframe)
 for (i in seq_len(m)) {
 nlen - nchar(dfnames[i], b)
 x - dataframe[, i]
 if (is.logical(x)) {
 precision[i] - 1L
 scale[i] - 0L


 }

 else if (is.integer(x)) {
 rx - range(x, na.rm = TRUE)
 rx[!is.finite(rx)] - 0
 if (any(rx == 0))
 rx - rx + 1
 mrx - as.integer(max(ceiling(log10(abs(rx +
 3L)
 precision[i] - min(max(nlen, mrx), 19L)
 scale[i] - 0L


 }

 else if (is.double(x)) {
 precision[i] - 19L
 rx - range(x, na.rm = TRUE)
 rx[!is.finite(rx)] - 0
 mrx - max(ceiling(log10(abs(rx
 scale[i] - min(precision[i] - ifelse(mrx  0L, mrx +
 3L, 3L), 15L)


 }

 else if (is.character(x)) {
 if (width == d) {
mf - max(nchar(x[!is.na(x)], b))
 p - max(nlen, mf)
 if (p  max_nchar)
 warning(gettext(character column %d will be truncated
 to %d bytes,
   i, max_nchar), domain = NA)
 precision[i] - min(p, max_nchar)
 scale[i] - 0L


 } else {


 if (width  max_nchar)
 warning(gettext(character column %d will be truncated
 to %d bytes,
   i, max_nchar), domain = NA)
 precision[i] - min(width, max_nchar)


 }

 }

 else stop(unknown column type in data frame)
 }
 if (any(is.na(precision)))
 stop(NA in precision)
 if (any(is.na(scale)))
 stop(NA in scale)
 invisible(.Call(DoWritedbf, as.character(file), dataframe,
 as.integer(precision), as.integer(scale),
 as.character(DataTypes))) }
 However, when I wanted to use this function ... it does not find the
 DoWritedbf function that is called in the last lines (a function written in
 C).
 Is there a way to temporally replace the original write.dbf function by
 this one in the foreign package ?
 Thanks,
 Arnaud
 R version 2.10.0 (2009-10-26)
 i386-pc-mingw32
 ##




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

[R] Pairwise deletion in a linear regression and in a GLM ?

2012-12-13 Thread Arnaud Mosnier
Dear useRs,

In a thesis, I found a mention of the use of pairwise deletion in linear
regression and GLM (binomial family).
The author said that he has used R to do the statistics, but I did not find
the option allowing pairwise deletion in both lm and glm functions. Is
there somewhere a package allowing that ?

Thanks,

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] Pairwise deletion in a linear regression and in a GLM ?

2012-12-13 Thread Arnaud Mosnier
Hi Jose,

To my perception na.omit is different from a pairwise deletion.
With na.omit, you omit totally that case if there is a missing value for
one of the variable you consider in the model.
In the pairwise deletion, the case with some missing value is kept and
values that are not missing are used in the statistics calculations.

However, I agree that pairwise deletion is not good practice (so it would
be surprising that it is the default in lm !!).
I just when to be able to recalculate the statistics given in this thesis.

Arnaud




2012/12/13 Jose Iparraguirre jose.iparragui...@ageuk.org.uk

 Hi Arnaud,

 A quick help search of lm or glm tells you that 'the factory-fresh
 default is na.omit'.
 If you then look up 'na.omit', you'll read that it 'returns the object
 with incomplete cases removed'.
 So, pairwise deletion is the default option in both lm and glm.

 On a related note, it goes without saying that pairwise deletion is not
 good practice in most cases, and that R has ways to impute these missing
 cases depending on assumptions regarding the cause or nature of their
 missingness.

 Regards,

 José


 José Iparraguirre
 Chief Economist
 Age UK




 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Arnaud Mosnier
 Sent: 13 December 2012 15:40
 To: r-help@r-project.org
 Subject: [R] Pairwise deletion in a linear regression and in a GLM ?

 Dear useRs,

 In a thesis, I found a mention of the use of pairwise deletion in linear
 regression and GLM (binomial family).
 The author said that he has used R to do the statistics, but I did not find
 the option allowing pairwise deletion in both lm and glm functions. Is
 there somewhere a package allowing that ?

 Thanks,

 Arnaud

 [[alternative HTML version deleted]]

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

 Wrap Up and Run 10k is back!

 Also, new for 2013 – 2km intergenerational walks at selected venues. So
 recruit a buddy, dust off the trainers and beat the winter blues by
 signing up now:

 http://www.ageuk.org.uk/10k

  Milton Keynes | Oxford | Sheffield | Crystal Palace |
 Exeter | Harewood House, Leeds |
  Tatton Park, Cheshire | Southampton |
 Coventry



 Age UK Improving later life

 http://www.ageuk.org.uk




 ---
 Age UK is a registered charity and company limited by guarantee,
 (registered charity number 1128267, registered company number 6825798).
 Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

 For the purposes of promoting Age UK Insurance, Age UK is an Appointed
 Representative of Age UK Enterprises Limited, Age UK is an Introducer
 Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth
 Access for the purposes of introducing potential annuity and health
 cash plans customers respectively.  Age UK Enterprises Limited, JLT
 Benefit Solutions Limited and Simplyhealth Access are all authorised and
 regulated by the Financial Services Authority.
 --

 This email and any files transmitted with it are confidential and intended
 solely for the use of the individual or entity to whom they are
 addressed. If you receive a message in error, please advise the sender and
 delete immediately.

 Except where this email is sent in the usual course of our business, any
 opinions expressed in this email are those of the author and do not
 necessarily reflect the opinions of Age UK or its subsidiaries and
 associated companies. Age UK monitors all e-mail transmissions passing
 through its network and may block or modify mails which are deemed to be
 unsuitable.

 Age Concern England (charity number 261794) and Help the Aged (charity
 number 272786) and their trading and other associated companies merged
 on 1st April 2009.  Together they have formed the Age UK Group, dedicated
 to improving the lives of people in later life.  The three national
 Age Concerns in Scotland, Northern Ireland and Wales have also merged with
 Help the Aged in these nations to form three registered charities:
 Age Scotland, Age NI, Age Cymru.












[[alternative HTML version deleted]]

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


Re: [R] Pairwise deletion in a linear regression and in a GLM ?

2012-12-13 Thread Arnaud Mosnier
Thanks Jose, but I doubt that the author of these analysis used such a
complex approach.

Arnaud


2012/12/13 Jose Iparraguirre jose.iparragui...@ageuk.org.uk

  Sorry, Arnaud, I misinterpreted the question.

 There isn’t a built-in option in lm or glm to run pairwise deletion, but
 in the ‘psych’ package you can run regressions on covariance matrices
 rather than on raw data. So, first, you can obtain a covariance matrix by
 cov() with the option use=pairwise.complete.obs –or within ‘psych’,
 set.cor(…,use=pairwise), which will give you the correlations pairwise,
 and then you use the function mat.regress using the pairwise matrix.

 Hope this helps,

 ** **

 José 

 ** **

 ** **

 *From:* Arnaud Mosnier [mailto:a.mosn...@gmail.com]
 *Sent:* 13 December 2012 16:13
 *To:* Jose Iparraguirre
 *Cc:* r-help@r-project.org
 *Subject:* Re: [R] Pairwise deletion in a linear regression and in a GLM ?
 

 ** **

 Hi Jose,

 To my perception na.omit is different from a pairwise deletion.
 With na.omit, you omit totally that case if there is a missing value for
 one of the variable you consider in the model.
 In the pairwise deletion, the case with some missing value is kept and
 values that are not missing are used in the statistics calculations.

 However, I agree that pairwise deletion is not good practice (so it would
 be surprising that it is the default in lm !!).
 I just when to be able to recalculate the statistics given in this thesis.

 Arnaud

   

 ** **

 2012/12/13 Jose Iparraguirre jose.iparragui...@ageuk.org.uk

 Hi Arnaud,

 A quick help search of lm or glm tells you that 'the factory-fresh
 default is na.omit'.
 If you then look up 'na.omit', you'll read that it 'returns the object
 with incomplete cases removed'.
 So, pairwise deletion is the default option in both lm and glm.

 On a related note, it goes without saying that pairwise deletion is not
 good practice in most cases, and that R has ways to impute these missing
 cases depending on assumptions regarding the cause or nature of their
 missingness.

 Regards,

 José


 José Iparraguirre
 Chief Economist
 Age UK





 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Arnaud Mosnier
 Sent: 13 December 2012 15:40
 To: r-help@r-project.org
 Subject: [R] Pairwise deletion in a linear regression and in a GLM ?

 Dear useRs,

 In a thesis, I found a mention of the use of pairwise deletion in linear
 regression and GLM (binomial family).
 The author said that he has used R to do the statistics, but I did not find
 the option allowing pairwise deletion in both lm and glm functions. Is
 there somewhere a package allowing that ?

 Thanks,

 Arnaud

 [[alternative HTML version deleted]]

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

 Wrap Up and Run 10k is back!

 Also, new for 2013 – 2km intergenerational walks at selected venues. So
 recruit a buddy, dust off the trainers and beat the winter blues by
 signing up now:

 http://www.ageuk.org.uk/10k

  Milton Keynes | Oxford | Sheffield | Crystal Palace |
 Exeter | Harewood House, Leeds |
  Tatton Park, Cheshire | Southampton |
 Coventry



 Age UK Improving later life

 http://www.ageuk.org.uk




 ---
 Age UK is a registered charity and company limited by guarantee,
 (registered charity number 1128267, registered company number 6825798).
 Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

 For the purposes of promoting Age UK Insurance, Age UK is an Appointed
 Representative of Age UK Enterprises Limited, Age UK is an Introducer
 Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth
 Access for the purposes of introducing potential annuity and health
 cash plans customers respectively.  Age UK Enterprises Limited, JLT
 Benefit Solutions Limited and Simplyhealth Access are all authorised and
 regulated by the Financial Services Authority.
 --

 This email and any files transmitted with it are confidential and intended
 solely for the use of the individual or entity to whom they are
 addressed. If you receive a message in error, please advise the sender and
 delete immediately.

 Except where this email is sent in the usual course of our business, any
 opinions expressed in this email are those of the author and do not
 necessarily reflect the opinions of Age UK or its subsidiaries and
 associated companies. Age UK monitors all e-mail transmissions passing
 through its network and may block or modify mails which are deemed to be
 unsuitable.

 Age Concern England (charity number 261794) and Help the Aged (charity
 number

Re: [R] increase the usage of CPU and Memory

2012-06-27 Thread Arnaud Mosnier
Hi Xi,

Maybe you should try to parallelize your calculations.
See package parallel.
http://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf

Arnaud

On Mon, Jun 25, 2012 at 8:07 PM, Xi amzhan...@gmail.com wrote:
 Dear All,

 I have been searching online for help increasing my R code more
efficiently
 for almost a whole day, however, there is no solution to my case. So if
 anyone could give any clue to solve my problem, I would be very appreciate
 for you help. Thanks in advance.

 Here is my issue:

 My desktop is with i7-950 Quad-core CPU with 24Gb memory, and a ?NVIDIA
GTX
 480 ?graphic card, and I am using a 64-bit version of R under 64-bit
Windows
 .

 I am running a for loop to generate a 461*5 matrix data, which is coming
 from the coefficients of 5 models. The loop would produce 5 values one
 time, and it will run 461 times in total. I have tried to run the code
 inside the loop just once, it will cost almost 10 seconds, so if
 we intuitively calculate the time of the whole loop will cost, it would be
 4610 seconds, equal to almost one and a half hours, which is exactly the
 whole loop taking indeed. But I have to run this kinda loop for
 30 data-sets!

 Although I thought I am using a not-bad at all desktop, I checked the
usage
 of CPU and memory during my running R code, and found out the whole code
 just used 15% of CPU and 10% of memory. Does anyone have the same issue
 with me? or Does anyone know some methods to shorten the running time and
 increase the usage of CPU and memory?

 Many thanks,
 Xi

[[alternative HTML version deleted]]

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


Re: [R] Define lower-upper bound for parameters in Optim using Nelder-Mead method

2012-05-02 Thread Arnaud Mosnier
Thanks for this good idea !

Arnaud

2012/5/1 Ted Harding ted.hard...@wlandres.net

 On 01-May-2012 19:58:41 Arnaud Mosnier wrote:
  Dear UseRs,
 
  Is there a way to define the lower-upper bounds for parameters
  fitted by optim using the Nelder-Mead method ?
 
  Thanks,
  Arnaud

 The Nelder-Mead method does not provide built-in capability
 to set bounds on the range of paramaters. However, you can
 achieve it by hand by re-defining the function being
 minimised, so that it tests whether an out-of-range parameter
 parameter value is being used.

 If not out-of-range, then return the standard value of the function.
 If out-of range, then return a very large value.

 Nelder-Mead will very happily bounce off high walls of this
 kind, and if the minimum of the function is at the wall will
 happily converge as close to it as you please.

 Hoping this helps,
 Ted.

 -
 E-Mail: (Ted Harding) ted.hard...@wlandres.net
 Date: 01-May-2012  Time: 22:39:15
 This message was sent by XFMail
 -


[[alternative HTML version deleted]]

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


[R] Define lower-upper bound for parameters in Optim using Nelder-Mead method

2012-05-01 Thread Arnaud Mosnier
Dear UseRs,

Is there a way to define the lower-upper bounds for parameters fitted by
optim using the Nelder-Mead method ?

Thanks,

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] Use of optim to fit two curves at the same time ?

2012-04-26 Thread Arnaud Mosnier
Nice, thank you !
I particularly appreciated the list of possible explanations for it does
not work ! :-)

Arnaud

Le 26 avril 2012 13:49, Greg Snow 538...@gmail.com a écrit :

 The phrase does not work is not very helpful, it can mean quit a few
 things including:

 * Your computer exploded.
 * No explosion, but smoke is pouring out the back and microsoft's
 NoSmoke utility is not compatible with your power supply.
 * The computer stopped working.
 * The computer sits around on the couch all day eating chips and
 watching talk shows.
 * The computer has started picketing your house shouting catchy
 slogans and demanding better working conditions and an increase in
 memory.
 * Everything went dark and you cannot check the cables on the back of
 the computer because the lights are off due to the power outage.
 * R crashed, but the other programs are still working.
 * R gave an error message and stopped processing your code after
 running for a while.
 * R gave an error message without running any of your code (and is
 waiting for your next command).
 * R is still running your code and the time has exceeded your patience
 so you think it has hung.
 * R completed and returned a result, but also gave warnings.
 * R completed your command, but gave an incorrect answer.
 * R completed your command but the answer is different from what you
 expect (but is correct according to the documentation)

 There are probably others.

 Running your code I think the answer is the last one.  The criteria
 for optim finishing is a small improvement relative to previous
 improvements, not a guarantee of an exactly correct answer.  Since
 your starting points were very different from the True values this
 means that what appears to be a good improvement can still be far from
 the answer that you know to be true.  There are various arguments that
 you can give to optim to improve the fitting process, but sometimes
 the easiest thing to do is to just run optim again using the previous
 results as the new starting values.  Try running the following:

 out4 - optim( par=out3$par, fn=function(x){optfunc3(x,dfxy,dfxy2)})
 (out4 - optim( par=out4$par, fn=function(x){optfunc3(x,dfxy,dfxy2)}))

 and see if it works.  Run the last line a couple more times to see
 how well it works (at least it worked for me, if this does not work
 for you, tell us what does not work means).

 On Wed, Apr 25, 2012 at 6:57 AM, Arnaud Mosnier a.mosn...@gmail.com
 wrote:
  Dear list,
 
  In order to find a solution to my problem, I created a third objective
  function including both calculations done in the previous cases. This
  function return a value (i.e. the value to be minimize by optim) equal to
  the sum of the two sum of squares, but it does not work (see the code
 added
  at the end of my previous script).
 
  Any suggestion ?
 
  Arnaud
 
 
  Dear list,
 
  Here is a small example code that use optim and optimize in order to fit
  two functions.
  Is it possible to fit two functions (like those two for example) at the
  same time using optim ... or another function in R ?
 
  Thanks
 
  Arnaud
 
  ##
  ## function 1
  x1 - 1:100
  y1 - 5.468 * x + 3 # + rnorm(100,0, 10)
  dfxy - cbind(x1,y1)
 
  # Objective function
  optfunc - function(x, dfxy){
a - x[1]
b - x[2]
xtest - dfxy[,1]
yobs - dfxy[,2]
ysim - a*xtest + b
sum((ysim - yobs)^2)
  }
 
  out- optim(par=c(0.2,5), fn=function(x){optfunc(x, dfxy)}, method =
  Nelder-Mead, hessian = F)
 
 
  ## function 2
 
  x2 - seq(0.01, 0.1, length=100)
  y2 - exp(30*x2)
  dfxy2 - cbind(x2,y2)
 
  # objective function
  optfunc2 - function(x, dfxy){
a - x[1]
xtest - dfxy[,1]
yobs - dfxy[,2]
ysim - exp(a*xtest)
sum((ysim - yobs)^2)
  }
 
  out- optimize(f=function(x){optfunc2(x, dfxy2)}, interval=c(0,500))
 
  ##
 
 
 
  optfunc3 - function(x,  dfxy, dfxy2){
 
   a - x[1]
   b - x[2]
   xtest - dfxy[,1]
   yobs - dfxy[,2]
   ysim - a*xtest + b
   obj1 - sum((ysim - yobs)^2)
 
   c - x[3]
   xtest2 - dfxy2[,1]
   yobs2 - dfxy2[,2]
   ysim2 - exp(c*xtest2)
   obj2 - sum((ysim2 - yobs2)^2)
 
  obj1 + obj2
  }
 
  out3- optim(par=c(0.2,5, 500), fn=function(x){optfunc3(x, dfxy, dfxy2)},
  method = Nelder-Mead, hessian = F)
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



 --
 Gregory (Greg) L. Snow Ph.D.
 538...@gmail.com


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting

Re: [R] Use of optim to fit two curves at the same time ?

2012-04-26 Thread Arnaud Mosnier
I second the proposition !
Thanks to let me discover that absolutely essential library !! :-)

Arnaud

Le 26 avril 2012 15:30, Marc Schwartz marc_schwa...@me.com a écrit :


 On Apr 26, 2012, at 12:49 PM, Greg Snow wrote:

  The phrase does not work is not very helpful, it can mean quit a few
  things including:
 
  * Your computer exploded.
  * No explosion, but smoke is pouring out the back and microsoft's
  NoSmoke utility is not compatible with your power supply.
  * The computer stopped working.
  * The computer sits around on the couch all day eating chips and
  watching talk shows.
  * The computer has started picketing your house shouting catchy
  slogans and demanding better working conditions and an increase in
  memory.
  * Everything went dark and you cannot check the cables on the back of
  the computer because the lights are off due to the power outage.
  * R crashed, but the other programs are still working.
  * R gave an error message and stopped processing your code after
  running for a while.
  * R gave an error message without running any of your code (and is
  waiting for your next command).
  * R is still running your code and the time has exceeded your patience
  so you think it has hung.
  * R completed and returned a result, but also gave warnings.
  * R completed your command, but gave an incorrect answer.
  * R completed your command but the answer is different from what you
  expect (but is correct according to the documentation)
 
  There are probably others.


 snip

 Since Greg has kindly raised the fortunes package today, I propose that
 the above be captured as an R Classic.

 Regards,

 Marc Schwartz



[[alternative HTML version deleted]]

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


Re: [R] Use of optim to fit two curves at the same time ?

2012-04-25 Thread Arnaud Mosnier
Dear list,

In order to find a solution to my problem, I created a third objective
function including both calculations done in the previous cases. This
function return a value (i.e. the value to be minimize by optim) equal to
the sum of the two sum of squares, but it does not work (see the code added
at the end of my previous script).

Any suggestion ?

Arnaud


Dear list,

 Here is a small example code that use optim and optimize in order to fit
 two functions.
 Is it possible to fit two functions (like those two for example) at the
 same time using optim ... or another function in R ?

 Thanks

 Arnaud

 ##
 ## function 1
 x1 - 1:100
 y1 - 5.468 * x + 3 # + rnorm(100,0, 10)
 dfxy - cbind(x1,y1)

 # Objective function
 optfunc - function(x, dfxy){
   a - x[1]
   b - x[2]
   xtest - dfxy[,1]
   yobs - dfxy[,2]
   ysim - a*xtest + b
   sum((ysim - yobs)^2)
 }

 out- optim(par=c(0.2,5), fn=function(x){optfunc(x, dfxy)}, method =
 Nelder-Mead, hessian = F)


 ## function 2

 x2 - seq(0.01, 0.1, length=100)
 y2 - exp(30*x2)
 dfxy2 - cbind(x2,y2)

 # objective function
 optfunc2 - function(x, dfxy){
   a - x[1]
   xtest - dfxy[,1]
   yobs - dfxy[,2]
   ysim - exp(a*xtest)
   sum((ysim - yobs)^2)
 }

 out- optimize(f=function(x){optfunc2(x, dfxy2)}, interval=c(0,500))

 ##



optfunc3 - function(x,  dfxy, dfxy2){

  a - x[1]
  b - x[2]
  xtest - dfxy[,1]
  yobs - dfxy[,2]
  ysim - a*xtest + b
  obj1 - sum((ysim - yobs)^2)

  c - x[3]
  xtest2 - dfxy2[,1]
  yobs2 - dfxy2[,2]
  ysim2 - exp(c*xtest2)
  obj2 - sum((ysim2 - yobs2)^2)

obj1 + obj2
}

out3- optim(par=c(0.2,5, 500), fn=function(x){optfunc3(x, dfxy, dfxy2)},
method = Nelder-Mead, hessian = F)

[[alternative HTML version deleted]]

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


[R] Use of optim to fit two curves at the same time ?

2012-04-24 Thread Arnaud Mosnier
Dear list,

Here is a small example code that use optim and optimize in order to fit
two functions.
Is it possible to fit two functions (like those two for example) at the
same time using optim ... or another function in R ?

Thanks

Arnaud

##
## function 1
x1 - 1:100
y1 - 5.468 * x + 3 # + rnorm(100,0, 10)
dfxy - cbind(x1,y1)

# Objective function
optfunc - function(x, dfxy){
  a - x[1]
  b - x[2]
  xtest - dfxy[,1]
  yobs - dfxy[,2]
  ysim - a*xtest + b
  sum((ysim - yobs)^2)
}

out- optim(par=c(0.2,5), fn=function(x){optfunc(x, dfxy)}, method =
Nelder-Mead, hessian = F)


## function 2

x2 - seq(0.01, 0.1, length=100)
y2 - exp(30*x2)
dfxy2 - cbind(x2,y2)

# objective function
optfunc2 - function(x, dfxy){
  a - x[1]
  xtest - dfxy[,1]
  yobs - dfxy[,2]
  ysim - exp(a*xtest)
  sum((ysim - yobs)^2)
}

out- optimize(f=function(x){optfunc2(x, dfxy2)}, interval=c(0,500))

##

[[alternative HTML version deleted]]

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


Re: [R] GAM (mgcv) warning: matrix not positive definite

2012-02-06 Thread Arnaud Mosnier
Thanks for the explanation !
Happy to know there is no problem with my models.

Have a good day,

Arnaud

2012/2/3 Simon Wood s.w...@bath.ac.uk

 It is completely safe to ignore this. Here is what is going on...

 mgcv routine 'mroot' is calling R routine 'chol' to find the *pivoted*
 Choleski factor of a positive semi definite matrix. This is deliberate, and
 completely ok to do, but 'chol' issues a warning when a matrix is only
 positive semi-definite (as opposed to strictly +ve def), even if pivoting
 has been requested. 'mroot' therefore suppresses the warning.

 best,
 Simon


 On 03/02/12 20:38, Arnaud Mosnier wrote:

 Dear list,


 I fitted the same GAM model using directly the function gam(mgcv) ...
 then as a parameter of another function that capture the warnings
 messages (see below).
 In the first case, there is no warning message printed, but in the last
 one, the function find two warning messages stating matrix not positive
 definite

 So my question is: Do I have to worry about those warnings and then why
 are they not printed in the simple use of the gam function.

 ##**###

 Here is some further description:

 ## Simple use of gam

 gam(USE ~ X1 + s(X2) + s(X3), family = binomial, data = data,
 method=REML) # print no warning message.

 ## Using a function that capture warnings

 Model_n_Warnings - function(expr) {
 localWarnings - list()
 outModel - withCallingHandlers(expr,
 warning = function(w) {
 localWarnings[[length(**localWarnings)+1]] - w$message  #
 store warning message
 invokeRestart(muffleWarning) # avoid printing warning
 message to console
 })
 list(outModel=outModel, warnings=localWarnings)
   }

 out - Model_n_Warnings (gam(USE ~ X1 + s(X2) + s(X3), family =
 binomial, data = data, method=REML))

 out$warnings

 [[1]]
 [1] matrix not positive definite

 [[2]]
 [1] matrix not positive definite


 Thanks,

 Arnaud



 --
 Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
 +44 (0)1225 386603   http://people.bath.ac.uk/sw283


[[alternative HTML version deleted]]

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


[R] GAM (mgcv) warning: matrix not positive definite

2012-02-03 Thread Arnaud Mosnier
Dear list,


I fitted the same GAM model using directly the function gam(mgcv) ... then
as a parameter of another function that capture the warnings messages (see
below).
In the first case, there is no warning message printed, but in the last
one, the function find two warning messages stating matrix not positive
definite

So my question is: Do I have to worry about those warnings and then why are
they not printed in the simple use of the gam function.

#

Here is some further description:

## Simple use of gam

gam(USE ~ X1 + s(X2) + s(X3), family = binomial, data = data,
method=REML) # print no warning message.

## Using a function that capture warnings

Model_n_Warnings - function(expr) {
localWarnings - list()
outModel - withCallingHandlers(expr,
warning = function(w) {
localWarnings[[length(localWarnings)+1]] - w$message  # store
warning message
invokeRestart(muffleWarning) # avoid printing warning message
to console
})
list(outModel=outModel, warnings=localWarnings)
  }

out - Model_n_Warnings (gam(USE ~ X1 + s(X2) + s(X3), family = binomial,
data = data, method=REML))

out$warnings

[[1]]
[1] matrix not positive definite

[[2]]
[1] matrix not positive definite


Thanks,

Arnaud

[[alternative HTML version deleted]]

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


[R] Model selection and model efficiency - Search for opinions

2011-08-24 Thread Arnaud Mosnier
Hi,

In order to find the best models I use AIC, more specifically I calculate
Akaike weights then Evidence Ratio (ER) and consider that models with a ER 
2 are equally likely.
But the same problem remain each time I do that. I selected the best models
from a set of them, but I don't know if those models are efficient to
predict (or at least represent) my data.
I can have selected the best element(s) of the list of the worst models.

Do you find it is correct to calculate R2 or pseudo-R2 for the best set of
models in order to have an idea of the representativeness of those models
and use this value to select the more efficient model ?

I would be glad to hear your opinions about this !

Thanks,

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] How to find the likelihood of a null model in R

2011-07-26 Thread Arnaud Mosnier
Try the logLik function with your model !

Arnaud

Date: Mon, 25 Jul 2011 12:16:37 +0100
From: Partha Pratim PATTNAIK p.pattn...@sms.ed.ac.uk
To: r-help@R-project.org
Subject: [R] How to find the likelihood of a null model in R
Message-ID: 20110725121637.jo1u2ctuxy8kw...@www.sms.ed.ac.uk
Content-Type: text/plain;   charset=ISO-8859-1; DelSp=Yes;
   format=flowed


Dear All,
I am working on a dataset having the dependent variable as ordinal
data(discrete data) and multiple independent variables. I need to find
the likelihood for the NULL model.i.e the model with only the
dependent variable and all other independent variables as zero. Kindly
let me know how to find the likelihood for a NULL model in R. Is there
any specific function in R that can do this task? Please share if
anyone has any information on this.

Thanks and Regards
Partha Pattnaik


--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

[[alternative HTML version deleted]]

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


[R] GLS models and variance explained

2011-06-22 Thread Arnaud Mosnier
Dear list,

Inspecting residuals of my linear models, I detected spatial autocorrelation.
In order to take this into account, I decided to use the GLS method
with the correlation = corGaus ( ~ X + Y).

Then, I can sort my GLS models based on their AIC.
But ... how to know the proportion of the variance explained by the
best one (it can be best of the worst models) ?
R-squared value has not the same meaning for OLS and GLS ...


- Could the R2 value calculated with the OLS model (using lm)
constitute a potential proxy of the variance explained by the GLS
model ? (the answer is probably no)

- Is a R-squared based on sqrt(cor(obs, predicted)) a better approach ?

- What about pseudo R-squared like Nagelkerke's ?

Suggestions for any better approach are welcome !


Thanks in advance,

Arnaud

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


Re: [R] Still have problems with tcltk in R 64 bit

2011-06-15 Thread Arnaud Mosnier
I agree that this is a really outdated source but I did not find the
way to tell R using correctly the tcl version included (at least for
the 64 bit version).
If I remove the environment variables, things work for R 32 bit (it
uses the tcl version included), but it does not work in R 64 bit.

Where are the configuration files used to define the path to each tcl version ?

Arnaud

2011/6/14 Uwe Ligges lig...@statistik.tu-dortmund.de:


 On 14.06.2011 22:01, Arnaud Mosnier wrote:

 I achieve to make tcltk work on R 64 installing Active tcltk8.5 64bit
 version then setting windows environment variables as in
 http://www.sciviews.org/_rgui/tcltk/InstallRTclTk.html.

 Don't read outdated sources but the manuals.

 The R binary distribution comes with tcltk under Windows (in ${R_HOME}/tcl)
 for both 32-bit and 64-bit and will user a different tcl if you set
 environment variables.

 Hence the easiest thing is just to tell R not to use your otehrwise set
 environment variabes and use its own tcl version.

 Uwe Ligges



 But now, it uses only this 64 bit version and thus do not work anymore
 in R 32 bit !

 In my case, it solves my problem as I will probably use only R 64bit
 but I do not like to end with an half solution.

 Arnaud

 2011/6/14 Peter Langfelderpeter.langfel...@gmail.com:

 On Tue, Jun 14, 2011 at 12:47 PM, Adrienne Woottenamwoo...@ncsu.edu
  wrote:

 Taking a quick look for it, it seems that they have replaced it with
 tcltk2.  I just did the installation with the same version in windows
 and it auto loaded the tcltk package and I never installed that
 package to begin with.  I would try it with tcltk2 and see if you get
 the package to install appropriately.  I'm not sure why tcltk isn't on
 CRAN anymore, it makes no sense not to have both tcltk and tcltk2, but
 here's hoping this helps you out.

 A

 FWIF, tcltk still exists but is now part of the standard R
 distribution (core packages is the term I think?) and as such is
 installed automatically when you install R. Therefore it is not
 available from CRAN.

 Peter


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


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


Re: [R] Still have problems with tcltk in R 64 bit

2011-06-15 Thread Arnaud Mosnier
I was pretty sure to have installed tcltk files for 64 bit from the
installer, but to be sure ...
- I removed previously created Environment variables (MY_TCLTK)
- I reinstalled R one more time ...  this time with the full
installation option

and ... it does not work (still works with R 32bit) !

- I also tried to define directly the path to the tcl version included
with R ... as the code you provided does ... thus MY_TCLTK =
C:\Program Files\R\R-2.13.0\Tcl\bin64

... still the same error in R 64 bit, and if I want to load tcltk in R
32, it gives me the following error (normal ... it tried to load a 64
bit application in a 32 bit environment).

Loading Tcl/Tk interface ...Error : .onLoad failed in loadNamespace()
for 'tcltk', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Program
Files/R/R-2.13.0/library/tcltk/libs/i386/tcltk.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

Error: package/namespace load failed for 'tcltk'

I believe that the problem may come from the tcltk.dll file but I do
not understand how it can be broken each time when I installed other
versions ...

Arnaud


2011/6/15 Uwe Ligges lig...@statistik.tu-dortmund.de:
 Well, the R code in package tcltk for startup under Windows is, as you could
 have found out yourself easily:

 .onLoad - function(lib, pkg)
 {
    packageStartupMessage(Loading Tcl/Tk interface ...,
                          domain = R-tcltk, appendLF = FALSE)
    if(!nzchar(tclbin - Sys.getenv(MY_TCLTK))) {
        tclbin - file.path(R.home(), Tcl,
                            if(.Machine$sizeof.pointer == 8) bin64 else
 bin)
        if(!file.exists(tclbin))
            stop(Tcl/Tk support files were not installed, call.=FALSE)
        if(.Machine$sizeof.pointer == 8) {
            lib64 - gsub(\\, /, file.path(R.home(), Tcl, lib64),
                          fixed=TRUE)
            Sys.setenv(TCLLIBPATH = lib64)
        }
    }
    library.dynam(tcltk, pkg, lib, DLLpath = tclbin)
    .C(tcltk_start, PACKAGE=tcltk)
    addTclPath(system.file(exec, package = tcltk))
    packageStartupMessage( , done, domain = R-tcltk)
    invisible()
 }


 This tells us that if you do not have MY_TCLTK defined on startup of R,
 you probably forgot to select the tcltk files for 64 bit from the installer
 when installing your version of R.

 Uwe Ligges




 On 15.06.2011 14:28, Arnaud Mosnier wrote:

 I agree that this is a really outdated source but I did not find the
 way to tell R using correctly the tcl version included (at least for
 the 64 bit version).
 If I remove the environment variables, things work for R 32 bit (it
 uses the tcl version included), but it does not work in R 64 bit.

 Where are the configuration files used to define the path to each tcl
 version ?

 Arnaud

 2011/6/14 Uwe Liggeslig...@statistik.tu-dortmund.de:


 On 14.06.2011 22:01, Arnaud Mosnier wrote:

 I achieve to make tcltk work on R 64 installing Active tcltk8.5 64bit
 version then setting windows environment variables as in
 http://www.sciviews.org/_rgui/tcltk/InstallRTclTk.html.

 Don't read outdated sources but the manuals.

 The R binary distribution comes with tcltk under Windows (in
 ${R_HOME}/tcl)
 for both 32-bit and 64-bit and will user a different tcl if you set
 environment variables.

 Hence the easiest thing is just to tell R not to use your otehrwise set
 environment variabes and use its own tcl version.

 Uwe Ligges



 But now, it uses only this 64 bit version and thus do not work anymore
 in R 32 bit !

 In my case, it solves my problem as I will probably use only R 64bit
 but I do not like to end with an half solution.

 Arnaud

 2011/6/14 Peter Langfelderpeter.langfel...@gmail.com:

 On Tue, Jun 14, 2011 at 12:47 PM, Adrienne Woottenamwoo...@ncsu.edu
  wrote:

 Taking a quick look for it, it seems that they have replaced it with
 tcltk2.  I just did the installation with the same version in windows
 and it auto loaded the tcltk package and I never installed that
 package to begin with.  I would try it with tcltk2 and see if you get
 the package to install appropriately.  I'm not sure why tcltk isn't on
 CRAN anymore, it makes no sense not to have both tcltk and tcltk2, but
 here's hoping this helps you out.

 A

 FWIF, tcltk still exists but is now part of the standard R
 distribution (core packages is the term I think?) and as such is
 installed automatically when you install R. Therefore it is not
 available from CRAN.

 Peter


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


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html

[R] Still have problems with tcltk in R 64 bit

2011-06-14 Thread Arnaud Mosnier
Dear R users,


Since a long time now, I have the following error when I want to load
the tcltk library in R 64 bit.


Loading Tcl/Tk interface ...Error : .onLoad failed in loadNamespace()
for 'tcltk', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Program
Files/R/R-2.13.0/library/tcltk/libs/x64/tcltk.dll':
  LoadLibrary failure:  This application has failed to start because
the application configuration is incorrect. Reinstalling the
application may fix this problem.

Error: package/namespace load failed for 'tcltk'


sessionInfo() gives

R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.13.0


The problem does not occur with the 32 bit version of R, thus, it is
probably linked to the 64 version of Tcltk...

I already tried:
-  to uninstall then reinstall R (changing version too...)
-  install ActiveTcl8.5.9.2.294317-win32-x86_64-threaded.exe (I also
tried installing previous version of ActiveTcl)

... without results !

 Reinstalling the application may fix this problem  ... I agree, but
what should I reinstall ?

Any suggestions  ?

Arnaud

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


Re: [R] Still have problems with tcltk in R 64 bit

2011-06-14 Thread Arnaud Mosnier
I achieve to make tcltk work on R 64 installing Active tcltk8.5 64bit
version then setting windows environment variables as in
http://www.sciviews.org/_rgui/tcltk/InstallRTclTk.html.
But now, it uses only this 64 bit version and thus do not work anymore
in R 32 bit !

In my case, it solves my problem as I will probably use only R 64bit
but I do not like to end with an half solution.

Arnaud

2011/6/14 Peter Langfelder peter.langfel...@gmail.com:
 On Tue, Jun 14, 2011 at 12:47 PM, Adrienne Wootten amwoo...@ncsu.edu wrote:
 Taking a quick look for it, it seems that they have replaced it with
 tcltk2.  I just did the installation with the same version in windows
 and it auto loaded the tcltk package and I never installed that
 package to begin with.  I would try it with tcltk2 and see if you get
 the package to install appropriately.  I'm not sure why tcltk isn't on
 CRAN anymore, it makes no sense not to have both tcltk and tcltk2, but
 here's hoping this helps you out.

 A

 FWIF, tcltk still exists but is now part of the standard R
 distribution (core packages is the term I think?) and as such is
 installed automatically when you install R. Therefore it is not
 available from CRAN.

 Peter


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


[R] Problems with tcltk

2011-05-11 Thread Arnaud Mosnier
Dear R-helpers,

I am using R x64 and when I want to load the tcltk library, it gives
me the following error:

Loading Tcl/Tk interface ...Error : .onLoad failed in loadNamespace()
for 'tcltk', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Program
Files/R/R-2.13.0/library/tcltk/libs/x64/tcltk.dll':
  LoadLibrary failure:  This application has failed to start because
the application configuration is incorrect. Reinstalling the
application may fix this problem.



I tried to reinstall tcltk
(ActiveTcl8.5.9.2.294317-win32-x86_64-threaded.exe) but it does not
solve my problem.

Here is my sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

Arnaud

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


[R] Problem with tcltk

2011-03-04 Thread Arnaud Mosnier
Dear all,

Since I installed the x64 version of R (v2.12.1), I got a problem with tcltk
that I did not achieve to resolve.
When loading the library, it gives me the following error message:

Loading Tcl/Tk interface ...Error : .onLoad failed in loadNamespace() for
'tcltk', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/PROGRA~1/R/R-212~1.1/
library/tcltk/libs/x64/tcltk.dll':
  LoadLibrary failure:  This application has failed to start because the
application configuration is incorrect. Reinstalling the application may fix
this problem.

Error: package/namespace load failed for 'tcltk'


The same occur with a freshly installed R 2.12.2

Loading Tcl/Tk interface ...Error : .onLoad failed in loadNamespace() for
'tcltk', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object
'C:/PROGRA~1/R/R-212~1.2/library/tcltk/libs/x64/tcltk.dll':
  LoadLibrary failure:  This application has failed to start because the
application configuration is incorrect. Reinstalling the application may fix
this problem.

Error: package/namespace load failed for 'tcltk'


Any suggestions ?

Arnaud

[[alternative HTML version deleted]]

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


[R] Variogram (nlme) of a lme object - corSpatial element question

2011-02-18 Thread Arnaud Mosnier
Dear Users,

From previous analysis (semi-variograms using package gstat), I found
spatial autocorrelation in my dataset.
The best fitted model to this spatial correlation structure is the Gaussian
model (Spherical, Exponential, Linear tested and comparison done by Sum of
Square errors).
So I used corGaus function to define this spatial autocorrelation in my lme
model using the option correlation.

The Variogram function (package nlme) used on a lme object calculates the
semi-variogram for the within-group residuals and add the semi-variogram of
the corSpatial element (corGaus in my case) included in my model ... so far
no problem.

I was surprised, however, to see on the plot of the semi-variogram issued
from the Variogram function, (see figure at http://imm.io/3OLe) the low
range value (~1600 meters) used in the corGaus structure included in the lme
object.
When I fitted the same corGaus structure manually or using the fit.variogram
function (package gstat) on the data of each group defined in lme, it gaves
me ranges between 2050 and 2700 meters (mean 2350 meters).

Can anyone explain me those differences ?

Note: As I mentioned in a previous message (
http://markmail.org/message/gjgag4ohjopevgax), I tried to define a different
range in the corGaus function directly in the lme function, but it is not
taken into account.

Arnaud

[[alternative HTML version deleted]]

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


[R] Bug in the function Variogram (package nlme) ?

2011-02-18 Thread Arnaud Mosnier
Dears UseRs,

In Zuur's book (Mixed effects models and extensions in ecology with R), p
167, it is mentionned that the Variogram function (package nlme) scale the
sill to 1.
Here is the plot of the semi-variogram given by the Variogram function on my
lme object. (http://imm.io/3OLe)
Note that the semi-variance exceed 1 !!

It can probably explain why the Gaussian correlation structure fitted in my
lme model is strange (curve is probably fitted to the data above 1).
See my previous message a few minutes ago untitled Variogram (nlme) of a
lme object - corSpatial element question.

I don't know if it is a bug, but Implications could be important for model
fitted with a spatial correlation structure.

Arnaud

[[alternative HTML version deleted]]

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


[R] Potential problem with subset !!!

2010-02-12 Thread Arnaud Mosnier
Dear useRs,

Just a little post to provide the answer of a problem that took me
some time to resolve !
Hope that reading this will permit the others to avoid that error.

When using the subset function, writing

subset (data, data$columnname == X) or subset (data, columnname == X)

do the same thing.

thus, the function consider that argument name given after the coma
(like columnname) is the name of a column of the data frame
considered.
A problem occur when other arguments such as X are the names of both a
column of the data frame and  an object !

Here is an example:

df - data.frame(ID = c(a,b,c,b,e), Other = 1:5)
ID - unique (df$ID)
ID

## Now the potential problem !!

subset (df, df$ID == ID[4])

## BE CAREFUL subset function use the column ID of the data.frame
## and NOT the object ID containing unique value 

Sorry if it seems obvious for some of you, but hope that others find
it useful !!

Arnaud

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


[R] Create a function with multiple object as an output

2010-02-10 Thread Arnaud Mosnier
Dear useRs,

I want to make a function that return several object (from a loop).
I know, I can put them in a list, then the function return  the list,
but is it possible that it returns several independent object.
I used the assign function to create several object, it works when I
use it outside the function, but not inside.

Any suggestion ?

Here is a piece of code that do something similar to my situation.

testfunc - function ( listobj, valueX) {
for (i in 1:length(listobj)) {
 objtemp - get (listobj[i])
 objtemp - objtemp * valueX
 assign(paste(listobj[i], _, valueX, sep=), objtemp)
}
return (??)
}

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


[R] Column width in dbf file ... again ...

2010-02-10 Thread Arnaud Mosnier
Hello,

First please excuse me for reposting the same question I sent a few
weeks ago, but I did not have any answer !

I am trying to manually choose the width (i.e. number of character
allowed) of columns containing text when creating dbf. files using
write.dbf (library foreign).
In particular, I want to define this width when the column have to
contain text but is empty.

In that case, by default, write.dbf give a warning message then choose
the width equal to the number of character in the column title.


Example:

df-data.frame(INDEX=1:10, TEXT=NA_character_)
write.dbf(df, paste(choose.dir(), //test.dbf,sep=))
# Give a warning message but create the dbf file. The width of the
column TEXT is 4 as the number of character in the word TEXT !


Thanks for your help,


P.S. : complementary info. R version 2.10.1 (2009-12-14) i386-pc-mingw32

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


[R] Write.dbf ... problem

2010-01-20 Thread Arnaud Mosnier
Hello,

I am trying to manually choose the width (i.e. number of character
allowed) of columns containing text when creating dbf. files using write.dbf
(library foreign).
In particular, I want to define this width when the column have to contain
text but is empty.

By default, write.dbf give a warning message then choose the width equal to
the number of character in the column title.


Example:

df-data.frame(INDEX=1:10, TEXT=NA_character_)
write.dbf(df, paste(choose.dir(), //test.dbf,sep=))
# Give a warning message but create the dbf file. The width of the column
TEXT is 4 as the number of character in the word TEXT !


Thanks for your help,

Arnaud

[[alternative HTML version deleted]]

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


Re: [R] How can I store the results

2010-01-14 Thread Arnaud Mosnier
If you absolutely need a single file for each iteration, you can also
include the iteration number into your output filename.

for(i in 1:dim(your input data)[1]) {
results- your calculation
   write.csv(results, paste(filename, _, i, sep=))
}

Arnaud

Date: Wed, 13 Jan 2010 15:59:37 +0100
From: Alex Roy alexroy2...@gmail.com
To: r-help@r-project.org
Subject: [R] How can I store the results
Message-ID:
   8bdeb1b51001130659n6341b0e6oe42a029efb7a1...@mail.gmail.com
Content-Type: text/plain

Dear R users,
   I am running a R code which gives me 10 columns and
160 rows. I need to run the code for 100 times and each time I need to store
the results in a single file.
I do not know how can I store them in a single file without over writting
the results?

Thanks

Alex

[[alternative HTML version deleted]]

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


[R] column width in .dbf files using write.dbf ... to be continued

2010-01-13 Thread Arnaud Mosnier
Dear UseRs,

I did not have any answer to my previous message (Is there a way to define
manually columns width when using write.dbf function from the library
foreign ?), so I tried to modify write.dbf function to do what I want.

Here is my modified version :

write.dbfMODIF - function (dataframe, file, factor2char = TRUE, max_nchar =
254, width = d)
{
allowed_classes - c(logical, integer, numeric, character,
factor, Date)
if (!is.data.frame(dataframe))
dataframe - as.data.frame(dataframe)
if (any(sapply(dataframe, function(x) !is.null(dim(x)
stop(cannot handle matrix/array columns)
cl - sapply(dataframe, function(x) class(x[1L]))
asis - cl == AsIs
cl[asis  sapply(dataframe, mode) == character] - character
if (length(cl0 - setdiff(cl, allowed_classes)))
stop(data frame contains columns of unsupported class(es) ,
paste(cl0, collapse = ,))
m - ncol(dataframe)
DataTypes - c(logical = L, integer = N, numeric = F,
character = C, factor = if (factor2char) C else N,
Date = D)[cl]
for (i in seq_len(m)) {
x - dataframe[[i]]
if (is.factor(x))
dataframe[[i]] - if (factor2char)
as.character(x)
else as.integer(x)
else if (inherits(x, Date))
dataframe[[i]] - format(x, %Y%m%d)
}
precision - integer(m)
scale - integer(m)
dfnames - names(dataframe)
for (i in seq_len(m)) {
nlen - nchar(dfnames[i], b)
x - dataframe[, i]
if (is.logical(x)) {
precision[i] - 1L
scale[i] - 0L
}
else if (is.integer(x)) {
rx - range(x, na.rm = TRUE)
rx[!is.finite(rx)] - 0
if (any(rx == 0))
rx - rx + 1
mrx - as.integer(max(ceiling(log10(abs(rx +
3L)
precision[i] - min(max(nlen, mrx), 19L)
scale[i] - 0L
}
else if (is.double(x)) {
precision[i] - 19L
rx - range(x, na.rm = TRUE)
rx[!is.finite(rx)] - 0
mrx - max(ceiling(log10(abs(rx
scale[i] - min(precision[i] - ifelse(mrx  0L, mrx +
3L, 3L), 15L)
}
else if (is.character(x)) {
if (width == d) {
   mf - max(nchar(x[!is.na(x)], b))
p - max(nlen, mf)
if (p  max_nchar)
warning(gettext(character column %d will be truncated
to %d bytes,
  i, max_nchar), domain = NA)
precision[i] - min(p, max_nchar)
scale[i] - 0L
} else {
if (width  max_nchar)
warning(gettext(character column %d will be truncated
to %d bytes,
  i, max_nchar), domain = NA)
precision[i] - min(width, max_nchar)
}
}
else stop(unknown column type in data frame)
}
if (any(is.na(precision)))
stop(NA in precision)
if (any(is.na(scale)))
stop(NA in scale)
invisible(.Call(DoWritedbf, as.character(file), dataframe,
as.integer(precision), as.integer(scale), as.character(DataTypes)))
}


However, when I wanted to use this function ... it does not find the
DoWritedbf function that is called in the last lines (a function written in
C).

Is there a way to temporally replace the original write.dbf function by this
one in the foreign package ?

Thanks,

Arnaud

R version 2.10.0 (2009-10-26)
i386-pc-mingw32

[[alternative HTML version deleted]]

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


[R] column width in .dbf files using write.dbf

2010-01-06 Thread Arnaud Mosnier
Dear useRs,

Is there a way to define manually columns width when using write.dbf
function from the library foreign ?

Thanks,

Arnaud


R version 2.10.0 (2009-10-26)
i386-pc-mingw32

[[alternative HTML version deleted]]

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


[R] Strange characters that block import

2009-10-14 Thread arnaud Mosnier
Dear useRs,

I try to import a text file that contain some strange characters coming from
the misinterpretation of foreign language characters by another software
(see below).


Here is an example of text with a line containing characters that bug the
import

name;number
zdsfbg;2
 ;3
dtryjh;4



R do not want to import lines after those strange characters (i.e. import
only the first two lines, one is the header, the second the first line of
data).

I already try to import using other encoding such as latin1 or UTF-8 but it
does not solve the problem.

Replacing those character in a text editor before importing solve the
solution, but I want that the user of my script do not have to edit the text
before the analysis in R.

Any hint ??

Thanks

[[alternative HTML version deleted]]

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