Title: | Tools for Exploring Multiple Response Data |
---|---|
Description: | Interaction and analysis of multiple response data, along with other tools for analysing these types of data including missing value analysis and calculation of standard errors for a range of covariance matrix results (proportions, multinomial, independent samples, and multiple response). |
Authors: | Tom Elliott [aut, cre] |
Maintainer: | Tom Elliott <[email protected]> |
License: | GPL-3 |
Version: | 2.3.0 |
Built: | 2025-03-13 05:32:45 UTC |
Source: | https://github.com/inzightvit/inzightmr |
The iNZightMR package provides a suite of functions which can be used in the analysis of multiple response data. It is used in the iNZight software package.
Junjie Zeng, Tom Elliott
Draws a barplot of a multiple response object (MRO), showing response rates for each option along with confidence intervals and comparison intervals.
barplotMR(obj, ...) ## S3 method for class 'mrocalc' barplotMR(obj, ...) ## S3 method for class 'bymrocalc' barplotMR(obj, g1.level = NULL, g2.level = "_MULTI", ...) ## S3 method for class 'between' barplotMR(obj, ...) ## S3 method for class 'b2' barplotMR(obj, g1.level = NULL, ...)
barplotMR(obj, ...) ## S3 method for class 'mrocalc' barplotMR(obj, ...) ## S3 method for class 'bymrocalc' barplotMR(obj, g1.level = NULL, g2.level = "_MULTI", ...) ## S3 method for class 'between' barplotMR(obj, ...) ## S3 method for class 'b2' barplotMR(obj, g1.level = NULL, ...)
obj |
an |
... |
additional parameters, currently not used |
g1.level |
vector of subset variable 1 levels to show |
g2.level |
vector of subset variable 2 levels to show |
barplotMR(mrocalc)
: method for class mrocalc
barplotMR(bymrocalc)
: method for class bymrocalc
barplotMR(between)
: method for class between
barplotMR(b2)
: method for class b2
Junjie Zheng
if (requireNamespace("iNZightPlots")) { require(iNZightPlots) mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000 ) barplotMR(mroPara(mr)) barplotMR(byMRO(mr, ~gender, mroPara)) }
if (requireNamespace("iNZightPlots")) { require(iNZightPlots) mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000 ) barplotMR(mroPara(mr)) barplotMR(byMRO(mr, ~gender, mroPara)) }
Between SEs
between(bymro)
between(bymro)
bymro |
a bymro object |
something about between.
Junjie Zheng
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) (bt <- between(byMRO(mr, ~gender, mroPara))) if (requireNamespace("iNZightPlots")) barplotMR(bt)
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) (bt <- between(byMRO(mr, ~gender, mroPara))) if (requireNamespace("iNZightPlots")) barplotMR(bt)
Constructs a multiple response object (MRO) subset by another explanatory variable.
byMRO(mro.obj, formula, FUN, ...)
byMRO(mro.obj, formula, FUN, ...)
mro.obj |
an mro object (created by |
formula |
variable for subsetting, as a formula (e.g., |
FUN |
the function to apply to subsets |
... |
additional arguments passed to |
an object with classes of by
and bymrocalc
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000 ) byMRO(mr, ~gender, mroPara) byMRO(mr, ~ gender + handed, mroPara)
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000 ) byMRO(mr, ~gender, mroPara) byMRO(mr, ~ gender + handed, mroPara)
Calculates the summary of missingness in a data set.
calcmissing(obj, ...) ## S3 method for class 'data.frame' calcmissing(obj, MRO.case = FALSE, ...) ## S3 method for class 'mro' calcmissing(obj, ...)
calcmissing(obj, ...) ## S3 method for class 'data.frame' calcmissing(obj, MRO.case = FALSE, ...) ## S3 method for class 'mro' calcmissing(obj, ...)
obj |
An object |
... |
additional arguments |
MRO.case |
does something with rownames |
Missing value object
calcmissing(data.frame)
: Method for a dataframe
calcmissing(mro)
: accepts a whole mr.object , which is first mro.mat, second element labels,
third element the input data frame.
Junjie Zeng
plotcombn
calcmissing(census.at.school.5000[, 1:20])
calcmissing(census.at.school.5000[, 1:20])
A dataset containing 5000 observations from a New Zealand census of school students. It includes binary response variables.
census.at.school.5000
census.at.school.5000
A data frame with 72 variables and 5000 rows.
unique identifier for each observation
their biological gender
their age, years
The country the student is from
Country code
A different country code
binary for ethnicity english
binary for ethnicity maori
binary for ethnicity wsm
binary for ethnicity cok
binary for ethnicity tonga
binary for ethnicity niue
binary for ethnicity china
binary for ethnicity india
factor for other ethnicity
factor for other ethnicity_en
factor for other ethnicity_mi
how many languages they know
left, right, or ambi
height measurement, cm
length of the right foot, mm
their armspan measurement, cm
wrist measurement
neck measurement
another measurement
index finger measurement
ring finger measurement
the length of their hair
travel method used to get to school
how long they spend travelling
the weight of the bag
weight of the bag
factor of how they're carrying
their favourite subject
their favourite subject?
a memory score
a reaction score
what sport they play
what sport they play
binary for use of TV
binary for use of mp3
binary for use of the internet
binary for use of mobile internet
binary for use of facebook
binary for use of twitter
binary for use of bebo
binary for use of myspace
binary for use of skype
binary for use of a console
binary for use of no technology
how many months they've had a cellphone?
binary for if they listen to music online
binary for if they watch video online
binary for if they play games online
binary for if they talk to friends online
binary for if they access school online
binary for if they do anything else online
binary for if they do nothing online
hours spent in bed
hours spent awake
the name of their favourite TV show
the name of their favourite TV show
binary about warm
binary about pollution
binary about recycling
binary about water
binary about lifestyle
binary about energy
binary about government
binary about computer
number of the region they're in
their school year
http://new.censusatschool.org.nz/
Creates a multiple response object (MRO) containing binary response matrix (zeros and ones) as well as the input data source.
iNZightMR(frm, data, Labels = NULL, inverse = FALSE, ...)
iNZightMR(frm, data, Labels = NULL, inverse = FALSE, ...)
frm |
formula containing the response variables |
data |
a data.frame containing response and explanatory variables |
Labels |
labels for the response categories; by default, the function
will attempt to. Can also be the function |
inverse |
if |
... |
additional arguments, passed to |
The individual response variable names can be detected from the
variable name by passing Labels = substrsplit
.
For example, in 'ethniceng' and 'ethnicmri', 'ethnic' is common
to both, so the labels will be 'eng' and 'mri'.
If a user wants to inverse the response (zeros becomes ones), then pass
inverse = TRUE
. This is useful when the responses are characters
(such as "correct" and "wrong", where correct would be given a zero)
and the order needs reversing (so that correct is 1 instead).
An mro
object containing a multiple response binary matrix and input
data source
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) # users can also override the variable names iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, Labels = c("gaming", "youtube", "spotify"), data = census.at.school.5000 )
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) # users can also override the variable names iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, Labels = c("gaming", "youtube", "spotify"), data = census.at.school.5000 )
Computes the margin of error for various objects.
moecalc( x, factorname = NULL, levelnames = NULL, coef.idx = NULL, est = NULL, ci = NULL, base = TRUE, basename = "base", conf.level = 1.96 )
moecalc( x, factorname = NULL, levelnames = NULL, coef.idx = NULL, est = NULL, ci = NULL, base = TRUE, basename = "base", conf.level = 1.96 )
x |
the object for which we compute margins of error |
factorname |
name of factor |
levelnames |
names of factor levels |
coef.idx |
index of coefficient to use |
est |
estimates |
ci |
confidence intervals |
base |
baseline |
basename |
name of baseline |
conf.level |
level of confidence to use |
If x
is a model, must have factorname or coefficient index (coef.idx)
If input factorname, will compute ErrBars by factorname (for given model)
If input coefficient index, will compute ErrBars simply by index only (even they are not factor)
If x
is ses.moecalc
object, will compute ErrBars simply by given ses.moecalc
object
a moecalc
object
fit <- lm(Sepal.Length ~ Species, data = iris) (mc <- moecalc(fit, "Species")) summary(mc) plot(mc)
fit <- lm(Sepal.Length ~ Species, data = iris) (mc <- moecalc(fit, "Species")) summary(mc) plot(mc)
Calculates required proportions, their differences, variance-covariance matrices, standard errors of differences, and comparison intervals for differences, over all of the data. To compute values over various subsets of another explanatory variable, see by.
mroPara(obj, conf.levels = 1.96, nonparallel = NULL)
mroPara(obj, conf.levels = 1.96, nonparallel = NULL)
obj |
an MRO object created by |
conf.levels |
confidence level to use, default is 1.96 for 95% intervals |
nonparallel |
Should these things be parallel? |
An object of class mrocalc
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) mrp <- mroPara(mr)
mr <- iNZightMR(online ~ onlinegame + onlinevideo + onlinemusic, data = census.at.school.5000) mrp <- mroPara(mr)
Plot of Missing Value combinations
plotcombn(obj)
plotcombn(obj)
obj |
a calcmissing object |
summarised info for plot
Junjie Zeng
plotcombn(census.at.school.5000[, 10:25])
plotcombn(census.at.school.5000[, 10:25])
Compute SEs for Independent Binomial Proportions
seBinprops(ns, phats)
seBinprops(ns, phats)
ns |
the number of observations in the independent groups |
phats |
the proportions of TRUE/1's etc. |
an ses.moecalc
object
Junjie Zeng
seBinprops(c(50, 30), c(0.3, 0.7))
seBinprops(c(50, 30), c(0.3, 0.7))
Compute the standard error information for a given covariance matrix.
seCovs(covs, addbase = FALSE)
seCovs(covs, addbase = FALSE)
covs |
covariance matrix |
addbase |
logical, is there a baseline? |
an ses.moecalc object
Junjie Zeng
seCovs(cov(iris[, -5]))
seCovs(cov(iris[, -5]))
Returns ses.moecalc for given SEs
seIndepSes(ses)
seIndepSes(ses)
ses |
the standard errors |
an ses.moecalc
object
Junjie Zeng
seIndepSes(c(0.02, 0.05, 0.1))
seIndepSes(c(0.02, 0.05, 0.1))
SEs for Multinomial Proportions
seMNprops(n, phat)
seMNprops(n, phat)
n |
the number of observations in each group |
phat |
the estimates proportions for each group |
an ses.moecalc
object
Junjie Zeng
phat <- table(iris$Species) / nrow(iris) seMNprops(nrow(iris), phat)
phat <- table(iris$Species) / nrow(iris) seMNprops(nrow(iris), phat)
SE's for multiple binary response
seMRprops(obj)
seMRprops(obj)
obj |
something that can be turned into a matrix |
an ses.moecalc
object
Junjie Zeng
x <- data.frame( v1 = rbinom(20, 1, 0.8), v2 = rbinom(20, 1, 0.3), v3 = rbinom(20, 1, 0.5) ) seMRprops(x)
x <- data.frame( v1 = rbinom(20, 1, 0.8), v2 = rbinom(20, 1, 0.3), v3 = rbinom(20, 1, 0.5) ) seMRprops(x)
Help mro variables extract common name out
substrsplit(obj, split_string = "")
substrsplit(obj, split_string = "")
obj |
It can be a vector or data frame, however, |
split_string |
Specification of a string to allow splits on (e.g., use " " to only allow splitting at words). |
A list with common character and unique variable name respectively
substrsplit(c("varx", "vary", "varz")) strings <- c("Do you like eating eggs?", "Do you like elephants?" , "Do you like elections?") substrsplit(strings) substrsplit(strings, split_string = " ")
substrsplit(c("varx", "vary", "varz")) strings <- c("Do you like eating eggs?", "Do you like elephants?" , "Do you like elections?") substrsplit(strings) substrsplit(strings, split_string = " ")