The Functions
One of the greatest things about R
is the ability to extend its native abilities by writing your own functions. This page provides several functions I have created to make analyses a bit easier. To use these functions in your analysis, you just need to include (and run) the line source("URL")
near the top of your script. Replace URL in the source
function with the URL of the function below.
Accuracy Functions | ||
accuracy | Accuracy calculation | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/accuracy.R | |
fnr | False negative rate | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/fnr.R | |
fpr | False positive rate | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/fpr.R | |
F1score | The F1 measure of accuracy | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/F1score.R | |
Fscore | The F measure of accuracy | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/Fscore.R | |
MCC | The Matthews correlation coefficient | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/MCC.R | |
odds.ratio | Odds ratio | |
26-Aug-11 | https://rfs.kvasaheim.com/Rfctns/odds.ratio.R | |
phi.coef | Phi coefficient | |
26-Aug-11 | https://rfs.kvasaheim.com/Rfctns/phi.coef.R | |
precision | Precision of a prediction | |
31-Jul-11 | https://rfs.kvasaheim.com/Rfctns/precision.R | |
recall | Recall rate | |
26-Aug-11 | https://rfs.kvasaheim.com/Rfctns/recall.R | |
Plotting functions | ||
curly.brace | Plotting function to easily plot braces | |
30-Jan-14 | https://rfs.kvasaheim.com/Rfctns/curly.brace.R | |
binom.plot | One way of plotting categorical data with errors shown (v2.0) | |
11-Nov-14 | https://rfs.kvasaheim.com/Rfctns/binom.plot.R | |
graphShade | Meaningfully shading areas of pdf and CDF plots | |
18-Jun-13 | https://rfs.kvasaheim.com/Rfctns/graphShade.R | |
histb2b | Create back-to-back histograms | |
24-Jun-15 | https://rfs.kvasaheim.com/Rfctns/histb2b.R | |
histb2b2 | Create back-to-back histograms (minor update) | |
20-Apr-16 | https://rfs.kvasaheim.com/Rfctns/histb2b2.R | |
histogram | Create better-looking histograms | |
26-May-14 | https://rfs.kvasaheim.com/Rfctns/histogram.R | |
normoverlay | Overlays a histogram with a Normal density function | |
29-Mar-15 | https://rfs.kvasaheim.com/Rfctns/normoverlay.R | |
placeFlag | Routine to plot a flag on your graphic. | |
13-Jan-17 | https://rfs.kvasaheim.com/Rfctns/placeFlag.R | |
sectorPlot | Create sector plots | |
1-Jul-13 | https://rfs.kvasaheim.com/Rfctns/sectorPlot.R | |
Utility functions | ||
bayes.law | Uses Bayes Law to calculate disease probability | |
7-May-14 | https://rfs.kvasaheim.com/Rfctns/bayes.law.R | |
conf.bounds | Confidence band calculation function | |
4-Apr-17 | https://rfs.kvasaheim.com/Rfctns/conf.bounds.R | |
cor | Correlations within a dataframe | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/cor.R | |
cv | Calculate the coefficient of variation | |
3-Jun-15 | https://rfs.kvasaheim.com/Rfctns/cv.R | |
drop.rownames | Returns a dataframe less the specified rownames | |
11-Mar-15 | https://rfs.kvasaheim.com/Rfctns/drop.rownames.R | |
getPermutations | Get all permutations on n values | |
10/11/13 | https://rfs.kvasaheim.com/Rfctns/getPermutations.R | |
kurtosis | Calculate the sample excess kurtosis | |
3-Jun-15 | https://rfs.kvasaheim.com/Rfctns/kurtosis.R | |
links | Ten bijective transformations to use as link functions | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/links.R | |
make.link | Extension to the make.link() function {stats}. This was updated to reflect the R v3 update |
|
22-Apr-15 | https://rfs.kvasaheim.com/Rfctns/make.link.R | |
means | Calculates arithmetic, geometric, and harmonic means | |
19-Dec-12 | https://rfs.kvasaheim.com/Rfctns/means.R | |
modal | Calculates the mode of a variable | |
2-Jan-14 | https://rfs.kvasaheim.com/Rfctns/modal.R | |
model.fit | Several model comparison measures | |
24-Nov-11 | https://rfs.kvasaheim.com/Rfctns/model.fit.R | |
quartile | Helper function to provide the quartiles of a variable. | |
13-Jan-17 | https://rfs.kvasaheim.com/Rfctns/quartile.R | |
separateData | Split the data into train, test, and evaluation parts | |
20-Apr-15 | https://rfs.kvasaheim.com/Rfctns/separateData.R | |
set.base | Change the base level in a factor | |
31-Jul-11 | https://rfs.kvasaheim.com/Rfctns/set.base.R | |
skew | Calculate the sample skew using the unbiased estimator | |
3-Jun-15 | https://rfs.kvasaheim.com/Rfctns/skew.R | |
summaryHCE | Provide the Huber-White adjustment to the standard errors | |
30-Mar-15 | https://rfs.kvasaheim.com/Rfctns/summaryHCE.R | |
summaryVIFA | Provide a VIF-adjusted regression table | |
13-Aug-13 | https://rfs.kvasaheim.com/Rfctns/summaryVIFA.R | |
tapd | Total Absolute Proportion Deviation, a measure of dispersion for categorical variables | |
30-Dec-16 | https://rfs.kvasaheim.com/Rfctns/tapd.R | |
trace | Calculates the trace of a square matrix | |
6-Apr-17 | https://rfs.kvasaheim.com/Rfctns/trace.R | |
zscore | Calculate the z-score for a value over a sample. | |
5-Jan-17 | https://rfs.kvasaheim.com/Rfctns/zscore.R | |
Statistical tests | ||
forsberg.test | Omnibus null test | |
18-Jan-15 | https://rfs.kvasaheim.com/Rfctns/forsberg.test.R | |
hildebrand.rule | Determines if the data are skewed according to Hildebrand (1986) | |
10-Apr-16 | https://rfs.kvasaheim.com/Rfctns/hildebrand.rule.R | |
HL.gof | Hosmer and Lemeshow goodness of fit measure | |
25-Oct-11 | https://rfs.kvasaheim.com/Rfctns/HL.gof.R | |
onevar.test | Confidence interval and hypothesis test for the variance of a single population. | |
27-Feb-17 | https://rfs.kvasaheim.com/Rfctns/onevar.test.R | |
shapiroTest | This tests Normality across several levels of a grouping variable | |
16-Oct-15 | https://rfs.kvasaheim.com/Rfctns/shapiroTest.R | |
t.test.sst | Perform a one- or two-sample t-test from summary statistics | |
1-Jul-13 | https://rfs.kvasaheim.com/Rfctns/t.test.sst.R | |
tukey.var.test | An equality of variance test as suggested by Tukey | |
15-Sep-14 | https://rfs.kvasaheim.com/Rfctns/tukey.var.test.R | |
z.test | The infamous z-test | |
31-Jul-11 | https://rfs.kvasaheim.com/Rfctns/z.test.R |