Skip to content

Commit 18f4db5

Browse files
committed
add categorical slides
1 parent 3af7d31 commit 18f4db5

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

categorical.Rmd

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pval <- round(csq$p.value,2)
9797
```
9898

9999
Test statistic: ${\chi_1}^2$ = `r pval`
100-
df = `degf`
100+
df = `r degf`
101101
P-value = `r pval`
102102

103103
***Do not reject $H_0$ (No evidence of an association between treatment group and tumour shrinkage)***
@@ -176,6 +176,42 @@ exp <- round(chisq.test(df)$expected,1)
176176
exp
177177
```
178178

179+
## CHi-square test for trend
180+
181+
```{r}
182+
df <- data.frame(Tumour.Did.Not.Shrink = c(18,15,11), Tumour.Did.Shrink = c(5,14,21))
183+
rownames(df) <- c("Grade 1","Grade 2", "Grade 3")
184+
obs.prop <- df$Tumour.Did.Shrink/ rowSums(df)
185+
plot(c(2,3,4),obs.prop,pch="x",col="blue",xlim=c(1,5),ylim=c(0,1),xlab="Tumour Grade",ylab="Proportion with tumour shrinkage ")
186+
lm.h0 <- lm(obs.prop ~ c(2,3,4))
187+
abline(lm.h0,col="blue")
188+
abline(h=0.5,col="red")
189+
points(c(2,3,4),rep(0.5,3),pch="x",col="red")
190+
legend("topright", col=c("blue","red"),legend=c("H0","H1"),lty=c(1,1))
191+
```
192+
193+
194+
## Chi-square test for trend - Results
195+
196+
Test statistic: $$\chi_1^2 = 10.18$$
197+
df = 1
198+
P-value = 0.001
199+
200+
Conclusion:- Reject $H`_0$ (evidence of a linear association between tumour grade and tumour shrinkage)
201+
202+
```{r fig.height=6,fig.width=6}
203+
degf <- 1
204+
205+
xmax <- max(4,csq$statistic)
206+
xs <- seq(0, xmax, length.out = 10000)
207+
df <- data.frame(X = xs, Y = dchisq(xs,degf))
208+
209+
title <- substitute(paste(chi^2, " with ", degf, " degrees of freedom"),list(degf=degf))
210+
211+
p <- ggplot(df, aes(x=X,y=Y)) + geom_line() + ggtitle(title)
212+
p
213+
```
214+
179215

180216
## Summary - Categorical variables
181217

@@ -185,6 +221,8 @@ exp
185221
- Fishers exact test
186222
+ Use when we have two categorical variables, each with two levels, and our expected frequencies are small.
187223

224+
- ***Exercise***
225+
+ Complete "Tests for categorical variables" section of practical
188226

189227

190228
## Small group Exercise

categorical.html

Lines changed: 16 additions & 4 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)