From 27856dfd2dca3eed4eaac28689b5746f74d006aa Mon Sep 17 00:00:00 2001 From: mjgaughan Date: Tue, 14 Nov 2023 22:54:32 -0600 Subject: [PATCH] binning age and trying to figure out power --- R/calculatePower.R | 11 +++++++++-- R/powerAnalysis.R | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/calculatePower.R b/R/calculatePower.R index 90be49f..669addf 100644 --- a/R/calculatePower.R +++ b/R/calculatePower.R @@ -34,12 +34,19 @@ table(data1$milestones) hist(data1$old_mmt) #inequality of participation hist(data1$formal.score) hist(data1$age/365) + +data1$new.age <- as.numeric(cut(data1$age/365, breaks=c(0,9,12,15,17), labels=c(1,2,3,4))) +data1$formal.score <- data1$mmt / (data1$milestones/data1$new.age) +hist(as.numeric(data1$new.age)) +table(data1$formal.score) kmodel1 <- lm(up.fac.mean ~ mmt, data=data1) summary(kmodel1) kmodel1 <- lm(up.fac.mean ~ old_mmt, data=data1) summary(kmodel1) kmodel1 <- lm(up.fac.mean ~ formal.score, data=data1) summary(kmodel1) +kmodel1 <- lm(up.fac.mean ~ new.age, data=data1) +summary(kmodel1) hist(data1$formal.score) cor.test(data1$formal.score, data1$up.fac.mean) cor.test(data1$mmt, data1$up.fac.mean) @@ -52,13 +59,13 @@ g <- ggplot(data1, aes(x=mmt, y=up.fac.mean)) + g data2 <- subset(data1, (data1$age / 365) < 14 ) -hist(data2$age) +hist(floor(data2$age)) g <- ggplot(data2, aes(x=formal.score, y=up.fac.mean)) + geom_point() + geom_smooth() g -data2$yearsOld <- data2$age / 365 +data2$yearsOld <- floor(data2$age / 365) kmodel2 <- lm(up.fac.mean ~ mmt + milestones + age, data=data1) kmodel5 <- lm(up.fac.mean ~ mmt + milestones, data=data1) diff --git a/R/powerAnalysis.R b/R/powerAnalysis.R index 8eb0c44..aab5f18 100644 --- a/R/powerAnalysis.R +++ b/R/powerAnalysis.R @@ -55,6 +55,7 @@ powerCheck <- function(n, nSims) { #run a power calculation on the dataset given simData <- makeDataNew(n) # make some data ## outcome goes here --v # e.g. simData$up.fac.mean <- (usefuleffsizeA * mmt) + (usefuleffsizeB * milestones) + rnorm(n=1, mean=0, sd=1) ##plus some noise + simData$up.fac.mean <- (2 * simData$mmt) + (1.5 * simData$milestones) + rnorm(n=1, mean=0, sd=1) #have updated for kkex through here, now need to look at the underproduction work #m1.sim <- lm(up.fac.mean ~ ((mmt)/ (milestones/age)), data=simData) ## could leave age out for now? @@ -84,7 +85,7 @@ powerCheck2 <- function(n, nSims) { #run a power calculation on the dataset give #have updated for kkex through here, now need to look at the underproduction work #m1.sim <- lm(up.fac.mean ~ ((mmt)/ (milestones/age)), data=simData) ## outcome goes here --v - ## e.g. simData$up.fac.mean <- (usefuleffsizeC * formal.score) + rnorm(1, mean=0, sd=1) ##plus some noise + simData$up.fac.mean <- (0.5 * simData$formal.score) + rnorm(1, mean=0, sd=1) ##plus some noise m1.sim <- lm(up.fac.mean ~ formal.score, data=simData) p0 <- coef(summary(m1.sim))[1,4] p1 <- coef(summary(m1.sim))[2,4]