Re: [R] problem installing R 2.5

2016-11-07 Thread Göran Broström

libX11-dev?

Göran

On 2016-11-07 19:27, Lentes, Bernd via R-help wrote:

Hi,

i'd like to install R 2.5 on an Ubuntu 14.04. I have a special
software requiring this old version.

While ./configure, i get the following error:

checking for mbstate_t... yes checking for X... no configure: error:
--with-x=yes (default) and X11 headers/libs are not available

The problem is that i don't know which headers or libraries are
missing, and when i search with aptitude in the Ubuntu repositories i
find a ton of them and don't know which one to install.

Can anyone help me ?

Thanks.


Bernd



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] a book recommendation, please [O/T]

2016-11-07 Thread Erin Hodgess
I like BH^2 as well as a reference book!  I actually think I will go with
the DOE with R by Larson.  Thanks to all for the help!

Sincerely,
Erin


On Mon, Nov 7, 2016 at 10:59 PM, Bert Gunter  wrote:

> Have you looked here:
>
> https://www.amazon.com/s/ref=sr_pg_2?rh=n%3A283155%2Ck%
> 3Aexperimental+design=2=experimental+design&
> ie=UTF8=1478580868
>
> I would think your choice depends strongly on the arena of application.
>
> Of course I like BH^2, but that was because I was taught by them.
>
> Cheers,
> Bert
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Mon, Nov 7, 2016 at 8:13 PM, Erin Hodgess 
> wrote:
> > Hello!
> >
> > Could someone recommend a good book on Design of Experiments for a
> Master's
> > in Data Analytics, please?
> >
> > I use Montgomery's book for my undergrad course, but was thinking about
> > something a little more advanced for this one.
> >
> > Any help much appreciated, particularly with R-related texts.
> >
> > Sincerely,
> > Erin
> >
> >
> > --
> > Erin Hodgess
> > Associate Professor
> > Department of Mathematical and Statistics
> > University of Houston - Downtown
> > mailto: erinm.hodg...@gmail.com
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] a book recommendation, please [O/T]

2016-11-07 Thread Bert Gunter
Have you looked here:

https://www.amazon.com/s/ref=sr_pg_2?rh=n%3A283155%2Ck%3Aexperimental+design=2=experimental+design=UTF8=1478580868

I would think your choice depends strongly on the arena of application.

Of course I like BH^2, but that was because I was taught by them.

Cheers,
Bert
Bert Gunter

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


On Mon, Nov 7, 2016 at 8:13 PM, Erin Hodgess  wrote:
> Hello!
>
> Could someone recommend a good book on Design of Experiments for a Master's
> in Data Analytics, please?
>
> I use Montgomery's book for my undergrad course, but was thinking about
> something a little more advanced for this one.
>
> Any help much appreciated, particularly with R-related texts.
>
> Sincerely,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] a book recommendation, please [O/T]

2016-11-07 Thread Erin Hodgess
Hello!

Could someone recommend a good book on Design of Experiments for a Master's
in Data Analytics, please?

I use Montgomery's book for my undergrad course, but was thinking about
something a little more advanced for this one.

Any help much appreciated, particularly with R-related texts.

Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Help with decrypting

2016-11-07 Thread Bob Rudis
Perhaps https://cran.r-project.org/web/packages/bcrypt/index.html
might be of assistance.

If not, drop a note back to the list as it'll be trivial to expand on
that to give you an R alternative to Perl.

On Mon, Nov 7, 2016 at 5:47 PM, MacQueen, Don  wrote:
> I have a file containing encrypted contents. The contents can be decrypted
> using perl, like this:
>
> open (FILEHANDLE, "/path/to/file")
> chomp ($ciphertext = );
>
>
> use Crypt::CBC;
> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>-cipher => 'Blowfish'
>   );
>
> $plaintext  = $cipher->decrypt($ciphertext);
>
>
> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
>
> M goal is to have the value of $plaintext in an R object, so, is there an
> R equivalent to this decrypt() perl function?
>
> I've found R packages
>   bcrypt
>   sodium
> that appear to have potential, but I don't understand this business well
> enough to figure out how to use them, if indeed they can be used, for
> this. Help would be much appreciated.
>
> Thanks
> -Don
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Help with decrypting

2016-11-07 Thread Marc Schwartz

> On Nov 7, 2016, at 4:47 PM, MacQueen, Don  wrote:
> 
> I have a file containing encrypted contents. The contents can be decrypted
> using perl, like this:
> 
> open (FILEHANDLE, "/path/to/file")
> chomp ($ciphertext = );
> 
> 
> use Crypt::CBC;
> $cipher = Crypt::CBC->new( -key=> 'my secret key',
>   -cipher => 'Blowfish'
>  );
> 
> $plaintext  = $cipher->decrypt($ciphertext);
> 
> 
> (See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)
> 
> M goal is to have the value of $plaintext in an R object, so, is there an
> R equivalent to this decrypt() perl function?
> 
> I've found R packages
>  bcrypt
>  sodium
> that appear to have potential, but I don't understand this business well
> enough to figure out how to use them, if indeed they can be used, for
> this. Help would be much appreciated.
> 
> Thanks
> -Don
> 



Hi Don,

Blowfish is Bruce Schneier's algorithm from the early 90's, which even Bruce 
suggested some time ago not be used. Bruce has some alternative Blowfish 
implementations available via his web site:

  https://www.schneier.com/academic/blowfish/download.html 


and there is a link there for some third party products that still have it and 
might provide for a CLI based interface as an alternative (e.g. GnuPG) if you 
need to use it.

>From what I can tell, 'sodium' does not support Blowfish and the 
>implementation in bcrypt, if I am reading correctly, only provides for a 
>one-way hash implementation, as opposed to encrypt/decrypt functions.

Thus, barring that my searching for alternative R implementations of Blowfish 
resulted in a Type II error, I do not see any R implementations of Blowfish 
that support encrypt/decrypt.

If you want to use the Perl module implementation via R, you can take a look at 
my WriteXLS package on GitHub:

  https://github.com/marcschwartz/WriteXLS 


and see how I call Perl scripts within WriteXLS.R:

  https://github.com/marcschwartz/WriteXLS/blob/master/R/WriteXLS.R 


around line 242.

That might provide one method for you.

That all being said, as per Bruce's recommendation, there are "better" 
encryption/decryption algorithms these days (some in the 'digest' package by 
Dirk), depending upon who you are trying to protect the data from... :-)

Regards,

Marc Schwartz



[[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 with decrypting

2016-11-07 Thread MacQueen, Don
I have a file containing encrypted contents. The contents can be decrypted
using perl, like this:

open (FILEHANDLE, "/path/to/file")
chomp ($ciphertext = );


use Crypt::CBC;
$cipher = Crypt::CBC->new( -key=> 'my secret key',
   -cipher => 'Blowfish'
  );

$plaintext  = $cipher->decrypt($ciphertext);


(See http://search.cpan.org/~lds/Crypt-CBC-2.33/CBC.pm)

M goal is to have the value of $plaintext in an R object, so, is there an
R equivalent to this decrypt() perl function?

I've found R packages
  bcrypt
  sodium
that appear to have potential, but I don't understand this business well
enough to figure out how to use them, if indeed they can be used, for
this. Help would be much appreciated.

Thanks
-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062

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

2016-11-07 Thread Jeff Newmiller
You have non-numeric data somewhere in that column, and factor is already a 
numeric type (Read about factors in the Introduction to R document that comes 
with R). Try 

DF$prec_new = as.numeric(as.character (DF$precip)

and then look at

DF$precip[ is.na( DF$precip_new ) ]

to see which values are corrupt. Eliminating the whole factor conversion in the 
first place might be as simple as adding an na.string argument to your 
read.table or read.csv call that imports the data.

If you need further help, next time send plain text format email with a 
reproducible example. 

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

http://adv-r.had.co.nz/Reproducibility.html
-- 
Sent from my phone. Please excuse my brevity.

On November 7, 2016 12:24:57 PM PST, lily li  wrote:
>Hi R users,
>
>I'm wondering why the values changed when I try to transform factors
>into
>numerics.
>
>For example, for a data frame DF, there is one column called
>precipitation,
>which is usually lower than 100mm. But this column is factor when I
>read in
>the data. When transform to numeric values, some rows can be higher
>than
>1000mm. What is the problem? Thanks.
>
>DF$prec_new = as.numeric(DF$precip)
>
>   [[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] Euler & Runge-Kutta

2016-11-07 Thread Thomas Petzoldt

Am 07.11.2016 um 21:52 schrieb Franklin Bretschneider:

Hello Tom Mosca,

Re:


Can someone help me with R code to perform approximations to second order 
differential equations and systems of first order differential equations using 
Euler's method and Runge-Kutta?  I am not a student and this is not for a test 
or graded assignment.

Examples (unrelated to each other):

h = 0.1

1.  3(t^2)y'' - 5ty' + 5y = 0
y(1) = 0, y'(1) = 2/3

2.  Lotka-Volterra
x' = x(3-y)
y' = y(x-3)




For solving differential equations, the famous "lsoda" solver is best, far better 
than the simple Euler method, and also better than Runge & Kutta.
Angels, or very nice people, implemented solving methods using the lsoda into R. Download 
the package "deSolve" and the world of numerical solutions is at your feet.


deSolve contains all of this: Euler, Runge-Kutta, lsoda and more ... and 
you will find many examples, papers, tutorials and books, and a special 
mailing list (special interest group) at:


http://desolve.r-forge.r-project.org

Have fun!

Thomas Petzoldt



Succes, Franklin
-


Thanks, Franklin :)






Franklin Bretschneider
Dept of Biology
Utrecht University
brets...@xs4all.nl

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

2016-11-07 Thread Franklin Bretschneider
Hello Tom Mosca,

Re:

> Can someone help me with R code to perform approximations to second order 
> differential equations and systems of first order differential equations 
> using Euler's method and Runge-Kutta?  I am not a student and this is not for 
> a test or graded assignment.
> 
> Examples (unrelated to each other):
> 
> h = 0.1
> 
> 1.  3(t^2)y'' - 5ty' + 5y = 0
> y(1) = 0, y'(1) = 2/3
> 
> 2.  Lotka-Volterra
> x' = x(3-y)
> y' = y(x-3)
> 


For solving differential equations, the famous "lsoda" solver is best, far 
better than the simple Euler method, and also better than Runge & Kutta.
Angels, or very nice people, implemented solving methods using the lsoda into 
R. Download the package "deSolve" and the world of numerical solutions is at 
your feet.

Succes, Franklin
-




Franklin Bretschneider
Dept of Biology
Utrecht University
brets...@xs4all.nl

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

2016-11-07 Thread Rui Barradas

Hello,

Try

as.numeric(as.character(DF$precip))

Hope this helps,

Rui Barradas

Em 07-11-2016 20:24, lily li escreveu:

Hi R users,

I'm wondering why the values changed when I try to transform factors into
numerics.

For example, for a data frame DF, there is one column called precipitation,
which is usually lower than 100mm. But this column is factor when I read in
the data. When transform to numeric values, some rows can be higher than
1000mm. What is the problem? Thanks.

DF$prec_new = as.numeric(DF$precip)

[[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] about data structure

2016-11-07 Thread lily li
Hi R users,

I'm wondering why the values changed when I try to transform factors into
numerics.

For example, for a data frame DF, there is one column called precipitation,
which is usually lower than 100mm. But this column is factor when I read in
the data. When transform to numeric values, some rows can be higher than
1000mm. What is the problem? Thanks.

DF$prec_new = as.numeric(DF$precip)

[[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] Dealing with -Inf in a maximisation problem.

2016-11-07 Thread William Dunlap via R-help
Using log1p instead of log improves the accuracy of the 'subtract xmax'
algorithm when the largest x is very close to zero.  Perhaps that is what
is missing in the Rf_logspace_add.

test <- function (x) {
x <- as.numeric(x)
i <- which.max(x)
rbind(Rmpfr = as.numeric(log(sum(exp(Rmpfr::mpfr(x, precBits=5000),
  Rf_logspace_sum = logspace_sum(x),
  subtract_xmax_log1p = log1p(sum(exp(x[-i] - x[i]))) + x[i],
  subtract_xmax_naive = log(sum(exp(x - x[i]))) + x[i],
  naive = log(sum(exp(x
}

> test(c(-1e-50, -46, -47))
[,1]
Rmpfr1.4404614986241e-20
Rf_logspace_sum -1.0e-50
subtract_xmax_log1p  1.4404614986241e-20
subtract_xmax_naive -1.0e-50
naive0.0e+00
> test(c(0, -46, -47))
   [,1]
Rmpfr   1.4404614986241e-20
Rf_logspace_sum 0.0e+00
subtract_xmax_log1p 1.4404614986241e-20
subtract_xmax_naive 0.0e+00
naive   0.0e+00


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Nov 7, 2016 at 11:09 AM, William Dunlap  wrote:

> It would be nice if the C functions Rf_logspace_sum, Rf_logspace_add, and
> Rf_logspace_sub were available as R functions.  (I wish the '_sub' were
> '_subtract' because 'sub' means too many things in R.)
>
> I think Rf_logspace_sum in R could be a little better. E.g., using the C
> code
>
> #include 
> #include 
> #include 
>
> SEXP Call_logspace_sum(SEXP x)
> {
> if (TYPEOF(x) != REALSXP)
> {
> Rf_error("'x' must be a numeric vector");
> }
> return ScalarReal(Rf_logspace_sum(REAL(x), length(x)));
> }
>
> and the R functions
>
> logspace_sum <- function (x) .Call("Call_logspace_sum", as.numeric(x))
>
> and
>
> test <- function (x) {
> x <- as.numeric(x)
> rbind(Rmpfr = as.numeric(log(sum(exp(Rmpfr::mpfr(x,
> precBits=5000),
>   Rf_logspace_sum = logspace_sum(x),
>   subtract_xmax = log(sum(exp(x - max(x + max(x),
>   naive = log(sum(exp(x
> }
>
>
> R-3.3.2 on Linux gives, after options(digits=17)
> > test(c(0, -50))
>   [,1]
> Rmpfr   1.9287498479639178e-22
> Rf_logspace_sum 1.9287498479639178e-22
> subtract_xmax   0.e+00
> naive   0.e+00
>
> which is nice, but also the not so nice
>
> > test(c(0, -50, -50))
>   [,1]
> Rmpfr   3.8574996959278356e-22
> Rf_logspace_sum 0.e+00
> subtract_xmax   0.e+00
> naive   0.e+00
>
> With TERR the second test has Rmpfr==Rf_logspace_sum for that example.
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Mon, Nov 7, 2016 at 3:08 AM, Martin Maechler <
> maech...@stat.math.ethz.ch> wrote:
>
>> > William Dunlap via R-help 
>> > on Sun, 6 Nov 2016 20:53:17 -0800 writes:
>>
>> > Perhaps the C function Rf_logspace_sum(double *x, int n) would help
>> in
>> > computing log(b).  It computes log(sum(exp(x_i))) for i in 1..n,
>> avoiding
>> > unnecessary under- and overflow.
>>
>> Indeed!
>>
>> I had thought more than twice to also export it to the R level
>> notably as we have been using two R level versions in a package
>> I maintain ('copula'). They are vectorized there in a way that
>> seemed particularly useful to our (Marius Hofert and my) use cases.
>>
>> More on this -- making these available in R, how exactly? --
>> probably should move to the R-devel list.
>>
>> Thank you Bill for bringing it up!
>> Martin
>>
>> > Bill Dunlap
>> > TIBCO Software
>> > wdunlap tibco.com
>>
>> > On Sun, Nov 6, 2016 at 5:25 PM, Rolf Turner <
>> r.tur...@auckland.ac.nz> wrote:
>>
>> >> On 07/11/16 13:07, William Dunlap wrote:
>> >>
>> >>> Have you tried reparameterizing, using logb (=log(b)) instead of
>> b?
>> >>>
>> >>
>> >> Uh, no.  I don't think that that makes any sense in my context.
>> >>
>> >> The "b" values are probabilities and must satisfy a "sum-to-1"
>> >> constraint.  To accommodate this constraint I re-parametrise via a
>> >> "logistic" style parametrisation --- basically
>> >>
>> >> b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n
>> >>
>> >> with the parameters that the optimiser works with being z_1, ...,
>> z_{n-1}
>> >> (and with z_n == 0 for identifiability).  The objective function
>> is of the
>> >> form sum_i(a_i * log(b_i)), so I transform back
>> >> from the z_i to the b_i in order calculate the value of the
>> objective
>> >> function.  But when the z_i get moderately large-negative, the b_i
>> become
>> >> numerically 0 and then log(b_i) becomes -Inf.  And the optimiser
>> falls over.
>> >>
>> >> cheers,
>> >>
>> >> Rolf
>> >>
>> >>
>> >>> Bill Dunlap
>> >>> TIBCO 

Re: [R] Three-component Negative Binomial Mixture: R code

2016-11-07 Thread Achim Zeileis

On Mon, 7 Nov 2016, danilo.car...@uniparthenope.it wrote:


I need a function for R software which computes a mixture of Negative
Binomial distributions with at least three components.


The package "countreg" on R-Forge provides a driver FLXMRnegbin() that can 
be combined with the "flexmix" package (i.e., functions flexmix() and 
stepFlexmix()). The manual page provides some worked illustrations in 
example("FLXMRnegbin", package = "countreg").


Note that the driver is mainly designed for negative binomial _regression_ 
models. But if you just regress on a constant (y ~ 1) you can also get 
negative binomial mixture distributions without covariates.



I found on another site the following function "mixnbinom". It works very
well, but it computes a mixture of only two components:



mixnbinom=function(y,k1,mu1,k2,mu2,prob,eps=1/10)
{
 new.parms=c(k1,mu1,k2,mu2,prob)
 err=1
 iter=1
 maxiter=100
 hist(y,probability=T,nclass=30,col="lightgrey",main="The EM algorithm")
 xvals=seq(min(y),max(y),1)
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="green")
 while(err>eps){
 if(iter<=maxiter){
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),lty=3)
 }
 bayes=(prob*dnbinom(y,size=k1,mu=mu1))/((prob*
 dnbinom(y,size=k1,mu=mu1))+((1-prob)*dnbinom(y,size=k2,mu=mu2)))
 mu1=sum(bayes*y)/sum(bayes)
 mu2=sum((1-bayes)*y)/sum((1-bayes))
 var1=sum(bayes*(y-mu1)^2)/sum(bayes)
 var2=sum((1-bayes)*(y-mu2)^2)/sum((1-bayes))
 k1=abs(mu1/((var1/mu1)-1))
 k2=abs(mu2/((var2/mu2)-1))
 prob=mean(bayes)
 old.parms=new.parms
 new.parms=c(k1,mu1,k2,mu2,prob)
 err=max(abs((old.parms-new.parms)/new.parms))
 iter=iter+1
 }
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="red")
 print(list(k1=k1,mu1=mu1,k2=k2,mu2=mu2,p=prob,iter=iter,err=err))
}



I would be grateful if someone can modify the previous function to
model a three-component mixture instead of a two-component one.

I also tried to look for a package which does the same job: I have
used the package "mixdist", but I am not able to set up a suitable set
of starting parameters for the function mix (they always converge to
zero). Hereafter, I found the package "DEXUS", but the related function
does not provide good estimates for the model, even in the event that
I already know what results I have to expect.

Any help is highly appreciated.


Danilo Carità

-
Danilo Carità

PhD Candidate
University of Naples "Parthenope"
Dipartimento di Studi Aziendali e Quantitativi
via G. Parisi, 13, 80132 Napoli - Italy

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

2016-11-07 Thread Jeff Newmiller
Google is your friend "R Runge kutta" [1][2]

This actually is not the "do my research for me" list... when you have a 
specific problem with R, this is a good place to get help by providing a 
reproducible example. You are expected to have some reasonable familiarity with 
the theory underlying the task you are working on and with basic R syntax so we 
can focus on where R is not doing what you want.

Why are you interested in Euler AND Runge-Kutta? Why aren't you just interested 
in solving the DEs to within some uncertainty?

[1] https://www.jstatsoft.org/article/view/v033i09/v033i09.pdf
[2] https://cran.r-project.org/web/views/DifferentialEquations.html
-- 
Sent from my phone. Please excuse my brevity.

On November 7, 2016 9:26:12 AM PST, Tom Mosca  wrote:
>Can someone help me with R code to perform approximations to second
>order differential equations and systems of first order differential
>equations using Euler's method and Runge-Kutta?  I am not a student and
>this is not for a test or graded assignment.
>
>Examples (unrelated to each other):
>
>h = 0.1
>
>1.  3(t^2)y'' - 5ty' + 5y = 0
> y(1) = 0, y'(1) = 2/3
>
>2.  Lotka-Volterra
> x' = x(3-y)
> y' = y(x-3)
>
>
>
>
>   [[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] Dealing with -Inf in a maximisation problem.

2016-11-07 Thread William Dunlap via R-help
It would be nice if the C functions Rf_logspace_sum, Rf_logspace_add, and
Rf_logspace_sub were available as R functions.  (I wish the '_sub' were
'_subtract' because 'sub' means too many things in R.)

I think Rf_logspace_sum in R could be a little better. E.g., using the C
code

#include 
#include 
#include 

SEXP Call_logspace_sum(SEXP x)
{
if (TYPEOF(x) != REALSXP)
{
Rf_error("'x' must be a numeric vector");
}
return ScalarReal(Rf_logspace_sum(REAL(x), length(x)));
}

and the R functions

logspace_sum <- function (x) .Call("Call_logspace_sum", as.numeric(x))

and

test <- function (x) {
x <- as.numeric(x)
rbind(Rmpfr = as.numeric(log(sum(exp(Rmpfr::mpfr(x, precBits=5000),
  Rf_logspace_sum = logspace_sum(x),
  subtract_xmax = log(sum(exp(x - max(x + max(x),
  naive = log(sum(exp(x
}


R-3.3.2 on Linux gives, after options(digits=17)
> test(c(0, -50))
  [,1]
Rmpfr   1.9287498479639178e-22
Rf_logspace_sum 1.9287498479639178e-22
subtract_xmax   0.e+00
naive   0.e+00

which is nice, but also the not so nice

> test(c(0, -50, -50))
  [,1]
Rmpfr   3.8574996959278356e-22
Rf_logspace_sum 0.e+00
subtract_xmax   0.e+00
naive   0.e+00

With TERR the second test has Rmpfr==Rf_logspace_sum for that example.



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Nov 7, 2016 at 3:08 AM, Martin Maechler 
wrote:

> > William Dunlap via R-help 
> > on Sun, 6 Nov 2016 20:53:17 -0800 writes:
>
> > Perhaps the C function Rf_logspace_sum(double *x, int n) would help
> in
> > computing log(b).  It computes log(sum(exp(x_i))) for i in 1..n,
> avoiding
> > unnecessary under- and overflow.
>
> Indeed!
>
> I had thought more than twice to also export it to the R level
> notably as we have been using two R level versions in a package
> I maintain ('copula'). They are vectorized there in a way that
> seemed particularly useful to our (Marius Hofert and my) use cases.
>
> More on this -- making these available in R, how exactly? --
> probably should move to the R-devel list.
>
> Thank you Bill for bringing it up!
> Martin
>
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com
>
> > On Sun, Nov 6, 2016 at 5:25 PM, Rolf Turner 
> wrote:
>
> >> On 07/11/16 13:07, William Dunlap wrote:
> >>
> >>> Have you tried reparameterizing, using logb (=log(b)) instead of b?
> >>>
> >>
> >> Uh, no.  I don't think that that makes any sense in my context.
> >>
> >> The "b" values are probabilities and must satisfy a "sum-to-1"
> >> constraint.  To accommodate this constraint I re-parametrise via a
> >> "logistic" style parametrisation --- basically
> >>
> >> b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n
> >>
> >> with the parameters that the optimiser works with being z_1, ...,
> z_{n-1}
> >> (and with z_n == 0 for identifiability).  The objective function is
> of the
> >> form sum_i(a_i * log(b_i)), so I transform back
> >> from the z_i to the b_i in order calculate the value of the
> objective
> >> function.  But when the z_i get moderately large-negative, the b_i
> become
> >> numerically 0 and then log(b_i) becomes -Inf.  And the optimiser
> falls over.
> >>
> >> cheers,
> >>
> >> Rolf
> >>
> >>
> >>> Bill Dunlap
> >>> TIBCO Software
> >>> wdunlap tibco.com 
> >>>
> >>> On Sun, Nov 6, 2016 at 1:17 PM, Rolf Turner <
> r.tur...@auckland.ac.nz
> >>> > wrote:
> >>>
> >>>
> >>> I am trying to deal with a maximisation problem in which it is
> >>> possible for the objective function to (quite legitimately) return
> >>> the value -Inf, which causes the numerical optimisers that I have
> >>> tried to fall over.
> >>>
> >>> The -Inf values arise from expressions of the form "a * log(b)",
> >>> with b = 0.  Under the *starting* values of the parameters, a must
> >>> equal equal 0 whenever b = 0, so we can legitimately say that a *
> >>> log(b) = 0 in these circumstances.  However as the maximisation
> >>> algorithm searches over parameters it is possible for b to take the
> >>> value 0 for values of
> >>> a that are strictly positive.  (The values of "a" do not change
> during
> >>> this search, although they *do* change between "successive
> searches".)
> >>>
> >>> Clearly if one is *maximising* the objective then -Inf is not a
> value
> >>> of
> >>> particular interest, and we should be able to "move away".  But the
> >>> optimising function just stops.
> >>>
> >>> It is also clear that "moving away" is not a simple task; you can't
> 

Re: [R] Euler & Runge-Kutta

2016-11-07 Thread Ismail SEZEN

> On 07 Nov 2016, at 19:26, Tom Mosca  wrote:
> 
> Can someone help me with R code to perform approximations to second order 
> differential equations and systems of first order differential equations 
> using Euler's method and Runge-Kutta?  I am not a student and this is not for 
> a test or graded assignment.

What is this for?

> 
> Examples (unrelated to each other):
> 
> h = 0.1
> 
> 1.  3(t^2)y'' - 5ty' + 5y = 0
> y(1) = 0, y'(1) = 2/3
> 
> 2.  Lotka-Volterra
> x' = x(3-y)
> y' = y(x-3)
> 
> 
> 
> 
>   [[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] problem installing R 2.5

2016-11-07 Thread Lentes, Bernd via R-help
Hi,

i'd like to install R 2.5 on an Ubuntu 14.04.
I have a special software requiring this old version.

While ./configure, i get the following error:

checking for mbstate_t... yes
checking for X... no
configure: error: --with-x=yes (default) and X11 headers/libs are not available

The problem is that i don't know which headers or libraries are missing, and 
when i search with aptitude in the Ubuntu repositories i find a ton of them and 
don't know which one to install.

Can anyone help me ?

Thanks.


Bernd

-- 
Bernd Lentes 

Systemadministration 
institute of developmental genetics 
Gebäude 35.34 - Raum 208 
HelmholtzZentrum München 
bernd.len...@helmholtz-muenchen.de 
phone: +49 (0)89 3187 1241 
fax: +49 (0)89 3187 2294 

Erst wenn man sich auf etwas festlegt kann man Unrecht haben 
Scott Adams
 

Helmholtz Zentrum Muenchen
Deutsches Forschungszentrum fuer Gesundheit und Umwelt (GmbH)
Ingolstaedter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrer: Prof. Dr. Guenther Wess, Dr. Alfons Enhsen
Registergericht: Amtsgericht Muenchen HRB 6466
USt-IdNr: DE 129521671

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

2016-11-07 Thread Tom Mosca
Can someone help me with R code to perform approximations to second order 
differential equations and systems of first order differential equations using 
Euler's method and Runge-Kutta?  I am not a student and this is not for a test 
or graded assignment.

Examples (unrelated to each other):

h = 0.1

1.  3(t^2)y'' - 5ty' + 5y = 0
 y(1) = 0, y'(1) = 2/3

2.  Lotka-Volterra
 x' = x(3-y)
 y' = y(x-3)




[[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] Three-component Negative Binomial Mixture: R code

2016-11-07 Thread Bert Gunter
Opinion only (and therefore ignorable):

Unless you have a lot (?) of data, fitting such a model successfully
is likely to be very challenging. I suggest that you consult a local
statistical expert to see if you might take a different approach.



On Mon, Nov 7, 2016 at 4:42 AM,   wrote:
> I need a function for R software which computes a mixture of Negative
> Binomial distributions with at least three components.
>
> I found on another site the following function "mixnbinom". It works very
> well, but it computes a mixture of only two components:
>
>
>> mixnbinom=function(y,k1,mu1,k2,mu2,prob,eps=1/10)
>> {
>>  new.parms=c(k1,mu1,k2,mu2,prob)
>>  err=1
>>  iter=1
>>  maxiter=100
>>  hist(y,probability=T,nclass=30,col="lightgrey",main="The EM algorithm")
>>  xvals=seq(min(y),max(y),1)
>>  lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
>>(1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="green")
>>  while(err>eps){
>>  if(iter<=maxiter){
>>  lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
>>(1-prob)*dnbinom(xvals,size=k2,mu=mu2),lty=3)
>>  }
>>  bayes=(prob*dnbinom(y,size=k1,mu=mu1))/((prob*
>>  dnbinom(y,size=k1,mu=mu1))+((1-prob)*dnbinom(y,size=k2,mu=mu2)))
>>  mu1=sum(bayes*y)/sum(bayes)
>>  mu2=sum((1-bayes)*y)/sum((1-bayes))
>>  var1=sum(bayes*(y-mu1)^2)/sum(bayes)
>>  var2=sum((1-bayes)*(y-mu2)^2)/sum((1-bayes))
>>  k1=abs(mu1/((var1/mu1)-1))
>>  k2=abs(mu2/((var2/mu2)-1))
>>  prob=mean(bayes)
>>  old.parms=new.parms
>>  new.parms=c(k1,mu1,k2,mu2,prob)
>>  err=max(abs((old.parms-new.parms)/new.parms))
>>  iter=iter+1
>>  }
>>  lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
>>(1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="red")
>>  print(list(k1=k1,mu1=mu1,k2=k2,mu2=mu2,p=prob,iter=iter,err=err))
>> }
>
>
>
> I would be grateful if someone can modify the previous function to
> model a three-component mixture instead of a two-component one.

Isn't that your job?

-- Bert

>
> I also tried to look for a package which does the same job: I have
> used the package "mixdist", but I am not able to set up a suitable set
> of starting parameters for the function mix (they always converge to
> zero). Hereafter, I found the package "DEXUS", but the related function
> does not provide good estimates for the model, even in the event that
> I already know what results I have to expect.
>
> Any help is highly appreciated.
>
>
> Danilo Carità
>
> -
> Danilo Carità
>
> PhD Candidate
> University of Naples "Parthenope"
> Dipartimento di Studi Aziendali e Quantitativi
> via G. Parisi, 13, 80132 Napoli - Italy
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Kosaraju's SCC Algorithm Running

2016-11-07 Thread Bert Gunter
See here -- found by googling "recursion limits in R"

http://stackoverflow.com/questions/26797537/r-programming-level-of-allowed-recursion-depth-differs-when-calling-a-local-hel

-- Bert
Bert Gunter

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


On Mon, Nov 7, 2016 at 7:49 AM, Jie C  wrote:
> Hi Jeff,
>
> Thanks for your reply! We are definitely not seeking for help with the
> assignment per se. Maybe we should have given you a simpler code to just
> illustrate the problem. We found this to be an interesting case for
> illustrating the recursion limit of R. For other languages such as Python,
> Java, and C++, it seems that they are less likely to hit the problem as R
> does. Even if they do, it is relatively easy to increase the recursion
> depth to the desired numbers. I want to clarify that our purpose is trying
> to understand the limitation of R language in handling big computational
> problems that relies on deep recursion. If you could point us to technical
> documents regarding this, that would be highly appreciated. Also, we could
> definitely re-post a simple code snippet that follows the Posting Guide to
> illustrate that R hits the recursion limitation. Looking forward to your
> advise!
>
> Thanks,
>
> Jie
>
>
>
>
>
> On Mon, Nov 7, 2016 at 2:28 AM, Jeff Newmiller 
> wrote:
>
>> Please read the Posting Guide mentioned at the bottom of this and every
>> post, which warns you that homework is off topic on this mailing list. Use
>> the support provided by your institution of learning (Coursera in this
>> case).
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On November 6, 2016 8:12:38 PM PST, Megan  wrote:
>> >To whom it may concerns,
>> >
>> >We encountered stack overflow issues when we implemented DFS(depth
>> >first search) algorithm on a directed graph having 800,000+ vertices
>> >and millions of edges.  The purpose of running DFS is to use Kosaraju
>> >Algorithm to calculate the size of SCC(strongly connected componment)
>> >in the graph. This is an assignment from Coursea.org
>> >. We know the maximum size of SCC in the graph is
>> >434,821, which means the maximum recursion depth during code running is
>> >434,821. We know it is a large calculation behind the scene, therefore,
>> >we’ve done the below pre-setup hopefully to solve the stack overflow
>> >issue. However, we have not got the luck yet. We’ve tried running on
>> >both R and RStudio.
>> >
>> >We would really appreciate if someone in your team can help to
>> >investigate. We can’t wait to see if our code is working in R.
>> >
>> >System Information:
>> >Model Name:MacBook Pro
>> >  Model Identifier:MacBookPro11,1
>> >  Processor Name:  Intel Core i5
>> >  Processor Speed: 2.4 GHz
>> >  Number of Processors:1
>> >  Total Number of Cores:   2
>> >  L2 Cache (per Core): 256 KB
>> >  L3 Cache:3 MB
>> >  Memory:  8 GB
>> >
>> >System settings we have tried:
>> >1. ulimit- s 65000 (to increase stack size before starting up R)
>> >2. R --max-ppsize =50 (start R with max ppsize)
>> >3. options(expression=50)
>> >
>> >
>> >The data we used can be found on
>> >https://d18ky98rnyall9.cloudfront.net/_410e934e6553ac56409b2cb7096a44
>> aa_SCC.txt?Expires=1478649600=YC0OjTn4hmzWpzAMw3WkQjXgxkAc0q
>> hZrCd07JAPtud3dGQqywpQgkAASf-bWX6qgGafVvObciJ3ww-7wbNqY0YhWxwcg-
>> IxmCnz1xJu1SORdDobiVKmhhfSaqgTyullX1hFmcxAA4y6Ud33hY1dhIP~
>> UTAlW~IV8Y-zSliAts8_=APKAJLTNE6QMUY6HBC5A
>> >> aa_SCC.txt?Expires=1478649600=YC0OjTn4hmzWpzAMw3WkQjXgxkAc0q
>> hZrCd07JAPtud3dGQqywpQgkAASf-bWX6qgGafVvObciJ3ww-7wbNqY0YhWxwcg-
>> IxmCnz1xJu1SORdDobiVKmhhfSaqgTyullX1hFmcxAA4y6Ud33hY1dhIP~
>> UTAlW~IV8Y-zSliAts8_=APKAJLTNE6QMUY6HBC5A>
>> >
>> >Data discription provided as follow:
>> >https://www.coursera.org/learn/algorithm-design-analysis/exam/rOtFq/
>> programming-assignment-4
>> >> programming-assignment-4>
>> >
>> >
>> >Below is our code:
>> >
>> >options(expressions=50)
>> >#Prepare input test file
>> >g=read.table("Downloads/scc.txt")
>> >x<<-as.matrix(g)
>> >remove(g)
>> >vector.is.empty<<-function(x) {return(length(x)==0)}
>> >'%!in%' <- function(x,y)!('%in%'(x,y))
>> >#g<-c(2,1,3,1,3,4,4,2,5,4,5,6,6,7,7,8,8,9,2,3)
>> >#x<<-matrix(g,nrow=10,ncol=2, byrow=TRUE)
>> >#g<-c(1,4,2,8,3,6,4,7,5,2,6,9,7,1,8,5,8,6,9,3,9,7,10,2)
>> >#x<<-matrix(g,nrow=12,ncol=2, byrow=TRUE)
>> >#g<-c(1,2,2,3,2,4,3,4,3,5,4,1,4,13,5,6,6,7,7,8,8,9,9,6,10,
>> 9,10,11,11,8,11,12,12,13,12,14,13,10,14,15)
>> >#x<<-matrix(g,20,2,byrow=TRUE)
>> >
>> >u1<-unique(x[,1])
>> >u2<-unique(x[,2])
>> >u<-c(u1,u2)
>> >n<<-length(unique(u))
>> >remove(u1,u2,u)
>> >
>> >G <<- vector("list", length=n)

Re: [R] Problem with downloading library(Rcmdr)

2016-11-07 Thread varin sacha
David, Jeff,

Many thanks, 

I have installed an older version of R and rmle packages works.

Best






De : David Winsemius 
À : Jeff Newmiller  

oject.org>
Envoyé le : Dimanche 6 novembre 2016 16h35
Objet : Re: [R] Problem with downloading library(Rcmdr)



> On Nov 6, 2016, at 6:10 AM, Jeff Newmiller  wrote:
> 
> I am not aware of a "-1" option for R CMD INSTALL  [1]. Nor do I have a 
> Macintosh.

It compiles from the MacGUI console using an ordinary call (no extra 
environment variables need be set) to install.packages, and then loads without 
error on my Mac running R 3.3.1 patched. (I do have a full set of tools and a 
current version of Rcpp, reference to which which showed up in the compiler 
messages.)  If I had been using the Unix command line I would have offer a full 
path to the *.tar.gz file and not used that "minus one" option.

The Imports line in the DESCRIPTION file:

Imports: MASS, quantreg, nlme, mgcv, stringr, magic, robustbase, Rcpp(>= 0.11.1)

-- 
David.
> 
> Do be prepared to keep reading the documentation once you get past this 
> point, as the whole reason you are doing this is that the original maintainer 
> chose to not fix whatever problems existed in that package, and I have never 
> used that package. Those problems might be minor, or they might be extensive.
> 
> [1] 
> https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Installing-packages
> -- 
> Sent from my phone. Please excuse my brevity.
> 

te:
>> Hi Jeff,
>> 
>> Many thanks for your reply.I know that R packages can be downloaded as
>> "tar.gz" file for Mac OS X from CRAN sources. I have found on Internet
>> that the command is the following :
>> 
>> R CMD INSTALL -1 rlme_0.4.tar.gz
>> 
>> When I run that command on my R console, I get an error as you can read
>> here below.
>> 
>> What am I doing wrong ?
>> 
>> 
>>> R CMD INSTALL -1 rlme_0.4.tar.gz
>> Erreur : unexpected symbol in "R CMD"
>> 
>> 
>> - Mail original -
>> De : Jeff Newmiller 

>> ; David Winsemius 
>> Cc : R-help Mailing List 
>> Envoyé le : Dimanche 6 novembre 2016 0h07
>> Objet : Re: [R] Problem with downloading library(Rcmdr)
>> 
>> Google is your friend... try searching for "CRAN rlme".
>> 
>> The bad thing about contributed packages is that sometimes the
>> maintainers stop maintaining their packages. The good thing is that the
>> source is still there so you can go fix it if you really need it. 
> 

David Winsemius
Alameda, CA, USA

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

[R] Three-component Negative Binomial Mixture: R code

2016-11-07 Thread danilo . carita

I need a function for R software which computes a mixture of Negative
Binomial distributions with at least three components.

I found on another site the following function "mixnbinom". It works very
well, but it computes a mixture of only two components:



mixnbinom=function(y,k1,mu1,k2,mu2,prob,eps=1/10)
{
 new.parms=c(k1,mu1,k2,mu2,prob)
 err=1
 iter=1
 maxiter=100
 hist(y,probability=T,nclass=30,col="lightgrey",main="The EM algorithm")
 xvals=seq(min(y),max(y),1)
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="green")
 while(err>eps){
 if(iter<=maxiter){
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),lty=3)
 }
 bayes=(prob*dnbinom(y,size=k1,mu=mu1))/((prob*
 dnbinom(y,size=k1,mu=mu1))+((1-prob)*dnbinom(y,size=k2,mu=mu2)))
 mu1=sum(bayes*y)/sum(bayes)
 mu2=sum((1-bayes)*y)/sum((1-bayes))
 var1=sum(bayes*(y-mu1)^2)/sum(bayes)
 var2=sum((1-bayes)*(y-mu2)^2)/sum((1-bayes))
 k1=abs(mu1/((var1/mu1)-1))
 k2=abs(mu2/((var2/mu2)-1))
 prob=mean(bayes)
 old.parms=new.parms
 new.parms=c(k1,mu1,k2,mu2,prob)
 err=max(abs((old.parms-new.parms)/new.parms))
 iter=iter+1
 }
 lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+
   (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="red")
 print(list(k1=k1,mu1=mu1,k2=k2,mu2=mu2,p=prob,iter=iter,err=err))
}



I would be grateful if someone can modify the previous function to
model a three-component mixture instead of a two-component one.

I also tried to look for a package which does the same job: I have
used the package "mixdist", but I am not able to set up a suitable set
of starting parameters for the function mix (they always converge to
zero). Hereafter, I found the package "DEXUS", but the related function
does not provide good estimates for the model, even in the event that
I already know what results I have to expect.

Any help is highly appreciated.


Danilo Carità

-
Danilo Carità

PhD Candidate
University of Naples "Parthenope"
Dipartimento di Studi Aziendali e Quantitativi
via G. Parisi, 13, 80132 Napoli - Italy

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Kosaraju's SCC Algorithm Running

2016-11-07 Thread Jie C
Hi Jeff,

Thanks for your reply! We are definitely not seeking for help with the
assignment per se. Maybe we should have given you a simpler code to just
illustrate the problem. We found this to be an interesting case for
illustrating the recursion limit of R. For other languages such as Python,
Java, and C++, it seems that they are less likely to hit the problem as R
does. Even if they do, it is relatively easy to increase the recursion
depth to the desired numbers. I want to clarify that our purpose is trying
to understand the limitation of R language in handling big computational
problems that relies on deep recursion. If you could point us to technical
documents regarding this, that would be highly appreciated. Also, we could
definitely re-post a simple code snippet that follows the Posting Guide to
illustrate that R hits the recursion limitation. Looking forward to your
advise!

Thanks,

Jie





On Mon, Nov 7, 2016 at 2:28 AM, Jeff Newmiller 
wrote:

> Please read the Posting Guide mentioned at the bottom of this and every
> post, which warns you that homework is off topic on this mailing list. Use
> the support provided by your institution of learning (Coursera in this
> case).
> --
> Sent from my phone. Please excuse my brevity.
>
> On November 6, 2016 8:12:38 PM PST, Megan  wrote:
> >To whom it may concerns,
> >
> >We encountered stack overflow issues when we implemented DFS(depth
> >first search) algorithm on a directed graph having 800,000+ vertices
> >and millions of edges.  The purpose of running DFS is to use Kosaraju
> >Algorithm to calculate the size of SCC(strongly connected componment)
> >in the graph. This is an assignment from Coursea.org
> >. We know the maximum size of SCC in the graph is
> >434,821, which means the maximum recursion depth during code running is
> >434,821. We know it is a large calculation behind the scene, therefore,
> >we’ve done the below pre-setup hopefully to solve the stack overflow
> >issue. However, we have not got the luck yet. We’ve tried running on
> >both R and RStudio.
> >
> >We would really appreciate if someone in your team can help to
> >investigate. We can’t wait to see if our code is working in R.
> >
> >System Information:
> >Model Name:MacBook Pro
> >  Model Identifier:MacBookPro11,1
> >  Processor Name:  Intel Core i5
> >  Processor Speed: 2.4 GHz
> >  Number of Processors:1
> >  Total Number of Cores:   2
> >  L2 Cache (per Core): 256 KB
> >  L3 Cache:3 MB
> >  Memory:  8 GB
> >
> >System settings we have tried:
> >1. ulimit- s 65000 (to increase stack size before starting up R)
> >2. R --max-ppsize =50 (start R with max ppsize)
> >3. options(expression=50)
> >
> >
> >The data we used can be found on
> >https://d18ky98rnyall9.cloudfront.net/_410e934e6553ac56409b2cb7096a44
> aa_SCC.txt?Expires=1478649600=YC0OjTn4hmzWpzAMw3WkQjXgxkAc0q
> hZrCd07JAPtud3dGQqywpQgkAASf-bWX6qgGafVvObciJ3ww-7wbNqY0YhWxwcg-
> IxmCnz1xJu1SORdDobiVKmhhfSaqgTyullX1hFmcxAA4y6Ud33hY1dhIP~
> UTAlW~IV8Y-zSliAts8_=APKAJLTNE6QMUY6HBC5A
> > aa_SCC.txt?Expires=1478649600=YC0OjTn4hmzWpzAMw3WkQjXgxkAc0q
> hZrCd07JAPtud3dGQqywpQgkAASf-bWX6qgGafVvObciJ3ww-7wbNqY0YhWxwcg-
> IxmCnz1xJu1SORdDobiVKmhhfSaqgTyullX1hFmcxAA4y6Ud33hY1dhIP~
> UTAlW~IV8Y-zSliAts8_=APKAJLTNE6QMUY6HBC5A>
> >
> >Data discription provided as follow:
> >https://www.coursera.org/learn/algorithm-design-analysis/exam/rOtFq/
> programming-assignment-4
> > programming-assignment-4>
> >
> >
> >Below is our code:
> >
> >options(expressions=50)
> >#Prepare input test file
> >g=read.table("Downloads/scc.txt")
> >x<<-as.matrix(g)
> >remove(g)
> >vector.is.empty<<-function(x) {return(length(x)==0)}
> >'%!in%' <- function(x,y)!('%in%'(x,y))
> >#g<-c(2,1,3,1,3,4,4,2,5,4,5,6,6,7,7,8,8,9,2,3)
> >#x<<-matrix(g,nrow=10,ncol=2, byrow=TRUE)
> >#g<-c(1,4,2,8,3,6,4,7,5,2,6,9,7,1,8,5,8,6,9,3,9,7,10,2)
> >#x<<-matrix(g,nrow=12,ncol=2, byrow=TRUE)
> >#g<-c(1,2,2,3,2,4,3,4,3,5,4,1,4,13,5,6,6,7,7,8,8,9,9,6,10,
> 9,10,11,11,8,11,12,12,13,12,14,13,10,14,15)
> >#x<<-matrix(g,20,2,byrow=TRUE)
> >
> >u1<-unique(x[,1])
> >u2<-unique(x[,2])
> >u<-c(u1,u2)
> >n<<-length(unique(u))
> >remove(u1,u2,u)
> >
> >G <<- vector("list", length=n)
> >G_REV <<- vector("list", length=n)
> >P = numeric(n)
> >FT = numeric(n)
> >
> >for (i in 1:nrow(x)) {
> >  a = x[i,1]
> >  b = x[i,2]
> >  #for G
> >  if (is.null(G[[a]])) {
> >G[[a]] = c(b)
> >  } else {
> >G[[a]] = c(G[[a]], b)
> >  }
> >  if (is.null(G[[b]])) {
> >G[[b]] = numeric()
> >  }
> >  #for G_VEV
> >  if (is.null(G_REV[[b]])) {
> >G_REV[[b]] = c(a)
> >  } else {
> >G_REV[[b]] = c(G_REV[[b]], a)
> >  }
> >  if (is.null(G_REV[[a]])) {
> >G_REV[[a]] = numeric()
> >  }
> >}
> >
> >G_TEMP <<- G_REV
> >
> >#G_REV<<-x[,c(2,1)]
> 

Re: [R] Dealing with -Inf in a maximisation problem.

2016-11-07 Thread Paul Gilbert


I am trying to deal with a maximisation problem in which it is possible
for the objective function to (quite legitimately) return the value
-Inf,


(Just to add to the pedantic part of the discuss by those of us that do 
not qualify as younger and wiser:)


Setting log(0) to -Inf is often convenient but really I think the log 
function is undefined at zero, so I would not refer to this as "legitimate".



which causes the numerical optimisers that I have tried to fall over.


In theory as well as practice. You need to have a function that is 
defined on the whole domain.




The -Inf values arise from expressions of the form "a * log(b)", with b
= 0.  Under the *starting* values of the parameters, a must equal equal
0 whenever b = 0, so we can legitimately say that a * log(b) = 0 in


This also is undefined and not "legitimate". I think there is no reason 
it should be equal zero. We tend to want to set it to the value we think 
of as the "limit": for a=0 the limit as b goes to zero would be zero, 
but the limit of a*(-inf) is -inf as a goes to zero.


So, you really do need to avoid zero because your function is not 
defined there, or find a redefinition that works properly at zero. I 
think you have a solution from another post.


Paul


these circumstances.  However as the maximisation algorithm searches
over parameters it is possible for b to take the value 0 for values of
a that are strictly positive.  (The values of "a" do not change during
this search, although they *do* change between "successive searches".)

Clearly if one is *maximising* the objective then -Inf is not a value of
particular interest, and we should be able to "move away".  But the
optimising function just stops.

It is also clear that "moving away" is not a simple task; you can't
estimate a gradient or Hessian at a point where the function value is -Inf.

Can anyone suggest a way out of this dilemma, perhaps an optimiser that
is equipped to cope with -Inf values in some sneaky way?

Various ad hoc kludges spring to mind, but they all seem to be fraught
with peril.

I have tried changing the value returned by the objective function from
"v" to exp(v) --- which maps -Inf to 0, which is nice and finite.
However this seemed to flatten out the objective surface too much, and
the search stalled at the 0 value, which is the antithesis of optimal.

The problem arises in a context of applying the EM algorithm where the
M-step cannot be carried out explicitly, whence numerical optimisation.
I can give more detail if anyone thinks that it could be relevant.

I would appreciate advice from younger and wiser heads! :-)

cheers,

Rolf Turner

-- Technical Editor ANZJS Department of Statistics University of
Auckland Phone: +64-9-373-7599 ext. 88276


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Dealing with -Inf in a maximisation problem.

2016-11-07 Thread Martin Maechler
> William Dunlap via R-help 
> on Sun, 6 Nov 2016 20:53:17 -0800 writes:

> Perhaps the C function Rf_logspace_sum(double *x, int n) would help in
> computing log(b).  It computes log(sum(exp(x_i))) for i in 1..n, avoiding
> unnecessary under- and overflow.

Indeed!

I had thought more than twice to also export it to the R level
notably as we have been using two R level versions in a package
I maintain ('copula'). They are vectorized there in a way that
seemed particularly useful to our (Marius Hofert and my) use cases.

More on this -- making these available in R, how exactly? --
probably should move to the R-devel list.

Thank you Bill for bringing it up!
Martin

> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com

> On Sun, Nov 6, 2016 at 5:25 PM, Rolf Turner  
wrote:

>> On 07/11/16 13:07, William Dunlap wrote:
>> 
>>> Have you tried reparameterizing, using logb (=log(b)) instead of b?
>>> 
>> 
>> Uh, no.  I don't think that that makes any sense in my context.
>> 
>> The "b" values are probabilities and must satisfy a "sum-to-1"
>> constraint.  To accommodate this constraint I re-parametrise via a
>> "logistic" style parametrisation --- basically
>> 
>> b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n
>> 
>> with the parameters that the optimiser works with being z_1, ..., z_{n-1}
>> (and with z_n == 0 for identifiability).  The objective function is of 
the
>> form sum_i(a_i * log(b_i)), so I transform back
>> from the z_i to the b_i in order calculate the value of the objective
>> function.  But when the z_i get moderately large-negative, the b_i become
>> numerically 0 and then log(b_i) becomes -Inf.  And the optimiser falls 
over.
>> 
>> cheers,
>> 
>> Rolf
>> 
>> 
>>> Bill Dunlap
>>> TIBCO Software
>>> wdunlap tibco.com 
>>> 
>>> On Sun, Nov 6, 2016 at 1:17 PM, Rolf Turner >> > wrote:
>>> 
>>> 
>>> I am trying to deal with a maximisation problem in which it is
>>> possible for the objective function to (quite legitimately) return
>>> the value -Inf, which causes the numerical optimisers that I have
>>> tried to fall over.
>>> 
>>> The -Inf values arise from expressions of the form "a * log(b)",
>>> with b = 0.  Under the *starting* values of the parameters, a must
>>> equal equal 0 whenever b = 0, so we can legitimately say that a *
>>> log(b) = 0 in these circumstances.  However as the maximisation
>>> algorithm searches over parameters it is possible for b to take the
>>> value 0 for values of
>>> a that are strictly positive.  (The values of "a" do not change during
>>> this search, although they *do* change between "successive searches".)
>>> 
>>> Clearly if one is *maximising* the objective then -Inf is not a value
>>> of
>>> particular interest, and we should be able to "move away".  But the
>>> optimising function just stops.
>>> 
>>> It is also clear that "moving away" is not a simple task; you can't
>>> estimate a gradient or Hessian at a point where the function value
>>> is -Inf.
>>> 
>>> Can anyone suggest a way out of this dilemma, perhaps an optimiser
>>> that is equipped to cope with -Inf values in some sneaky way?
>>> 
>>> Various ad hoc kludges spring to mind, but they all seem to be
>>> fraught with peril.
>>> 
>>> I have tried changing the value returned by the objective function
>>> from
>>> "v" to exp(v) --- which maps -Inf to 0, which is nice and finite.
>>> However this seemed to flatten out the objective surface too much,
>>> and the search stalled at the 0 value, which is the antithesis of
>>> optimal.
>>> 
>>> The problem arises in a context of applying the EM algorithm where
>>> the M-step cannot be carried out explicitly, whence numerical
>>> optimisation.
>>> I can give more detail if anyone thinks that it could be relevant.
>>> 
>>> I would appreciate advice from younger and wiser heads! :-)
>>> 
>>> cheers,
>>> 
>>> Rolf Turner
>>> 
>>> --
>>> Technical Editor ANZJS
>>> Department of Statistics
>>> University of Auckland
>>> Phone: +64-9-373-7599 ext. 88276  
>>> 
>>> __
>>> R-help@r-project.org  mailing list --
>>> To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> 
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> 
>>> and provide commented, minimal, 

Re: [R] Rmpfr into data.frame

2016-11-07 Thread Martin Maechler
> Troels Ring 
> on Mon, 7 Nov 2016 10:09:02 +0100 writes:

> Dear friends - Windows, R version 3.2.1
> I wanted to make a ggplot2 using Rmpfr high precision data - but cannot 
> make the data into a data.frame, as wanted by ggplot2. Hence

> library(Rmpfr)
> a <- mpfr(1,120)
> b <- mpfr(2,120)
> dff <- data.frame(a=a,b=b)

> elicits errors

> Error in as.data.frame.default(x[[i]], optional = TRUE) :
> cannot force class »structure("mpfr1", package = "Rmpfr")« into 
> data.frame

ggplot2 nor any other "R-based" (*) plotting engine can make use
of the extra precision in the mpfr numbers.

So for plotting (and other purposes), there's the   asNumeric(.)
function in Rmpfr, which keeps Rmpfr - arrays or matrices.
For the present case (of mpfr-vectors with no attributes), you
can also use  as.numeric() :

> (Pi <- Const("pi"))
1 'mpfr' number of precision  120   bits 
[1] 3.1415926535897932384626433832795028847
> asNumeric(Pi)
[1] 3.141593
> all.equal(pi, asNumeric(Pi), tol=1e-17)
[1] TRUE
> identical(asNumeric(Pi), as.numeric(Pi))
[1] TRUE
> 

and your case
data.frame(a=as.numeric(a), b=as.numeric(b))

As author and maintainer of Rmpfr, I'm curious why you'd be
interested to use high-precision numbers in plots, because even
double precision is usually far from being needed for graphics.

Martin Maechler, ETH Zurich

--
*) in the sense of either relying on "base R"s packages 'graphics' or 'grid';
   the latter is used by lattice and ggplot2.


> (my translation of Danish error)

> How can I do it best?

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

2016-11-07 Thread Troels Ring

Dear friends - Windows, R version 3.2.1

I wanted to make a ggplot2 using Rmpfr high precision data - but cannot 
make the data into a data.frame, as wanted by ggplot2. Hence


library(Rmpfr)
a <- mpfr(1,120)
b <- mpfr(2,120)
dff <- data.frame(a=a,b=b)

elicits errors

Error in as.data.frame.default(x[[i]], optional = TRUE) :
  cannot force class »structure("mpfr1", package = "Rmpfr")« into 
data.frame


(my translation of Danish error)

How can I do it best?

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