Dear Ken,
Thank you for your quick and useful response.
So firstly
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] car_3.0-10 carData_3.0-4 MuMIn_1.43.17 unmarked_1.1.1 lattice_0.20-38
loaded via a namespace (and not attached):
[1] zip_2.1.1 Rcpp_1.0.6 cellranger_1.1.0 compiler_3.6.3 pillar_1.5.1 nloptr_1.2.2.2
[7] plyr_1.8.6 forcats_0.5.1 tools_3.6.3 boot_1.3-24 lme4_1.1-26 statmod_1.4.35
[13] lifecycle_1.0.0 tibble_3.1.0 nlme_3.1-144 pkgconfig_2.0.3 rlang_0.4.10 openxlsx_4.2.3
[19] Matrix_1.2-18 curl_4.3 parallel_3.6.3 haven_2.3.1 rio_0.5.26 raster_3.4-5
[25] vctrs_0.3.6 hms_1.0.0 stats4_3.6.3 grid_3.6.3 data.table_1.14.0 fansi_0.4.2
[31] readxl_1.3.1 foreign_0.8-75 sp_1.4-5 minqa_1.2.4 magrittr_2.0.1 codetools_0.2-16
[37] ellipsis_0.3.1 MASS_7.3-51.5 splines_3.6.3 abind_1.4-5 utf8_1.2.1 stringi_1.5.3
[43] crayon_1.4.1
Then str(allsites) showed me there was of course something very obviously wrong, a number of my continuous covariates were factors not numerics. But have now corrected that using for example "allsites$bog<-as.numeric(as.character(allsites$bog))".
> str(allsites)
'data.frame': 14401 obs. of 11 variables:
$ lat : num 55.1 54.8 54.9 54.8 54.9 ...
$ long : num -7.64 -7.47 -7.47 -7.46 -7.46 ...
$ bog : num 0 0 0 0.0086 0.0106 0 0 0 0 0 ...
$ broadleaf : num 0.0256 0 0 0 0.055 ...
$ built : num 0.056 0.0257 0 0.0505 0.043 0 0 0 0.0284 0.0339 ...
$ conifer : num 0.028 0.135 0 0 0 ...
$ dwarf : num 0.0275 0 0 0.0156 0 0 0 0 0 0 ...
$ rough : num 0 0 0 0 0 ...
$ River.Length..m.: num 705 809 0 3107 2101 ...
$ people_km2 : num 164.62 23.89 27.94 1296.72 4.74 ...
$ Grassland : num 0.863 0.84 1 0.925 0.891 ...
Now I try and run:
> occuPred <- predict(topmodel,
+ type = "state",
+ newdata = allsites,
+ na.rm = TRUE,
+ inf.rm = TRUE)
Error: Matrices must have same number of rows in cbind2(.Call(dense_to_Csparse, x), y).
Is unmarked like presence, where my initial occurrence data file (y) and sitecovs data should have the same number of rows as the predict file (allsites, n =14,402) rows just NA'd throughout?
Alternatively. I am thinking the error may be coming from the fact that lat long as in my top model as covariates, but in the predict file, the first two columns are lat long. I have played around having lat, long in once (just first two columns of predict file) and twice (first two columns for location, and in the same position as in original sitecovs file), but did not achieve anything.
I will send on the data and covariate CSVs and full script privately now, just again a quick thank you for your time and help with this, much appreciated,
All the best
Josh