In the following code I'm attempting to perform a logistic regression of with a dependent and independent variable, while adjusting for the factors Age and Gender.
# Assuming your dataframe is called df
# Make sure your dependent variable is a factor
heart_data$LAV_Over34 <- as.factor(heart_data$LAV_Over34)
heart_data$Age <- as.numeric(heart_data$Age)
heart_data$Gender <- as.numeric(heart_data$Gender)
# Fit logistic regression model adjusted for age and sex (change the variable names if necessary)
logistic_model <- glm(LAV_Over34 ~ HA_nonP_gap, data = heart_data + heart_data$Age + heart_data$Gender, family = "binomial")
summary(logistic_model)$coefficients[, "Estimate"]
# Calculate the 95% confidence intervals for odds ratios
conf_intervals <- confint(logistic_model, level = 0.95)
# Print the confidence intervals
conf_intervals
summary(logistic_model)
When running the code, I receive the error saying that I'm using a non-numeric argument.
However, as seen above, I've converted these variables to numerical (previously integers), and when checking the df they show up as numerical (list shortened for convenience):
'data.frame': 2896 obs. of 69 variables:
$ ECG_ID : int 62 65 66 68 69 71 74 76 88 89 ...
$ Index : int 1 2 3 4 5 6 7 8 9 10 ...
$ Age : num 40 67 42 71 48 38 66 73 64 39 ...
$ Gender : num 1 0 0 0 1 1 0 0 0 0 ...
$ Heartage_P : num 51 84 47.1 97.7 48.2 ...
$ HAG_P : num 11.04 16.99 5.08 26.7 0.21 ...
$ HA_nonP : num 49.8 57.4 43.6 83.7 47.9 ...
$ HA_nonP_gap : num 9.79 -9.57 1.56 12.72 -0.14 ...
$ LA_area : num 15 28 17 NA 18 25 23 25 24 NA ...
$ LA_volume : num NA NA NA NA NA NA NA 61 NA NA ...
$ LAV_Over34 : Factor w/ 2 levels "0","1": NA NA NA NA NA NA NA 2 NA NA ...
The error disappears when removing Age and Gender and running it unadjusted, and using other numerical varibles as factors to adjust for also cause the error.