Never mind, I figured it out.
You need to use sapply(), for instance, curve(sapply(x, p), from = 0, to
=10)
Thanks all!
On Tue, Oct 27, 2015 at 11:14 AM, C W <tmrsg11 at gmail.com> wrote:
> Dear R list,
>
> I am trying to plot the curve of a function.
>
> Here's the R code:
>
> library(mvtnorm)
>
> p <- function(x, mu){
> mu <- c(mu, 0)
> dmvnorm(c(x, 1), mu, diag(2))
> }
>
> > curve(p(x, 2), from = 0, to =1)
> Error in dmvnorm(c(x, 1), mu, diag(2)) :
> mean and sigma have non-conforming size
>
> I think my matrix probably have different size inside curve(), maybe I
> need to use apply()? I am not sure.
>
> Thanks so much!
>
[[alternative HTML version deleted]]