Calculate mean and standard deviation, and mean, mean \(\pm\) one standard deviation, respectively.

# S4 method for numeric
mean_sd(x, na.rm = TRUE, ...)

# S4 method for matrix
mean_sd(x, na.rm = TRUE, ...)

# S4 method for hyperSpec
mean_sd(x, na.rm = TRUE, ...)

# S4 method for numeric
mean_pm_sd(x, na.rm = TRUE, ...)

# S4 method for matrix
mean_pm_sd(x, na.rm = TRUE, ...)

# S4 method for hyperSpec
mean_pm_sd(x, na.rm = TRUE, ...)

# S4 method for hyperSpec
mean(x, na.rm = TRUE, ...)

# S4 method for hyperSpec
quantile(x, probs = seq(0, 1, 0.5), na.rm = TRUE, names = "num", ...)

Arguments

x

a numeric vector

na.rm

handed to base::mean() and stats::sd()

...

ignored (needed to make function generic)

probs

the quantiles, see stats::quantile()

names

"pretty" results in percentages (like stats::quantile()'s names = TRUE), "num" results in the row names being as.character(probs) (good for ggplot2 getting the order of the quantiles right). Otherwise, no names are assigned.

Value

mean_sd returns a vector with two values (mean and standard deviation) of x.

mean_sd (matrix) returns a matrix with the mean spectrum in the first row and the standard deviation in the 2nd.

mean_sd returns a hyperSpec object with the mean spectrum in the first row and the standard deviation in the 2nd.

mean_pm_sd returns a vector with 3 values: mean - 1 sd, mean, mean + 1 sd

mean_pm_sd (matrix) returns a matrix containing mean - sd, mean, and mean + sd rows.

For hyperSpec objects, mean_pm_sd returns a hyperSpec object containing mean - sd, mean, and mean + sd spectra.

For hyperSpec object, mean returns a hyperSpec object containing the mean spectrum.

For hyperSpec object, quantile() returns a hyperSpec object containing the respective quantile spectra.

Details

These functions are provided for convenience.

See also

Author

C. Beleites

Examples

mean_sd(flu [, , 405 ~ 410])
#> hyperSpec object #> 2 spectra #> 1 data columns #> 11 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 410 #> data: (2 rows x 1 columns) #> 1. spc: I[fl]/"a.u." [matrix, array11] 113.90939 63.95161 ... 88.86944
mean_sd(flu$spc)
#> 405 405.5 406 406.5 407 407.5 408 #> mean 113.90939 120.08039 123.88961 128.63661 132.78711 138.26267 142.52667 #> sd 63.95161 66.68462 68.53711 71.32635 73.27403 76.26193 79.05704 #> 408.5 409 409.5 410 410.5 411 411.5 #> mean 146.35206 151.43228 156.09817 161.82439 165.86478 171.5021 176.3894 #> sd 81.11082 83.44635 86.21839 88.86944 90.86983 93.5278 97.0369 #> 412 412.5 413 413.5 414 414.5 415 415.5 #> mean 180.51522 185.6836 190.1309 195.8358 200.4855 204.6093 210.0138 214.64 #> sd 99.25456 102.7686 104.5448 107.9088 110.2483 111.9924 115.4464 118.26 #> 416 416.5 417 417.5 418 418.5 419 419.5 #> mean 219.1380 224.5761 227.9237 232.8236 237.7171 241.7527 246.4742 250.5289 #> sd 120.7447 123.9144 126.1828 128.7551 129.8156 132.8904 135.4853 137.1431 #> 420 420.5 421 421.5 422 422.5 423 423.5 #> mean 254.6781 258.4790 264.0061 267.9860 273.0221 277.4778 281.3341 285.0475 #> sd 139.3884 141.3262 144.7961 146.7983 149.8890 152.0896 154.3166 156.1366 #> 424 424.5 425 425.5 426 426.5 427 427.5 #> mean 290.1924 294.2909 298.3123 302.2134 307.5095 312.6365 316.1736 319.8145 #> sd 159.9184 162.8058 164.8594 165.1881 168.6816 172.6384 173.9014 175.6463 #> 428 428.5 429 429.5 430 430.5 431 431.5 #> mean 325.3752 328.9191 332.6454 336.7873 340.4211 344.5639 349.2603 351.5914 #> sd 178.6666 181.0399 183.3152 185.6277 186.6223 189.7741 192.6296 194.1671 #> 432 432.5 433 433.5 434 434.5 435 435.5 #> mean 354.2620 358.1013 361.8068 363.6526 365.7068 366.8592 369.8816 372.5533 #> sd 195.5245 196.7954 198.6743 200.5592 200.9523 201.5470 203.8599 204.7726 #> 436 436.5 437 437.5 438 438.5 439 439.5 #> mean 374.8713 375.8997 378.4399 378.6621 380.7669 382.7149 382.8039 383.6267 #> sd 206.1331 207.0960 208.1450 208.7843 210.1876 210.3305 210.1147 211.5687 #> 440 440.5 441 441.5 442 442.5 443 443.5 #> mean 383.4117 384.9124 384.9061 386.2123 386.0671 386.8118 387.1116 387.9868 #> sd 210.9692 211.1969 212.3513 210.9188 210.6814 211.5056 213.4941 212.2282 #> 444 444.5 445 445.5 446 446.5 447 447.5 #> mean 388.2645 386.9496 387.7631 387.6842 388.9684 388.8592 387.6974 387.5131 #> sd 213.8395 213.8715 212.7600 212.7473 214.0275 214.1388 213.7061 213.5430 #> 448 448.5 449 449.5 450 450.5 451 451.5 #> mean 387.8354 387.7904 388.0669 388.3706 388.3181 388.0719 386.9387 387.4204 #> sd 213.4142 212.5135 213.5708 211.6471 212.2151 212.5157 211.6122 212.4420 #> 452 452.5 453 453.5 454 454.5 455 455.5 #> mean 387.2329 385.1973 385.5947 385.0308 384.9724 385.6444 383.5018 382.0557 #> sd 213.0798 212.6830 211.5552 211.7677 211.6549 211.7323 208.8900 209.5972 #> 456 456.5 457 457.5 458 458.5 459 459.5 #> mean 380.9131 379.6323 379.4236 376.7526 376.1533 373.7147 371.8777 369.0225 #> sd 209.3029 208.5275 207.9218 207.2801 206.3606 205.1782 204.3870 202.7046 #> 460 460.5 461 461.5 462 462.5 463 463.5 #> mean 367.3478 364.0053 363.2114 361.1244 358.5899 354.8971 352.0969 349.0689 #> sd 202.7634 199.7319 199.7003 197.7912 196.5260 195.9355 193.7476 190.8617 #> 464 464.5 465 465.5 466 466.5 467 467.5 #> mean 347.7439 344.6271 340.4968 338.4603 335.9258 332.6344 329.3642 325.6729 #> sd 190.1415 188.8953 186.8400 185.6940 185.2942 183.5705 181.6199 178.8888 #> 468 468.5 469 469.5 470 470.5 471 471.5 #> mean 322.0702 319.5687 314.7917 312.4208 310.4492 305.3859 302.4756 299.4622 #> sd 176.0399 176.1274 173.3872 172.4460 170.4795 166.8526 166.5719 163.6277 #> 472 472.5 473 473.5 474 474.5 475 475.5 #> mean 296.7000 292.2196 288.3032 286.7105 283.4853 280.3511 276.9047 274.8581 #> sd 162.6267 161.2979 158.8969 157.3042 155.7632 153.7710 151.6023 150.2532 #> 476 476.5 477 477.5 478 478.5 479 479.5 #> mean 271.2237 269.0067 266.5739 263.3924 260.4180 258.1373 255.791 253.8093 #> sd 148.9218 148.0351 146.8918 144.1210 143.0114 142.0281 140.028 140.1034 #> 480 480.5 481 481.5 482 482.5 483 483.5 #> mean 249.5182 248.2199 245.3162 241.8370 240.8851 238.1019 235.3928 232.0592 #> sd 137.6791 135.9537 134.2462 131.9646 131.4004 130.0671 129.0721 128.4586 #> 484 484.5 485 485.5 486 486.5 487 487.5 #> mean 230.1664 227.5049 224.4877 221.6313 219.4647 215.9441 213.1634 210.1469 #> sd 127.6313 124.3675 123.2050 121.3864 120.2081 118.3317 116.9249 114.8779 #> 488 488.5 489 489.5 490 490.5 491 491.5 #> mean 208.6204 205.8629 203.6631 200.3850 198.2890 195.3428 192.3032 189.3392 #> sd 114.6096 113.3597 111.3558 109.7793 109.5708 106.8053 105.5473 103.6283 #> 492 492.5 493 493.5 494 494.5 495 #> mean 186.5108 183.8356 180.6879 178.78053 175.72864 173.40081 170.52147 #> sd 102.6725 101.4147 99.9830 98.97507 97.29897 95.44527 93.76262
mean_sd(flu)
#> hyperSpec object #> 2 spectra #> 1 data columns #> 181 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 #> data: (2 rows x 1 columns) #> 1. spc: I[fl]/"a.u." [matrix, array181] 113.90939 63.95161 ... 93.76262
mean_pm_sd(flu$c)
#> mean.minus.sd mean mean.plus.sd #> 0.08145857 0.17500000 0.26854143
mean_pm_sd(flu$spc)
#> 405 405.5 406 406.5 407 407.5 408 #> mean - sd 49.95778 53.39577 55.3525 57.31027 59.51308 62.00074 63.46963 #> mean 113.90939 120.08039 123.8896 128.63661 132.78711 138.26267 142.52667 #> mean + sd 177.86100 186.76501 192.4267 199.96296 206.06114 214.52459 221.58371 #> 408.5 409 409.5 410 410.5 411 411.5 #> mean - sd 65.24124 67.98593 69.87977 72.95495 74.99495 77.97425 79.35249 #> mean 146.35206 151.43228 156.09817 161.82439 165.86478 171.50206 176.38939 #> mean + sd 227.46287 234.87862 242.31656 250.69383 256.73461 265.02986 273.42629 #> 412 412.5 413 413.5 414 414.5 415 #> mean - sd 81.26066 82.9150 85.58614 87.92704 90.23721 92.61698 94.56743 #> mean 180.51522 185.6836 190.13094 195.83583 200.48550 204.60933 210.01383 #> mean + sd 279.76979 288.4521 294.67575 303.74462 310.73379 316.60168 325.46024 #> 415.5 416 416.5 417 417.5 418 418.5 #> mean - sd 96.37996 98.39334 100.6617 101.7409 104.0685 107.9015 108.8622 #> mean 214.64000 219.13800 224.5761 227.9237 232.8236 237.7171 241.7527 #> mean + sd 332.90004 339.88266 348.4904 354.1065 361.5787 367.5328 374.6431 #> 419 419.5 420 420.5 421 421.5 422 #> mean - sd 110.9890 113.3858 115.2896 117.1528 119.2100 121.1877 123.1330 #> mean 246.4742 250.5289 254.6781 258.4790 264.0061 267.9860 273.0221 #> mean + sd 381.9595 387.6720 394.0665 399.8052 408.8021 414.7843 422.9111 #> 422.5 423 423.5 424 424.5 425 425.5 #> mean - sd 125.3882 127.0175 128.9109 130.2740 131.4851 133.4529 137.0253 #> mean 277.4778 281.3341 285.0475 290.1924 294.2909 298.3123 302.2134 #> mean + sd 429.5674 435.6506 441.1841 450.1108 457.0967 463.1717 467.4016 #> 426 426.5 427 427.5 428 428.5 429 #> mean - sd 138.8279 139.9981 142.2722 144.1681 146.7086 147.8792 149.3303 #> mean 307.5095 312.6365 316.1736 319.8145 325.3752 328.9191 332.6454 #> mean + sd 476.1911 485.2749 490.0750 495.4608 504.0418 509.9590 515.9606 #> 429.5 430 430.5 431 431.5 432 432.5 #> mean - sd 151.1596 153.7988 154.7898 156.6307 157.4243 158.7375 161.3059 #> mean 336.7873 340.4211 344.5639 349.2603 351.5914 354.2620 358.1013 #> mean + sd 522.4151 527.0434 534.3380 541.8899 545.7585 549.7865 554.8966 #> 433 433.5 434 434.5 435 435.5 436 #> mean - sd 163.1325 163.0934 164.7544 165.3122 166.0218 167.7807 168.7382 #> mean 361.8068 363.6526 365.7068 366.8592 369.8816 372.5533 374.8713 #> mean + sd 560.4812 564.2118 566.6591 568.4062 573.7415 577.3258 581.0044 #> 436.5 437 437.5 438 438.5 439 439.5 #> mean - sd 168.8037 170.2950 169.8777 170.5793 172.3844 172.6892 172.0580 #> mean 375.8997 378.4399 378.6621 380.7669 382.7149 382.8039 383.6267 #> mean + sd 582.9957 586.5849 587.4464 590.9546 593.0454 592.9186 595.1954 #> 440 440.5 441 441.5 442 442.5 443 #> mean - sd 172.4425 173.7155 172.5548 175.2936 175.3857 175.3063 173.6175 #> mean 383.4117 384.9124 384.9061 386.2123 386.0671 386.8118 387.1116 #> mean + sd 594.3809 596.1093 597.2574 597.1311 596.7484 598.3174 600.6056 #> 443.5 444 444.5 445 445.5 446 446.5 #> mean - sd 175.7587 174.4250 173.0780 175.0031 174.9369 174.9409 174.7203 #> mean 387.9868 388.2645 386.9496 387.7631 387.6842 388.9684 388.8592 #> mean + sd 600.2150 602.1040 600.8211 600.5230 600.4315 602.9959 602.9980 #> 447 447.5 448 448.5 449 449.5 450 #> mean - sd 173.9914 173.9701 174.4212 175.2769 174.4961 176.7235 176.1030 #> mean 387.6974 387.5131 387.8354 387.7904 388.0669 388.3706 388.3181 #> mean + sd 601.4035 601.0562 601.2497 600.3040 601.6376 600.0177 600.5332 #> 450.5 451 451.5 452 452.5 453 453.5 #> mean - sd 175.5562 175.3266 174.9784 174.1531 172.5142 174.0396 173.2631 #> mean 388.0719 386.9387 387.4204 387.2329 385.1973 385.5947 385.0308 #> mean + sd 600.5876 598.5509 599.8624 600.3128 597.8803 597.1499 596.7985 #> 454 454.5 455 455.5 456 456.5 457 #> mean - sd 173.3176 173.9120 174.6118 172.4585 171.6102 171.1048 171.5018 #> mean 384.9724 385.6444 383.5018 382.0557 380.9131 379.6323 379.4236 #> mean + sd 596.6273 597.3767 592.3918 591.6530 590.2161 588.1597 587.3454 #> 457.5 458 458.5 459 459.5 460 460.5 #> mean - sd 169.4725 169.7926 168.5365 167.4907 166.3179 164.5844 164.2734 #> mean 376.7526 376.1533 373.7147 371.8777 369.0225 367.3478 364.0053 #> mean + sd 584.0326 582.5139 578.8929 576.2647 571.7271 570.1112 563.7373 #> 461 461.5 462 462.5 463 463.5 464 #> mean - sd 163.5111 163.3332 162.0640 158.9616 158.3493 158.2073 157.6023 #> mean 363.2114 361.1244 358.5899 354.8971 352.0969 349.0689 347.7439 #> mean + sd 562.9118 558.9157 555.1159 550.8326 545.8446 539.9306 537.8854 #> 464.5 465 465.5 466 466.5 467 467.5 #> mean - sd 155.7317 153.6568 152.7663 150.6317 149.0639 147.7443 146.7840 #> mean 344.6271 340.4968 338.4603 335.9258 332.6344 329.3642 325.6729 #> mean + sd 533.5224 527.3368 524.1543 521.2200 516.2048 510.9840 504.5617 #> 468 468.5 469 469.5 470 470.5 471 #> mean - sd 146.0302 143.4413 141.4045 139.9748 139.9697 138.5334 135.9037 #> mean 322.0702 319.5687 314.7917 312.4208 310.4492 305.3859 302.4756 #> mean + sd 498.1101 495.6961 488.1790 484.8668 480.9288 472.2385 469.0476 #> 471.5 472 472.5 473 473.5 474 474.5 #> mean - sd 135.8345 134.0733 130.9217 129.4063 129.4063 127.7221 126.5801 #> mean 299.4622 296.7000 292.2196 288.3032 286.7105 283.4853 280.3511 #> mean + sd 463.0900 459.3267 453.5175 447.2001 444.0147 439.2485 434.1220 #> 475 475.5 476 476.5 477 477.5 478 #> mean - sd 125.3025 124.6049 122.3018 120.9717 119.6821 119.2714 117.4066 #> mean 276.9047 274.8581 271.2237 269.0067 266.5739 263.3924 260.4180 #> mean + sd 428.5070 425.1113 420.1455 417.0418 413.4656 407.5134 403.4294 #> 478.5 479 479.5 480 480.5 481 481.5 #> mean - sd 116.1092 115.763 113.7058 111.8390 112.2662 111.0700 109.8724 #> mean 258.1373 255.791 253.8093 249.5182 248.2199 245.3162 241.8370 #> mean + sd 400.1654 395.819 393.9127 387.1973 384.1735 379.5624 373.8016 #> 482 482.5 483 483.5 484 484.5 485 #> mean - sd 109.4847 108.0348 106.3207 103.6006 102.5350 103.1374 101.2827 #> mean 240.8851 238.1019 235.3928 232.0592 230.1664 227.5049 224.4877 #> mean + sd 372.2856 368.1690 364.4648 360.5178 357.7977 351.8724 347.6928 #> 485.5 486 486.5 487 487.5 488 488.5 #> mean - sd 100.2449 99.25656 97.61239 96.23855 95.26908 94.01085 92.50318 #> mean 221.6313 219.46467 215.94411 213.16344 210.14694 208.62042 205.86292 #> mean + sd 343.0178 339.67277 334.27583 330.08834 325.02481 323.22998 319.22265 #> 489 489.5 490 490.5 491 491.5 492 #> mean - sd 92.30722 90.60566 88.71826 88.53754 86.75587 85.71093 83.83838 #> mean 203.66306 200.38500 198.28903 195.34281 192.30317 189.33922 186.51083 #> mean + sd 315.01889 310.16434 307.85980 302.14807 297.85047 292.96751 289.18329 #> 492.5 493 493.5 494 494.5 495 #> mean - sd 82.42095 80.70487 79.80546 78.42967 77.95554 76.75885 #> mean 183.83564 180.68786 178.78053 175.72864 173.40081 170.52147 #> mean + sd 285.25032 280.67086 277.75559 273.02761 268.84607 264.28409
mean_pm_sd(flu)
#> hyperSpec object #> 3 spectra #> 1 data columns #> 181 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 #> data: (3 rows x 1 columns) #> 1. spc: I[fl]/"a.u." [matrix, array181] 49.95778 113.90939 ... 264.2841
plot(mean(faux_cell))
plot(quantile(faux_cell))
flu_quantiles <- quantile(flu) rownames(flu_quantiles)
#> [1] "0" "0.5" "1"
flu_quantiles$..
#> filename c #> 0 <NA> NA #> 0.5 <NA> NA #> 1 <NA> NA
flu_pretty_quantiles <- quantile(flu, names = "pretty") rownames(flu_pretty_quantiles)
#> [1] " 0 %" " 50 %" "100 %"
flu_pretty_quantiles$..
#> filename c #> 0 % <NA> NA #> 50 % <NA> NA #> 100 % <NA> NA