I'm trying to do Bayesian Occupancy Analysis with site covariates. My first step is making a function. I keep on getting the + in my R console indicating it thinks my code is incomplete. Having ran lines individually I am pretty certain the issue lies in the first line of code. However, I can't work out where exactly I've missed something out and hence where the problem originally lies.
data.fn <- function(R = 39, T = 14, xmin= 0, xmax= 1, alpha.psi = 0.4567,
beta.psi = 0.0338, alpha.p = 0.4, beta.p = 0.4) {
y <- array(dim = c(R,T)) #This creates an array for counts
#Ecological Process
#Covariate values
X <- sort(runif(n=R, min = xmin, max = xmax))
#Expected occurence-covariate relationship
psi <- plogis(alpha.psi + beta.psi *X) #this applies the inverse logit
#Add Bernoulli Noise - drawing indicator of occurence (z) from bernoulli psi
z<- rbinom(n = R, size = 1, prob = psi)
occ.fs <- sum(z) #"Finite Sample Occupancy"
"Make a census"
p.eff <- z*p
for (i in 1:T) {
y[,i] <- rbinom(n=R, size = 1, prob = p.eff)
}
}
There's more code - i.e. the {} function is complete but the issue started before that was ran and I keep having issues uploading the code into Stack. The error message is simply + all down the left hand side of the R console
EDIT
Could there be something wrong with how R is sensing stuff? For instance with the following code
naive.pred <- plogis(predict(glm(apply(y, 1, max) ~ X + I (X^2),
family = binomial)))
I got the error message - unexpected symbol (the bracket) in the family = binomial yet each bracket is paired correctly- there's no extra unnecessary brackets?