我需要在以下R代码中绘制函数(f2)中定义的圆形密度
library(circular)
mu=c(1,1.166) # true values of the mean vector of bivariate normal variables
var.1 =1.096# sigma.1.squared for first normal variable
var.2=1#sigma.2.squared of second normal variable
cov.1.2=-0.31 # covariance between the two normal variables
var.cov<-matrix(c(var.1,cov.1.2,cov.1.2,var.2),nrow=2,ncol=2,byrow=T) #variance covariance matrix of the bivariate normal random variables
f2=function(x){
u=cbind(cos(x),sin(x))
a=drop((u)%*%solve(var.cov)%*%t(u))
b=drop((u)%*%solve(var.cov)%*%(mu))
c=drop(-0.5*t(mu)%*%solve(var.cov)%*%mu)
d=drop(b/sqrt(a))
aa=(cos(x))*(1/(2*pi*a*sqrt(det(var.cov))))*exp(c)*(1+((d*pnorm(d))/dnorm(d)))
return(aa)
}
curve.circular(f2,from=0,to=2*pi,n=101)
问题是我收到错误消息:
lines.circular(x,y,...)中的错误:找不到对象'll' 另外:警告消息: 在sqrt(a)中:产生了NaNs
我不知道该如何处理该错误