Computes the summed probability density (SPD) for a set of felling date ranges.
Usage
sw_sum(
x,
series = "series",
last = "last",
n_sapwood = "n_sapwood",
waneyedge = "waneyedge",
sw_data = "Hollstein_1980",
densfun = "lognormal",
cred_mass = 0.954,
plot = FALSE,
scale_p = FALSE
)
Arguments
- x
A
data.frame
with columns c("series", "swr", "waneyedge" , "last"), Column "sw_model" is optional. Could be the output of read_fh(x, header = TRUE)- series
Name of the column in
x
where ID's of the tree-ring series are listed ascharacter
values.- last
Name of the column in
x
where calendar years assigned to the last measured ring are listed (should benumeric
).- n_sapwood
Name of the column in
x
where the number of observed sapwood rings are listed (should benumeric
)- waneyedge
Name of the column in
x
indicating the presence (TRUE
)/absence (FALSE
) of waney edge (should be alogical
).- 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 adata.frame
with sapwood data in columnsn_sapwood
andcount
.- densfun
Name of the density function fitted to the sapwood data set. Should be one of:
lognormal (the default value),
normal,
weibull,
gammma.
- cred_mass
A
scalar [0, 1]
specifying the mass within the credible interval (default = .954).- plot
A
logical
.If
TRUE
,sw_sum_plot()
is triggered and a ggplot-style graph is returned with the summed probability density (SPD).If
FALSE
, alist
with the numeric output of the modelling process is returned.
- scale_p
A
logical
. IfTRUE
the summed probability density is scaled to 1 (default).
Examples
trs_example7
#> series last n_sapwood waneyedge
#> 1 trs_34 1000 5 FALSE
#> 2 trs_35 1009 10 FALSE
#> 3 trs_36 1007 15 TRUE
#> 4 trs_37 1007 16 TRUE
#> 5 trs_38 1010 8 FALSE
#> 6 trs_39 1020 0 FALSE
#> 7 trs_40 1025 10 FALSE
#> 8 trs_41 1050 NA TRUE
#> 9 trs_42 1035 1 FALSE
sw_sum(trs_example7, densfun = "lognormal", cred_mass = 0.63, plot = FALSE)
#> Warning: --> 1 series without sapwood rings or waney edge detected
#> and removed from the data set
#> year trs_34 trs_35 trs_36 trs_37 trs_38 trs_39
#> 1 1000 2.920043e-03 NA NA NA NA NA
#> 2 1001 7.851298e-03 NA NA NA NA NA
#> 3 1002 1.559931e-02 NA NA NA NA NA
#> 4 1003 2.530653e-02 NA NA NA NA NA
#> 5 1004 3.560188e-02 NA NA NA NA NA
#> 6 1005 4.514475e-02 NA NA NA NA NA
#> 7 1006 5.295763e-02 NA NA NA NA NA
#> 8 1007 5.852318e-02 NA 1 1 NA NA
#> 9 1008 6.172910e-02 NA NA NA NA NA
#> 10 1009 6.275012e-02 4.946162e-02 NA NA NA NA
#> 11 1010 6.192577e-02 5.802159e-02 NA NA 2.599192e-02 NA
#> 12 1011 5.966178e-02 6.411934e-02 NA NA 3.656611e-02 NA
#> 13 1012 5.636249e-02 6.763182e-02 NA NA 4.636743e-02 NA
#> 14 1013 5.239111e-02 6.875047e-02 NA NA 5.439192e-02 NA
#> 15 1014 4.805105e-02 6.784729e-02 NA NA 6.010820e-02 NA
#> 16 1015 4.358132e-02 6.536681e-02 NA NA 6.340095e-02 NA
#> 17 1016 3.916031e-02 6.175203e-02 NA NA 6.444962e-02 NA
#> 18 1017 3.491366e-02 5.740090e-02 NA NA 6.360294e-02 NA
#> 19 1018 3.092373e-02 5.264582e-02 NA NA 6.127763e-02 NA
#> 20 1019 2.723891e-02 4.774869e-02 NA NA 5.788899e-02 NA
#> 21 1020 2.388199e-02 4.290493e-02 NA NA 5.381005e-02 0.000000e+00
#> 22 1021 2.085722e-02 3.825220e-02 NA NA 4.935244e-02 1.143866e-10
#> 23 1022 1.815606e-02 3.388074e-02 NA NA 4.476166e-02 1.107676e-06
#> 24 1023 1.576156e-02 2.984357e-02 NA NA 4.022091e-02 6.572213e-05
#> 25 1024 1.365177e-02 2.616565e-02 NA NA 3.585924e-02 6.697701e-04
#> 26 1025 1.180219e-02 2.285165e-02 NA NA 3.176125e-02 2.917902e-03
#> 27 1026 1.018753e-02 1.989219e-02 NA NA 2.797663e-02 7.845541e-03
#> 28 1027 8.782840e-03 1.726872e-02 NA NA 2.452880e-02 1.558787e-02
#> 29 1028 7.564365e-03 1.495719e-02 NA NA 2.142211e-02 2.528798e-02
#> 30 1029 6.509952e-03 1.293075e-02 NA NA 1.864779e-02 3.557577e-02
#> 31 1030 5.599317e-03 1.116169e-02 NA NA 1.618844e-02 4.511164e-02
#> 32 1031 4.814127e-03 9.622680e-03 NA NA 1.402151e-02 5.291880e-02
#> 33 1032 4.137990e-03 8.287691e-03 NA NA 1.212184e-02 5.848027e-02
#> 34 1033 3.556369e-03 7.132453e-03 NA NA 1.046344e-02 6.168383e-02
#> 35 1034 3.056461e-03 6.134739e-03 NA NA 9.020711e-03 6.270410e-02
#> 36 1035 2.627053e-03 5.274467e-03 NA NA 7.769235e-03 6.188036e-02
#> 37 1036 2.258366e-03 4.533676e-03 NA NA 6.686265e-03 5.961803e-02
#> 38 1037 1.941909e-03 3.896439e-03 NA NA 5.750966e-03 5.632116e-02
#> 39 1038 1.670326e-03 3.348729e-03 NA NA 4.944510e-03 5.235269e-02
#> 40 1039 1.437267e-03 2.878259e-03 NA NA 4.250061e-03 4.801581e-02
#> 41 1040 1.237256e-03 2.474318e-03 NA NA 3.652688e-03 4.354936e-02
#> 42 1041 1.065583e-03 2.127600e-03 NA NA 3.139241e-03 3.913159e-02
#> 43 1042 9.182015e-04 1.830048e-03 NA NA 2.698203e-03 3.488806e-02
#> 44 1043 7.916380e-04 1.574702e-03 NA NA 2.319531e-03 3.090105e-02
#> 45 1044 6.829145e-04 1.355566e-03 NA NA 1.994503e-03 2.721893e-02
#> 46 1045 5.894792e-04 1.167477e-03 NA NA 1.715565e-03 2.386447e-02
#> 47 1046 5.091468e-04 1.006003e-03 NA NA 1.476193e-03 2.084193e-02
#> 48 1047 4.400463e-04 8.673367e-04 NA NA 1.270765e-03 1.814275e-02
#> 49 1048 3.805764e-04 7.482168e-04 NA NA 1.094443e-03 1.575000e-02
#> 50 1049 3.293667e-04 6.458469e-04 NA NA 9.430697e-04 1.364176e-02
#> 51 1050 2.852445e-04 5.578329e-04 NA NA 8.130784e-04 1.179354e-02
#> 52 1051 2.472060e-04 4.821247e-04 NA NA 7.014103e-04 1.018006e-02
#> 53 1052 2.143919e-04 4.169682e-04 NA NA 6.054444e-04 8.776400e-03
#> 54 1053 1.860666e-04 3.608617e-04 NA NA 5.229363e-04 7.558818e-03
#> 55 1054 1.616000e-04 3.125204e-04 NA NA 4.519643e-04 6.505178e-03
#> 56 1055 1.404525e-04 2.708445e-04 NA NA 3.908837e-04 5.595211e-03
#> 57 1056 1.221612e-04 2.348926e-04 NA NA 3.382872e-04 4.810596e-03
#> 58 1057 1.063297e-04 2.038588e-04 NA NA 2.929699e-04 4.134955e-03
#> 59 1058 9.261748e-05 1.770527e-04 NA NA 2.539012e-04 3.553761e-03
#> 60 1059 8.073262e-05 1.538829e-04 NA NA 2.201984e-04 3.054220e-03
#> 61 1060 7.042428e-05 1.338427e-04 NA NA 1.911059e-04 2.625127e-03
#> 62 1061 6.147701e-05 1.164972e-04 NA NA 1.659767e-04 2.256710e-03
#> 63 1062 5.370554e-05 1.014738e-04 NA NA 1.442564e-04 1.940485e-03
#> 64 1063 4.695055e-05 8.845250e-05 NA NA 1.254698e-04 1.669101e-03
#> 65 1064 4.107488e-05 7.715845e-05 NA NA 1.092095e-04 1.436213e-03
#> 66 1065 3.596040e-05 6.735561e-05 NA NA 9.512589e-05 1.236348e-03
#> 67 1066 3.150532e-05 5.884102e-05 NA NA 8.291914e-05 1.064802e-03
#> 68 1067 2.762185e-05 5.144010e-05 NA NA 7.233162e-05 9.175282e-04
#> 69 1068 2.423423e-05 4.500257e-05 NA NA 6.314202e-05 7.910575e-04
#> 70 1069 2.127706e-05 3.939903e-05 NA NA 5.516008e-05 6.824137e-04
#> 71 1070 1.869382e-05 3.451794e-05 NA NA 4.822214e-05 5.890470e-04
#> 72 1071 1.643562e-05 3.026313e-05 NA NA 4.218733e-05 5.087734e-04
#> 73 1072 1.446018e-05 2.655158e-05 NA NA 3.693433e-05 4.397236e-04
#> 74 1073 1.273089e-05 2.331164e-05 NA NA 3.235859e-05 3.802973e-04
#> 75 1074 1.121603e-05 2.048137e-05 NA NA 2.836994e-05 3.291252e-04
#> 76 1075 9.888093e-06 1.800724e-05 NA NA 2.489058e-05 2.850353e-04
#> 77 1076 8.723209e-06 1.584291e-05 NA NA 2.185332e-05 2.470247e-04
#> 78 1077 7.700665e-06 1.394826e-05 NA NA 1.920011e-05 2.142346e-04
#> 79 1078 6.802458e-06 1.228854e-05 NA NA 1.688075e-05 1.859301e-04
#> 80 1079 6.012940e-06 1.083362e-05 NA NA 1.485181e-05 1.614815e-04
#> 81 1080 5.318494e-06 9.557348e-06 NA NA 1.307569e-05 1.403495e-04
#> 82 1081 4.707268e-06 8.437024e-06 NA NA 1.151980e-05 1.220717e-04
#> 83 1082 4.168935e-06 7.452929e-06 NA NA 1.015590e-05 1.062517e-04
#> 84 1083 3.694492e-06 6.587914e-06 NA NA 8.959465e-06 9.254956e-05
#> 85 1084 3.276086e-06 5.827064e-06 NA NA 7.909226e-06 8.067341e-05
#> 86 1085 2.906861e-06 5.157390e-06 NA NA 6.986693e-06 7.037264e-05
#> 87 1086 2.580830e-06 4.567580e-06 NA NA 6.175792e-06 6.143192e-05
#> 88 1087 2.292757e-06 4.047769e-06 NA NA 5.462538e-06 5.366616e-05
#> 89 1088 2.038063e-06 3.589354e-06 NA NA 4.834758e-06 4.691612e-05
#> 90 1089 1.812742e-06 3.184824e-06 NA NA 4.281844e-06 4.104476e-05
#> 91 1090 1.613283e-06 2.827616e-06 NA NA 3.794552e-06 3.593403e-05
#> 92 1091 1.436610e-06 2.511997e-06 NA NA 3.364814e-06 3.148221e-05
#> 93 1092 1.280025e-06 2.232949e-06 NA NA 2.985589e-06 2.760159e-05
#> 94 1093 1.141162e-06 1.986082e-06 NA NA 2.650728e-06 2.421646e-05
#> 95 1094 1.017941e-06 1.767550e-06 NA NA 2.354853e-06 2.126146e-05
#> 96 1095 9.085354e-07 1.573983e-06 NA NA 2.093262e-06 1.868011e-05
#> 97 1096 8.113406e-07 1.402425e-06 NA NA 1.861838e-06 1.642356e-05
#> 98 1097 7.249434e-07 1.250283e-06 NA NA 1.656977e-06 1.444958e-05
#> 99 1098 6.481003e-07 1.115279e-06 NA NA 1.475519e-06 1.272156e-05
#> 100 1099 5.797162e-07 9.954121e-07 NA NA 1.314693e-06 1.120781e-05
#> 101 1100 5.188255e-07 8.889233e-07 NA NA 1.172068e-06 9.880841e-06
#> 102 1101 NA 7.942645e-07 NA NA 1.045510e-06 8.716812e-06
#> 103 1102 NA 7.100736e-07 NA NA 9.331418e-07 7.695018e-06
#> 104 1103 NA 6.351503e-07 NA NA 8.333145e-07 6.797470e-06
#> 105 1104 NA 5.684371e-07 NA NA 7.445774e-07 6.008530e-06
#> 106 1105 NA 5.090011e-07 NA NA 6.656532e-07 5.314594e-06
#> 107 1106 NA 4.560195e-07 NA NA 5.954169e-07 4.703816e-06
#> 108 1107 NA 4.087654e-07 NA NA 5.328771e-07 4.165877e-06
#> 109 1108 NA 3.665970e-07 NA NA 4.771594e-07 3.691782e-06
#> 110 1109 NA 3.289465e-07 NA NA 4.274921e-07 3.273683e-06
#> 111 1110 NA NA NA NA 3.831942e-07 2.904730e-06
#> 112 1111 NA NA NA NA NA 2.578937e-06
#> 113 1112 NA NA NA NA NA 2.291076e-06
#> 114 1113 NA NA NA NA NA 2.036569e-06
#> 115 1114 NA NA NA NA NA 1.811413e-06
#> 116 1115 NA NA NA NA NA 1.612100e-06
#> 117 1116 NA NA NA NA NA 1.435557e-06
#> 118 1117 NA NA NA NA NA 1.279087e-06
#> 119 1118 NA NA NA NA NA 1.140325e-06
#> 120 1119 NA NA NA NA NA 1.017194e-06
#> 121 1120 NA NA NA NA NA 9.078691e-07
#> 122 1121 NA NA NA NA NA NA
#> 123 1122 NA NA NA NA NA NA
#> 124 1123 NA NA NA NA NA NA
#> 125 1124 NA NA NA NA NA NA
#> 126 1125 NA NA NA NA NA NA
#> 127 1126 NA NA NA NA NA NA
#> 128 1127 NA NA NA NA NA NA
#> 129 1128 NA NA NA NA NA NA
#> 130 1129 NA NA NA NA NA NA
#> 131 1130 NA NA NA NA NA NA
#> 132 1131 NA NA NA NA NA NA
#> 133 1132 NA NA NA NA NA NA
#> 134 1133 NA NA NA NA NA NA
#> 135 1134 NA NA NA NA NA NA
#> 136 1135 NA NA NA NA NA NA
#> trs_40 trs_42 spd spd_wk
#> 1 NA NA 2.920043e-03 0
#> 2 NA NA 7.851298e-03 0
#> 3 NA NA 1.559931e-02 0
#> 4 NA NA 2.530653e-02 0
#> 5 NA NA 3.560188e-02 0
#> 6 NA NA 4.514475e-02 0
#> 7 NA NA 5.295763e-02 0
#> 8 NA NA 5.852318e-02 2
#> 9 NA NA 6.172910e-02 0
#> 10 NA NA 1.122117e-01 0
#> 11 NA NA 1.459393e-01 0
#> 12 NA NA 1.603472e-01 0
#> 13 NA NA 1.703617e-01 0
#> 14 NA NA 1.755335e-01 0
#> 15 NA NA 1.760065e-01 0
#> 16 NA NA 1.723491e-01 0
#> 17 NA NA 1.653620e-01 0
#> 18 NA NA 1.559175e-01 0
#> 19 NA NA 1.448472e-01 0
#> 20 NA NA 1.328766e-01 0
#> 21 NA NA 1.205970e-01 0
#> 22 NA NA 1.084619e-01 0
#> 23 NA NA 9.679957e-02 0
#> 24 NA NA 8.589176e-02 0
#> 25 NA NA 7.634643e-02 0
#> 26 4.946162e-02 NA 1.187946e-01 0
#> 27 5.802159e-02 NA 1.239235e-01 0
#> 28 6.411934e-02 NA 1.302876e-01 0
#> 29 6.763182e-02 NA 1.368635e-01 0
#> 30 6.875047e-02 NA 1.424147e-01 0
#> 31 6.784729e-02 NA 1.459084e-01 0
#> 32 6.536681e-02 NA 1.467439e-01 0
#> 33 6.175203e-02 NA 1.447798e-01 0
#> 34 5.740090e-02 NA 1.402370e-01 0
#> 35 5.264582e-02 NA 1.335618e-01 0
#> 36 4.774869e-02 1.143865e-10 1.252998e-01 0
#> 37 4.290493e-02 1.107675e-06 1.160024e-01 0
#> 38 3.825220e-02 6.572208e-05 1.062284e-01 0
#> 39 3.388074e-02 6.697696e-04 9.686677e-02 0
#> 40 2.984357e-02 2.917900e-03 8.934286e-02 0
#> 41 2.616565e-02 7.845534e-03 8.492481e-02 0
#> 42 2.285165e-02 1.558785e-02 8.390352e-02 0
#> 43 1.989219e-02 2.528795e-02 8.551466e-02 0
#> 44 1.726872e-02 3.557574e-02 8.843139e-02 0
#> 45 1.495719e-02 4.511160e-02 9.132071e-02 0
#> 46 1.293075e-02 5.291876e-02 9.318650e-02 0
#> 47 1.116169e-02 5.848022e-02 9.347518e-02 0
#> 48 9.622680e-03 6.168378e-02 9.202736e-02 0
#> 49 8.287691e-03 6.270405e-02 8.896498e-02 0
#> 50 7.132453e-03 6.188030e-02 8.457280e-02 0
#> 51 6.134739e-03 5.961798e-02 7.920241e-02 0
#> 52 5.274467e-03 5.632111e-02 7.320638e-02 0
#> 53 4.533676e-03 5.235265e-02 6.689953e-02 0
#> 54 3.896439e-03 4.801577e-02 6.054089e-02 0
#> 55 3.348729e-03 4.354933e-02 5.432932e-02 0
#> 56 2.878259e-03 3.913156e-02 4.840721e-02 0
#> 57 2.474318e-03 3.488803e-02 4.286828e-02 0
#> 58 2.127600e-03 3.090103e-02 3.776674e-02 0
#> 59 1.830048e-03 2.721891e-02 3.312629e-02 0
#> 60 1.574702e-03 2.386445e-02 2.894819e-02 0
#> 61 1.355566e-03 2.084191e-02 2.521798e-02 0
#> 62 1.167477e-03 1.814273e-02 2.191087e-02 0
#> 63 1.006003e-03 1.574999e-02 1.899591e-02 0
#> 64 8.673367e-04 1.364175e-02 1.643906e-02 0
#> 65 7.482168e-04 1.179353e-02 1.420540e-02 0
#> 66 6.458469e-04 1.018005e-02 1.226069e-02 0
#> 67 5.578329e-04 8.776392e-03 1.057229e-02 0
#> 68 4.821247e-04 7.558812e-03 9.109858e-03 0
#> 69 4.169682e-04 6.505173e-03 7.845578e-03 0
#> 70 3.608617e-04 5.595206e-03 6.754318e-03 0
#> 71 3.125204e-04 4.810592e-03 5.813594e-03 0
#> 72 2.708445e-04 4.134952e-03 5.003456e-03 0
#> 73 2.348926e-04 3.553758e-03 4.306320e-03 0
#> 74 2.038588e-04 3.054218e-03 3.706775e-03 0
#> 75 1.770527e-04 2.625124e-03 3.191370e-03 0
#> 76 1.538829e-04 2.256709e-03 2.748413e-03 0
#> 77 1.338427e-04 1.940483e-03 2.367770e-03 0
#> 78 1.164972e-04 1.669100e-03 2.040681e-03 0
#> 79 1.014738e-04 1.436212e-03 1.759587e-03 0
#> 80 8.845250e-05 1.236347e-03 1.517980e-03 0
#> 81 7.715845e-05 1.064801e-03 1.310260e-03 0
#> 82 6.735561e-05 9.175274e-04 1.131619e-03 0
#> 83 5.884102e-05 7.910569e-04 9.779274e-04 0
#> 84 5.144010e-05 6.824132e-04 8.456447e-04 0
#> 85 4.500257e-05 5.890465e-04 7.317349e-04 0
#> 86 3.939903e-05 5.087730e-04 6.335956e-04 0
#> 87 3.451794e-05 4.397232e-04 5.489973e-04 0
#> 88 3.026313e-05 3.802970e-04 4.760293e-04 0
#> 89 2.655158e-05 3.291249e-04 4.130548e-04 0
#> 90 2.331164e-05 2.850351e-04 3.586709e-04 0
#> 91 2.048137e-05 2.470245e-04 3.116753e-04 0
#> 92 1.800724e-05 2.142345e-04 2.710373e-04 0
#> 93 1.584291e-05 1.859300e-04 2.358730e-04 0
#> 94 1.394826e-05 1.614814e-04 2.054241e-04 0
#> 95 1.228854e-05 1.403494e-04 1.790397e-04 0
#> 96 1.083362e-05 1.220716e-04 1.561611e-04 0
#> 97 9.557348e-06 1.062516e-04 1.363081e-04 0
#> 98 8.437024e-06 9.254949e-05 1.190683e-04 0
#> 99 7.452929e-06 8.067335e-05 1.040867e-04 0
#> 100 6.587914e-06 7.037258e-05 9.105813e-05 0
#> 101 5.827064e-06 6.143187e-05 7.971960e-05 0
#> 102 5.157390e-06 5.366612e-05 6.938010e-05 0
#> 103 4.567580e-06 4.691608e-05 6.082190e-05 0
#> 104 4.047769e-06 4.104472e-05 5.335843e-05 0
#> 105 3.589354e-06 3.593400e-05 4.684490e-05 0
#> 106 3.184824e-06 3.148219e-05 4.115626e-05 0
#> 107 2.827616e-06 2.760157e-05 3.618444e-05 0
#> 108 2.511997e-06 2.421644e-05 3.183596e-05 0
#> 109 2.232949e-06 2.126144e-05 2.802993e-05 0
#> 110 1.986082e-06 1.868009e-05 2.469630e-05 0
#> 111 1.767550e-06 1.642355e-05 2.147903e-05 0
#> 112 1.573983e-06 1.444957e-05 1.860249e-05 0
#> 113 1.402425e-06 1.272155e-05 1.641505e-05 0
#> 114 1.250283e-06 1.120780e-05 1.449465e-05 0
#> 115 1.115279e-06 9.880833e-06 1.280753e-05 0
#> 116 9.954121e-07 8.716805e-06 1.132432e-05 0
#> 117 8.889233e-07 7.695012e-06 1.001949e-05 0
#> 118 7.942645e-07 6.797464e-06 8.870816e-06 0
#> 119 7.100736e-07 6.008526e-06 7.858924e-06 0
#> 120 6.351503e-07 5.314590e-06 6.966934e-06 0
#> 121 5.684371e-07 4.703812e-06 6.180118e-06 0
#> 122 5.090011e-07 4.165874e-06 4.674875e-06 0
#> 123 4.560195e-07 3.691779e-06 4.147799e-06 0
#> 124 4.087654e-07 3.273681e-06 3.682446e-06 0
#> 125 3.665970e-07 2.904727e-06 3.271324e-06 0
#> 126 3.289465e-07 2.578935e-06 2.907882e-06 0
#> 127 NA 2.291074e-06 2.291074e-06 0
#> 128 NA 2.036567e-06 2.036567e-06 0
#> 129 NA 1.811411e-06 1.811411e-06 0
#> 130 NA 1.612099e-06 1.612099e-06 0
#> 131 NA 1.435555e-06 1.435555e-06 0
#> 132 NA 1.279086e-06 1.279086e-06 0
#> 133 NA 1.140324e-06 1.140324e-06 0
#> 134 NA 1.017193e-06 1.017193e-06 0
#> 135 NA 9.078684e-07 9.078684e-07 0
#> 136 NA 8.107449e-07 8.107449e-07 0