So I am trying to use the package ppmLasso to create species distribution models. Before I can run my models I need to put my environmental data into a data frame instead of as a raster. I have done the conversion using the following code for all the variables in the ClimateTreeStack Raster:
class : RasterStack
dimensions : 4746, 5858, 27802068, 6 (nrow, ncol, ncell, nlayers)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 92.19167, 141.0083, -11, 28.55 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
names : bio_1, bio_2, bio_3, bio_12, bio_15, Allsea1
min values : -45, 45, 34, 581, 5, 0
max values : 289, 132, 96, 7008, 126, 89
bio1_FRAME<-as.data.frame(ClimateTreeStack$bio_1, xy=TRUE)
FrameOmit1<-na.omit(bio1_FRAME)
X<-FrameOmit1$x
Y<-FrameOmit1$y
BIO_1<-FrameOmit1$bio_1*
Which yields the following data frame:
head(frame)
X Y BIO_1 BIO_2 BIO_3 BIO_12 BIO_15 tree
1 97.55417 28.54583 8 114 44 698 85 8
2 97.56250 28.54583 -2 115 44 688 86 5
3 97.57083 28.54583 -1 115 44 688 86 1
4 97.55417 28.53750 2 115 44 692 86 4
5 97.56250 28.53750 2 115 44 692 86 5
6 97.57083 28.53750 11 114 44 703 86 4
I then try to use this environmental data frame but the ppmlasso package fails. I have figured out that an issue may be that the environmental data frame doesn't represent a true grid as seen using the diff() function:
varX = sort(unique(frame$X))
varY = sort(unique(frame$Y))
X.step = diff(varX)
Y.step = diff(varY)
table(X.step)
X.step
0.00833333333332575 0.00833333333333997 0.00833333333335418
3177 2261 419
table(Y.step)
Y.step
0.00833333333332931 0.00833333333333286 0.00833333333333464 0.00833333333333641 0.00833333333333997
1 4107 110 457 60
0.0250000000000057 0.05833333333333
1 1
When using the diff() function data appropriate for ppmlasso should look like this:
BM.X = sort(unique(BlueMountains$env$X))
BM.Y = sort(unique(BlueMountains$env$Y))
BM.X.step = diff(BM.X)
BM.Y.step = diff(BM.Y)
table(BM.X.step)
BM.X.step
0.5
200
table(BM.Y.step)
BM.Y.step
0.5
300
So I know what my problem probably is. But I do not know how to fix it. Can someone please suggest the easiest way to coerce my data frame (or raster) so that it has equal grid cells and can be run through ppmlasso?
signif
can be your friend.signif
but I still had the same issue.ppmlasso
for my dissertation so I am under a time crunch and I am getting so frustrated....So I GREATLY appreciate any help and ideas.