Coder Social home page Coder Social logo

Comments (3)

statnmap avatar statnmap commented on June 4, 2024 1

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.

statnmap avatar statnmap commented on June 4, 2024 1

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.

Saadi4469 avatar Saadi4469 commented on June 4, 2024

Thank you so much for your guidance.

Cheers

from blog_tips.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.