function returning observed Cronbach alpha with bootstrap confidence interval around that value
getBootCIalpha.Rdfunction returning observed Cronbach alpha with bootstrap confidence interval around that value
Usage
getBootCIalpha(
dat,
verbose = TRUE,
na.rm = TRUE,
nLT20err = TRUE,
nGT10kerr = TRUE,
bootReps = 1000,
conf = 0.95,
bootCImethod = c("perc", "norm", "basic", "bca")
)Arguments
- dat
data, matrix, data frame or tibble and numeric item data as columns
- verbose
logical, if FALSE switches off messages
- na.rm
logical which causes function to throw error if there is missing data
- nLT20err
logical, throws error if length(na.omit(dat)) < 20, otherwise returns NA for CI
- nGT10kerr
logical, throws error if length(na.omit(dat)) > 10k to prevent very long rusn, override with FALSE
- bootReps
integer for number of bootstrap replications
- conf
numeric confidence interval desired as fraction, e.g. .95
- bootCImethod
method of deriving bootstrap CI from "perc", "norm", "basic" or "bca"
See also
Other bootstrap CI functions:
getBootCICSC(),
getBootCICorr(),
getBootCIgrpMeanDiff(),
getBootCImean()
Other Chronbach alpha functions:
getChronbachAlpha()
Examples
if (FALSE) { # \dontrun{
### I will create some examples of how the function can be used,
### in base R or tidyverse modes.
### create some data: 200 rows, 10 variables
### Gaussian distribution
set.seed(12345) # just to get same data every time
matrix(rnorm(2000), ncol = 10) -> matDat
### now pipe that matrix into a data frame
matDat %>%
### this next line saves going through the rather
### laborious way of constructing variable
### names that you have to follow if
### you go direct to as_tibble() !
as.data.frame() %>%
as_tibble() %>%
### so now we have a 200x10 tibble (i.e. a
### tidyverse version of a data frame)
### let's make some of these participants
### young and some old
### make the odd numbered ones "young"
mutate(age = if_else(row_number() %% 2 == 1,
"young",
"old")) %>%
### get variables in a more sensible order
select(age, everything()) -> tibDat
### OK, we have some data, let's use it!
### As with all bootstrap functions, it's wise
### to set the random number generator (RNG) seed
### before running the function to ensure you see
### exactly the same results every time.
### That's a different issue from the one above
### about setting the RNG seed to get the same data
### every time when generating data. Same principle
### different effect.
###
### this is base R idiom and using the function's default arguments
### to analyse a matrix
getBootCIalpha(matDat)
###
### this is base R analysing a tibble (or data frame)
getBootCIalpha(tibDat[ , -1])
###
### now tidyverse, still entire tibble
tibDat %>%
select(-age) %>%
summarise(alphaCI = list(getBootCIalpha(pick(everything())))) %>%
unnest_wider(alphaCI) # unnest to get the results
### more useful tidyverse, analysing the age groups separately
tibDat %>%
group_by(age) %>%
summarise(alphaCI = list(getBootCIalpha(pick(everything())))) %>%
ungroup %>%
unnest_wider(alphaCI) # unnest again
} # }