1 Background

The big light project puts a LED light into old-growth, secondary and man made forest(rubber tree forest) separetely, which shines at night. We rekon it as a long term disturbance to forest which has continued more than one year. Now we want to know whether this disturbance would effect the understory or not.

1.1 Our hypothesis

  1. Prolong the light time may effect the nutrition circulation of understory
  2. LED light attracts insects and insects dead may increase soil nitrogen, then effect the nutrition circulation of understory.

1.2 Place and species I choosed

We choose man made forest, for simulating the street tree and species Colocasia_gigantea and Melastoma_candidum

1.3 method

we punch leaf using leaf-disc to measure leaf nutrition.

2 Data Exploration

the pacakges we’ll use:

library(kableExtra)
library(tidyverse)
#> -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
#> v ggplot2 3.3.5     v purrr   0.3.4
#> v tibble  3.1.6     v dplyr   1.0.7
#> v tidyr   1.2.0     v stringr 1.4.0
#> v readr   2.1.2     v forcats 0.5.1
#> Warning: 程辑包'tidyr'是用R版本4.1.3 来建造的
#> Warning: 程辑包'readr'是用R版本4.1.3 来建造的
#> -- Conflicts ------------------------------------------ tidyverse_conflicts() --
#> x dplyr::filter()     masks stats::filter()
#> x dplyr::group_rows() masks kableExtra::group_rows()
#> x dplyr::lag()        masks stats::lag()
library(lme4)
#> Warning: 程辑包'lme4'是用R版本4.1.3 来建造的
#> 载入需要的程辑包:Matrix
#> Warning: 程辑包'Matrix'是用R版本4.1.3 来建造的
#> 
#> 载入程辑包:'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack

input our data

llp <- read_csv("../data-raw/leaf_light_project.csv")
#> Rows: 260 Columns: 11
#> -- Column specification --------------------------------------------------------
#> Delimiter: ","
#> chr  (1): species
#> dbl (10): Plot, Distance, angel, individual, leaf ID, disc, disc_area, fresh...
#> 
#> i Use `spec()` to retrieve the full column specification for this data.
#> i Specify the column types or set `show_col_types = FALSE` to quiet this message.
llp[1:5,] %>% kbl() %>% kable_styling()
Plot species Distance angel individual leaf ID disc disc_area fresh_weight dry_weight canopy_openness
5 Melastoma_candidum 7.3 246 1 1 5 10 0.0469 0.0133 0.093571
5 Melastoma_candidum 7.3 246 1 2 5 10 0.0497 0.0140 0.093571
5 Melastoma_candidum 7.3 246 1 3 5 10 0.0476 0.0141 0.093571
5 Melastoma_candidum 7.3 246 1 4 5 10 0.0453 0.0140 0.093571
5 Melastoma_candidum 7.3 246 1 5 5 10 0.0489 0.0158 0.093571

Then we calculate LMA and show our samples location away from the light.

llp1 <- llp |>mutate(LMA = dry_weight/(disc*pi*(0.005)^2))
llp1 |> 
  mutate(x_loc = Distance*cos(angel*pi/180))|>
  mutate(y_loc = Distance*sin(angel*pi/180))|>
  ggplot(aes(x_loc, y_loc, size = LMA))+
  geom_point(shape =17)+
  facet_grid(cols = vars(species))+
  theme_bw()

(Notation: coordinate (0,0) is where the light is.)

Next, because we want to know whether light give an effect to understory, so we consider a graph between LMA and Distance away from the light which is on behalf of the gradient of light strength.

llp1 |> 
  filter(Plot == 2) |>
ggplot(aes(x = Distance, y = LMA))+
  geom_point()+
  labs(title = "LMA_Colocasia_gigantea")+
  theme_bw()

llp1 |>
  filter(Plot == 5) |>
ggplot(aes(x = Distance, y = LMA))+
  geom_point()+
   labs(title = "LMA_Melastoma_candidum")+
  theme_bw()

(We see there can be a negative correlation between LMA and Distance, while we can’t simply draw the conclusion based on that, instead we add canopy openness into our consideration. )

llp1|> 
  ggplot(aes(x = LMA))+
  facet_grid(cols = vars(species))+
  geom_histogram()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

3 Data Mining

mod <- lmer(data = llp1, formula = LMA ~ log(Distance)*log(canopy_openness)+(1|species))
summary(mod)
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: LMA ~ log(Distance) * log(canopy_openness) + (1 | species)
#>    Data: llp1
#> 
#> REML criterion at convergence: 1394.3
#> 
#> Scaled residuals: 
#>      Min       1Q   Median       3Q      Max 
#> -2.75665 -0.75270  0.02021  0.62920  3.00758 
#> 
#> Random effects:
#>  Groups   Name        Variance Std.Dev.
#>  species  (Intercept)  4.657   2.158   
#>  Residual             12.554   3.543   
#> Number of obs: 260, groups:  species, 2
#> 
#> Fixed effects:
#>                                    Estimate Std. Error t value
#> (Intercept)                          22.714      4.139   5.487
#> log(Distance)                        11.460      2.393   4.789
#> log(canopy_openness)                 -1.392      1.713  -0.812
#> log(Distance):log(canopy_openness)    2.836      1.039   2.731
#> 
#> Correlation of Fixed Effects:
#>             (Intr) lg(Ds) lg(c_)
#> log(Distnc) -0.869              
#> lg(cnpy_pn)  0.916 -0.924       
#> lg(Dst):(_) -0.870  0.987 -0.950

4 stan

4.1 example

library(rstan)
#> Warning: 程辑包'rstan'是用R版本4.1.3 来建造的
library(bayesplot)
#> Warning: 程辑包'bayesplot'是用R版本4.1.3 来建造的
rstan::rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores()) # Run on multiple cores

Data for Melastoma_candidum

sp1 <- llp1 |>
  filter(species == "Melastoma_candidum")

x <- cbind(1,
            log(1/(sp1$Distance)^2) |> scale(),
            scale(sp1$canopy_openness))

x <- cbind(x, x[,2] * x[,3])

list_d <- list(
  N = nrow(sp1),
  J = sp1$individual |> unique() |> length(),
  K = 4,
  ind = sp1$individual,
  x = x,
  y = log(sp1$LMA))

Mathematical model

Main likelihood functions: \[ y_{i,j} \sim \mathcal{N}(\mu_{i,j}, \sigma) \\ \mu_{i,j} = \boldsymbol{X} \cdot \boldsymbol{\beta} + \phi_j\\ \phi_j \sim \mathcal{N}(0, \tau) \]

where,

  • \(y_{i,j}\) is log(LMA) of leaf disc i of individual j,

  • \(\sigma\) is the standard deviation of the model,

  • \(\boldsymbol{X}\) is an \(n \times 4\) matrix with intercepts, distance, canopy_openness and the interaction between distance and canopy_openness,

  • \(\boldsymbol{\beta}\) is a coefficient vector of size 4 (intercepts, distance, canopy_openness and the interaction between distance and canopy_openness),

  • \(\phi_j\) is the vayring intercept for individuals,

  • \(\tau\) is the scaling parameter for individual effects

Prior:

  • we usually use weakly informative priors and we don’t use non-informative prirors such as unif(0, 1000).

\[ \boldsymbol{\beta} \sim \mathcal{N}(0, 5) \\ \]

Hyperprior:

  • Half-cauchy works best for the scaling parameters for varying intercepts

\[ \boldsymbol{\tau} \sim \text{Half-Caucy}(0, 2.5) \\ \]

In reality, we use a lot of tricks to make the above model works better. For example, we do not try to fit the individual effects directly, but instead, we fit a latent Gaussian variable from which we can recover the individual effects.

\[ \phi_j \sim \mathcal{N}(0, \tau) \]

cab be rewritten as:

\[ \phi_j = \tau \cdot \tilde{\phi_j} \\ \tilde{\phi_j} \sim \mathcal{N}(0, 1) \\ \tau \sim \text{Half-cauchy}(0, 2.5)\\ \]

A Half-cauchy distribution can be also represented using the tangent function and an uniform distribution:

\[ \boldsymbol{\tau} = 2.5 \times tan(\boldsymbol{\tilde{\tau}}) \\ \boldsymbol{\tilde{\tau}} \sim \mathcal{U}(0, \pi / 2) \]

model <- rstan::stan_model("../stan/model.stan")
writeLines(readLines("../stan/model.stan"))
data{
  int<lower=0> N; // number of sample
  int<lower=1> J; // number of individual
  int<lower=1> K; // number of parameters
  matrix[N, K] x; // tree-level predictor
  vector[N] y; //log(LMA)
  int<lower=1,upper=J> ind[N]; // integer
}


parameters{
  matrix[K,1] beta;
  vector[J] phi_raw;
  real<lower=0,upper=pi()/2> tau_unif;
  real<lower=0> sigma;
}

transformed parameters{
  real<lower=0> tau;
  vector[J] phi;
  tau = 2.5 * tan(tau_unif); // implies tau ~ cauchy(0, 2.5)
  phi = phi_raw * tau;
}

model {
  //vector[N] mu;
  //for (n in 1:N) mu[n] = x[n, ] * beta + phi[ind[n]];
  phi_raw ~ std_normal();
  to_vector(beta) ~ normal(0, 5);
  y ~ normal(to_vector(x * beta) + phi[ind], sigma);
}
fit <- rstan::sampling(model,
            data = list_d,
            verbose = TRUE,
            iter = 2000,
            warmup = 1000,
            thin = 1,
            chains = 4,
            refresh = 200,
            seed = 123)
#> 
#> CHECKING DATA AND PREPROCESSING FOR MODEL 'model' NOW.
#> 
#> COMPILING MODEL 'model' NOW.
#> 
#> STARTING SAMPLER FOR MODEL 'model' NOW.
summary(fit)$summary
#>                      mean      se_mean          sd          2.5%           25%
#> beta[1,1]    3.459415e+00 7.853398e-04 0.030530273   3.400709374   3.439755005
#> beta[2,1]   -4.217701e-02 8.895009e-04 0.035601825  -0.112851838  -0.064869256
#> beta[3,1]   -6.066213e-04 9.227563e-04 0.037315900  -0.076133762  -0.024549484
#> beta[4,1]   -3.083868e-02 6.313788e-04 0.026634990  -0.083572593  -0.048281005
#> phi_raw[1]   6.684914e-01 1.664479e-02 0.713349518  -0.756827727   0.191520685
#> phi_raw[2]   9.094645e-01 9.926824e-03 0.408960234   0.139765019   0.631546170
#> phi_raw[3]   4.588917e-01 1.601212e-02 0.632781780  -0.804461566   0.036797751
#> phi_raw[4]  -4.399054e-02 7.877831e-03 0.374580264  -0.780476272  -0.302218183
#> phi_raw[5]   1.169361e-01 8.087798e-03 0.383490651  -0.635332749  -0.131444116
#> phi_raw[6]  -1.649391e+00 1.338614e-02 0.569026117  -2.807049285  -2.017514902
#> phi_raw[7]   1.585166e+00 1.751336e-02 0.807104881   0.019132666   1.031307790
#> phi_raw[8]  -6.090502e-01 1.182087e-02 0.535483923  -1.642468384  -0.978791784
#> phi_raw[9]   2.194273e-01 1.266569e-02 0.522747700  -0.832486846  -0.128603272
#> phi_raw[10] -4.720144e-01 1.015264e-02 0.447495288  -1.334117775  -0.779435176
#> phi_raw[11] -3.662253e-01 8.371914e-03 0.371679664  -1.097309931  -0.611605487
#> phi_raw[12]  3.018512e-01 8.517681e-03 0.373659135  -0.411958781   0.044866642
#> phi_raw[13] -8.965657e-01 1.173896e-02 0.521534788  -1.920424495  -1.250224968
#> phi_raw[14]  7.402119e-01 9.727350e-03 0.434684793  -0.063503648   0.444242291
#> phi_raw[15] -5.413399e-01 9.301956e-03 0.426498219  -1.398656395  -0.832494995
#> phi_raw[16] -1.083221e+00 1.032768e-02 0.457129601  -1.997108614  -1.394973818
#> phi_raw[17]  1.160439e+00 1.391346e-02 0.625891867  -0.058789727   0.739203055
#> phi_raw[18]  3.529175e-01 9.923761e-03 0.469646899  -0.565044761   0.027482412
#> phi_raw[19] -8.918375e-01 1.301269e-02 0.581157935  -2.005837678  -1.294028332
#> tau_unif     3.937281e-02 2.605414e-04 0.008486024   0.026647742   0.033278082
#> sigma        5.429960e-02 9.485467e-05 0.004509095   0.046222650   0.051225495
#> tau          9.849056e-02 6.526393e-04 0.021258000   0.066635129   0.083225930
#> phi[1]       6.390834e-02 1.647767e-03 0.070519058  -0.077111914   0.018610719
#> phi[2]       8.667453e-02 8.652838e-04 0.037621220   0.014971126   0.061600457
#> phi[3]       4.380325e-02 1.603377e-03 0.062738376  -0.080983231   0.003154367
#> phi[4]      -3.961511e-03 7.816415e-04 0.036745247  -0.076656433  -0.028568320
#> phi[5]       1.117928e-02 8.082640e-04 0.037745253  -0.064328086  -0.012582282
#> phi[6]      -1.564174e-01 9.781927e-04 0.048742891  -0.254440532  -0.187173361
#> phi[7]       1.504259e-01 1.637569e-03 0.076152419   0.001611483   0.101117362
#> phi[8]      -5.776885e-02 1.121579e-03 0.052518027  -0.163906988  -0.091411678
#> phi[9]       2.090914e-02 1.293484e-03 0.052266795  -0.083749701  -0.012662683
#> phi[10]     -4.443222e-02 9.716910e-04 0.043447038  -0.128651018  -0.073126835
#> phi[11]     -3.442275e-02 7.994778e-04 0.035715209  -0.103112730  -0.057971242
#> phi[12]      2.884252e-02 8.368405e-04 0.036215285  -0.039175742   0.004344796
#> phi[13]     -8.478522e-02 1.074608e-03 0.048491380  -0.182592574  -0.115599688
#> phi[14]      7.045599e-02 9.017627e-04 0.040977679  -0.007031062   0.043150119
#> phi[15]     -5.125951e-02 8.464533e-04 0.040289229  -0.131300068  -0.077986656
#> phi[16]     -1.025267e-01 8.231940e-04 0.040209865  -0.182435842  -0.129081090
#> phi[17]      1.100477e-01 1.262728e-03 0.058846223  -0.005532723   0.071863670
#> phi[18]      3.353886e-02 9.727631e-04 0.045858556  -0.056784222   0.002611720
#> phi[19]     -8.486760e-02 1.217299e-03 0.055892865  -0.198489046  -0.121157580
#> lp__         2.146476e+02 1.592966e-01 4.755898672 204.288106361 211.603486874
#>                       50%          75%         97.5%     n_eff      Rhat
#> beta[1,1]    3.459649e+00   3.47952132   3.518213629 1511.2843 1.0026155
#> beta[2,1]   -4.181159e-02  -0.01945860   0.027638929 1601.9602 1.0011173
#> beta[3,1]   -9.629045e-04   0.02347595   0.074350187 1635.3615 1.0009074
#> beta[4,1]   -3.061634e-02  -0.01365202   0.021578246 1779.6109 1.0019361
#> phi_raw[1]   6.624724e-01   1.13991589   2.070403266 1836.7420 1.0013119
#> phi_raw[2]   9.064038e-01   1.17708614   1.710161574 1697.2332 1.0045413
#> phi_raw[3]   4.635980e-01   0.89105810   1.693875251 1561.7455 1.0026672
#> phi_raw[4]  -4.438511e-02   0.21006333   0.673092861 2260.8747 1.0001659
#> phi_raw[5]   1.107323e-01   0.37490918   0.878915948 2248.2724 1.0000986
#> phi_raw[6]  -1.631799e+00  -1.26861729  -0.567808107 1806.9813 1.0012613
#> phi_raw[7]   1.576065e+00   2.13892185   3.160146417 2123.8361 1.0002110
#> phi_raw[8]  -6.066202e-01  -0.24705222   0.421002589 2052.0780 1.0008602
#> phi_raw[9]   2.175190e-01   0.56672041   1.244796906 1703.4381 1.0017344
#> phi_raw[10] -4.710468e-01  -0.16503121   0.414011422 1942.7596 1.0001207
#> phi_raw[11] -3.633776e-01  -0.11426987   0.334293415 1971.0065 1.0023940
#> phi_raw[12]  3.022662e-01   0.54944489   1.044635670 1924.4580 1.0015757
#> phi_raw[13] -8.859444e-01  -0.54821886   0.097550484 1973.8173 1.0003018
#> phi_raw[14]  7.237264e-01   1.03305239   1.632751505 1996.9160 1.0015596
#> phi_raw[15] -5.215882e-01  -0.25214204   0.246147141 2102.2572 1.0022819
#> phi_raw[16] -1.072930e+00  -0.77015553  -0.232388458 1959.1744 1.0018845
#> phi_raw[17]  1.154933e+00   1.57776754   2.391571348 2023.6173 0.9998111
#> phi_raw[18]  3.409689e-01   0.67028171   1.293775726 2239.7024 1.0001395
#> phi_raw[19] -8.948750e-01  -0.47590199   0.205927140 1994.5937 1.0011467
#> tau_unif     3.805605e-02   0.04393989   0.059602332 1060.8531 1.0017791
#> sigma        5.396330e-02   0.05702135   0.063934316 2259.7551 1.0010920
#> tau          9.518607e-02   0.10992048   0.149182525 1060.9584 1.0017775
#> phi[1]       6.302077e-02   0.10911629   0.204227579 1831.5620 1.0007852
#> phi[2]       8.623714e-02   0.11163314   0.161573105 1890.3778 1.0023479
#> phi[3]       4.379105e-02   0.08493576   0.167979570 1531.0706 1.0020598
#> phi[4]      -3.910235e-03   0.02061067   0.068335433 2209.9739 0.9999519
#> phi[5]       1.042480e-02   0.03597433   0.084797721 2180.8118 1.0000415
#> phi[6]      -1.546797e-01  -0.12476679  -0.061801998 2482.9831 1.0005970
#> phi[7]       1.500223e-01   0.19858448   0.303725474 2162.5590 1.0010141
#> phi[8]      -5.687883e-02  -0.02408947   0.045831163 2192.5898 1.0010408
#> phi[9]       2.099505e-02   0.05464485   0.126876129 1632.7882 1.0017405
#> phi[10]     -4.487422e-02  -0.01629578   0.042520795 1999.2358 1.0004984
#> phi[11]     -3.444885e-02  -0.01140790   0.034733153 1995.6921 1.0019295
#> phi[12]      2.942737e-02   0.05225277   0.099893093 1872.8302 1.0007509
#> phi[13]     -8.452041e-02  -0.05301994   0.009719547 2036.2404 1.0004532
#> phi[14]      6.930699e-02   0.09853478   0.150203556 2064.9530 1.0007749
#> phi[15]     -5.006007e-02  -0.02492949   0.026815864 2265.5410 1.0019455
#> phi[16]     -1.030092e-01  -0.07524773  -0.023696920 2385.9470 1.0012877
#> phi[17]      1.086331e-01   0.14897601   0.227382207 2171.7872 1.0000436
#> phi[18]      3.309196e-02   0.06381402   0.125281057 2222.4221 1.0001972
#> phi[19]     -8.503282e-02  -0.04675622   0.020114280 2108.2302 1.0002783
#> lp__         2.150419e+02 217.99342919 222.873066075  891.3578 1.0048836

95% CI

  • beta[1,1] is the intercept which is not showing the figure.
beta_name <- paste0("beta[", 2:4, ",1]")
mcmc_areas(fit,
           pars = beta_name,
           prob = 0.95)

NO EFECT!

Data for Colocasia_gigantea

sp2 <- llp1 |>
  filter(species == "Colocasia_gigantea")

x1 <- cbind(1,
           log(1/(sp2$Distance) ^2)|> scale(),
           scale(sp2$canopy_openness))

x1 <- cbind(x1, x1[,2] * x1[,3])

list_d <- list(
  N = nrow(sp2),
  J = sp2$individual |> unique() |> length(),
  K = 4,
  ind = sp2$individual,
  x = x1,
  y = log(sp2$LMA))
model1 <- rstan::stan_model("../stan/model.stan")
writeLines(readLines("../stan/model.stan"))
data{
  int<lower=0> N; // number of sample
  int<lower=1> J; // number of individual
  int<lower=1> K; // number of parameters
  matrix[N, K] x; // tree-level predictor
  vector[N] y; //log(LMA)
  int<lower=1,upper=J> ind[N]; // integer
}


parameters{
  matrix[K,1] beta;
  vector[J] phi_raw;
  real<lower=0,upper=pi()/2> tau_unif;
  real<lower=0> sigma;
}

transformed parameters{
  real<lower=0> tau;
  vector[J] phi;
  tau = 2.5 * tan(tau_unif); // implies tau ~ cauchy(0, 2.5)
  phi = phi_raw * tau;
}

model {
  //vector[N] mu;
  //for (n in 1:N) mu[n] = x[n, ] * beta + phi[ind[n]];
  phi_raw ~ std_normal();
  to_vector(beta) ~ normal(0, 5);
  y ~ normal(to_vector(x * beta) + phi[ind], sigma);
}
fit1 <- rstan::sampling(model1,
                       data = list_d,
                       verbose = TRUE,
                       iter = 2000,
                       warmup = 1000,
                       thin = 1,
                       chains = 4,
                       refresh = 200,
                       seed = 123)
#> 
#> CHECKING DATA AND PREPROCESSING FOR MODEL 'model' NOW.
#> 
#> COMPILING MODEL 'model' NOW.
#> 
#> STARTING SAMPLER FOR MODEL 'model' NOW.
summary(fit1)$summary
#>                      mean      se_mean          sd          2.5%           25%
#> beta[1,1]     3.551391519 5.376012e-04 0.017458616   3.515889044  3.540520e+00
#> beta[2,1]    -0.104344079 6.332197e-04 0.021320624  -0.145763798 -1.189100e-01
#> beta[3,1]     0.049533548 6.897554e-04 0.022518089   0.005063399  3.432049e-02
#> beta[4,1]    -0.011957716 4.417596e-04 0.015659305  -0.042827858 -2.176306e-02
#> phi_raw[1]    0.699591918 1.134201e-02 0.554506126  -0.344208048  3.228900e-01
#> phi_raw[2]    0.324973707 1.094525e-02 0.496455291  -0.669034824 -7.404382e-03
#> phi_raw[3]   -0.276551415 1.099761e-02 0.529131297  -1.311322946 -6.275432e-01
#> phi_raw[4]   -0.031491326 1.639461e-02 0.814279468  -1.627836474 -5.838141e-01
#> phi_raw[5]   -1.260930583 1.169365e-02 0.454407390  -2.177003906 -1.550213e+00
#> phi_raw[6]   -0.842655073 1.050027e-02 0.446960304  -1.719985237 -1.144829e+00
#> phi_raw[7]   -1.401290254 1.368088e-02 0.549536548  -2.471333746 -1.769725e+00
#> phi_raw[8]   -0.587762952 9.320389e-03 0.409373244  -1.399255006 -8.674027e-01
#> phi_raw[9]   -0.987648322 1.510734e-02 0.553423986  -2.071983260 -1.364338e+00
#> phi_raw[10]  -0.720335117 8.364697e-03 0.400973259  -1.507262293 -9.897081e-01
#> phi_raw[11]   1.423210652 8.321207e-03 0.386608026   0.694826946  1.151029e+00
#> phi_raw[12]  -0.871170933 1.268835e-02 0.504646618  -1.870667391 -1.205162e+00
#> phi_raw[13]  -0.574040660 1.457756e-02 0.532867874  -1.613431463 -9.394422e-01
#> phi_raw[14]   1.100276083 1.163716e-02 0.492474543   0.160823623  7.684129e-01
#> phi_raw[15]   0.789587370 1.039887e-02 0.455030310  -0.098412285  4.814152e-01
#> phi_raw[16]   0.701940151 7.143924e-03 0.365751211   0.011337286  4.582888e-01
#> phi_raw[17]   0.463558298 7.097726e-03 0.372788861  -0.247654318  2.117034e-01
#> phi_raw[18]  -0.202381545 6.966059e-03 0.392731861  -1.002077345 -4.572065e-01
#> phi_raw[19]   0.800195018 7.306029e-03 0.374817060   0.111596427  5.453684e-01
#> phi_raw[20]   0.425647139 7.304931e-03 0.371343955  -0.266293696  1.647563e-01
#> phi_raw[21]  -0.376053482 8.013846e-03 0.372671634  -1.116453903 -6.226209e-01
#> phi_raw[22]   2.107829381 1.142668e-02 0.463517075   1.260313296  1.780679e+00
#> phi_raw[23]  -0.167484302 8.121748e-03 0.395946777  -0.969485210 -4.294159e-01
#> phi_raw[24]  -1.451797879 9.689083e-03 0.467155814  -2.392664165 -1.755272e+00
#> phi_raw[25]   0.844564444 1.037982e-02 0.440084620  -0.004448025  5.434343e-01
#> phi_raw[26]  -1.142078744 1.073524e-02 0.465069776  -2.081559034 -1.449243e+00
#> phi_raw[27]  -0.747486599 9.226300e-03 0.424151937  -1.583113826 -1.030400e+00
#> phi_raw[28]  -0.488616686 9.495459e-03 0.440745336  -1.349014948 -7.839176e-01
#> phi_raw[29]  -0.446917001 1.108846e-02 0.476830320  -1.386614536 -7.580102e-01
#> phi_raw[30]  -0.035987135 9.283643e-03 0.404899426  -0.848720767 -3.030314e-01
#> phi_raw[31]   0.937098106 7.674587e-03 0.375322700   0.218462458  6.936933e-01
#> phi_raw[32]   0.753998850 9.175108e-03 0.401571505  -0.020811736  4.879268e-01
#> phi_raw[33]   0.104764656 1.021159e-02 0.416396834  -0.724245299 -1.751225e-01
#> phi_raw[34]   1.312013965 1.091468e-02 0.436670304   0.486846505  1.016193e+00
#> phi_raw[35]  -0.071820255 1.183941e-02 0.492917271  -1.027714429 -3.991602e-01
#> tau_unif      0.035865228 1.749985e-04 0.005442722   0.026857173  3.196186e-02
#> sigma         0.065802341 7.607081e-05 0.004034621   0.058422581  6.296364e-02
#> tau           0.089704280 4.381377e-04 0.013626510   0.067159082  7.993187e-02
#> phi[1]        0.061552218 1.011627e-03 0.049108081  -0.031837298  2.873364e-02
#> phi[2]        0.028665292 9.893500e-04 0.043873857  -0.058817353 -6.592868e-04
#> phi[3]       -0.024344000 1.000612e-03 0.047027668  -0.120054947 -5.530033e-02
#> phi[4]       -0.002910694 1.508953e-03 0.073445013  -0.147367923 -5.123449e-02
#> phi[5]       -0.111170023 9.337915e-04 0.038526385  -0.188828294 -1.361169e-01
#> phi[6]       -0.074240357 9.191357e-04 0.038965652  -0.150572184 -1.003092e-01
#> phi[7]       -0.123578764 1.219170e-03 0.047566629  -0.220606181 -1.541196e-01
#> phi[8]       -0.051755348 8.100312e-04 0.036080936  -0.124326755 -7.625771e-02
#> phi[9]       -0.086989103 1.280728e-03 0.048444826  -0.181720182 -1.197135e-01
#> phi[10]      -0.063448750 6.883092e-04 0.034770411  -0.131325887 -8.653713e-02
#> phi[11]       0.125483589 5.803671e-04 0.031119527   0.063153599  1.048662e-01
#> phi[12]      -0.076731071 1.077715e-03 0.044231162  -0.162946927 -1.065451e-01
#> phi[13]      -0.050521048 1.283719e-03 0.047267252  -0.141126407 -8.298963e-02
#> phi[14]       0.097214427 1.041188e-03 0.042970052   0.014464036  6.817264e-02
#> phi[15]       0.069713155 9.311865e-04 0.040038990  -0.009170628  4.277125e-02
#> phi[16]       0.061842649 6.017047e-04 0.031375940   0.001008979  4.145421e-02
#> phi[17]       0.040949209 6.276722e-04 0.032662980  -0.022447435  1.872365e-02
#> phi[18]      -0.017893271 6.228139e-04 0.034578471  -0.087360093 -4.055644e-02
#> phi[19]       0.070695505 6.033602e-04 0.032297511   0.009103373  4.887955e-02
#> phi[20]       0.037632516 6.321466e-04 0.032463594  -0.024207936  1.475622e-02
#> phi[21]      -0.033169926 7.021059e-04 0.032765218  -0.095389574 -5.564626e-02
#> phi[22]       0.185848026 7.344018e-04 0.035332189   0.118240693  1.621001e-01
#> phi[23]      -0.014709036 7.250784e-04 0.034907468  -0.081832127 -3.807411e-02
#> phi[24]      -0.128015610 7.877454e-04 0.039069762  -0.202763650 -1.543972e-01
#> phi[25]       0.074420141 8.678444e-04 0.038233493  -0.000467207  4.897980e-02
#> phi[26]      -0.100631753 9.063127e-04 0.039511143  -0.179724619 -1.276242e-01
#> phi[27]      -0.065809688 8.143920e-04 0.036827690  -0.137879899 -9.080363e-02
#> phi[28]      -0.042916399 8.497280e-04 0.038708566  -0.115735128 -6.863808e-02
#> phi[29]      -0.039341766 1.009394e-03 0.042301199  -0.123201547 -6.735023e-02
#> phi[30]      -0.003068622 8.342816e-04 0.035851598  -0.074894255 -2.660556e-02
#> phi[31]       0.082681179 6.247334e-04 0.031880270   0.019928568  6.240795e-02
#> phi[32]       0.066465465 7.737133e-04 0.034688259  -0.001890577  4.363748e-02
#> phi[33]       0.009391427 9.196422e-04 0.037102860  -0.064644177 -1.539377e-02
#> phi[34]       0.115645161 8.520530e-04 0.036413590   0.043854374  9.195582e-02
#> phi[35]      -0.006410288 1.054748e-03 0.043691692  -0.092460251 -3.499123e-02
#> lp__        343.901596991 2.253899e-01 6.255869133 331.058639324  3.397765e+02
#>                       50%           75%         97.5%     n_eff      Rhat
#> beta[1,1]     3.551545462   3.562483350   3.585804476 1054.6278 1.0078589
#> beta[2,1]    -0.104395643  -0.089768192  -0.062071174 1133.6813 1.0026273
#> beta[3,1]     0.049525615   0.064747643   0.093790999 1065.7928 1.0072752
#> beta[4,1]    -0.012089802  -0.001825354   0.019510556 1256.5304 1.0042267
#> phi_raw[1]    0.684743722   1.082478246   1.806472417 2390.1900 1.0014333
#> phi_raw[2]    0.323226257   0.650949892   1.308272661 2057.3529 1.0015732
#> phi_raw[3]   -0.272575385   0.079326022   0.760381238 2314.8883 1.0007752
#> phi_raw[4]   -0.029697091   0.518391464   1.508359207 2466.8607 0.9998896
#> phi_raw[5]   -1.245784809  -0.962668385  -0.383661755 1510.0465 1.0013994
#> phi_raw[6]   -0.844685729  -0.540184736   0.021581422 1811.9132 1.0026648
#> phi_raw[7]   -1.401743510  -1.015808466  -0.378670600 1613.4846 1.0029138
#> phi_raw[8]   -0.587112865  -0.309532121   0.199629948 1929.1715 1.0009372
#> phi_raw[9]   -0.992957607  -0.614267765   0.073474809 1341.9619 1.0031924
#> phi_raw[10]  -0.724845399  -0.451141925   0.067170248 2297.8960 0.9997452
#> phi_raw[11]   1.421857210   1.663180065   2.208475500 2158.5847 1.0024199
#> phi_raw[12]  -0.868457893  -0.538670703   0.111098601 1581.8480 1.0010537
#> phi_raw[13]  -0.582594116  -0.207539989   0.445106426 1336.1938 1.0023518
#> phi_raw[14]   1.086393116   1.429569950   2.068511921 1790.9107 1.0016765
#> phi_raw[15]   0.798996527   1.087336408   1.689657209 1914.7328 1.0014335
#> phi_raw[16]   0.690299324   0.932893639   1.459278156 2621.1865 1.0003134
#> phi_raw[17]   0.450590034   0.709015002   1.236264538 2758.5913 1.0016859
#> phi_raw[18]  -0.201646020   0.063398224   0.564653376 3178.4694 1.0014050
#> phi_raw[19]   0.786098130   1.048703381   1.580783864 2631.9398 1.0022241
#> phi_raw[20]   0.419813530   0.667653829   1.165705803 2584.1664 1.0012897
#> phi_raw[21]  -0.374635436  -0.124693897   0.368604969 2162.5724 1.0034795
#> phi_raw[22]   2.079637833   2.417525004   3.053682976 1645.4743 1.0042987
#> phi_raw[23]  -0.158527103   0.104935740   0.604269713 2376.7011 1.0005125
#> phi_raw[24]  -1.454866821  -1.134621013  -0.512741763 2324.6534 1.0010043
#> phi_raw[25]   0.840303327   1.141872327   1.737889989 1797.5971 1.0024357
#> phi_raw[26]  -1.116071296  -0.822599315  -0.272177201 1876.7777 1.0007335
#> phi_raw[27]  -0.743177616  -0.454419435   0.059316672 2113.4295 1.0021117
#> phi_raw[28]  -0.484550675  -0.192561562   0.348929809 2154.4851 1.0027136
#> phi_raw[29]  -0.438925844  -0.136918373   0.492191011 1849.2056 1.0034898
#> phi_raw[30]  -0.028808816   0.224304125   0.750907752 1902.2058 1.0019136
#> phi_raw[31]   0.919116696   1.175754646   1.714965888 2391.6612 1.0015739
#> phi_raw[32]   0.751770623   1.017446621   1.542726559 1915.5935 1.0041195
#> phi_raw[33]   0.114181511   0.380665171   0.926508236 1662.7535 1.0018845
#> phi_raw[34]   1.304575658   1.599714090   2.178363483 1600.6083 1.0065140
#> phi_raw[35]  -0.070665396   0.253463753   0.908981748 1733.3555 1.0012128
#> tau_unif      0.035252324   0.039141107   0.048233650  967.3051 1.0040803
#> sigma         0.065733866   0.068497441   0.073908730 2812.9979 1.0007337
#> tau           0.088167335   0.097902768   0.120677723  967.2709 1.0040818
#> phi[1]        0.060244038   0.094677734   0.159414027 2356.4859 1.0006652
#> phi[2]        0.028696827   0.057398187   0.115010678 1966.5805 1.0013949
#> phi[3]       -0.023486377   0.007052944   0.068332899 2208.8976 1.0009820
#> phi[4]       -0.002739357   0.046576339   0.137141293 2369.0439 0.9999203
#> phi[5]       -0.110278473  -0.085558629  -0.034872792 1702.2239 1.0034667
#> phi[6]       -0.073731490  -0.047983394   0.002111177 1797.2340 1.0043579
#> phi[7]       -0.123795476  -0.091803383  -0.035543238 1522.2164 1.0046599
#> phi[8]       -0.051704096  -0.027595019   0.017401900 1984.0475 1.0010526
#> phi[9]       -0.087063140  -0.054805179   0.006824878 1430.8062 1.0030148
#> phi[10]      -0.063954103  -0.040518690   0.006165732 2551.8346 0.9997969
#> phi[11]       0.125728806   0.146539483   0.186679175 2875.1489 1.0009080
#> phi[12]      -0.077056643  -0.047723681   0.009646001 1684.4132 1.0011615
#> phi[13]      -0.051272244  -0.018573033   0.040848238 1355.7541 1.0027629
#> phi[14]       0.095688985   0.126358997   0.183060628 1703.2308 1.0010971
#> phi[15]       0.069841883   0.095863684   0.148208824 1848.8125 1.0012016
#> phi[16]       0.061239591   0.082613245   0.124070971 2719.1091 0.9999606
#> phi[17]       0.039990740   0.063104776   0.105030641 2707.9823 1.0013847
#> phi[18]      -0.017985947   0.005781485   0.049669546 3082.4429 1.0016751
#> phi[19]       0.070233159   0.091728942   0.137082473 2865.3971 1.0012106
#> phi[20]       0.037552467   0.059206843   0.102915411 2637.2880 1.0010851
#> phi[21]      -0.033456801  -0.011141177   0.031712282 2177.8143 1.0039086
#> phi[22]       0.185867245   0.209800766   0.254462958 2314.5875 1.0023651
#> phi[23]      -0.014184347   0.009026518   0.053100806 2317.7511 1.0005492
#> phi[24]      -0.128143370  -0.102178885  -0.051025492 2459.8564 1.0003827
#> phi[25]       0.074024515   0.099213663   0.151458572 1940.9047 1.0023656
#> phi[26]      -0.099654583  -0.073738215  -0.024611373 1900.5666 1.0004700
#> phi[27]      -0.065556165  -0.041110320   0.005725060 2044.9465 1.0020240
#> phi[28]      -0.042541503  -0.017499160   0.032945274 2075.1731 1.0030915
#> phi[29]      -0.039117325  -0.012095313   0.044393338 1756.2414 1.0039358
#> phi[30]      -0.002559186   0.020382431   0.068860357 1846.6802 1.0020050
#> phi[31]       0.081693565   0.104024215   0.146253575 2604.0815 1.0007208
#> phi[32]       0.066197558   0.089348542   0.135034991 2010.0408 1.0030812
#> phi[33]       0.010007552   0.034043178   0.080988712 1627.7100 1.0018832
#> phi[34]       0.115541826   0.139269577   0.189050774 1826.3911 1.0061915
#> phi[35]      -0.006193792   0.022690490   0.079580074 1715.9313 1.0009852
#> lp__        344.087949600 348.326915839 355.203139067  770.3826 1.0042396
beta_name <- paste0("beta[", 2:4, ",1]")
mcmc_areas(fit1,
           pars = beta_name,
           prob = 0.95)

So we can see for species Colocasia_gigantea the regression coefficients of distance and canopy openness are significant.

5 Table the results

For species one “Melastoma_candidum”, coefficients table.


test <- summary(fit)$summary[2:4,] |> as_tibble()

quantile_interval <-  paste0("[",round(test$`2.5%`,4),", ",  round(test$`97.5%`,4),"]")

table_sp1 <- data.frame(
  "Parameters" = c(
                   "ALAN's effect",
                   "Daylight's effect",
                   "interaction"),
  "mean_value" = round(test$mean,4),
 quantile_interval 
)

table_sp1 %>%
  kbl(caption = "Coefficients table of species Melastoma_candidum") %>%column_spec(3,bold =  ifelse(test$`2.5%`*test$`97.5%`>0, "T","F"))%>% 
  kable_classic(full_width = F, html_font = "Cambria")
Coefficients table of species Melastoma_candidum
Parameters mean_value quantile_interval
ALAN’s effect -0.0422 [-0.1129, 0.0276]
Daylight’s effect -0.0006 [-0.0761, 0.0744]
interaction -0.0308 [-0.0836, 0.0216]

For species “Colocasia_gigantea”, coefficients table.

test1 <- summary(fit1)$summary[2:4,] |> as_tibble()

quantile_interval <-  paste0("[",round(test1$`2.5%`,4),", ",  round(test1$`97.5%`,4),"]")

table_sp2 <- data.frame(
  "Parameters" = c(
                   "ALAN's effect",
                   "Daylight's effect",
                   "interaction"),
  "mean_value" = round(test1$mean,4),
 quantile_interval 
)

table_sp2 %>%
  kbl(caption = "Coefficients table of species Colocasia_gigantea") %>%column_spec(3,bold =  ifelse(test1$`2.5%`*test1$`97.5%`>0, "T","F"))%>% 
  kable_classic(full_width = F, html_font = "Cambria")
Coefficients table of species Colocasia_gigantea
Parameters mean_value quantile_interval
ALAN’s effect -0.1043 [-0.1458, -0.0621]
Daylight’s effect 0.0495 [0.0051, 0.0938]
interaction -0.0120 [-0.0428, 0.0195]

#Put together

rbind(table_sp1,table_sp2)|>
  kbl( caption = "Coefficients table") %>%
  kable_paper("striped", full_width = F) %>%
  column_spec(3,bold =c(ifelse(test$`2.5%`*test$`97.5%`>0, "T","F"),       ifelse(test1$`2.5%`*test1$`97.5%`>0, "T","F"))) %>% 
  pack_rows("Melastoma_candidum", 1, 3) %>%
  pack_rows("Colocasia_gigantea", 4, 6)
Coefficients table
Parameters mean_value quantile_interval
Melastoma_candidum
ALAN’s effect -0.0422 [-0.1129, 0.0276]
Daylight’s effect -0.0006 [-0.0761, 0.0744]
interaction -0.0308 [-0.0836, 0.0216]
Colocasia_gigantea
ALAN’s effect -0.1043 [-0.1458, -0.0621]
Daylight’s effect 0.0495 [0.0051, 0.0938]
interaction -0.0120 [-0.0428, 0.0195]