[R] Plotting the Log-Likelihood

2009-08-25 Thread enrico.fosco...@libero.it
Dear Users,

I would like to plot the log-likelihood (depending on two 
parameters).

I wrote the following code:





library(mvtnorm)


sigma<-
matrix(c(4,2,2,3),ncol=2)

x<-rmvnorm(n=500,mean=c(1,2),sigma=sigma)


likel<-
function(param,data){


pos1<-which(data[,1]<0)

pos2<-which(data[,1]>=0)



#density


dens<-rep(0,nrow(data))

dens[pos1]<-dmvnorm(data[pos1,])
*param[1]

dens[pos2]<-dmvnorm(data[pos2,])*param[2]


#return log-
likelihood


sum(log(dens))


}


#plotting the log-likelihood

param1<-
seq(from=0,to=1,length=200)

param2<-seq(from=0,to=1,length=200)

combin<-
as.matrix(expand.grid(param1,param2,KEEP.OUT.ATTRS=FALSE))

likel.values<-
apply(combin,1,likel,data=x)

matr.likel.values<-matrix(likel.values,200,200)


persp(param1,param2,matr.likel.values,

xlab="param1",ylab="param2",


zlab="Likelihood",

theta=5,phi=20,expand=0.5,

col="lightblue",
ltheta=120,shade=0.75,ticktype="detailed")




It is all ok, but I am searching 
for a new "lighting" way in order to earn time.

I need an alternative function 
for apply(), when I calculate the log-likelihood for every single couple of 
values (param1,param2).

Do you have any ideas?

Thank you in advance,




Enrico Foscolo

__
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] Including greek letters in a pairs() plot

2009-03-25 Thread enrico.fosco...@libero.it
Good Morning,

I have a stupid problem about inclusion of greek letters in a 
plot built with function pairs().

First of all, I have a matrix with 3 columns 
and 1000 rows and I would like to use pairs() in order to plot points in the 
upper panel and to compute correlation in the lower panel.

In the lower panel 
I would like to see the following text in each ij-plot: hat(rho)[i,j]=cor(x,y). 
Obviously, rho should be written in according to greek alphabet.

This is my 
function:

panel.cor <- function(x,y){

cor<-0
cor<-round(cor(x,y),4)
text
(0.5,0.5,cor,cex=2)

}

Thank You very much,

Enrico Foscolo

__
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] Find a zero of a composition of functions

2009-04-09 Thread enrico.fosco...@libero.it
Good morning to all,

I should find the zero of a specific function,

func(x,f.
me,c,t)=x+f.me*c-t

where 'c' and 't' are constants and 'f.me' is an other 
function of 'x'.
Actually, I am interested in considering 'f.me' as an 
expression().

Namely,

uniroot.me<-function(f.me,c,t){


func<-function(x,
f.me,c,t) x+eval(f.me)*c-t



uniroot(func,c(0,1),f.me=f.me,c=c,t=t)$root




}


uniroot.me(expression(x*(1-x)),c=1,t=1)

For instance, let me suppose 
that 'f.me=expression(x^a*(1-x))'. How should I do in order to introduce the 
new constant 'a' in function 'uniroot.me'?

Thank you very much,

Enrico 
Foscolo

__
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] Two or more dimensional root (Zero) finding

2009-04-20 Thread enrico.fosco...@libero.it
Good morning to all,

I should find the zero of a specific function with 
respect to a vector of arguments.
Does it exist something similar in R?

Thank 
you very much,

Enrico Foscolo

__
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] Function able to identify the row and the column in a matrix

2009-01-21 Thread enrico.fosco...@libero.it
Good morning to all,

I should evaluate a function for every cell of a given 
matrix with n rows and n columns.

This function, named fun(), has got two 
arguments: the number of the row and the number of the column which 
characterized every single cell.

So the result should be

 fun(1,1) fun(1,2) 
... fun(1,n)
 fun(2,1) fun(2,2) ... fun(2,n)
 ......... 
...
 fun(n,1) fun(n,2) ... fun(n,n)

Does it exist a function which could build 
this new matrix, where each element in the cell (i,j) is fun(i,j), with 1<=i,
j<=n?

Thank you very much,

Enrico Foscolo

__
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] Function able to identify the row and the column in a matrix

2009-01-21 Thread enrico.fosco...@libero.it
Good morning to all,

I should evaluate a function for every cell of a given 
matrix with n rows and n columns.

This function, named fun(), has got two 
arguments: the number of the row and the number of the column which 
characterized every single cell.

So the result should be

 fun(1,1) fun(1,2) 
... fun(1,n)
 fun(2,1) fun(2,2) ... fun(2,n)
 ......... 
...
 fun(n,1) fun(n,2) ... fun(n,n)

Does it exist a function which could build 
this new matrix, where each element in the cell (i,j) is fun(i,j), with 1<=i,
j<=n?

Thank you very much,

Enrico Foscolo

__
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] Color Function

2009-02-18 Thread enrico.fosco...@libero.it
Good Morning to Everybody,

I am searching a function which could define a 
vector of colors from a vector of gray, from white to black (not from black to 
white as the function gray()).

I have to use it in the function image(), 
parameter "col".

Thank You very much,

Enrico Foscolo

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