data(lsa)
### Example 1: only means, SD and variances for each country
### subsetting: We only consider domain 'reading'
rd <- lsa[which(lsa[,"domain"] == "reading"),]
### We only consider the first "nest".
rdN1 <- rd[which(rd[,"nest"] == 1),]
### First, we only consider year 2010
rdN1y10<- rdN1[which(rdN1[,"year"] == 2010),]
# \donttest{
### First example: Computes frequencies of polytomous competence levels (1, 2, 3, 4, 5)
### conditionally on country, using a chi-square test to decide whether the distribution
### varies between countries (it's an overall test, i.e. with three groups, df1=8).
freq.tab1 <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country",
group.differences.by = "country", dependent = "comp", chiSquare = TRUE)
res1 <- report(freq.tab1, add = list ( domain = "reading" ))
### Second example: Computes frequencies of polytomous competence levels (1, 2, 3, 4, 5)
### conditionally on country. Now we test whether the frequency of each single category
### differs between pairs of countries (it's not an overall test ... repTable now
### calls repMean internally, using dummy variables)
freq.tab2 <- repTable(datL = rdN1y10, ID = "idstud", wgt = "wgt", imp="imp",
type = "JK2", PSU = "jkzone", repInd = "jkrep", groups = "country",
group.differences.by = "country", dependent = "comp", chiSquare = FALSE)
res2 <- report(freq.tab2, add = list ( domain = "reading" ))
### Third example: trend estimation and nested imputation and 'by' loop
### (to date, only crossDiffSE = "old" works)
freq.tab3 <- by ( data = lsa, INDICES = lsa[,"domain"], FUN = function (subdat) {
repTable(datL = subdat, ID = "idstud", wgt = "wgt", imp="imp",
nest = "nest", type = "JK2", PSU = "jkzone", repInd = "jkrep",
groups = "country", group.differences.by = "country",
group.splits = 0:1, cross.differences = TRUE, crossDiffSE = "old",
dependent = "comp", chiSquare = FALSE, trend = "year",
linkErr = "leComp") })
res3 <- do.call("rbind", lapply(names(freq.tab3), FUN = function (domain) {
report(freq.tab3[[domain]], add = list ( domain = domain )) }))
### Fourth example: similar to example 3. trend estimation using a linking
### error data.frame
linkErrs <- data.frame ( trendLevel1 = 2010, trendLevel2 = 2015, depVar = "comp",
unique(lsa[,c("domain", "comp", "leComp")]), stringsAsFactors = FALSE)
colnames(linkErrs) <- car::recode(colnames(linkErrs),
"'comp'='parameter'; 'leComp'='linkingError'")
freq.tab4 <- by ( data = lsa, INDICES = lsa[,"domain"], FUN = function (subdat) {
repTable(datL = subdat, ID = "idstud", wgt = "wgt", type="none",
imp="imp", nest = "nest", groups = "country",
group.differences.by = "country", group.splits = 0:1,
cross.differences = FALSE, dependent = "comp", chiSquare = FALSE,
trend = "year",
linkErr = linkErrs[which(linkErrs[,"domain"] == subdat[1,"domain"]),])
})
res4 <- do.call("rbind", lapply(names(freq.tab4), FUN = function (domain) {
report(freq.tab4[[domain]], add = list ( domain = domain )) }))
### Fifth example: minimal example for three measurement occasions
### borrow data from the eatGADS package
trenddat1 <- system.file("extdata", "trend_gads_2010.db", package = "eatGADS")
trenddat2 <- system.file("extdata", "trend_gads_2015.db", package = "eatGADS")
trenddat3 <- system.file("extdata", "trend_gads_2020.db", package = "eatGADS")
trenddat <- eatGADS::getTrendGADS(filePaths = c(trenddat1, trenddat2, trenddat3),
years = c(2010, 2015, 2020), fast=FALSE)
dat <- eatGADS::extractData(trenddat)
### use template linking Error Object
load(system.file("extdata", "linking_error.rda", package = "eatRep"))
### check consistency of data and linking error object
check1 <- checkLEs(c(trenddat1, trenddat2, trenddat3), lErr)
### Analysis for reading comprehension
freq.tab5 <- repTable(datL = dat[which(dat[,"dimension"] == "reading"),],
ID = "idstud", type="none", imp="imp", dependent = "traitLevel",
chiSquare = FALSE, trend = "year",
linkErr = lErr[which(lErr[,"domain"] == "reading"),])
res5 <- report(freq.tab5, add = list ( domain = "reading" ))
res5A <- report2(freq.tab5, add = list ( domain = "reading" ))
# }
Run the code above in your browser using DataLab