Skip to content

Commit

Permalink
change DESCRIPTION, README, app.R, FILES
Browse files Browse the repository at this point in the history
  • Loading branch information
Phichchaya27 committed Jul 11, 2022
1 parent 9f4662f commit 76794fd
Show file tree
Hide file tree
Showing 12 changed files with 492 additions and 315 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Title: ANCOVA
Title: Analysis of Covariance
ShortName: ANCOVA
Date: 2022-06-10
Lifecycle: experimental
Date: 2018-08-01
Lifecycle: questioning
Authors@R: c(
person(given = "Luxin", family = "Wang", role = c("aut", "cre")),
person(given = "Zhiruo", family = "Wang", role = c("aut")),
Expand All @@ -11,7 +11,7 @@ Authors@R: c(
person(given = "Phichchaya", family = "Sutaporn", role = c("ctb"))
)
Chapter: Chapter 7
Description: This app introduces the concept of ANCOVA focusing on interpreting interaction plots.
Description: "The student will learn to use interaction plots to decide whether interaction terms are significant in ANCOVA settings."
LearningObjectives: c(
"The student will learn to how to interpret interaction plots in order to determine
if interaction terms are significant."
Expand Down
123 changes: 58 additions & 65 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ library(shinydashboard)
library(simstudy)
library(shinyWidgets)
library(boastUtils)
library(fontawesome)
# library(sortable)
library(sortable)

# Set constants ----
maxScore <- 10

# Load data ? ----
# Load data ----
seaotters <- read.csv("Otter.csv",header=T)

diet <- read.csv("Diet.csv",header=T)
diet$Diet<-as.character(diet$Diet)

bank = read.csv("questionbank.csv")
bank = data.frame(lapply(bank, as.character), stringsAsFactors = FALSE)

# Define UI ----
ui <- list(
Expand Down Expand Up @@ -255,17 +261,17 @@ ui <- list(
conditionalPanel(
condition = "input.menu1 == 'Diet'",
radioButtons(
inputId = 'select_conti',
label = 'Select Continous Variable',
inputId = 'selectConti',
label = 'Select Continuous Variable',
inline = TRUE,
choices = c('Age',
'Height',
'Pre-diet Weight'),
selected = 'Age'
),
radioButtons(
inputId = 'select_covar',
label = 'Select Covariance',
inputId = 'selectCovar',
label = 'Select Covariate',
inline = TRUE,
choices = c('Gender',
'Diet'),
Expand Down Expand Up @@ -318,7 +324,7 @@ ui <- list(
),

mainPanel(
plotOutput('plot_gg'),
plotOutput('plotGg'),
tags$b(verbatimTextOutput('analysis1')),
)
),
Expand All @@ -332,6 +338,7 @@ ui <- list(
)
)
),
### Game page ----
tabItem(tabName='game',
h2("Matching Game"),
p("Drag the items in each column so that the plots in the first column
Expand Down Expand Up @@ -459,11 +466,6 @@ ui <- list(
"Hijmans, R. J. (2021). raster: Geographic Data Analysis and Modeling.
(v3.4-10) [R Package]. Available from https://CRAN.R-project.org/package=raster"
),
p(
class = "hangingindent",
"Iannone, R. (2021). fontawesome: Easily work with 'Font Awesome' Icons.
(v0.2.1) [R Package]. Available from https://CRAN.R-project.org/package=fontawesome"
),
p(
class = "hangingindent",
"Perrier, V., Meyer, F., Granjon, D. (2019). shinyWidgets: Custom in
Expand Down Expand Up @@ -498,24 +500,15 @@ ui <- list(
)



seaotters <- read.csv("Otter.csv",header=T)

diet <- read.csv("Diet.csv",header=T)
diet$Diet<-as.character(diet$Diet)

bank = read.csv("questionbank.csv")
bank = data.frame(lapply(bank, as.character), stringsAsFactors = FALSE)

#Server ----
server <- function(input, output, session) {
observeEvent(
eventExpr = input$info,
handlerExpr = {
sendSweetAlert(
session = session,
title = "Instructions:",
type = NULL,
title = "Instructions",
type = info,
closeOnClickOutside = TRUE,
text = "Pick a data set and variables to view the interaction plot and the
associated ANOVA table."
Expand Down Expand Up @@ -587,49 +580,49 @@ server <- function(input, output, session) {
pred.data <- mutate(pred.data,
Otters = predict(otters.model, pred.data))

diet.model<-lm(ab_change ~ gender + Diet + Age + Height + pre.weight + gender:Age
diet.model<-lm(abChange ~ gender + Diet + Age + Height + pre.weight + gender:Age
+ gender:Height + gender:pre.weight + Diet:Age + Diet:Height +
Diet:pre.weight,
data = diet)

diet.model2<-lm(ab_change ~ Age + gender + Age:gender,
diet.model2<-lm(abChange ~ Age + gender + Age:gender,
data=diet)
pred.data2 <- expand.grid(Age = 16:60, gender = c("M", "F"))
pred.data2 <- mutate(pred.data2, ab_change = predict(diet.model2, pred.data2))
pred.data2 <- mutate(pred.data2, abChange = predict(diet.model2, pred.data2))

diet.model3 <- lm(ab_change ~ Height + gender + Height:gender,
diet.model3 <- lm(abChange ~ Height + gender + Height:gender,
data=diet)
pred.data3 <- expand.grid(Height = 141:201, gender = c("M", "F"))
pred.data3 <- mutate(pred.data3, ab_change = predict(diet.model3, pred.data3))
pred.data3 <- mutate(pred.data3, abChange = predict(diet.model3, pred.data3))

diet.model4 <- lm(ab_change ~ pre.weight + gender + pre.weight:gender,
diet.model4 <- lm(abChange ~ pre.weight + gender + pre.weight:gender,
data=diet)
pred.data4 <- expand.grid(pre.weight = 58:103, gender = c("M", "F"))
pred.data4 <- mutate(pred.data4, ab_change = predict(diet.model4, pred.data4))
pred.data4 <- mutate(pred.data4, abChange = predict(diet.model4, pred.data4))

diet.model5 <- lm(ab_change ~ Age + Diet + Age:Diet,
diet.model5 <- lm(abChange ~ Age + Diet + Age:Diet,
data=diet)
pred.data5 <- expand.grid(Age = 16:60, Diet = c('1','2','3'))
pred.data5 <- mutate(pred.data5, ab_change = predict(diet.model5, pred.data5))
pred.data5 <- mutate(pred.data5, abChange = predict(diet.model5, pred.data5))

diet.model6 <- lm(ab_change ~ Height + Diet + Height:Diet,
diet.model6 <- lm(abChange ~ Height + Diet + Height:Diet,
data=diet)
pred.data6 <- expand.grid(Height = 141:201, Diet = c('1','2','3'))
pred.data6 <- mutate(pred.data6, ab_change = predict(diet.model6, pred.data6))
pred.data6 <- mutate(pred.data6, abChange = predict(diet.model6, pred.data6))


diet.model7 <- lm(ab_change ~ pre.weight + Diet + pre.weight:Diet,
diet.model7 <- lm(abChange ~ pre.weight + Diet + pre.weight:Diet,
data = diet)
pred.data7 <- expand.grid(pre.weight = 58:103, Diet = c('1','2','3'))
pred.data7 <- mutate(pred.data7, ab_change = predict(diet.model7, pred.data7))
pred.data7 <- mutate(pred.data7, abChange = predict(diet.model7, pred.data7))


###save random model
rand <- reactiveValues(rand_mod=NULL)
rand <- reactiveValues(randMod=NULL)

###Graph the plot of interaction###

output$plot_gg <- renderPlot(
output$plotGg <- renderPlot(
if (input$menu1 == 'Otter') {
ggplot(pred.data,
aes(x = Year,
Expand All @@ -646,10 +639,10 @@ server <- function(input, output, session) {
axis.line = element_line(colour = "black"))
}
else if (input$menu1 == 'Diet') {
if (input$select_conti == 'Age' & input$select_covar == 'Gender') {
if (input$selectConti == 'Age' & input$selectCovar == 'Gender') {
ggplot(pred.data2,
aes(x = Age,
y = ab_change,
y = abChange,
colour = gender)) +
geom_line() +
geom_point(data = diet) +
Expand All @@ -661,10 +654,10 @@ server <- function(input, output, session) {
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
}
else if (input$select_conti == 'Height' & input$select_covar == 'Gender') {
else if (input$selectConti == 'Height' & input$selectCovar == 'Gender') {
ggplot(pred.data3,
aes(x = Height,
y = ab_change,
y = abChange,
colour = gender)) +
geom_line() +
geom_point(data = diet) +
Expand All @@ -676,10 +669,10 @@ server <- function(input, output, session) {
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Gender') {
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Gender') {
ggplot(pred.data4,
aes(x = pre.weight,
y = ab_change,
y = abChange,
colour = gender)) +
geom_line() +
geom_point(data = diet) +
Expand All @@ -691,10 +684,10 @@ server <- function(input, output, session) {
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
}
else if (input$select_conti == 'Age' & input$select_covar=='Diet') {
else if (input$selectConti == 'Age' & input$selectCovar=='Diet') {
ggplot(pred.data5,
aes(x = Age,
y = ab_change,
y = abChange,
colour =Diet)) +
geom_line() +
geom_point(data = diet) +
Expand All @@ -706,10 +699,10 @@ server <- function(input, output, session) {
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
}
else if (input$select_conti == 'Height' & input$select_covar == 'Diet') {
else if (input$selectConti == 'Height' & input$selectCovar == 'Diet') {
ggplot(pred.data6,
aes(x = Height,
y = ab_change,
y = abChange,
colour = Diet)) +
geom_line() +
geom_point(data = diet) +
Expand All @@ -721,10 +714,10 @@ server <- function(input, output, session) {
panel.background = element_blank(),
axis.line = element_line(colour = "black"))
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Diet') {
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Diet') {
ggplot(pred.data7,
aes(x = pre.weight,
y = ab_change,
y = abChange,
colour = Diet)) +
geom_line() +
geom_point(data = diet) +
Expand Down Expand Up @@ -825,22 +818,22 @@ server <- function(input, output, session) {
anova(otters.model)
}
else if (input$menu1 == 'Diet') {
if (input$select_conti == 'Age' & input$select_covar == 'Gender'){
if (input$selectConti == 'Age' & input$selectCovar == 'Gender'){
anova(diet.model2)
}
else if (input$select_conti == 'Height' & input$select_covar == 'Gender'){
else if (input$selectConti == 'Height' & input$selectCovar == 'Gender'){
anova(diet.model3)
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Gender'){
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Gender'){
anova(diet.model4)
}
else if (input$select_conti == 'Age' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Age' & input$selectCovar == 'Diet'){
anova(diet.model5)
}
else if (input$select_conti == 'Height' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Height' & input$selectCovar == 'Diet'){
anova(diet.model6)
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Diet'){
anova(diet.model7)
}
}
Expand Down Expand Up @@ -903,7 +896,7 @@ server <- function(input, output, session) {
aov.model <- lm(Y~X+cov+cov:X, data=comb)

##testing passing the model
rand$rand_mod <- anova(aov.model)[3, "Pr(>F)"]
rand$randMod <- anova(aov.model)[3, "Pr(>F)"]

anova(aov.model)
}
Expand All @@ -917,27 +910,27 @@ server <- function(input, output, session) {
var$p <- as.numeric(anova(otters.model)[3,"Pr(>F)"])
}
else if (input$menu1 == 'Diet'){
if (input$select_conti == 'Age' & input$select_covar == 'Gender'){
if (input$selectConti == 'Age' & input$selectCovar == 'Gender'){
var$p <- as.numeric(anova(diet.model2)[3,"Pr(>F)"])
}
else if (input$select_conti == 'Height' & input$select_covar == 'Gender'){
else if (input$selectConti == 'Height' & input$selectCovar == 'Gender'){
var$p <- as.numeric(anova(diet.model3)[3,"Pr(>F)"])
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Gender'){
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Gender'){
var$p <- as.numeric(anova(diet.model4)[3,"Pr(>F)"])
}
else if (input$select_conti == 'Age' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Age' & input$selectCovar == 'Diet'){
var$p <- as.numeric(anova(diet.model5)[3,"Pr(>F)"])
}
else if (input$select_conti == 'Height' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Height' & input$selectCovar == 'Diet'){
var$p <- as.numeric(anova(diet.model6)[3,"Pr(>F)"])
}
else if (input$select_conti == 'Pre-diet Weight' & input$select_covar == 'Diet'){
else if (input$selectConti == 'Pre-diet Weight' & input$selectCovar == 'Diet'){
var$p <- as.numeric(anova(diet.model7)[3,"Pr(>F)"])
}
}
else if (input$menu1 == 'Random'){
var$p <- as.numeric(rand$rand_mod)
var$p <- as.numeric(rand$randMod)
}
})

Expand Down
428 changes: 428 additions & 0 deletions docs/README.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ANCOVA

# Analysis of Covariance
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/) ![questioning](https://img.shields.io/badge/lifecycle-questioning-blue) ![year](https://img.shields.io/badge/year-2018-lightgrey)

![App Screenshot](https://sites.psu.edu/shinyapps/files/2018/12/10f8a8a7c394688207324178ba30d37354defcc6-ancova-t7s4t9.png)

# App Description
This app introduces the concept of ANCOVA focusing on interpreting interaction plots.
25 changes: 0 additions & 25 deletions model2.csv

This file was deleted.

Binary file removed www/arrow.gif
Binary file not shown.
Binary file removed www/arrow.png
Binary file not shown.
Binary file removed www/check.png
Binary file not shown.
Binary file removed www/cross.png
Binary file not shown.
Binary file removed www/homebut.PNG
Binary file not shown.
Loading

0 comments on commit 76794fd

Please sign in to comment.