Title: | Data and Functions for Web-Based Analysis |
---|---|
Description: | Several analysis-related functions for the book entitled "Web-based Analysis without R in Your Computer"(written in Korean, ISBN 978-89-5566-185-9) by Keon-Woong Moon. The main function plot.htest() shows the distribution of statistic for the object of class 'htest'. |
Authors: | Keon-Woong Moon [aut, cre], Tommaso Martino [ctb] |
Maintainer: | Keon-Woong Moon <[email protected]> |
License: | GPL-3 |
Version: | 0.1.6 |
Built: | 2025-02-12 04:43:28 UTC |
Source: | https://github.com/cardiomoon/webr |
Extract bivariate variables
BiVar(df)
BiVar(df)
df |
a data.frame |
Extract continuous variables
ContinuousVar(df)
ContinuousVar(df)
df |
a data.frame |
Cox-Stuart test for trend analysis The Cox-Stuart test is defined as a little powerful test (power equal to 0.78), but very robust for the trend analysis. It is therefore applicable to a wide variety of situations, to get an idea of the evolution of values obtained. The proposed method is based on the binomial distribution. This function was written by Tommaso Martino<[email protected]> (See 'References')
cox.stuart.test(x)
cox.stuart.test(x)
x |
A numeric vector |
A list with class "htest"
Original code: http://statistic-on-air.blogspot.kr/2009/08/trend-analysis-with-cox-stuart-test-in.html
customers = c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14) cox.stuart.test(customers)
customers = c(5, 9, 12, 18, 17, 16, 19, 20, 4, 3, 18, 16, 17, 15, 14) cox.stuart.test(customers)
Extract labels
extractLabels(x)
extractLabels(x)
x |
a vector |
Make table summarizing frequency
freqSummary(x, digits = 1, lang = "en")
freqSummary(x, digits = 1, lang = "en")
x |
A vector |
digits |
integer indicating the number of decimal places |
lang |
Language. choices are one of c("en","kor") |
require(moonBook) freqSummary(acs$Dx) #freqSummary(acs$smoking,lang="kor")
require(moonBook) freqSummary(acs$Dx) #freqSummary(acs$smoking,lang="kor")
Make flextable summarizing frequency
freqTable( x, digits = 1, lang = getOption("freqTable.lang", "en"), vanilla = FALSE, ... )
freqTable( x, digits = 1, lang = getOption("freqTable.lang", "en"), vanilla = FALSE, ... )
x |
A vector |
digits |
integer indicating the number of decimal places |
lang |
Language. choices are one of c("en","kor") |
vanilla |
Logical. Whether make vanilla table or not |
... |
Further arguments to paseed to the df2flextable function |
An object of clss flextable
require(moonBook) freqTable(acs$Dx) #freqTable(acs$smoking,lang="kor",vanilla=TRUE,fontsize=12)
require(moonBook) freqTable(acs$Dx) #freqTable(acs$smoking,lang="kor",vanilla=TRUE,fontsize=12)
Make default palette
gg_color_hue(n)
gg_color_hue(n)
n |
number of colors |
Extract categorical variables
GroupVar(df, max.ylev = 20)
GroupVar(df, max.ylev = 20)
df |
a data.frame |
max.ylev |
maximal length of unique values of catergorical variables |
Select word
langchoice1(id, lang = "en")
langchoice1(id, lang = "en")
id |
data id |
lang |
language. Possible choices are c("en","kor") |
Make subtitle
makeSub(x)
makeSub(x)
x |
An object of class "htest" |
Make subcolors with main colors
makeSubColor(main, no = 3)
makeSubColor(main, no = 3)
main |
character. main colors |
no |
number of subcolors |
My chisquare test
mychisq.test(x)
mychisq.test(x)
x |
a table |
Numerical Summary
numSummary(x, ..., digits = 2, lang = "en") numSummary1(x, ..., digits = 2, lang = "en") numSummary2(x, ..., digits = 2, lang = "en")
numSummary(x, ..., digits = 2, lang = "en") numSummary1(x, ..., digits = 2, lang = "en") numSummary2(x, ..., digits = 2, lang = "en")
x |
A numeric vector or a data.frame or a grouped_df |
... |
further arguments to be passed |
digits |
integer indicating the number of decimal places |
lang |
Language. choices are one of c("en","kor") |
numSummary1
: Numerical Summary of a data.frame or a vector
numSummary2
: Numerical Summary of a grouped_df
require(moonBook) require(magrittr) require(dplyr) require(rrtable) require(webr) require(tibble) numSummary(acs) numSummary(acs$age) numSummary(acs,age,EF) acs %>% group_by(sex) %>% numSummary(age,BMI) acs %>% group_by(sex) %>% select(age) %>% numSummary acs %>% group_by(sex) %>% select(age,EF) %>% numSummary acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummary acs %>% group_by(sex,Dx) %>% select(age) %>% numSummary #acs %>% group_by(sex,Dx) %>% numSummary(age,EF,lang="kor")
require(moonBook) require(magrittr) require(dplyr) require(rrtable) require(webr) require(tibble) numSummary(acs) numSummary(acs$age) numSummary(acs,age,EF) acs %>% group_by(sex) %>% numSummary(age,BMI) acs %>% group_by(sex) %>% select(age) %>% numSummary acs %>% group_by(sex) %>% select(age,EF) %>% numSummary acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummary acs %>% group_by(sex,Dx) %>% select(age) %>% numSummary #acs %>% group_by(sex,Dx) %>% numSummary(age,EF,lang="kor")
Make a table showing numerical summary
numSummaryTable( x, ..., lang = getOption("numSummaryTable.lang", "en"), vanilla = FALSE, add.rownames = NULL )
numSummaryTable( x, ..., lang = getOption("numSummaryTable.lang", "en"), vanilla = FALSE, add.rownames = NULL )
x |
A grouped_df or a data.frame or a vector |
... |
further argument to be passed |
lang |
Language. choices are one of c("en","kor") |
vanilla |
Logical. Whether make vanilla table or not |
add.rownames |
Logical. Whether or not add rownames |
require(moonBook) require(dplyr) numSummaryTable(acs) numSummaryTable(acs$age) acs %>% group_by(sex) %>% select(age) %>% numSummaryTable acs %>% group_by(sex) %>% select(age,EF) %>% numSummaryTable acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummaryTable(vanilla=FALSE) acs %>% group_by(sex,Dx) %>% numSummaryTable(age,EF,add.rownames=FALSE)
require(moonBook) require(dplyr) numSummaryTable(acs) numSummaryTable(acs$age) acs %>% group_by(sex) %>% select(age) %>% numSummaryTable acs %>% group_by(sex) %>% select(age,EF) %>% numSummaryTable acs %>% group_by(sex,Dx) %>% select(age,EF) %>% numSummaryTable(vanilla=FALSE) acs %>% group_by(sex,Dx) %>% numSummaryTable(age,EF,add.rownames=FALSE)
Draw a PieDonut plot
PieDonut( data, mapping, start = getOption("PieDonut.start", 0), addPieLabel = TRUE, addDonutLabel = TRUE, showRatioDonut = TRUE, showRatioPie = TRUE, ratioByGroup = TRUE, showRatioThreshold = getOption("PieDonut.showRatioThreshold", 0.02), labelposition = getOption("PieDonut.labelposition", 2), labelpositionThreshold = 0.1, r0 = getOption("PieDonut.r0", 0.3), r1 = getOption("PieDonut.r1", 1), r2 = getOption("PieDonut.r2", 1.2), explode = NULL, selected = NULL, explodePos = 0.1, color = "white", pieAlpha = 0.8, donutAlpha = 1, maxx = NULL, showPieName = TRUE, showDonutName = FALSE, title = NULL, pieLabelSize = 4, donutLabelSize = 3, titlesize = 5, explodePie = TRUE, explodeDonut = FALSE, use.label = TRUE, use.labels = TRUE, family = getOption("PieDonut.family", "") )
PieDonut( data, mapping, start = getOption("PieDonut.start", 0), addPieLabel = TRUE, addDonutLabel = TRUE, showRatioDonut = TRUE, showRatioPie = TRUE, ratioByGroup = TRUE, showRatioThreshold = getOption("PieDonut.showRatioThreshold", 0.02), labelposition = getOption("PieDonut.labelposition", 2), labelpositionThreshold = 0.1, r0 = getOption("PieDonut.r0", 0.3), r1 = getOption("PieDonut.r1", 1), r2 = getOption("PieDonut.r2", 1.2), explode = NULL, selected = NULL, explodePos = 0.1, color = "white", pieAlpha = 0.8, donutAlpha = 1, maxx = NULL, showPieName = TRUE, showDonutName = FALSE, title = NULL, pieLabelSize = 4, donutLabelSize = 3, titlesize = 5, explodePie = TRUE, explodeDonut = FALSE, use.label = TRUE, use.labels = TRUE, family = getOption("PieDonut.family", "") )
data |
A data.frame |
mapping |
Set of aesthetic mappings created by aes or aes_. |
start |
offset of starting point from 12 o'clock in radians |
addPieLabel |
A logical value. If TRUE, labels are added to the Pies |
addDonutLabel |
A logical value. If TRUE, labels are added to the Donuts |
showRatioDonut |
A logical value. If TRUE, ratios are added to the DonutLabels |
showRatioPie |
A logical value. If TRUE, ratios are added to the PieLabels |
ratioByGroup |
A logical value. If TRUE, ratios ara calculated per group |
showRatioThreshold |
An integer. Threshold to show label as a ratio of total. default value is 0.02. |
labelposition |
A number indicating the label position |
labelpositionThreshold |
label position threshold. Default value is 0.1. |
r0 |
Integer. start point of pie |
r1 |
Integer. end point of pie |
r2 |
Integer. end point of donut |
explode |
pies to explode |
selected |
donuts to explode |
explodePos |
explode position |
color |
color |
pieAlpha |
transparency of pie |
donutAlpha |
transparency of pie |
maxx |
maximum position of plot |
showPieName |
logical. Whether or not show Pie Name |
showDonutName |
logical. Whether or not show Pie Name |
title |
title of plot |
pieLabelSize |
integer. Pie label size |
donutLabelSize |
integer. Donut label size |
titlesize |
integer. Title size |
explodePie |
Logical. Whether or not explode pies |
explodeDonut |
Logical. Whether or not explode donuts |
use.label |
Logical. Whether or not use column label in case of labelled data |
use.labels |
Logical. Whether or not use value labels in case of labelled data |
family |
font family |
require(moonBook) require(ggplot2) browser=c("MSIE","Firefox","Chrome","Safari","Opera") share=c(50,21.9,10.8,6.5,1.8) df=data.frame(browser,share) PieDonut(df,aes(browser,count=share),r0=0.7,start=3*pi/2,labelpositionThreshold=0.1) PieDonut(df,aes(browser,count=share),r0=0.7,explode=5,start=3*pi/2) PieDonut(mtcars,aes(gear,carb),start=3*pi/2,explode=3,explodeDonut=TRUE,maxx=1.7) PieDonut(mtcars,aes(carb,gear),r0=0) PieDonut(acs,aes(smoking,Dx),title="Distribution of smoking status by diagnosis") PieDonut(acs,aes(Dx,smoking),ratioByGroup=FALSE,r0=0) PieDonut(acs,aes(Dx,smoking),selected=c(1,3,5,7),explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),explode=1,selected=c(2,4,6,8),labelposition=0,explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),explode=1) PieDonut(acs,aes(Dx,smoking),explode=1,explodeDonut=TRUE,labelposition=0) PieDonut(acs,aes(Dx,smoking),explode=1,explodePie=FALSE,explodeDonut=TRUE,labelposition=0) PieDonut(acs,aes(Dx,smoking),selected=c(2,5,8), explodeDonut=TRUE,start=pi/2,labelposition=0) PieDonut(acs,aes(Dx,smoking),r0=0.2,r1=0.9,r2=1.3,explode=1,start=pi/2,explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),r0=0.2,r1=0.9,r2=1.3,explode=1,start=pi/2,labelposition=0) PieDonut(acs,aes(Dx,smoking),explode=1,start=pi,explodeDonut=TRUE,labelposition=0) require(dplyr) df=mtcars %>% group_by(gear,carb) %>% summarize(n=n()) PieDonut(df,aes(pies=gear,donuts=carb,count=n),ratioByGroup=FALSE)
require(moonBook) require(ggplot2) browser=c("MSIE","Firefox","Chrome","Safari","Opera") share=c(50,21.9,10.8,6.5,1.8) df=data.frame(browser,share) PieDonut(df,aes(browser,count=share),r0=0.7,start=3*pi/2,labelpositionThreshold=0.1) PieDonut(df,aes(browser,count=share),r0=0.7,explode=5,start=3*pi/2) PieDonut(mtcars,aes(gear,carb),start=3*pi/2,explode=3,explodeDonut=TRUE,maxx=1.7) PieDonut(mtcars,aes(carb,gear),r0=0) PieDonut(acs,aes(smoking,Dx),title="Distribution of smoking status by diagnosis") PieDonut(acs,aes(Dx,smoking),ratioByGroup=FALSE,r0=0) PieDonut(acs,aes(Dx,smoking),selected=c(1,3,5,7),explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),explode=1,selected=c(2,4,6,8),labelposition=0,explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),explode=1) PieDonut(acs,aes(Dx,smoking),explode=1,explodeDonut=TRUE,labelposition=0) PieDonut(acs,aes(Dx,smoking),explode=1,explodePie=FALSE,explodeDonut=TRUE,labelposition=0) PieDonut(acs,aes(Dx,smoking),selected=c(2,5,8), explodeDonut=TRUE,start=pi/2,labelposition=0) PieDonut(acs,aes(Dx,smoking),r0=0.2,r1=0.9,r2=1.3,explode=1,start=pi/2,explodeDonut=TRUE) PieDonut(acs,aes(Dx,smoking),r0=0.2,r1=0.9,r2=1.3,explode=1,start=pi/2,labelposition=0) PieDonut(acs,aes(Dx,smoking),explode=1,start=pi,explodeDonut=TRUE,labelposition=0) require(dplyr) df=mtcars %>% group_by(gear,carb) %>% summarize(n=n()) PieDonut(df,aes(pies=gear,donuts=carb,count=n),ratioByGroup=FALSE)
Plotting distribution of statistic for object "htest"
## S3 method for class 'htest' plot(x, ...)
## S3 method for class 'htest' plot(x, ...)
x |
object of class "htest" |
... |
further arguments to ggplot |
a ggplot or NULL
require(moonBook) require(webr) ## chi-square test x=chisq.test(table(mtcars$am,mtcars$cyl)) plot(x) #Welch Two Sample t-test x=t.test(mpg~am,data=mtcars) plot(x) x=t.test(BMI~sex,data=acs) plot(x) # F test to compare two variances x=var.test(age~sex,data=acs,alternative="less") plot(x) # Paired t-test x=t.test(iris$Sepal.Length,iris$Sepal.Width,paired=TRUE) plot(x) # One sample t-test plot(t.test(acs$age,mu=63)) # Two sample t-test x=t.test(age~sex, data=acs,conf.level=0.99,alternative="greater",var.equal=TRUE) plot(x)
require(moonBook) require(webr) ## chi-square test x=chisq.test(table(mtcars$am,mtcars$cyl)) plot(x) #Welch Two Sample t-test x=t.test(mpg~am,data=mtcars) plot(x) x=t.test(BMI~sex,data=acs) plot(x) # F test to compare two variances x=var.test(age~sex,data=acs,alternative="less") plot(x) # Paired t-test x=t.test(iris$Sepal.Length,iris$Sepal.Width,paired=TRUE) plot(x) # One sample t-test plot(t.test(acs$age,mu=63)) # Two sample t-test x=t.test(age~sex, data=acs,conf.level=0.99,alternative="greater",var.equal=TRUE) plot(x)
Renew dictionary Renew dictionary
renew_dic()
renew_dic()
replace vector with labels
replaceWithLabels(x)
replaceWithLabels(x)
x |
A vector |
Runs test for randomness
runs.test( y, plot.it = FALSE, alternative = c("two.sided", "positive.correlated", "negative.correlated") )
runs.test( y, plot.it = FALSE, alternative = c("two.sided", "positive.correlated", "negative.correlated") )
y |
A vector |
plot.it |
A logical. whether or not draw a plot |
alternative |
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". |
A list with class "htest" containing the following components: statistic,p-value,method and data.name
y=c(1,2,2,1,1,2,1,2) runs.test(y) y=c("A","B","B","A","A","B","A","B") runs.test(y,alternative="p")
y=c(1,2,2,1,1,2,1,2) runs.test(y) y=c("A","B","B","A","A","B","A","B") runs.test(y,alternative="p")
Make transparent theme
transparent(size = 0)
transparent(size = 0)
size |
border size. default value is 0 |
Extract x2 statistical result
x2result(x)
x2result(x)
x |
a table |
Summarize chisquare result
x2summary( data = NULL, x = NULL, y = NULL, a, b, margin = 1, show.percent = TRUE, show.label = TRUE )
x2summary( data = NULL, x = NULL, y = NULL, a, b, margin = 1, show.percent = TRUE, show.label = TRUE )
data |
A data.frame |
x |
a column name |
y |
a column name |
a |
a vector |
b |
a vector |
margin |
numeric If 1 row percent, if 2 col percent |
show.percent |
logical |
show.label |
logical |
require(moonBook) x2summary(acs,sex,DM)
require(moonBook) x2summary(acs,sex,DM)
Make a chisquare result table
x2Table( data, x, y, margin = 1, show.percent = TRUE, show.label = TRUE, show.stat = TRUE, vanilla = FALSE, fontsize = 12, ... )
x2Table( data, x, y, margin = 1, show.percent = TRUE, show.label = TRUE, show.stat = TRUE, vanilla = FALSE, fontsize = 12, ... )
data |
A data.frame |
x |
a column name |
y |
a column name |
margin |
numeric If 1 row percent, if 2 col percent |
show.percent |
logical |
show.label |
logical |
show.stat |
logical |
vanilla |
logical whether or not make vanilla table |
fontsize |
A numeric |
... |
Further arguments to be passed to df2flextable() |
require(moonBook) x2Table(acs,sex,DM)
require(moonBook) x2Table(acs,sex,DM)