R:错误:函数中的维数不正确

我正在尝试在R中为内核方法创建一个函数,该方法是https://shareok.org/bitstream/handle/11244/11006/Chen_okstate_0664D_12928.pdf?sequence=1中提供的方法的多变量扩展

library(mvtnorm)
library(MASS)
Kij<- function(x,y,n,H)
{
  temp1<-temp1b<-array(,dim = c(n-1,p))
  temp1=(1/det(H^(1/2)))*dmvnorm((x-y)%*%(solve(H^(1/2))))
  temp2=(x^2)*mean(temp1 %*% t(temp1))  ##KKij
  temp1b=((1/2)*(x+y))*temp1   

  return (matrix(c(x*mean(temp1),temp2,c(sum(temp1b[1,]^2),sum(temp1b[2,]^2))),ncol=p))
}

Qomega<- function(x,H){
temp1<- array(,dim=c(p,3))
temp2=temp3=temp4=matrix(0,nrow=p)
   for (j in 1:n){
     temp1=Kij(x[j,],x[-j,H)
     temp2=temp2+temp1[1,]        #Kij to \hat{Q}i
     temp3=temp3+temp1[2,]        # int_{x^2 f^3(x)}
     temp4=temp4+temp1[3,]        #Aij^2 to Ai^2
   }
return(matrix(c(temp2*(1/n),4*(temp3/n-(temp2/n)^2),temp4),nrow=p))
}

然后,当我尝试使用

测试功能时
H <- n[1]^(-1/(p+4))*solve(sigma^(1/2))
p <- 2
n<-c(20,20,20) 
mu1=rep(1,p)
mu2=rep(1,p)
mu3=rep(1,p)
sigma <- matrix(c(1.0,1.0),nrow = 2)
groups<-rep(1:3,n)
x1=mvrnorm(n[1],mu1,sigma)
x2=mvrnorm(n[2],mu2,sigma)
x3=mvrnorm(n[3],mu3,sigma)
x=rbind(x1,x2,x3)

我收到以下错误

R:错误:函数中的维数不正确

但是当我尝试用实际数字测试错误时,如下所示,它工作得很好

R:错误:函数中的维数不正确

我不明白到底是什么问题。

caiczy000 回答:R:错误:函数中的维数不正确

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2581803.html

大家都在问