I am looking for a way to make a proper power analysis for a logistical regression in R. So, I created this model for a logistical regression:
model <- glm(df1$fish. ~ df1$Temperature, family="binomial", data=df1)
options(scipen=999)
summary(model)
# McFadden’s R2 to test if model fits
library("pscl")
pscl::pR2(model)["McFadden"]
To evaluate if I have a good sample size, I wanted to make a power analysis. Here
I found a code to use for that.
library("pwr")
plot(pwr.f2.test(u=1, v=(1:48), f2=?, sig.level=0.05)$power,
3:50, xlab="power", ylab="sample size")
# u = number of coefficients in the model minus the intercept (2 - 1 = 1)
# v = number of error degrees of freedom (v = n - u - 1)
# f2 = effect size = ?
abline(h=19) # enter my sample size
pwr.f2.test(u=1, v=(19-1-1), f2=?, sig.level=0.05)$power # output number (percentage probability)
However, my problem now is, that I don't know what to enter for an effect size f2. On the link above it says, that you use R2/(1-R2). In my case, I don't have an R2, only a MC Fadden's R2 (~0.495555), which is obviously not the same, so I cannot use it the same way.
Can someone explain to me, what exactly the McFadden's R2, as well as the f2 is and what it tells me? Does anyone know what I have to enter for f2 in my case?
I used the following steps, to validate my regression model:
# make predictions
predicted <- predict(model, df1, type="response")
predicted
# predicts the probability of fish appearing at a certain temperature
# validate model with confusion matrix
confmatrix <- table(actualValue = df1$fish, predictedValue = predicted > 0.5)
confmatrix
# percentage accuracy
(confmatrix[[1, 1]] + confmatrix[[2, 2]]) / sum(confmatrix)
#find optimal cutoff probability to use to maximize accuracy
library(InformationValue)
optimal <- optimalCutoff(df1$fish, predicted)[1]
optimal
# calculate sensitivity: “true positive rate”
sensitivity(df1$fish, predicted)
#calculate specificity: “true negative rate”
specificity(df1$fish, predicted)
# calculate total misclassification error rate
misClassError(df1$fish, predicted, threshold=optimal)
#plot the ROC curve
plotROC(df1$fish, predicted)
My thought was, whether I can use the confmatrix as an effect size? It seems to be similar to R2, however I am not sure if I have understood it correctly. It is just an idea I had, but I am only guessing here.