Re: [R] how to plot an user-defined function

2008-02-06 Thread John Smith
Thank all of you for your helps. They are very helpful. But I have a further question. Suppose I have the following mixed effect model thetaMixed <- function(tau, i) { w <- 1 / (s^2 + tau^2) mu <- sum(theta * w) / sum(w) b <- s[i]^2 / (s[i]^2 + tau^2) theta[i]*(1-b) + mu*b) }

Re: [R] how to plot an user-defined function

2008-02-05 Thread Duncan Murdoch
jim holtman wrote: > Your function 'll' only returns a single value when passed a vector: > > >> x <- seq(0,2,.1) >> ll(x) >> > [1] -7.571559 > > > 'plot' expects to pass a vector to the function and have it return a > vector of the same length; e.g., > > >> sin(x) >> > [1] 0.0

Re: [R] how to plot an user-defined function

2008-02-05 Thread jim holtman
Your function 'll' only returns a single value when passed a vector: > x <- seq(0,2,.1) > ll(x) [1] -7.571559 'plot' expects to pass a vector to the function and have it return a vector of the same length; e.g., > sin(x) [1] 0. 0.09983342 0.19866933 0.29552021 0.38941834 0.47942554 0.5

[R] how to plot an user-defined function

2008-02-05 Thread John Smith
Dear R-users, Suppose I have defined a likelihood function as ll(tau), how can I plot this likelihood function by calling it by plot? I want to do it like this: ll <- function(tau) { w <- 1 / (s^2 + tau^2) mu <- sum(theta * w) / sum(w) -1/2*sum((theta-mu)^2*w -log(w)) } plot(ll,