I’m using the
quap routine from the
rethinking package. I’m modeling solar PV generation for a largish region, where there are a few unknown parameters that are easy-ish to constrain.
PV generation can be scaled by cos ( angle of incidence on PV panel ) – the parameter I’m modeling is cos(angle_incidence). This angle is a function of the day of the year, the hour of the day, the solar azimuth (gamma – oriented east or west? zero is due south), the latitude, and the tilt of the PV panel (0 is flat, 90 is upright).
For the raw generation data (actual production), I know the general latitude and the datetime.
My confusion is this: I’m not entirely clear on how to set this up in Stan.
I’ve done this, using
m1 <- quap( alist( PV ~ dnorm( mu, sigma ), lat ~ dnorm(N,39,.5), gamma ~ dnorm(N,0,30), tilt ~ dunif(N,0,lat), sigma ~ dexp(1), capacity <- ifelse(solar_altitude(lat,datetime)<0,0,cap), cos_incidence <- ifelse(cos_theta_i(solar_altitude(lat,datetime),tilt,gamma,datetime)<0, 0,cos_theta_i(solar_altitude(lat,datetime),tilt,gamma,datetime)), mu <- capacity*cos_incidence ), data = cleandf)
I’ve already used this model to create a prior predictive simulation
These plots show two things – there are bad data, and the simulated data generally describe the actual data.
I’d like to use Stan to identify the most likely values of the parameters in
quap, but when I run it as above, I get this error:
Error in rfelse(1, c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, : could not find function "rfelse"
Am I doing this all wrong? How should models like this be set up?