Title: | Rmisc: Ryan Miscellaneous |
---|---|
Description: | The Rmisc library contains many functions useful for data analysis and utility operations. |
Authors: | Ryan M. Hope <[email protected]> |
Maintainer: | Ryan M. Hope <[email protected]> |
License: | GPL-3 |
Version: | 1.6 |
Built: | 2024-11-16 03:49:29 UTC |
Source: | https://github.com/ryanhope/rmisc |
Calculates the confidence interval of a vector of data.
CI(x, ci = 0.95)
CI(x, ci = 0.95)
x |
a vector of data |
ci |
the confidence interval to be calculated |
upper |
Upper bound of interval. |
mean |
Mean of data. |
lower |
Lower bound of interval. |
CI(rnorm(100))
CI(rnorm(100))
Calculates the confidence interval of grouped data
group.CI(x, data, ci = 0.95)
group.CI(x, data, ci = 0.95)
x |
an 'aggregate' compatible formula |
data |
a data frame (or list) from which the variables in formula should be taken |
ci |
the confidence interval to be calculated |
A data frame consisting of one column for each grouping factor plus three columns for the upper bound, mean and lower bound of the confidence interval for each level of the grouping factor
require(latticeExtra) with(group.CI(weight~feed,chickwts), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.CI(Temp~Month,airquality), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
require(latticeExtra) with(group.CI(weight~feed,chickwts), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.CI(Temp~Month,airquality), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
Calculates the standard error interval of grouped data.
group.STDERR(x, data)
group.STDERR(x, data)
x |
an 'aggregate' compatible formula |
data |
a data frame (or list) from which the variables in formula should be taken. |
A data frame consisting of one column for each grouping factor plus three columns for the upper bound, mean and lower bound of the standard error interval for each level of the grouping factor.
require(latticeExtra) with(group.STDERR(weight~feed,chickwts), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.STDERR(Temp~Month,airquality), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
require(latticeExtra) with(group.STDERR(weight~feed,chickwts), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.STDERR(Temp~Month,airquality), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
Applies a function which calculates a parameter with lower/uper bounds to groups of data.
group.UCL(x, data, FUN, ...)
group.UCL(x, data, FUN, ...)
x |
an 'aggregate' compatible formula |
data |
a data frame (or list) from which the variables in formula should be taken. |
FUN |
the function to apply to each group |
... |
extra params passed on to aggregate |
A data frame consisting of one column for each grouping factor plus three columns for the upper bound, mean and lower bound of the standard error interval for each level of the grouping factor.
require(latticeExtra) with(group.UCL(weight~feed,chickwts,FUN=CI), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.UCL(Temp~Month,airquality,FUN=STDERR), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
require(latticeExtra) with(group.UCL(weight~feed,chickwts,FUN=CI), segplot(feed~weight.lower+weight.upper,center=weight.mean) ) require(Hmisc) with(group.UCL(Temp~Month,airquality,FUN=STDERR), xYplot(Cbind(Temp.mean,Temp.lower,Temp.upper)~numericScale(Month),type="b",ylim=c(60,90)) )
Computes a likelihood ratio statistic which reflects the relative likelihood of the data given two competing models.
lr.glover(object, ..., name = NULL)
lr.glover(object, ..., name = NULL)
object |
an object. See below for details. |
... |
further object specifications passed to methods. See below for details. |
name |
a function for extracting a suitable name/description from a fitted model object. By default the name is queried by calling formula. |
An object of class "anova" which contains the log-likelihood, degrees of freedom, the difference in degrees of freedom, likelihood ratio, and AIC/BIC corrected likelihood ratios.
lr.glover performs comparisons of models via likelihood ratio tests. The default method consecutively compares the fitted model object object with the models passed in .... Subsequently, a likelihood ratio test for each two consecutive models is carried out.
Glover, S. & Dixon, P. (2004). Likelihood ratios: A simple and flexible statistic for empirical psychologists. Psychonomic Bulletin & Review, 11(5), 791-806.
m1 <- lm(mpg~.,mtcars) m2 <- step(m1,~.,trace=0) m3 <- step(m1,~.+.^2,trace=0) lr.glover(m1,m2,m3)
m1 <- lm(mpg~.,mtcars) m2 <- step(m1,~.,trace=0) m3 <- step(m1,~.+.^2,trace=0) lr.glover(m1,m2,m3)
Renders multiple ggplot plots in one image
multiplot(..., plotlist = NULL, cols = 1, layout = NULL)
multiplot(..., plotlist = NULL, cols = 1, layout = NULL)
... |
ggplot objects |
plotlist |
a list of ggplot objects |
cols |
Number of columns in layout |
layout |
A matrix specifying the layout. If present, 'cols' is ignored |
If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), then plot 1 will go in the upper left, 2 will go in the upper right, and 3 will go all the way across the bottom.
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)
Norms the data within specified groups in a data frame; it normalizes each subject (identified by idvar) so that they have the same mean, within each group specified by betweenvars.
normDataWithin(data = NULL, idvar, measurevar, betweenvars = NULL, na.rm = FALSE, .drop = TRUE)
normDataWithin(data = NULL, idvar, measurevar, betweenvars = NULL, na.rm = FALSE, .drop = TRUE)
data |
a data frame. |
idvar |
the name of a column that identifies each subject (or matched subjects) |
measurevar |
the name of a column that contains the variable to be summariezed |
betweenvars |
a vector containing names of columns that are between-subjects variables |
na.rm |
a boolean that indicates whether to ignore NA's |
.drop |
should combinations of variables that do not appear in the input data be preserved (FALSE) or dropped (TRUE, default) |
a data frame with normalized data
http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)
A panel function for drawing circles.
panel.circle(x, y, r, segments = 50L, groups = NULL, ...)
panel.circle(x, y, r, segments = 50L, groups = NULL, ...)
x |
The x coordinate of the circle center |
y |
The y coordinate of the circle center |
r |
The radius of the circle |
segments |
The number of polygon segments used to create the circle |
groups |
A factor defining groups |
... |
Additional arguments passed to panel.polygon |
panel.circle(0, 0, 10)
panel.circle(0, 0, 10)
Rounds a value to nearest increment
rounder(x, inc, fun = "round")
rounder(x, inc, fun = "round")
x |
The value to be rounded |
inc |
The increment to round to |
fun |
The rounding function. Valid options are 'floor', 'round' and 'ceiling'. |
an object of class numeric
rounder(.92, .05) rounder(.93, .05) rounder(.93, .05, "floor") rounder(.93, .05, "ceiling")
rounder(.92, .05) rounder(.93, .05) rounder(.93, .05, "floor") rounder(.93, .05, "ceiling")
Find the starting indices of runs in a vector.
rsi(x)
rsi(x)
x |
a vector of data. |
a vector of indices indicating starting points for runs
rsi(c(0,0,0,1,2,2,3,3,3,3,3,4))
rsi(c(0,0,0,1,2,2,3,3,3,3,3,4))
Calculates the standard error interval of a vector of data
STDERR(x)
STDERR(x)
x |
a vector of data. |
upper |
Upper bound of interval. |
mean |
Mean of data. |
lower |
Lower bound of interval. |
STDERR(rnorm(100))
STDERR(rnorm(100))
Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
summarySE(data = NULL, measurevar, groupvars = NULL, na.rm = FALSE, conf.interval = 0.95, .drop = TRUE)
summarySE(data = NULL, measurevar, groupvars = NULL, na.rm = FALSE, conf.interval = 0.95, .drop = TRUE)
data |
a data frame |
measurevar |
the name of a column that contains the variable to be summariezed |
groupvars |
a vector containing names of columns that contain grouping variables |
na.rm |
a boolean that indicates whether to ignore NA's |
conf.interval |
the percent range of the confidence interval (default is 95%) |
.drop |
should combinations of variables that do not appear in the input data be preserved (FALSE) or dropped (TRUE, default) |
a data frame with count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)
Summarizes data, handling within-subjects variables by removing inter-subject variability. It will still work if there are no within-S variables. Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%). If there are within-subject variables, calculate adjusted values using method from Morey (2008).
summarySEwithin(data = NULL, measurevar, betweenvars = NULL, withinvars = NULL, idvar = NULL, na.rm = FALSE, conf.interval = 0.95, .drop = TRUE)
summarySEwithin(data = NULL, measurevar, betweenvars = NULL, withinvars = NULL, idvar = NULL, na.rm = FALSE, conf.interval = 0.95, .drop = TRUE)
data |
a data frame |
measurevar |
the name of a column that contains the variable to be summariezed |
betweenvars |
a vector containing names of columns that are between-subjects variables |
withinvars |
a vector containing names of columns that are within-subjects variables |
idvar |
the name of a column that identifies each subject (or matched subjects) |
na.rm |
a boolean that indicates whether to ignore NA's |
conf.interval |
the percent range of the confidence interval (default is 95%) |
.drop |
should combinations of variables that do not appear in the input data be preserved (FALSE) or dropped (TRUE, default) |
a data frame with count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)