RShinyCleaning

Will use dplyr to pull data together into a big file, then pull off subsets for shinyItemAnalysis.

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

ACED Items

allitems <- read.csv("data/allItems.csv")
bnscores <- read.csv("data/bnscores.csv")
demographics <- read.csv("data/prepost.csv")
demographics |> inner_join(allitems,join_by(SubjID)) |>
  inner_join(bnscores,join_by(SubjID)) ->
  acedall
#acedall                             # Only useful in interactive mode.

Data – items only

The write.csv by default puts row names/numbers as the first column, but ShinyItemAnalysis does not want them, so need to use the row.names=FALSE switch.

select(acedall,starts_with("t")) |>
  write.csv("data/shinyACED/acedItems.csv",row.names=FALSE)

Item Subsets

63 items is too many for Wright Map, so break into subscales.

select(acedall,contains("Solve")) |>
  write.csv("data/shinyACED/sgpItems.csv",row.names=FALSE)
select(acedall,contains("Ratio")) |>
  write.csv("data/shinyACED/crItems.csv",row.names=FALSE)
select(acedall,matches("Solve|Ratio")) |>
  write.csv("data/shinyACED/sgpcrItems.csv",row.names=FALSE)
select(acedall,contains("Ratio")) |>
  write.csv("data/shinyACED/crItems.csv",row.names=FALSE)
select(acedall,contains("Example")) |>
  write.csv("data/shinyACED/egItems.csv",row.names=FALSE)
select(acedall,contains("Explicit")) |>
  write.csv("data/shinyACED/expItems.csv",row.names=FALSE)
select(acedall,contains("Extend")) |>
  write.csv("data/shinyACED/extItems.csv",row.names=FALSE)
select(acedall,contains("Model")) |>
  write.csv("data/shinyACED/modItems.csv",row.names=FALSE)
select(acedall,contains("Recursive")) |>
  write.csv("data/shinyACED/rrItems.csv",row.names=FALSE)
select(acedall,contains("Table")) |>
  write.csv("data/shinyACED/tabItems.csv",row.names=FALSE)
select(acedall,contains("Verbal")) |>
  write.csv("data/shinyACED/vrItems.csv",row.names=FALSE)
select(acedall,contains("Visual")) |>
  write.csv("data/shinyACED/picItems.csv",row.names=FALSE)

Key – not needed

Group – Condition/Race/Gender/Level

ShinyItemAnalysis only accepts 0,1

For gender, we just need to map factor variable onto 0,1.

mutate(acedall,Gender1=as.integer(Gender=="Female")) |>
  select(Gender1) |> 
  write.csv("data/shinyACED/gender.csv",
            row.names=FALSE)

Study condition has three levels, related to sequencing and feedback, we can use those binary variables.

table(acedall$Condition)

 adaptive_acc adaptive_full   linear_full 
           81            77            72 
table(acedall$Sequencing.x)

Adaptive   Linear 
     158       72 
table(acedall$Feedback.x)

Accuracy     Full 
      81      149 
mutate(acedall,Sequencing=as.integer(Sequencing.x=="Adaptive")) |>
  select(Sequencing) |> 
  write.csv("data/shinyACED/sequencing.csv",
            row.names=FALSE)
mutate(acedall,Feedback=as.integer(Feedback.x=="Full")) |>
  select(Feedback) |> 
  write.csv("data/shinyACED/feedback.csv",
            row.names=FALSE)

Race is a bit more complex, as there are 8 groups.

table(acedall$Race)

 1  2  3  4  5  6  7  8 
 3 25 32  6  6 55 90 12 

Group 7 has the biggest number, so lets call that reference. Groups 2, 3 and 6 are big enough to be interesting. The dplyr::case_match function allows us to do this.

mutate(acedall,focal2=case_match(Race,
                           7 ~ 0,
                           2 ~ 1)) |>
  select(focal2) |>  
  write.csv("data/shinyACED/racef2.csv",
            row.names=FALSE)
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `focal2 = case_match(Race, 7 ~ 0, 2 ~ 1)`.
Caused by warning:
! `case_match()` was deprecated in dplyr 1.2.0.
ℹ Please use `recode_values()` instead.
mutate(acedall,focal3=case_match(Race,
                           7 ~ 0,
                           3 ~ 1)) |>
  select(focal3) |>
  write.csv("data/shinyACED/racef3.csv",
            row.names=FALSE)
mutate(acedall,focal6=case_match(Race,
                           7 ~ 0,
                           6 ~ 1)) |>
  select(focal6) |>  
  write.csv("data/shinyACED/racef6.csv",
            row.names=FALSE)

Level code has to do with the classroom type

table(acedall$Level_Code)

Academic      ELL   Honors   Part 1   Part 2  Regular 
     129       17       35       23        7       19 

Some interesting contrasts here are the regular (Honors, Academic and Regular) versus ELL and Special Ed (Parts 1 and 2). ELL had some irregularities in administration, so it is worth looking at separately.

mutate(acedall,ELL=case_match(Level_Code,
                        c("Honors", "Accademic", "Regular") ~ 0,
                        "ELL" ~1)) |>
  select(ELL) |>
  write.csv("data/shinyACED/ell.csv",
            row.names=FALSE)
mutate(acedall,SpecialEd=case_match(Level_Code,
                        c("Honors", "Accademic", "Regular") ~ 0,
                        c("Part 1","Part 2") ~1)) |>
  select(SpecialEd) |>
  write.csv("data/shinyACED/specialed.csv",
            row.names=FALSE)

Criterion – Pretest, posttest

select(acedall,pre_scaled) |> 
  write.csv("data/shinyACED/pretest.csv",
            row.names=FALSE)
select(acedall,post_scaled) |> 
  write.csv("data/shinyACED/posttest.csv",
            row.names=FALSE)

Observed Score – number right EAP

select(acedall,Correct) |> 
  write.csv("data/shinyACED/correct.csv",
            row.names=FALSE)

The best “Score” from ACED is the EAP (expected value) for the Solve Geometric Problems node.

select(acedall,EAP.sgp) |> 
  write.csv("data/shinyACED/aced_sgp.csv",
            row.names=FALSE)

Pretest and Posttest

pretestA <- read.csv("data/PretestAraw.csv")
pretestA |> filter(ItemID!="Key") |>
  select(!ItemID) |>
  write.csv("data/shinyACED/PretestAraw.csv",
            row.names=FALSE)
pretestA |> filter(ItemID=="Key") |>
  select(!ItemID) |>
  write.csv("data/shinyACED/Akey.csv")
pretestB <- read.csv("data/PretestBraw.csv")
pretestB |> filter(ItemID!="Key") |>
  select(!ItemID) |>
  write.csv("data/shinyACED/PretestBraw.csv",
            row.names=FALSE)
pretestB |> filter(ItemID=="Key") |>
  select(!ItemID) |>
  write.csv("data/shinyACED/Bkey.csv")

Equating pretest and posttest