[R] trying to plot function using curve
Thomas W Blackwell
tblackw at umich.edu
Wed Apr 16 17:13:57 CEST 2003
Faheem -
I observe that function unnorm1() explicitly returns a vector of
length one, constructed from the first and second elements of its
argument. Possibly, it was intended to use the first and second
columns of its argument, in which case the subscripts should read
y[ ,1] and y[ ,2]. Uwe Ligges' comment applies.
HTH - tom blackwell - u michigan medical school - ann arbor -
On Tue, 15 Apr 2003, Faheem Mitha wrote:
> Dear People,
>
> I hope someone can help me with this. I have a function (density) which I
> am trying to plot using curve. I am calling mg.hist(3,2,1), and getting
> the following errors.
> . . .
>
> and more of the same.
>
> I'm not sure where the problem is. I assume it has something to do with me
> incorrectly vectorising my functions(s). However, it seems to me that
> density() is vectorised.
>
> By the way, if anyone would like to suggest a better way to plot density
> plots, please let me know. curve() was suggested to me, which is why I am
> using it. Actually, I want to plot a density curve on top of a histogram.
> I was thinking of trying to use trellis graphics for this, but I'm not
> sure it has any advantages for this purpose.
> Faheem.
>
> ***********************************************************************
> . . .
> unnorm1 <- function(y) ##here y is 2-dim
> {
> ifelse(y[2] == 0,2*theta,
> (1/y[2])*(exp(y[1]*y[2] + y[2]*theta)
> - exp(y[1]*y[2] - y[2]*theta)))
> }
> unnorm2 <- function(y)
> {
> ## return(unnorm1(c(x,y))) ##here y is 1-dim
> ifelse(y == 0,2*theta,
> (1/y)*(exp(x*y + y*theta)
> - exp(x*y - y*theta)))
> }
> . . .
>
More information about the R-help
mailing list