Comments (3)
You need to define what to do when all values are the same in the focal window. Sometimes you have something like this : cor(rep(1, 3), rep(1, 3))
.
If you consider that all values the same means that correlation is 1
, then you can use this function:
focal_cor = focal(
x = a_b_nb,
w = matrix(1, 5, 5),
# fun = function(x, y = a_b_stack){ # Original
# cor(values(y)[x, 1], values(y)[x, 2], # Original
# use = "na.or.complete")
# },
fun = function(x, y = matrix_a_b){ # [MW]
# If all values the same
if (isTRUE(var(y[x, 1], y[x, 2], # [MW]
use = "na.or.complete") == 0)) {
return(1)
}
cor(y[x, 1], y[x, 2], # [MW]
use = "na.or.complete")
},
filename = file.path("~/focal_cor.tif"),
overwrite = TRUE
)
Then you can play with w = matrix(1, 3, 3)
in focal()
; use
and method
in cor()
from blog_tips.
Note that you can use {cartomisc} for gplot_data()
, which is lighter than {SDMSelect}:
https://statnmap.github.io/cartomisc/
# remotes::install_github("statnmap/cartomisc")
cartomisc::gplot_data()
from blog_tips.
Thank you so much for your guidance.
Cheers
from blog_tips.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog_tips.