I am using the sdm
package in R to run a species distribution model of a species. I tried running the following:
sdmData <-sdmData(sp~ Wetland +Distance_Protected_Area +Distance_Shore +
Distance_Settlement +Distance_Cages +
Cages_Present + Bathymetry,
train = sdm_Data, predictors = AllOccRasters, bg = BackgroundPoints)
And got the following error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘sdmData’ for signature ‘"formula", "data.frame", "RasterStack"’
Having seen this query (Unable to compile datasets using {sdmData} - error)
I tried
sdm_Data <- as(sdm_Data, 'Spatial')
and got
Error in as(sdm_Data_nets, "Spatial") :
no method or default for coercing “data.frame” to “Spatial”
In case it helps, here is an example of my data, from the sdm_Data
structure(list(sp = c("F_ardesiaca", "F_ardesiaca", "F_ardesiaca", "F_ardesiaca", "F_ardesiaca"),
Totora = c(-0.239973815, -0.239973815, -0.239973815,
-0.239973815, -0.239973815), Distance_Protected_Area = c(-1.378201598,
-1.123927933, -1.137970591, -1.123927933, -1.162127222),
Distance_Shore = c(-1.094753612, -0.960762706, -0.911857012,
-0.960762706, -1.086927111), Distance_Settlement = c(-1.100245165,
-0.972346735, -0.935389232, -0.972346735, -1.141459148),
Distance_Cages = c(-1.445217077, -1.437232488, -1.260983258,
-1.437232488, -1.181728985), Cages_Present = c(0L, 0L,
0L, 0L, 0L), Bathymetry = c(1.122127163, 0.740096285,
0.369610894, 0.740096285, 0.836073376), latitude = c(-15.86403,
-15.48954, -15.50397, -15.4846, -15.5163), longitude = c(-69.93177,
-69.88749, -69.8816, -69.89034, -69.87735)), na.action = structure(c(`1` = 1L,
`2` = 2L, `46` = 46L, `71` = 71L, `73` = 73L, `76` = 76L, `77` = 77L,
`87` = 87L, `89` = 89L, `113` = 113L, `140` = 140L, `141` = 141L,
`142` = 142L, `143` = 143L, `144` = 144L, `147` = 147L, `152` = 152L,
`163` = 163L, `174` = 174L, `185` = 185L, `188` = 188L, `193` = 193L,
`196` = 196L, `207` = 207L, `218` = 218L, `229` = 229L, `240` = 240L,
`241` = 241L, `252` = 252L, `263` = 263L, `274` = 274L, `285` = 285L,
`296` = 296L, `307` = 307L, `318` = 318L, `327` = 327L, `328` = 328L,
`329` = 329L, `340` = 340L, `351` = 351L, `352` = 352L, `363` = 363L,
`374` = 374L, `385` = 385L, `396` = 396L, `407` = 407L, `418` = 418L,
`429` = 429L, `440` = 440L, `451` = 451L, `462` = 462L, `463` = 463L,
`467` = 467L, `468` = 468L, `474` = 474L, `485` = 485L, `493` = 493L,
`496` = 496L, `507` = 507L, `516` = 516L, `518` = 518L, `524` = 524L,
`525` = 525L, `526` = 526L, `529` = 529L, `540` = 540L, `551` = 551L,
`554` = 554L, `562` = 562L, `566` = 566L, `573` = 573L, `574` = 574L,
`585` = 585L, `596` = 596L, `607` = 607L, `618` = 618L, `629` = 629L,
`640` = 640L, `651` = 651L, `662` = 662L, `673` = 673L, `682` = 682L,
`684` = 684L, `685` = 685L, `687` = 687L, `688` = 688L, `690` = 690L,
`693` = 693L, `694` = 694L, `696` = 696L, `707` = 707L, `718` = 718L,
`729` = 729L, `740` = 740L, `751` = 751L, `762` = 762L, `773` = 773L,
`782` = 782L, `784` = 784L, `795` = 795L, `796` = 796L, `807` = 807L,
`808` = 808L, `818` = 818L, `829` = 829L, `840` = 840L, `851` = 851L,
`862` = 862L, `873` = 873L, `874` = 874L, `878` = 878L, `884` = 884L,
`885` = 885L, `888` = 888L, `895` = 895L, `903` = 903L, `906` = 906L,
`907` = 907L, `918` = 918L, `921` = 921L, `929` = 929L, `934` = 934L,
`935` = 935L, `937` = 937L, `939` = 939L, `940` = 940L, `948` = 948L,
`950` = 950L, `951` = 951L, `952` = 952L, `954` = 954L, `956` = 956L,
`962` = 962L, `969` = 969L, `973` = 973L, `974` = 974L, `984` = 984L,
`992` = 992L, `995` = 995L, `998` = 998L, `999` = 999L, `1004` = 1004L,
`1006` = 1006L, `1017` = 1017L, `1018` = 1018L, `1029` = 1029L,
`1053` = 1053L, `1054` = 1054L, `1073` = 1073L, `1084` = 1084L,
`1095` = 1095L, `1106` = 1106L), class = "omit"), row.names = 3:7, class = "data.frame")
I think that the omit refers to the fact I used the omit.na()
function to remove datapoints for which I did not have information on all environmental rasters from the dataset.
Please let me know if you know what is going wrong here/if there is a solution, and whether this might be more appropriate for the GIS stack exchange
Converting the data.frame into a SpatialPointsDataFrame object solved my issue:
coordinates(sdm_Data) <-(~longitude + latitude)