Working with the raply-Output

Hello everybody,

I'm new to working with R and now I want to do a few simulations with logistic Regression. I created a data set with a binary Outcome and a normally distributed predictor. I also wrote a function() that performs the logistic Regression and Returns the confidence Intervalls of the Odd Ratios at the end.

I would like to have issued the OR itself, but that didn't work, because you only write one Argument in return(). But at first that doesn't matter.

My Goal is to get the whole CI to summarize, i.e. to take the Limits of the intervals and determine the mean value for These.

It that possible somehow?

Here is my Code:

library(plyr)
library(MASS)
library(epitools)

#sigmoid-function
sigmoid <- function(x){
return(1/(1 + exp(-x)))
}

#create a data set
simdat <- function(n, beta_0, beta_1, x.mean, x.sd){
x <- rnorm(n)
lin_pred <- beta_0 + beta_1 * x
prob <- sigmoid(lin_pred)
y <- rbinom(n, size = 1, prob = prob)
data.frame(x, y)
}

#logistic function and CI
CI <- function(d){
fit <- glm(y~x, family = binomial(link='logit'), data = d)
return(exp(confint(fit)))
}

#run 100 times
raply(100,CI(simdat(100, 1, 2, 5, 1)))

Thank you and best wishes :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.