Title: | A Data Analysis GUI for R |
---|---|
Description: | An intuitive, cross-platform graphical data analysis system. It uses menus and dialogs to guide the user efficiently through the data manipulation and analysis process, and has an excel like spreadsheet for easy data frame visualization and editing. Deducer works best when used with the Java based R GUI JGR, but the dialogs can be called from the command line. Dialogs have also been integrated into the Windows Rgui. |
Authors: | Ian Fellows with contributions from others (see documentation). |
Maintainer: | Ian Fellows <[email protected]> |
License: | GPL-2 |
Version: | 0.7-9 |
Built: | 2024-11-26 06:45:59 UTC |
Source: | CRAN |
Applies and adds a hypothesis test to a contingency.tables
object.
add.cross.strata.test(tables,name,htests,types=c("asymptotic","monte.carlo","exact"))
add.cross.strata.test(tables,name,htests,types=c("asymptotic","monte.carlo","exact"))
tables |
An object of class |
name |
The name of the hypothesis test |
htests |
A function or list of functions which take a three dimensional array as it's argument
and returns an object of class |
types |
A character vector with the same number of items as htests, indicating what type of test was done |
A contingency.tables
object identical to tables
, but with the test applied to each table.
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) add.cross.strata.test(tables,"Mantel-Haenszel",list(function(x) mantelhaen.test(x,correct=FALSE)), "asymptotic") tables
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) add.cross.strata.test(tables,"Mantel-Haenszel",list(function(x) mantelhaen.test(x,correct=FALSE)), "asymptotic") tables
Applies and adds the Cochran-Mantel-Haenzsel test to a contingency.tables
object. The Cochran-Mantel-Haenzsel tests
the independence of two nominal variables, stratified by a third nominal variable, assuming no three way interaction.
add.mantel.haenszel(tables,conservative=FALSE)
add.mantel.haenszel(tables,conservative=FALSE)
tables |
An object of class |
conservative |
Should a continuity 'correction' be applied |
This is a convenience function wrapping mantelhaen.test
in a add.cross.strata.test
call.
See mantelhaen.test
for further details.
A contingency.tables
object identical to tables
, but with the test applied to each table.
add.cross.strata.test
add.test
mantelhaen.test
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables1<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) tables1<-add.mantel.haenszel(tables1) print(tables1,prop.r=TRUE,prop.c=TRUE,prop.t=FALSE)
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables1<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) tables1<-add.mantel.haenszel(tables1) print(tables1,prop.r=TRUE,prop.c=TRUE,prop.t=FALSE)
Applies and adds a test to a contingency.tables
object.
add.test(tables,name,htests,types=c("asymptotic","monte.carlo","exact")) add.chi.squared(tables, simulate.p.value = FALSE, B = 10000) add.likelihood.ratio(tables, conservative = FALSE, simulate.p.value = FALSE, B = 10000) add.fishers.exact(tables, simulate.p.value = FALSE, B = 10000) add.correlation(tables,method=c("spearman","kendall")) add.kruskal(tables,nominal=c("both","rows","cols"))
add.test(tables,name,htests,types=c("asymptotic","monte.carlo","exact")) add.chi.squared(tables, simulate.p.value = FALSE, B = 10000) add.likelihood.ratio(tables, conservative = FALSE, simulate.p.value = FALSE, B = 10000) add.fishers.exact(tables, simulate.p.value = FALSE, B = 10000) add.correlation(tables,method=c("spearman","kendall")) add.kruskal(tables,nominal=c("both","rows","cols"))
tables |
An object of class |
name |
Name of the test |
htests |
A function or list of functions which take a matrix as it's argument
and returns an object of class |
types |
A character vector with the same number of items as |
conservative |
Should a conservative p-value be computed. i.e. One with a continuity correction for asymptotic tests and not using the mid p-value for exact and approximate tests |
simulate.p.value |
If |
B |
the number of samples for the monte carlo simulation |
method |
the type of correlation |
nominal |
Should the rows or columns be considered nominal. |
add.test applies a supplied list of tests to all of the tables in tables
.
add.chi.squared is a wrapper function applying the chisq.test
function to each table.
add.likelihood.ratio is a wrapper function applying the likelihood.test
function to each table.
add.fishers.exact is a wrapper function applying the fisher.test
function to each table.
add.correlation is a wrapper function applying the cor.test
function to each table.
add.kruskal is a wrapper function applying the kruskal.test
function to each table.
A contingency.tables
object identical to tables
, but with the test applied to each table.
add.cross.strata.test
likelihood.test
cor.test
kruskal.test
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) tables<-add.chi.squared(tables,simulate.p.value=TRUE,B=10000) tables<-add.likelihood.ratio(tables) tables<-add.fishers.exact(tables) tables<-add.correlation(tables,method='kendall') tables<-add.kruskal(tables) tables<-add.mantel.haenszel(tables) print(tables) remove(tables)
dat<-data.frame(a=rnorm(100)>.5,b=rnorm(100)>0,c=rnorm(100)>(-.5)) tables<-contingency.tables( row.vars=a, col.vars=b, stratum.var=c,data=dat) tables<-add.chi.squared(tables,simulate.p.value=TRUE,B=10000) tables<-add.likelihood.ratio(tables) tables<-add.fishers.exact(tables) tables<-add.correlation(tables,method='kendall') tables<-add.kruskal(tables) tables<-add.mantel.haenszel(tables) print(tables) remove(tables)
as matrix
## S3 method for class 'cor.matrix' as.matrix(x,...)
## S3 method for class 'cor.matrix' as.matrix(x,...)
x |
Object of class |
... |
further arguments. unsued |
a matrix
Confidence interval for the Non-centrality parameter of Non-central chi-squared distribution
chi.noncentral.conf(chival,df,conf,prec=.00001)
chi.noncentral.conf(chival,df,conf,prec=.00001)
chival |
The observed Chi-Squared value |
conf |
The confidence level (e.g. .95) |
df |
Degrees of freedom |
prec |
Precision of estimate |
A 2X2 matrix whose rows represent the upper and lower bounds, and whose columns represent the parameter value and upper tail percentiles.
Smithson, M.J. (2003). Confidence Intervals, Quantitative Applications in the Social Sciences Series, No. 140. Thousand Oaks, CA: Sage.
chi.noncentral.conf(6,1,.95) # Result: # Non-Central % #Lower 0.2089385 0.97500899 #Upper 19.4443359 0.02499302
chi.noncentral.conf(6,1,.95) # Result: # Non-Central % #Lower 0.2089385 0.97500899 #Upper 19.4443359 0.02499302
Makes a nice table out of a contin.tests
object
contin.tests.to.table(tests,test.digits=3,...)
contin.tests.to.table(tests,test.digits=3,...)
tests |
a |
test.digits |
The number of digits to round to |
... |
other paramaters |
A nice table
Creates a contingency.tables object
contingency.tables(row.vars, col.vars, stratum.var, data=NULL, missing.include=FALSE )
contingency.tables(row.vars, col.vars, stratum.var, data=NULL, missing.include=FALSE )
row.vars |
A variable or data frame evaluated in data |
col.vars |
A variable or data frame evaluated in data |
stratum.var |
A variable evaluated in data |
data |
A |
missing.include |
A logical indicating whether a missing category should be included in the table |
A list with class "contingency.tables." Each element of the list is a single contingency table of
class "contin.table" corresponding to each combination of elements of row.vars
and col.vars
stratified by stratum.var
temp.data<-data.frame(a=rnorm(100)>0,b=rnorm(100)>0,gender=rep(c("male","female"),50)) #a vs. b stratified by gender tab<-contingency.tables(a,b,gender,data=temp.data) tab ##add in chi-squared tests tab<-add.chi.squared(tab) tab
temp.data<-data.frame(a=rnorm(100)>0,b=rnorm(100)>0,gender=rep(c("male","female"),50)) #a vs. b stratified by gender tab<-contingency.tables(a,b,gender,data=temp.data) tab ##add in chi-squared tests tab<-add.chi.squared(tab) tab
Creates a correlation matrix
cor.matrix(variables,with.variables,data=NULL,test=cor.test,...)
cor.matrix(variables,with.variables,data=NULL,test=cor.test,...)
variables |
variables |
with.variables |
An optional set of variables to correlate with |
data |
A data.frame from which the variables and factor will be selected. |
test |
A function whose first two arguments are the variables upon which the correlation will be calculated,
and whose result is an object of class |
... |
further arguments for |
A multi.test
object, representing a table of the results of func
applied to each of the variables.
dat<-data.frame(aa=rnorm(100),bb=rnorm(100),cc=rnorm(100),dd=rnorm(100)) dat$aa<-dat$aa+dat$dd dat$cc<-dat$cc+dat$aa cor.matrix(dat,test=cor.test) cor.matrix(d(aa,cc),data=dat,test=cor.test,method="kendall") cor.matrix(d(aa,cc),d(dd,bb),data=dat,test=cor.test,method="spearman")
dat<-data.frame(aa=rnorm(100),bb=rnorm(100),cc=rnorm(100),dd=rnorm(100)) dat$aa<-dat$aa+dat$dd dat$cc<-dat$cc+dat$aa cor.matrix(dat,test=cor.test) cor.matrix(d(aa,cc),data=dat,test=cor.test,method="kendall") cor.matrix(d(aa,cc),d(dd,bb),data=dat,test=cor.test,method="spearman")
This function creates data frames, tightly coupled collections of variables which share many of the properties of matrices and of lists, used as the fundamental data structure by most of R's modeling software. It is a keystroke saving wrapper for the data.frame function. The only difference is that check.names and stringsAsFactors are FALSE by default.
d(..., row.names = NULL, check.rows = FALSE, check.names = FALSE, stringsAsFactors = FALSE)
d(..., row.names = NULL, check.rows = FALSE, check.names = FALSE, stringsAsFactors = FALSE)
... |
items |
row.names |
NULL or a single integer or character string specifying a column to be used as row names, or a character or integer vector giving the row names for the data frame. |
check.rows |
if TRUE then the rows are checked for consistency of length and names. |
check.names |
logical. If TRUE then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names and are not duplicated. If necessary they are adjusted (by make.names) so that they are. |
stringsAsFactors |
logical: should character vectors be converted to factors? |
x <- d(rnorm(10),1:10)
x <- d(rnorm(10),1:10)
splits a variable into two groups
deducer(cmd=NULL) data.viewer()
deducer(cmd=NULL) data.viewer()
cmd |
The command to be executed |
Table of descriptive statistics, possibly stratified
descriptive.table(vars, strata, data, func.names = c("Mean","St. Deviation","Median", "25th Percentile","75th Percentile", "Minimum","Maximum","Skew","Kurtosis","Valid N"), func.additional)
descriptive.table(vars, strata, data, func.names = c("Mean","St. Deviation","Median", "25th Percentile","75th Percentile", "Minimum","Maximum","Skew","Kurtosis","Valid N"), func.additional)
vars |
A variable or data.frame containing variables on which to run descriptive statistics. |
data |
The data frame in which vars is evaluated |
strata |
A variable or data.frame containing variables on which to stratify |
func.names |
A character vector of built-in statistics |
func.additional |
A named list of functions. Each function should take a numeric vector as its argument, and return a single value |
Returns a list of matrix
objects containing descriptive information on all variables in dat
.
One for each level or combination of levels in strata
.
data(mtcars) ##means and standard deviations descriptive.table(vars = d(mpg,hp),data= mtcars, func.names =c("Mean","St. Deviation","Valid N")) ##stratifying by cyl descriptive.table(vars = d(mpg,hp) , strata = d(cyl),data= mtcars, func.names =c("Mean","St. Deviation","Valid N")) func.list=list(mean.deviance=function(x) mean(abs(x-mean(x)))) ##Adding deviance as a statistic descriptive.table(vars = d(mpg,hp) , strata = d(cyl),data= mtcars, func.names =c("Mean","St. Deviation","Valid N"),func.additional=func.list)
data(mtcars) ##means and standard deviations descriptive.table(vars = d(mpg,hp),data= mtcars, func.names =c("Mean","St. Deviation","Valid N")) ##stratifying by cyl descriptive.table(vars = d(mpg,hp) , strata = d(cyl),data= mtcars, func.names =c("Mean","St. Deviation","Valid N")) func.list=list(mean.deviance=function(x) mean(abs(x-mean(x)))) ##Adding deviance as a statistic descriptive.table(vars = d(mpg,hp) , strata = d(cyl),data= mtcars, func.names =c("Mean","St. Deviation","Valid N"),func.additional=func.list)
functions pertaining to GUI development
addComponent(container, component, top, right, bottom, left, topType = "REL", rightType = "REL", bottomType = "REL", leftType = "REL") getSize(component) setSize(component,width,height) execute(cmd) ButtonGroupWidget CheckBoxesWidget DeducerMain JLabel RDialog SimpleRDialog SimpleRSubDialog SingleVariableWidget SliderWidget TextAreaWidget VariableListWidget VariableSelectorWidget ComboBoxWidget RDialogMonitor ListWidget AddRemoveButtons TextFieldWidget ObjectChooserWidget
addComponent(container, component, top, right, bottom, left, topType = "REL", rightType = "REL", bottomType = "REL", leftType = "REL") getSize(component) setSize(component,width,height) execute(cmd) ButtonGroupWidget CheckBoxesWidget DeducerMain JLabel RDialog SimpleRDialog SimpleRSubDialog SingleVariableWidget SliderWidget TextAreaWidget VariableListWidget VariableSelectorWidget ComboBoxWidget RDialogMonitor ListWidget AddRemoveButtons TextFieldWidget ObjectChooserWidget
container |
A Java Swing container with Anchor layout |
component |
a Java Swing component |
top |
location of top of component 0 - 1000 |
right |
location of right of component 0 - 1000 |
bottom |
location of bottom of component 0 - 1000 |
left |
location of left of component 0 - 1000 |
topType |
Type of constraint on top of component. Can be "REL", "ABS", or "NONE" |
rightType |
Type of constraint on right of component. Can be "REL", "ABS", or "NONE" |
bottomType |
Type of constraint on bottom of component. Can be "REL", "ABS", or "NONE" |
leftType |
Type of constraint on left of component. Can be "REL", "ABS", or "NONE" |
height |
new height of component or window in pixels |
width |
new width of component or window in pixels |
cmd |
the command to be executed |
addComponent adds a Java object of class Component to a container (usually an RDialog or SimpleRDialog). the location of the component is determined by the top, right, bottom, and left arguments, which are numbers between 1 and 1000 indicating the distance from either the top (or left) of the container, with 1000 indicating the opposite side of the container. Each side can be constrained in three different ways. If the Type is "REL", the side will scale proportional to the container when the container is resized. If it is "ABS", it is not rescaled. If it is "NONE", the location of that side is determined by the componet's preferred size, which can be set with the "setPreferedSize" method.
getSize gets the height and width
setSize sets the height and width
execute executes a character representing a command, as if it were entered into the console
The rest of the items are references to the Java classes of commonly used GUI components. see www.deducer.org for more details and usage.
splits a variable into two groups
dich(variables,data=NULL,cut=NULL,group1=NULL,group2=NULL)
dich(variables,data=NULL,cut=NULL,group1=NULL,group2=NULL)
variables |
variables to be dichotomized |
data |
A data.frame |
cut |
An optional cut point dividing |
group1 |
An optional vector of levels of |
group2 |
An optional vector of levels of |
a data.frame containing the variables, recoded into two groups.
Extracts the counts of a contingency.tables object
extract.counts(tables)
extract.counts(tables)
tables |
A |
A named list of three dimensional arrays. One for each contin.table
in tables
temp.data<-data.frame(a=rnorm(100)>0,b=rnorm(100)>0,gender=rep(c("male","female"),50)) #a vs. b stratified by gender tab<-contingency.tables(a,b,gender,data=temp.data) tab ##extract counts extract.counts(tab) ##Yields something like the following: #$`a by b` #, , female # # FALSE TRUE #FALSE 11 9 #TRUE 15 15 # #, , male # # FALSE TRUE #FALSE 10 10 #TRUE 22 8
temp.data<-data.frame(a=rnorm(100)>0,b=rnorm(100)>0,gender=rep(c("male","female"),50)) #a vs. b stratified by gender tab<-contingency.tables(a,b,gender,data=temp.data) tab ##extract counts extract.counts(tab) ##Yields something like the following: #$`a by b` #, , female # # FALSE TRUE #FALSE 11 9 #TRUE 15 15 # #, , male # # FALSE TRUE #FALSE 10 10 #TRUE 22 8
Creates a set of frequency tables.
frequencies(data,r.digits=1)
frequencies(data,r.digits=1)
data |
A data.frame containing the variables on which to run frequencies |
r.digits |
how many digits should the percentages be rounded to |
Returns a list of freq.table
objects. One for each variable in data
.
table
xtabs
descriptive.table
prop.table
dat<-data.frame(rnorm(100)>0,trunc(runif(100,0,5))) ##rounding to 1 frequencies(dat) ##rounding to 4 frequencies(dat,4)
dat<-data.frame(rnorm(100)>0,trunc(runif(100,0,5))) ##rounding to 1 frequencies(dat) ##rounding to 4 frequencies(dat,4)
Enumerates all objects of a certain class
get.objects(cn,env = globalenv(),includeInherited=TRUE)
get.objects(cn,env = globalenv(),includeInherited=TRUE)
cn |
The name of the class |
env |
environment to look in |
includeInherited |
Should objects inheriting cn be included |
a character vector
Plots a correlation matrix
ggcorplot(cor.mat,data=NULL,lines=TRUE,line.method=c("lm","loess"),type="points", alpha=.25,main="auto",var_text_size=5, cor_text_limits=c(5,25),level=.05)
ggcorplot(cor.mat,data=NULL,lines=TRUE,line.method=c("lm","loess"),type="points", alpha=.25,main="auto",var_text_size=5, cor_text_limits=c(5,25),level=.05)
cor.mat |
a |
data |
the data.frame used to compute the correlation matrix |
lines |
Logical. Should regression lines be drawn. |
type |
type of plot. "points" or "bins" |
line.method |
Character. Type of regression line. |
alpha |
numeric. level of alpha transparency for the points. |
main |
Title of the plot. defaults to the method of cor.mat. |
var_text_size |
size of the diagonal variable names. |
cor_text_limits |
lower and upper bounds for the size of the correlation text. |
level |
the size of the test differentiated by text color. |
Mike Lawrence and Ian Fellows
data(mtcars) corr.mat1<-cor.matrix(variables=d(mpg,carb,carb+rnorm(length(carb))),, data=mtcars, test=cor.test, method='spearman', alternative="two.sided",exact=FALSE) p<-ggcorplot(corr.mat1,data = mtcars) print(p) ## Not run: has.hex<-require("hexbin") if(has.hex){ data(diamonds) corr.mat<-cor.matrix(variables=d(price,carat,color),, data=diamonds, test=cor.test, method='spearman', alternative="two.sided") p1 <- ggcorplot(cor.mat=corr.mat,data=diamonds,type="bins", cor_text_limits=c(5,15), lines=FALSE) print(p1) rm('corr.mat') } ## End(Not run)
data(mtcars) corr.mat1<-cor.matrix(variables=d(mpg,carb,carb+rnorm(length(carb))),, data=mtcars, test=cor.test, method='spearman', alternative="two.sided",exact=FALSE) p<-ggcorplot(corr.mat1,data = mtcars) print(p) ## Not run: has.hex<-require("hexbin") if(has.hex){ data(diamonds) corr.mat<-cor.matrix(variables=d(price,carat,color),, data=diamonds, test=cor.test, method='spearman', alternative="two.sided") p1 <- ggcorplot(cor.mat=corr.mat,data=diamonds,type="bins", cor_text_limits=c(5,15), lines=FALSE) print(p1) rm('corr.mat') } ## End(Not run)
Performs a K independent sample test.
k.sample.test(formula,data,test=oneway.test,...)
k.sample.test(formula,data,test=oneway.test,...)
formula |
A formula, the left hand side of which indicated the outcomes, and the right hand side of which contains the factor |
data |
A data.frame |
test |
A function whose first argument is a formula with the outcome on the lhs and the factor on the rhs.
The second argument should be the data to be used for the formula. The result of the function should be an object of class |
... |
further arguments for func |
A multi.test
object, representing a table of the results of func
applied to each of the variables.
oneway.test
kruskal.test
wilcox.test
dat<-data.frame(a=rnorm(100),b=rnorm(100),c=rnorm(100),d=cut(rnorm(100),4)) k.sample.test(d(a,b)~d,dat) k.sample.test(dat[,-4]~dat$d,var.equal=TRUE) k.sample.test(d(a,c)~d,dat,kruskal.test)
dat<-data.frame(a=rnorm(100),b=rnorm(100),c=rnorm(100),d=cut(rnorm(100),4)) k.sample.test(d(a,b)~d,dat) k.sample.test(dat[,-4]~dat$d,var.equal=TRUE) k.sample.test(d(a,c)~d,dat,kruskal.test)
Performs a likelihood ratio test of independence
likelihood.test(x,y=NULL,conservative=FALSE)
likelihood.test(x,y=NULL,conservative=FALSE)
x |
A vector or a matrix |
y |
A vector that is ignored if x is a matrix and required if x is a vector |
conservative |
If |
A list with class "htest" containing the following components:
statistic |
the value the chi-squared test statistic. |
parameter |
the degrees of freedom of the approximate chi-squared distribution of the test statistic. |
p.value |
the p-value for the test. |
method |
a character string indicating the type of test performed, and whether the continuity correction was used. |
data.name |
a character string giving the name(s) of the data. |
Pete Hurd and Ian Fellows
data(InsectSprays) likelihood.test(InsectSprays$count>7,InsectSprays$spray)
data(InsectSprays) likelihood.test(InsectSprays$count>7,InsectSprays$spray)
Creates a table from a list of htests
multi.test(tests)
multi.test(tests)
tests |
A named list of htest objects representing the same test applied to a number of different conditions or variables. |
A multi.test
object, representing a table of the htest
objects.
Performs a one sample test.
one.sample.test(variables,data=NULL,test=t.test,...)
one.sample.test(variables,data=NULL,test=t.test,...)
variables |
A variable or dataframe of variables |
data |
The data frame in which variables is evaluated |
test |
A function whose first argument is the sample to be tested,
and whose result is an object of class |
... |
further arguments for func |
A multi.test
object, representing a table of the results of test
applied to each of the variables.
data(anorexia) #are subjects' weights at baseline and endpoint significantly different from normal one.sample.test(variables=d(Prewt,Postwt), data=anorexia, test=shapiro.test) #does CBT work at increasing mean wt anorexia.sub<-subset(anorexia,Treat=="CBT") one.sample.test(variables=Postwt-Prewt, data=anorexia.sub, test=t.test)
data(anorexia) #are subjects' weights at baseline and endpoint significantly different from normal one.sample.test(variables=d(Prewt,Postwt), data=anorexia, test=shapiro.test) #does CBT work at increasing mean wt anorexia.sub<-subset(anorexia,Treat=="CBT") one.sample.test(variables=Postwt-Prewt, data=anorexia.sub, test=t.test)
plots for one sample tests
onesample.plot(variables,data=NULL,test.value,scale=FALSE,type="hist",alpha=.2)
onesample.plot(variables,data=NULL,test.value,scale=FALSE,type="hist",alpha=.2)
variables |
An expression denoting a set of variable. |
data |
A data.frame from which the variables will be selected. |
test.value |
null hypothesis test value |
scale |
scale variables |
type |
type of plot. 'hist' or 'box' are allowed |
alpha |
transparency of points for box plot |
data(mtcars) onesample.plot(variables=d(mpg,cyl,disp,hp,drat,wt,qsec,vs,am, gear,carb),data=mtcars,type='hist') onesample.plot(variables=d(mpg,cyl,disp,hp,drat,wt,qsec,vs,am, gear,carb),data=mtcars,type='box',alpha=1)
data(mtcars) onesample.plot(variables=d(mpg,cyl,disp,hp,drat,wt,qsec,vs,am, gear,carb),data=mtcars,type='hist') onesample.plot(variables=d(mpg,cyl,disp,hp,drat,wt,qsec,vs,am, gear,carb),data=mtcars,type='box',alpha=1)
plots a categorical variable against a series of continuous variables
oneway.plot(formula,data=NULL,alpha=.2, box=TRUE,points=TRUE,scale=FALSE)
oneway.plot(formula,data=NULL,alpha=.2, box=TRUE,points=TRUE,scale=FALSE)
formula |
A formula, the left hand side of which indicated the outcomes, and the right hand side of which contains the factor |
data |
A data.frame |
alpha |
alpha transparency level for the points. |
box |
prints boxplot |
points |
prints jitter plot |
scale |
standardize the variables prior to plotting |
a ggplot object
oneway.plot(d(DriversKilled, drivers, front, rear, kms, PetrolPrice)~law,as.data.frame(Seatbelts))
oneway.plot(d(DriversKilled, drivers, front, rear, kms, PetrolPrice)~law,as.data.frame(Seatbelts))
Enumerates all permutations of a vector
perm(vec,duplicates=FALSE)
perm(vec,duplicates=FALSE)
vec |
The vector to permute |
duplicates |
Should duplicate permutations be listed |
Returns a matrix where each row is a permutation of vec. All possible permutations are listed, and if duplicates=TRUE
non-unique permutations are also listed.
perm(1:4) perm(LETTERS[4:8])
perm(1:4) perm(LETTERS[4:8])
Two Sample t-test via monte-carlo permutation
perm.t.test(x,y,statistic=c("t","mean"), alternative=c("two.sided", "less", "greater"), midp=TRUE, B=10000)
perm.t.test(x,y,statistic=c("t","mean"), alternative=c("two.sided", "less", "greater"), midp=TRUE, B=10000)
x |
a numeric vector containing the first sample |
y |
a numeric vector containing the second sample |
statistic |
The statistic to be permuted. See details |
alternative |
The alternative hypothesis |
midp |
should the mid p-value be used |
B |
The number of monte-carlo samples to be generated |
This function performs a two sample permutation test. If the mean is permuted, then the test assumes exchangability between the two samples. if the t-statistic is used, the test assumes either exchangability or a sufficiently large sample size. Because there is little lost in the way of power, and the assumptions are weaker, the t-statistic is used by default.
A list with class "htest" containing the following components:
statistic |
The observed value of the statistic. |
p.value |
the p-value for the test. |
method |
a character string indicating the type of test performed. |
data.name |
a character string giving the name(s) of the data. |
B |
The number of samples generated |
alternative |
the direction of the test |
perm.t.test(rnorm(100),runif(100,-.5,.5))
perm.t.test(rnorm(100),runif(100,-.5,.5))
Produces a circle plot for an object of class "plot.cor.matrix"
## S3 method for class 'cor.matrix' plot(x,y=NULL,size=10,...)
## S3 method for class 'cor.matrix' plot(x,y=NULL,size=10,...)
x |
Object of class |
y |
unused |
size |
maximum radius size |
... |
further arguments. unsued |
a ggplot object
Print object of class "contin.table"
in nice layout.
## S3 method for class 'contin.table' print( x,digits=3,prop.r=TRUE,prop.c=TRUE,prop.t=TRUE, expected.n=FALSE,residuals=FALSE,std.residuals=FALSE, adj.residuals=FALSE,no.tables=FALSE,...)
## S3 method for class 'contin.table' print( x,digits=3,prop.r=TRUE,prop.c=TRUE,prop.t=TRUE, expected.n=FALSE,residuals=FALSE,std.residuals=FALSE, adj.residuals=FALSE,no.tables=FALSE,...)
x |
Object of class |
digits |
Number of digits to round to. |
prop.r |
Logical. print row proportions. |
prop.c |
Logical. print column proportions. |
prop.t |
Logical. print proportions. |
expected.n |
Logical print expected cell counts. |
residuals |
Logical. print residuals. |
std.residuals |
Logical. print standardized residuals. |
adj.residuals |
Logical. Print Adjusted residuals |
no.tables |
Logical. Suppress tables |
... |
further arguments |
none
Ian Fellows based on the CrossTable function from the gmodels package maintained by Gregory R. Warnes
Print object of class "contin.tests"
in nice layout.
## S3 method for class 'contin.tests' print(x,test.digits, ...)
## S3 method for class 'contin.tests' print(x,test.digits, ...)
x |
Object of class |
test.digits |
Number of digits to be printed |
... |
further arguments to be passed to or from methods. |
none
Print object of class "contingency.tables"
in nice layout.
## S3 method for class 'contingency.tables' print(x,digits=3,prop.r=TRUE,prop.c=TRUE,prop.t=TRUE, expected.n=FALSE,no.tables=FALSE,...)
## S3 method for class 'contingency.tables' print(x,digits=3,prop.r=TRUE,prop.c=TRUE,prop.t=TRUE, expected.n=FALSE,no.tables=FALSE,...)
x |
Object of class |
digits |
Number of digits to round to. |
prop.r |
Logical. print row proportions. |
prop.c |
Logical. print column proportions. |
prop.t |
Logical. print proportions. |
expected.n |
Logical print expected cell counts. |
no.tables |
Logical. Suppress tables |
... |
further arguments |
none
Print object of class "cor.matrix"
in nice layout.
## S3 method for class 'cor.matrix' print(x,digits=4,N=TRUE,CI=TRUE,stat=TRUE,p.value=TRUE,...)
## S3 method for class 'cor.matrix' print(x,digits=4,N=TRUE,CI=TRUE,stat=TRUE,p.value=TRUE,...)
x |
Object of class |
digits |
Number of digits to round to. |
N |
Logical. print a row for sample size. |
CI |
Logical. print a row for confidence intervals if they exist. |
stat |
Logical. print a row for test statistics. |
p.value |
Logical. print a row for p-values. |
... |
further arguments |
none
Print object of class "freq.table"
in nice layout.
## S3 method for class 'freq.table' print(x,...)
## S3 method for class 'freq.table' print(x,...)
x |
Object of class |
... |
further arguments |
none
Print object of class "multi.test"
in nice layout.
## S3 method for class 'multi.test' print(x,...)
## S3 method for class 'multi.test' print(x,...)
x |
Object of class |
... |
further arguments |
none
Creates an array of scatterplots
qscatter_array(variables,with.variables,data,x.lab="",y.lab="", main="Correlation Array",common.scales=TRUE,alpha=.25)
qscatter_array(variables,with.variables,data,x.lab="",y.lab="", main="Correlation Array",common.scales=TRUE,alpha=.25)
variables |
variables |
with.variables |
An optional set of variables to correlate with |
data |
A data.frame from which the variables will be selected. |
x.lab |
A label for the x axis |
y.lab |
A label for the y axis |
main |
A label for the plot |
common.scales |
should common x and y scales be used. |
alpha |
alpha transparency |
data(mtcars) qscatter_array(d(cyl,disp,hp,drat), data=mtcars) + geom_smooth(method="lm") qscatter_array(d(cyl,disp,hp,drat),d(wt,carb),data=mtcars,common.scales=FALSE)
data(mtcars) qscatter_array(d(cyl,disp,hp,drat), data=mtcars) + geom_smooth(method="lm") qscatter_array(d(cyl,disp,hp,drat),d(wt,carb),data=mtcars,common.scales=FALSE)
Recodes a set of variables according to a set of rules
recode.variables(data,recodes)
recode.variables(data,recodes)
data |
A |
recodes |
Definition of the recoding rules. See details |
recodes
contains a set of recoding rules separated by ";".
There are three different types of recoding rules:
1. The simplest codes one value to another. If we wish to recode 1 into 2, we could use the rule "1->2;"
.
2. A range of values can be coded to a single value using "1:3->4;"
.
This rule would code all values between 1 and 3 inclusive into 4. For factors, a value is
between two levels if it is between them in the factor ordering.
One sided ranges can be specified using the Lo and Hi key words (e.g."Lo:3->0; 4:Hi->1"
)
3. Default conditions can be coded using "else." For example, if we wish to recode all
values >=0 to 1 and all values <0 to missing, we could use ("0:Hi->1; else->NA"
)
returns a recoded data.frame
Ian Fellows adapted from code by John Fox
data<-data.frame(a=rnorm(100),b=rnorm(100),male=rnorm(100)>0) recode.variables(data[c("a","b")] , "Lo:0 -> 0;0:Hi -> 1;") data[c("male")] <- recode.variables(data[c("male")] , "1 -> 'Male';0 -> 'Female';else -> NA;")
data<-data.frame(a=rnorm(100),b=rnorm(100),male=rnorm(100)>0) recode.variables(data[c("a","b")] , "Lo:0 -> 0;0:Hi -> 1;") data[c("male")] <- recode.variables(data[c("male")] , "1 -> 'Male';0 -> 'Female';else -> NA;")
Plots the ROC Curve
rocplot(logistic.model,diag=TRUE,pred.prob.labels=FALSE,prob.label.digits=3,AUC=TRUE)
rocplot(logistic.model,diag=TRUE,pred.prob.labels=FALSE,prob.label.digits=3,AUC=TRUE)
logistic.model |
a glm object with binomial link function. |
diag |
a logical value indicating whether a diagonal reference line should be displayed. |
pred.prob.labels |
a logical value indicating whether the predictive probabilities should be displayed |
prob.label.digits |
The number of digits of the predictive probabilities to be displayed. |
AUC |
a logical value indicating whether the estimated area under the curve should be displayed |
a ggplot object
Ian Fellows adapted from the lroc function by Virasakdi Chongsuvivatwong
model.glm <- glm(formula=income>5930.5 ~ education + women + type, family=binomial(),data=Prestige,na.action=na.omit) rocplot(model.glm)
model.glm <- glm(formula=income>5930.5 ~ education + women + type, family=binomial(),data=Prestige,na.action=na.omit) rocplot(model.glm)
Sorts a data frame
## S3 method for class 'data.frame' sort(x, decreasing, by, ...)
## S3 method for class 'data.frame' sort(x, decreasing, by, ...)
x |
A |
decreasing |
unused |
by |
A character, a one sided formula, or an expression indicating the sorting order |
... |
further arguments |
If by
is a formula, or a character vector coerce-able into a formula,
x
is sorted by each element of the formula, with ties broken by subsequent elements.
Elements preceded by a '-' indicate descending order, otherwise ascending order is used. Parentheses or any formula
operator other than + and - are ignored, so sorting by a*b
will sort based on the product of a and b.
If by
is not a formula, a ~
is appended to the left hand side of the call, and coerced into
a formula.
The decreasing argument is included for generic method consistency, and is not used.
returns x
, sorted.
Ian Fellows adapted from code by Ari Friedman and Kevin Wright
data(mtcars) #sort by the number of cylenders sort(mtcars, by= ~cyl) sort(mtcars, by= cyl) #identical: no need for ~ #sort in descending order sort(mtcars, by= -cyl) #break ties with horse power sort(mtcars,by= cyl +hp ) sort(mtcars,by= cyl -hp ) #randomly permute the data sort(mtcars,by= rnorm(nrow(mtcars)) ) #reverse order sort(mtcars,by= nrow(mtcars):1 ) #sort by squared deviation from mean hp sort(mtcars,by= -(hp-mean(hp))^2 ) sort(mtcars,by= "-(hp-mean(hp))^2" ) #identical
data(mtcars) #sort by the number of cylenders sort(mtcars, by= ~cyl) sort(mtcars, by= cyl) #identical: no need for ~ #sort in descending order sort(mtcars, by= -cyl) #break ties with horse power sort(mtcars,by= cyl +hp ) sort(mtcars,by= cyl -hp ) #randomly permute the data sort(mtcars,by= rnorm(nrow(mtcars)) ) #reverse order sort(mtcars,by= nrow(mtcars):1 ) #sort by squared deviation from mean hp sort(mtcars,by= -(hp-mean(hp))^2 ) sort(mtcars,by= "-(hp-mean(hp))^2" ) #identical
Computes the coefficients, std. errors, t values, and p-values for a linear model in the presence of possible heteroskedasticity.
summarylm(object,correlation=FALSE,symbolic.cor = FALSE,white.adjust=FALSE,...)
summarylm(object,correlation=FALSE,symbolic.cor = FALSE,white.adjust=FALSE,...)
object |
an object of class lm. |
correlation |
a logical value indicating whether parameter correlations should be printed. |
symbolic.cor |
logical. If TRUE, print the correlations in a symbolic form (see symnum) rather than as numbers. Effective only if white.adjust is FALSE. |
white.adjust |
value passed to |
... |
additional parameters passed to stats::summary.lm |
If white.adjust is false, the function returns a value identical to stats::summary.lm. Otherwise, robust summaries are computed
A summary table
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2,10,20, labels=c("Ctl","Trt")) weight <- c((ctl-mean(ctl))*10+mean(ctl), trt) lm.D9 <- lm(weight ~ group) summarylm(lm.D9,white.adjust=TRUE)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2,10,20, labels=c("Ctl","Trt")) weight <- c((ctl-mean(ctl))*10+mean(ctl), trt) lm.D9 <- lm(weight ~ group) summarylm(lm.D9,white.adjust=TRUE)
Creates a data.frame from a table
table.to.data(x)
table.to.data(x)
x |
A matrix or table representing the cross tabulation of two variables |
A two column data.frame where each row is an observation and each column is a variable.
tab<-matrix(c(4,5,6,9,7,3),ncol=3) tab table.to.data(tab)
tab<-matrix(c(4,5,6,9,7,3),ncol=3) tab table.to.data(tab)
Performs a two independent sample test.
two.sample.test(formula,data=NULL,test=t.test,...)
two.sample.test(formula,data=NULL,test=t.test,...)
formula |
A formula, the left hand side of which indicated the outcomes, and the right hand side of which contains the factor |
data |
A data.frame |
test |
A function whose first two arguments are the two-samples to be tested,
and whose result is an object of class |
... |
further arguments for test |
A multi.test
object, representing a table of the results of test
applied to each of the variables.
dat<-data.frame(a=rnorm(100),b=rnorm(100),c=rnorm(100),d=rnorm(100)>(-.5)) two.sample.test(d(a,b) ~ d,dat,ks.test) two.sample.test(a ~ dich(b,cut=0) ,dat,t.test) two.sample.test(d(a^2,abs(b),c)~d,dat,wilcox.test)
dat<-data.frame(a=rnorm(100),b=rnorm(100),c=rnorm(100),d=rnorm(100)>(-.5)) two.sample.test(d(a,b) ~ d,dat,ks.test) two.sample.test(a ~ dich(b,cut=0) ,dat,t.test) two.sample.test(d(a^2,abs(b),c)~d,dat,wilcox.test)