Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to calculate a partial correlation between 6 (observed and modelled data) variables in a single NetCDF using ppcor package in r, but I'm not successful yet. I am still learning loops. This is what I tried so far :

library(ppcor)
mods <- nc_open("Obs_model_1981-2018.nc")
lon <- ncvar_get(mods, varid = "lon")
lat <- ncvar_get(mods, varid = "lat")

nx <- length(lon)
ny <- length(lat)
    obss <- ncvar_get(mods, "obs")
    mods1 <- ncvar_get(mods, "mod1")
    mods2 <- ncvar_get(mods, "mod2")
    mods3 <- ncvar_get(mods, "mod3")
    mods4 <- ncvar_get(mods, "mod4")
    mods5 <- ncvar_get(mods, "mod5")

rl=array(0, c(nx,ny))
err=array(0, c(nx,ny))

for (x in 1:nx) {
  print(x)
  for (y in 1:ny) {
    pp =data.frame(obss,mods1,mods2,mods3,mods4,mods5)         
    ## pcor need a data frame
    rl[x,y] = pcor(pp, "pearson")
   }
}
question from:https://stackoverflow.com/questions/65943414/partial-correlation-netcdf

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
130 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...