---
title: "Lesson context teaching practices"
author: "Matteo"
date: "19/01/2021"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

library(stats)
library(readr)
library(tidyverse)
library(MASS)
library(sjPlot)
library(DCluster)
library(rcompanion)
#dataset
setwd("C:/Users/Utente/Documents/Matteo PhD/study3")
data<-read_csv("C:/Users/Utente/Documents/Matteo PhD/study3/TeachingFINALdata.csv")
#to check variance
data1<-data%>%
  filter(group %in% c(1))
data2<-data%>%
  filter(group %in% c(2))
data3<-data%>%
  filter(group %in% c(3))

data$group<-as.factor(data$group)
data$group
data$teacher<-as.factor(data$teacher)
data$teacher

```





```{r cars, message=FALSE, warning=FALSE, paged.print=FALSE, include=FALSE}

#Knowledge Poisson / Negative Binomial
mean(data1$Knowledge)
var(data1$Knowledge)
mean(data2$Knowledge)
var(data2$Knowledge)
mean(data3$Knowledge)
var(data3$Knowledge)

Knowledge1<-glm(Knowledge~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
Knowledge2<-glm.nb(Knowledge ~ group +offset(log(Countofnumber)), data= data)

summary(Knowledge1)
summary(Knowledge2)

#likelyhood ratio test and Dean's test
test.nb.pois(Knowledge2, Knowledge1)
DeanB(Knowledge1, alternative="greater")
DeanB2(Knowledge1, alternative="greater")

#exponentialised coefficients
x<-coef(Knowledge2)
exp(x)

tab_model(Knowledge1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(Knowledge2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)


#Management Poisson / Negative Binomial
mean(data1$Management)
var(data1$Management)
mean(data2$Management)
var(data2$Management)
mean(data3$Management)
var(data3$Management)

Management1<-glm(Management~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
Management2<-glm.nb(Management ~ group +offset(log(Countofnumber)), data= data)

summary(Management1)
summary(Management2)

#likelyhood ratio test and Dean's test
test.nb.pois(Management2, Management1)
DeanB(Management1, alternative="greater")
DeanB2(Management1, alternative="greater")

#exponentialised coefficients
x<-coef(Management2)
exp(x)

tab_model(Management1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(Management2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)





#Motorcontent Poisson / Negative Binomial
mean(data1$Motorcontent)
var(data1$Motorcontent)
mean(data2$Motorcontent)
var(data2$Motorcontent)
mean(data3$Motorcontent)
var(data3$Motorcontent)

Motorcontent1<-glm(Motorcontent~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
Motorcontent2<-glm.nb(Motorcontent ~ group +offset(log(Countofnumber)), data= data)

summary(Motorcontent1)
summary(Motorcontent2)

#likelyhood ratio test and Dean's test
test.nb.pois(Motorcontent2, Motorcontent1)
DeanB(Motorcontent1, alternative="greater")
DeanB2(Motorcontent1, alternative="greater")

#exponentialised coefficients
x<-coef(Motorcontent2)
exp(x)

tab_model(Motorcontent1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(Motorcontent2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)



#Fitness Poisson / Negative Binomial
mean(data1$Fitness)
var(data1$Fitness)
mean(data2$Fitness)
var(data2$Fitness)
mean(data3$Fitness)
var(data3$Fitness)

Fitness1<-glm(Fitness~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
Fitness2<-glm.nb(Fitness ~ group +offset(log(Countofnumber)), data= data)

summary(Fitness1)
summary(Fitness2)

#likelyhood ratio test and Dean's test
test.nb.pois(Fitness2, Fitness1)
DeanB(Fitness1, alternative="greater")
DeanB2(Fitness1, alternative="greater")

#exponentialised coefficients
x<-coef(Fitness2)
exp(x)

tab_model(Fitness1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(Fitness2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)



#SkillPractice Poisson / Negative Binomial
mean(data1$SkillPractice)
var(data1$SkillPractice)
mean(data2$SkillPractice)
var(data2$SkillPractice)
mean(data3$SkillPractice)
var(data3$SkillPractice)

SkillPractice1<-glm(SkillPractice~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
SkillPractice2<-glm.nb(SkillPractice ~ group +offset(log(Countofnumber)), data= data)

summary(SkillPractice1)
summary(SkillPractice2)

#likelyhood ratio test and Dean's test
test.nb.pois(SkillPractice2, SkillPractice1)
DeanB(SkillPractice1, alternative="greater")
DeanB2(SkillPractice1, alternative="greater")

#exponentialised coefficients
x<-coef(SkillPractice2)
exp(x)

tab_model(SkillPractice1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(SkillPractice2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)




#GamePlay Poisson / Negative Binomial
mean(data1$GamePlay)
var(data1$GamePlay)
mean(data2$GamePlay)
var(data2$GamePlay)
mean(data3$GamePlay)
var(data3$GamePlay)

GamePlay1<-glm(GamePlay~ group+offset(log(Countofnumber)), family= "poisson",  data= data)
GamePlay2<-glm.nb(GamePlay ~ group +offset(log(Countofnumber)), data= data)

summary(GamePlay1)
summary(GamePlay2)

#likelyhood ratio test and Dean's test
test.nb.pois(GamePlay2, GamePlay1)
DeanB(GamePlay1, alternative="greater")
DeanB2(GamePlay1, alternative="greater")

#exponentialised coefficients
x<-coef(GamePlay2)
exp(x)

tab_model(GamePlay1,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
tab_model(GamePlay2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)





```

## Results


```{r pressure, echo=FALSE}

summary(Knowledge2)
tab_model(Knowledge2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(Knowledge2)



summary(Management2)
tab_model(Management2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(Management2)


summary(Motorcontent2)
tab_model(Motorcontent2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(Motorcontent2)


summary(Fitness2)
tab_model(Fitness2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(Fitness2)


summary(SkillPractice2)
tab_model(SkillPractice2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(SkillPractice2)


summary(GamePlay2)
tab_model(GamePlay2,show.ci = 0.95,string.ci=TRUE, show.se = TRUE)
nagelkerke(GamePlay2)


```


