Quantcast
Channel: Active questions tagged lm - Stack Overflow
Viewing all articles
Browse latest Browse all 124

Factor as variable in linear model in r

$
0
0

My dataset is on predictors of diabetes and I am to create a linear model. I initially was going to try out some of the variables but my professor told me it would make the most sense to use whether or not someone was diagnosed with diabetes as my variable for the lm. I thought it made sense but didn't think I could use a factor but he assured me there's an easy way to do this. I constantly get an error saying its the wrong model type and wants me to do a classification. Is there a way for me to use "diabetes" (whether or not someone has diabetes or not represented by a 1 or 0) in this linear model?

My_Betes <- read_csv("diabetes_prediction_dataset.csv",col_types = cols(hypertension = col_factor(),heart_disease = col_factor(),blood_glucose_level = col_integer(),diabetes = col_factor()))`data(My_Betes)set.seed(35)Split_Betes <- initial_split(My_Betes, prop = 0.7, strata = diabetes)Train_Betes <- training(Split_Betes)Test_Betes <- testing(Split_Betes)lm_Betes <- train(diabetes ~ ., data = Train_Betes, method = "lm")

I tried re-labeling as a numeric value and using "as.factor". I read that I can use "relevel()" some way but it didn't make sense to me. Someone please help a novice.


Viewing all articles
Browse latest Browse all 124

Trending Articles