Yes, indeed, the whole example needs to be rewritten! See the new post about this.

]]>Thanks for your reply.

On page 134, we have the following R codes

“> cau=rcauchy(10^2)

> mcau=median(cau)

> rcau=diff(quantile(cau,c(.25,.75)))

> f=function(x){

+ z=dcauchy(outer(x,cau,FUN=”-“))

+ apply(z,1,mean)}

> fcst=integrate(f,from=-20,to=20)

> ft=function(x){f(x)/fcst}

> g=function(x){dt((x-mcau)/rcau,df=49)/rcau}

> curve(ft,from=-10,to=10)

> curve(g,add=T)

”

I think we should replace apply(z,1,mean) with apply(z,1,prod). I am 100% sure about this.

Thanks.

Ashley

]]>Indeed, this is a clear mistake! The right syntax is c(rnorm(10^2),2.5+rnorm(3*10^2)). Note that you do not need to use sample, though, because the order in which the sample is produced does not matter. And da is not a sample from a mixture, either, because the proportion from each component is fixed.

]]>My question is still on example 5.2, to simulate a sample of 400 observations from the mixture, we use

> da=rbind(rnorm(10^2),2.5+rnorm(3*10^2))

> like=function(mu){

+ sum(log((.25*dnorm(da-mu[1])+.75*dnorm(da-mu[2]))))}

I think we need to replace rbind with c.

> da=sample(c(rnorm(10^2),2.5+rnorm(3*10^2)))

> like=function(mu){

+ sum(log((.25*dnorm(da-mu[1])+.75*dnorm(da-mu[2]))))}

Since rnorm(10^2) is shorter than norm2.5+(3*10^2), rbind will recycle the values in rnorm(10^2).

Regards,

Ashley

]]>After one night’s sleep, I realized what a silly question I asked. Now I got to know the meaning of the R codes.

For your information, the package relaimpo, for assessing relative importance of repressors in linear regression, has different versions for users in US and users outside US.

Thank you very much.

Ashley

]]>It is indeed no longer possible with latest versions of R to use abbreviations in functions like optimise or nlm. A shame in my opinion! Note that R is international and does not have different versions for the US and for the EU.

]]>I am reading chapter 5. I try to reproduced the result on page 128. The R codes don’t work on my laptop. When I try to run the following codes on page 128

“for (i in 1:(nlm(like,sta)$it)){

mmu=rbind(mmu,nlm(like,sta,iter=i)$est)}”,

I always get the error message “Error in f(x, …) : unused argument(s) (iter = 1)”.

It seems that the nlm function doesn’t accept the argument iter. I don’t know how to deal with it. I am in US. I guess the nlm version available to US R users is different from the version in EU. Please help.

Best regards,

Ashley

]]>