I am running a gam model with a soap smoother
mod_aut_X10 <- bam(occurrenceStatus ~
s(x, y, bs = "so", xt = list(bnd = shap_bnd_ls, nmax = 1000)) +
s(watertemp) +
s(WaterDepth) +
s(lunar_day, bs = "cc") +
s(hour_of_day, bs = "cc") +
s(distAbs) +
s(distStInp)+
s(distLPInp)+
s(Abs_Max_ls)+
s(InpSt_Max_ls)+
s(InpLP_Max_ls)+
offset(log(cumulative_count)),
data = filter(eel.Agg.70, season == 'Autumn'),
family = binomial(link = "logit"),
method = "fREML",
discrete = TRUE,
knots = lake_knots,
weights = weight)
But I am getting an error when it runs
Error in smooth.construct.so.smooth.spec(object, dk$data, dk$knots) :
data outside soap boundary
Before I run the model I filter any data points outside the boundary of the shapefile I am using, using this code
# Create sf object for background points
eel.Agg.sf <- st_as_sf(eel.Agg, coords = c("Avg_Longitude", "Avg_Latitude"), crs = 4326) # Assuming WGS 84
eel.Agg.sf <- st_transform(eel.Agg.sf, st_crs(shape_simp)) # Transform to match the CRS of the shapefile
# Use st_intersects to filter points
intersections <- st_intersects(eel.Agg.sf, shape_simp)
eel.Agg.within <- eel.Agg.sf[lengths(intersections) > 0, ]
# Extract indices of intersecting points
intersecting_indices <- which(lengths(intersections) > 0)
# Filter the original data frame (grp_DAT)
eel.Agg.filtered <- eel.Agg[intersecting_indices, ]
This has run fine with different datasets, but this is a bit larger. It removes any points outside the shapefile and the model runs fine with these smaller datasets. I also added a buffer around my shapefile to test this issue and the error in the model still persists. As such I'm thinking it might be some other issue.
Is there any other reason why this error could be occurring? The dataset to run the model can be found here, list data for the shapefile here and list of lake knots for the soap smoother here.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744356811a4570271.html
评论列表(0条)