[R] error on fitting bayesian logistic in r

Hana Tezera h@n@tezer@ @end|ng |rom gm@||@com
Sat Jun 18 10:24:48 CEST 2022


I try to fit Bayesian logistic regression using rstan but i got the
following error
### Model 2 Bayesian Logistic Regression  model using rstan
###the follwing package must be loded or install inorder to reproduce the code
library(dplyr)
library(rstan)
##install.packages("rstan", dependecies=TRUE)
library(readr)
setwd("C:/Users/hp/Desktop/exercise
Data/challenges_part_2/challenges_part_2/1_model_comparison/")# Change
working directory
Data <- read.table("simdata_covar.txt",colClasses=c(rep("numeric",6),rep("factor",2),rep("numeric",2)),as.is=T,na.strings=".",quote="",
header=T, sep="\t")
str(Data)
head(Data)
tail(Data)
dim(Data)
summary(Data)
summary(Data$y)
### when we look the summary of the data there is an outlies in bmi and age
### methods of detecting and removing outliers from the data.
## Using inter quartle rage
#find Q1, Q3, and interquartile range for values in column Age
Q1 <- quantile(Data$age, .25)
Q3 <- quantile(Data$age, .75)
IQR <- IQR(Data$age)
#only keep rows in dataframe that have values within 1.5*IQR of Q1 and Q3
Data_without_outliers <- subset(Data, Data$age> (Q1 - 1.5*IQR) &
Data$age< (Q3 + 1.5*IQR))
dim(Data_without_outliers)
str(Data_without_outliers)
head(Data_without_outliers)
tail(Data_without_outliers)
summary(Data_without_outliers)
sapply(Data_without_outliers, levels)##to see the level of the variables
Data1<-Data_without_outliers
dim(Data1)
str(Data1)
head(Data1)
tail(Data1)
summary(Data1)
Data_list<-list(N=dim(Data1)[1],No_pred=9,x=Data1 %>% select(age, bmi,
smoke,hypertension,diabetes ,edlevel ,region ,score ,score2
),y=Data1$y)
str(Data_list)
## returning the stan code
library(rstan)
require(rstan)
options(mc.Cores=parallel:: detectCores())
rstan_options(auto_write=TRUE)
setwd("C:/Users/hp/Desktop/exercise
Data/challenges_part_2/challenges_part_2/1_model_comparison/")#
working directory for stan code
### define the stan model
hfit<-stan(file= "logit_sta_code.stan", data=Data_list, iter=10,000, chains=4)
Error in stan_model(file, model_name = model_name, model_code = model_code,  :
  model name must match (^[[:alnum:]]{2,}.*$)|(^[A-E,G-S,U-Z,a-z].*$)|(^[F,T].+)
any one can help me with this error
Best,
Hana



More information about the R-help mailing list