# [R] Error in n * rvec : non-numeric argument to binary operator

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Tue Apr 20 00:01:11 CEST 2021

```Hello,

I have this code, and when I run it:
> kbpowerf()
Error in n * rvec : non-numeric argument to binary operator

this is the code:

function (){
#USER SPECIFICATION PORTION
alpha=0.05 #DESIGNATED ALPHA
g=3 #NUMBER OF GROUPS
nvec=c(25,10,15) #GROUP SIZES
beta1vec=c(789.93,122.87,1871.99) #SLOPE COEFFICIENTS
sigsq=209460.57 #ERROR VARIANCE
tausqvec=c(0.1596,0.1602,0.1360) #PREDICTOR VARIANCES
#END OF SPECIFICATION
df1<-g-1
numint<-200
l<-numint+1
dd<-1e-6
coevec<-c(1,rep(c(4,2),numint/2-1),4,1)
set.seed(2017)
repn<-20000
kbpowerf<-function(){
df<-sum(nvec)-2*g
fcrit<-qf(1-alpha,df1,df)
dfkvec<-nvec-1
dfk<-sum(dfkvec)
cl<-dd
cu<-qchisq(1-dd,dfk)
intc<-(cu-cl)/numint
cvec<-cl+intc*(0:numint)
wcpdf<-(intc/3)*coevec*dchisq(cvec,dfk)
dfb1<-cumsum(dfkvec[1:g-1])
dfb2<-dfkvec[2:g]
ep<-0
for (i in seq(repn)) {
bvec<-rbeta(df1,dfb1/2,dfb2/2)
avec<-rep(0,g)
avec[1]<-exp(sum(log(bvec)))
for (ig in (2:df1)) {
avec[ig]<-(1-bvec[ig-1])*exp(sum(log(bvec[ig:df1])))
}
avec[g]<-1-bvec[df1]
oavec<-tausqvec*avec
buw<-sum(oavec*beta1vec)/sum(oavec)
lamvec<-cvec*sum(oavec*(beta1vec-buw)^2)/sigsq
ep<-ep+sum(wcpdf*pf(fcrit,df1,df,lamvec,lower.tail=FALSE))
}
kbpower<-ep/repn
}
kbpower<-kbpowerf()
return(list(sample_size=nvec,attained_power=kbpower))
}