Skip to contents

This function fits a distribution to a data set of observed sapwood numbers and computes the highest posterior density interval (hdi) for a given credibility mass.

Usage

sw_model(
  sw_data = "Hollstein_1980",
  densfun = "lognormal",
  cred_mass = 0.954,
  source = NA,
  plot = FALSE
)

Arguments

sw_data

The name of the sapwood data set to use for modelling. It should be one of the data sets listed in sw_data_overview(), or the name of a data.frame with sapwood data in columns n_sapwood and count.

densfun

Name of the density function to fit to the sapwood data set. Should be one of:

  • lognormal (the default value),

  • normal,

  • weibull,

  • gammma.

cred_mass

A scalar in the range of [0, 1] specifying the mass within the credible interval (default = .954).

source

A character string with info on the data source. This info is incorporated in the titel of the plot when a sapwood data set is provided from a user-defined data.frame.

plot

A logical. If TRUE a plot of the fitted density function is returned. When FALSE, a list with numeric output of the modelling process is returned.

Value

The return value depends on the plot parameter.

  • if plot is TRUE, a ggplot-style graph is returned.

  • if plot is FALSE, a list with the numeric output of the modelling process is returned.

Examples

sw_model(sw_data = "Sohar_2012_ELL_c",
          densfun = "lognormal",
          cred_mass = .095,
          plot = FALSE)
#> $sapwood_data
#> [1] "Sohar_2012_ELL_c"
#> 
#> $n
#> [1] 562
#> 
#> $range
#>   min  mean   max 
#>  2.00 14.05 27.00 
#> 
#> $density_function
#> [1] "lognormal"
#> 
#> $fit_parameters
#>      meanlog        sdlog   
#>   2.426831039   0.259874475 
#>  (0.010962143) (0.007751406)
#> 
#> $sapwood_model
#>     n_sapwood            p    model_fit count
#> 1           1 1.775685e-19 9.979348e-17    NA
#> 2           2 1.663010e-10 9.346118e-08     1
#> 3           3 1.088009e-06 6.114613e-04    NA
#> 4           4 1.267019e-04 7.120648e-02    NA
#> 5           5 2.182256e-03 1.226428e+00     2
#> 6           6 1.291805e-02 7.259944e+00    12
#> 7           7 3.957205e-02 2.223949e+01    18
#> 8           8 7.852913e-02 4.413337e+01    35
#> 9           9 1.154500e-01 6.488290e+01    60
#> 10         10 1.369339e-01 7.695686e+01    63
#> 11         11 1.386953e-01 7.794674e+01    79
#> 12         12 1.247730e-01 7.012242e+01    94
#> 13         13 1.025333e-01 5.762373e+01    60
#> 14         14 7.855963e-02 4.415051e+01    60
#> 15         15 5.698656e-02 3.202645e+01    30
#> 16         16 3.959475e-02 2.225225e+01    24
#> 17         17 2.658857e-02 1.494277e+01     5
#> 18         18 1.737775e-02 9.766296e+00     7
#> 19         19 1.111591e-02 6.247143e+00     5
#> 20         20 6.989977e-03 3.928367e+00     2
#> 21         21 4.336480e-03 2.437101e+00     2
#> 22         22 2.661888e-03 1.495981e+00     1
#> 23         23 1.620552e-03 9.107503e-01     1
#> 24         24 9.804003e-04 5.509850e-01    NA
#> 25         25 5.903513e-04 3.317774e-01    NA
#> 26         26 3.542948e-04 1.991137e-01    NA
#> 27         27 2.121533e-04 1.192302e-01     1
#> 28         28 1.268731e-04 7.130269e-02    NA
#> 29         29 7.583378e-05 4.261858e-02    NA
#> 30         30 4.533286e-05 2.547707e-02    NA
#> 31         31 2.711814e-05 1.524039e-02    NA
#> 32         32 1.624066e-05 9.127252e-03    NA
#> 33         33 9.741231e-06 5.474572e-03    NA
#> 34         34 5.853724e-06 3.289793e-03    NA
#> 35         35 3.525157e-06 1.981138e-03    NA
#> 36         36 2.127906e-06 1.195883e-03    NA
#> 37         37 1.287769e-06 7.237261e-04    NA
#> 38         38 7.814555e-07 4.391780e-04    NA
#> 39         39 4.755642e-07 2.672671e-04    NA
#> 40         40 2.902683e-07 1.631308e-04    NA
#> 41         41 1.777110e-07 9.987356e-05    NA
#> 42         42 1.091399e-07 6.133662e-05    NA
#> 43         43 6.724062e-08 3.778923e-05    NA
#> 44         44 4.156016e-08 2.335681e-05    NA
#> 45         45 2.577115e-08 1.448339e-05    NA
#> 46         46 1.603285e-08 9.010462e-06    NA
#> 47         47 1.000723e-08 5.624062e-06    NA
#> 48         48 6.266796e-09 3.521939e-06    NA
#> 49         49 3.937367e-09 2.212800e-06    NA
#> 50         50 2.481946e-09 1.394854e-06    NA
#> 51         51 1.569641e-09 8.821384e-07    NA
#> 52         52 9.959186e-10 5.597063e-07    NA
#> 53         53 6.339499e-10 3.562799e-07    NA
#> 54         54 4.048413e-10 2.275208e-07    NA
#> 55         55 2.593601e-10 1.457604e-07    NA
#> 56         56 1.666860e-10 9.367752e-08    NA
#> 57         57 1.074634e-10 6.039446e-08    NA
#> 58         58 6.949855e-11 3.905818e-08    NA
#> 59         59 4.508489e-11 2.533771e-08    NA
#> 60         60 2.933683e-11 1.648730e-08    NA
#> 61         61 1.914733e-11 1.076080e-08    NA
#> 62         62 1.253436e-11 7.044310e-09    NA
#> 63         63 8.229636e-12 4.625056e-09    NA
#> 64         64 5.419124e-12 3.045548e-09    NA
#> 65         65 3.578763e-12 2.011265e-09    NA
#> 66         66 2.370158e-12 1.332029e-09    NA
#> 67         67 1.574155e-12 8.846752e-10    NA
#> 68         68 1.048404e-12 5.892033e-10    NA
#> 69         69 7.001748e-13 3.934983e-10    NA
#> 70         70 4.688844e-13 2.635130e-10    NA
#> 71         71 3.148415e-13 1.769409e-10    NA
#> 72         72 2.119682e-13 1.191261e-10    NA
#> 73         73 1.430827e-13 8.041250e-11    NA
#> 74         74 9.683394e-14 5.442067e-11    NA
#> 75         75 6.570182e-14 3.692442e-11    NA
#> 76         76 4.469127e-14 2.511649e-11    NA
#> 77         77 3.047541e-14 1.712718e-11    NA
#> 78         78 2.083263e-14 1.170794e-11    NA
#> 79         79 1.427556e-14 8.022863e-12    NA
#> 80         80 9.805796e-15 5.510858e-12    NA
#> 81         81 6.751500e-15 3.794343e-12    NA
#> 82         82 4.659425e-15 2.618597e-12    NA
#> 83         83 3.223043e-15 1.811350e-12    NA
#> 84         84 2.234544e-15 1.255814e-12    NA
#> 85         85 1.552703e-15 8.726191e-13    NA
#> 86         86 1.081315e-15 6.076989e-13    NA
#> 87         87 7.546889e-16 4.241351e-13    NA
#> 88         88 5.278664e-16 2.966609e-13    NA
#> 89         89 3.700057e-16 2.079432e-13    NA
#> 90         90 2.599021e-16 1.460650e-13    NA
#> 91         91 1.829434e-16 1.028142e-13    NA
#> 92         92 1.290380e-16 7.251938e-14    NA
#> 93         93 9.120153e-17 5.125526e-14    NA
#> 94         94 6.458904e-17 3.629904e-14    NA
#> 95         95 4.583290e-17 2.575809e-14    NA
#> 96         96 3.258719e-17 1.831400e-14    NA
#> 97         97 2.321440e-17 1.304649e-14    NA
#> 98         98 1.656909e-17 9.311829e-15    NA
#> 99         99 1.184842e-17 6.658814e-15    NA
#> 100       100 8.488547e-18 4.770564e-15    NA
#> 
#> $hdi_model
#>   lower upper         p
#> 1    11    11 0.1386953
#> 

sw_model("Hollstein_1980")
#> $sapwood_data
#> [1] "Hollstein_1980"
#> 
#> $n
#> [1] 490
#> 
#> $range
#>   min  mean   max 
#>  6.00 25.05 67.00 
#> 
#> $density_function
#> [1] "lognormal"
#> 
#> $fit_parameters
#>     meanlog       sdlog   
#>   2.81357890   0.41620736 
#>  (0.01880233) (0.01329526)
#> 
#> $sapwood_model
#>     n_sapwood            p    model_fit count
#> 1           1 1.143856e-10 5.604897e-08    NA
#> 2           2 1.107667e-06 5.427569e-04    NA
#> 3           3 6.572161e-05 3.220359e-02    NA
#> 4           4 6.697648e-04 3.281848e-01    NA
#> 5           5 2.917879e-03 1.429761e+00    NA
#> 6           6 7.845478e-03 3.844284e+00     4
#> 7           7 1.558774e-02 7.637994e+00     9
#> 8           8 2.528777e-02 1.239101e+01    18
#> 9           9 3.557549e-02 1.743199e+01    21
#> 10         10 4.511128e-02 2.210453e+01    21
#> 11         11 5.291838e-02 2.593001e+01    21
#> 12         12 5.847980e-02 2.865510e+01    27
#> 13         13 6.168335e-02 3.022484e+01    27
#> 14         14 6.270361e-02 3.072477e+01    37
#> 15         15 6.187987e-02 3.032113e+01    25
#> 16         16 5.961755e-02 2.921260e+01    21
#> 17         17 5.632071e-02 2.759715e+01    24
#> 18         18 5.235228e-02 2.565261e+01    29
#> 19         19 4.801543e-02 2.352756e+01    23
#> 20         20 4.354902e-02 2.133902e+01    18
#> 21         21 3.913128e-02 1.917433e+01    19
#> 22         22 3.488778e-02 1.709501e+01    26
#> 23         23 3.090081e-02 1.514139e+01    17
#> 24         24 2.721872e-02 1.333717e+01    19
#> 25         25 2.386428e-02 1.169350e+01    14
#> 26         26 2.084176e-02 1.021246e+01     9
#> 27         27 1.814260e-02 8.889875e+00    11
#> 28         28 1.574987e-02 7.717438e+00     8
#> 29         29 1.364165e-02 6.684408e+00     6
#> 30         30 1.179345e-02 5.778789e+00     3
#> 31         31 1.017998e-02 4.988188e+00     3
#> 32         32 8.776330e-03 4.300402e+00     3
#> 33         33 7.558758e-03 3.703792e+00     5
#> 34         34 6.505127e-03 3.187512e+00    NA
#> 35         35 5.595166e-03 2.741631e+00     4
#> 36         36 4.810558e-03 2.357174e+00     5
#> 37         37 4.134922e-03 2.026112e+00     4
#> 38         38 3.553733e-03 1.741329e+00     1
#> 39         39 3.054196e-03 1.496556e+00     3
#> 40         40 2.625106e-03 1.286302e+00    NA
#> 41         41 2.256692e-03 1.105779e+00     1
#> 42         42 1.940470e-03 9.508301e-01     1
#> 43         43 1.669088e-03 8.178532e-01    NA
#> 44         44 1.436201e-03 7.037387e-01    NA
#> 45         45 1.236339e-03 6.058060e-01    NA
#> 46         46 1.064793e-03 5.217487e-01     2
#> 47         47 9.175209e-04 4.495852e-01    NA
#> 48         48 7.910512e-04 3.876151e-01    NA
#> 49         49 6.824083e-04 3.343801e-01    NA
#> 50         50 5.890423e-04 2.886307e-01    NA
#> 51         51 5.087694e-04 2.492970e-01    NA
#> 52         52 4.397201e-04 2.154628e-01    NA
#> 53         53 3.802943e-04 1.863442e-01    NA
#> 54         54 3.291226e-04 1.612701e-01    NA
#> 55         55 2.850331e-04 1.396662e-01    NA
#> 56         56 2.470227e-04 1.210411e-01    NA
#> 57         57 2.142330e-04 1.049741e-01    NA
#> 58         58 1.859287e-04 9.110504e-02    NA
#> 59         59 1.614803e-04 7.912533e-02    NA
#> 60         60 1.403484e-04 6.877070e-02    NA
#> 61         61 1.220707e-04 5.981464e-02    NA
#> 62         62 1.062509e-04 5.206292e-02    NA
#> 63         63 9.254883e-05 4.534893e-02    NA
#> 64         64 8.067277e-05 3.952966e-02    NA
#> 65         65 7.037208e-05 3.448232e-02    NA
#> 66         66 6.143144e-05 3.010140e-02    NA
#> 67         67 5.366574e-05 2.629621e-02     1
#> 68         68 4.691575e-05 2.298872e-02    NA
#> 69         69 4.104443e-05 2.011177e-02    NA
#> 70         70 3.593374e-05 1.760753e-02    NA
#> 71         71 3.148196e-05 1.542616e-02    NA
#> 72         72 2.760137e-05 1.352467e-02    NA
#> 73         73 2.421627e-05 1.186597e-02    NA
#> 74         74 2.126129e-05 1.041803e-02    NA
#> 75         75 1.867996e-05 9.153180e-03    NA
#> 76         76 1.642343e-05 8.047483e-03    NA
#> 77         77 1.444946e-05 7.080237e-03    NA
#> 78         78 1.272146e-05 6.233514e-03    NA
#> 79         79 1.120772e-05 5.491782e-03    NA
#> 80         80 9.880763e-06 4.841574e-03    NA
#> 81         81 8.716743e-06 4.271204e-03    NA
#> 82         82 7.694957e-06 3.770529e-03    NA
#> 83         83 6.797416e-06 3.330734e-03    NA
#> 84         84 6.008483e-06 2.944157e-03    NA
#> 85         85 5.314552e-06 2.604130e-03    NA
#> 86         86 4.703779e-06 2.304852e-03    NA
#> 87         87 4.165844e-06 2.041264e-03    NA
#> 88         88 3.691753e-06 1.808959e-03    NA
#> 89         89 3.273657e-06 1.604092e-03    NA
#> 90         90 2.904707e-06 1.423306e-03    NA
#> 91         91 2.578917e-06 1.263669e-03    NA
#> 92         92 2.291057e-06 1.122618e-03    NA
#> 93         93 2.036553e-06 9.979109e-04    NA
#> 94         94 1.811399e-06 8.875853e-04    NA
#> 95         95 1.612087e-06 7.899228e-04    NA
#> 96         96 1.435545e-06 7.034171e-04    NA
#> 97         97 1.279077e-06 6.267475e-04    NA
#> 98         98 1.140316e-06 5.587548e-04    NA
#> 99         99 1.017186e-06 4.984211e-04    NA
#> 100       100 9.078620e-07 4.448524e-04    NA
#> 
#> $hdi_model
#>   lower upper         p
#> 1     6    34 0.9561202
#>