glm

Incorrect splitting of data using sample.split in R and issue with logistic regression

自作多情 提交于 2021-02-08 05:21:10
问题 I have 2 issues. When I try to split my data into test and train sets, using sample.split as below, the sampling is done rather unclearly. What I mean is that the data d, has a length of 392 and so, 4:1 division should show 0.8*392= 313.6 i.e. 313 or 314 rows in test set, but the shown length is 304. Is there something that I might be missing? require(caTools) set.seed(101) samplev = sample.split(d[,], SplitRatio= 0.80) train = subset(d, samplev == TRUE) test = subset(d, samplev == FALSE) I'm

Confint() with glm {stats} very, very slow

浪尽此生 提交于 2021-02-07 19:06:16
问题 I have a problem with calculating OR confidence intervals from a glm in the latest version of R, but I have not had this issue before. With any glm where family="binomial" , no matter how simple the model is, it will easily allow me to extract the summary and exp(coef(model)), however when I try to extract the confint() or exp(confint(model)) , the "Waiting for profiling to be done..." message is displayed and nothing happens (I've waited up to 10 mins then cancelled the procedure, this

Confint() with glm {stats} very, very slow

十年热恋 提交于 2021-02-07 19:02:05
问题 I have a problem with calculating OR confidence intervals from a glm in the latest version of R, but I have not had this issue before. With any glm where family="binomial" , no matter how simple the model is, it will easily allow me to extract the summary and exp(coef(model)), however when I try to extract the confint() or exp(confint(model)) , the "Waiting for profiling to be done..." message is displayed and nothing happens (I've waited up to 10 mins then cancelled the procedure, this

R Step function looks for data in global environment, not inside defined function

╄→尐↘猪︶ㄣ 提交于 2021-02-07 10:15:07
问题 I have a problem with step forward regression and My understanding is that i don't pass argument Data correctly. I have the function: ForwardStep <- function(df,yName, Xs, XsMin) { Data <- df[, c(yName,Xs)] fit <- glm(formula = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), data = Data, family = binomial(link = "logit") ) ScopeFormula <- list(lower = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), upper = paste(yName, " ~ ", paste0(Xs, collapse = " + "))) result <- step(fit,

R Step function looks for data in global environment, not inside defined function

巧了我就是萌 提交于 2021-02-07 10:14:55
问题 I have a problem with step forward regression and My understanding is that i don't pass argument Data correctly. I have the function: ForwardStep <- function(df,yName, Xs, XsMin) { Data <- df[, c(yName,Xs)] fit <- glm(formula = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), data = Data, family = binomial(link = "logit") ) ScopeFormula <- list(lower = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), upper = paste(yName, " ~ ", paste0(Xs, collapse = " + "))) result <- step(fit,

R Step function looks for data in global environment, not inside defined function

时光怂恿深爱的人放手 提交于 2021-02-07 10:13:48
问题 I have a problem with step forward regression and My understanding is that i don't pass argument Data correctly. I have the function: ForwardStep <- function(df,yName, Xs, XsMin) { Data <- df[, c(yName,Xs)] fit <- glm(formula = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), data = Data, family = binomial(link = "logit") ) ScopeFormula <- list(lower = paste(yName, " ~ ", paste0(XsMin, collapse = " + ")), upper = paste(yName, " ~ ", paste0(Xs, collapse = " + "))) result <- step(fit,

how to work with prais.winsten results in stargazer and broom (r)

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 09:13:58
问题 The package "prais" contains the function prais.winsten to run a regression models with Prais Winsten estimator. However, neither stargazer nor broom packages seem to work with the results from the prais.winsten function. After fitting a model of the form pw<- prais.winsten(speed ~ dist, cars) When I try to report the results with stargazer I get the following error: stargazer(pw, out = "pw.html") Error: $ operator is invalid for atomic vectors and likewise tidying the model with the broom

How to fit multiple interaction models in a loop?

孤街浪徒 提交于 2021-01-28 06:00:43
问题 Lets say i have 3 response variables A,C and M and i want to fit a model for all possible models ie fit Y ~ A, Y ~ C, Y ~ M, Y ~ A * C, Y ~ A * M, Y ~ C * M, etc. Is there a quick way to do this without manually specifiying the interactions each time? i do not want to write M1 = glm(Y ~ A , data = subs, family = "poisson") M2 = glm(Y ~ C , data = subs, family = "poisson") M3 = glm(Y ~ M , data = subs, family = "poisson") M4 = glm(Y ~ A*C , data = subs, family = "poisson") ... In reality i

How to calculate nonlinear (binary) Fixed-Effects Logit for Longitudinal/Panel Data?

坚强是说给别人听的谎言 提交于 2021-01-27 14:35:57
问题 I'm trying to estimate child work based on a lagged variable on children's school aspirations. I'm deciding whether I should use glm or clogit to run my models (need fixed effect logits). When I run my glm, my coefficients are very different from my clogit. model1 <- glm(chldwork~lag_aspgrade_binned+age+as.factor(childid), data=finaletdtlag, family='binomial') GLM Output: Call: glm(formula = chldwork ~ lag_aspgrade_binned + age + as.factor(childid), family = "binomial", data = finaletdtlag)

Anova test for GLM in python

浪子不回头ぞ 提交于 2021-01-19 04:16:31
问题 I am trying to get the F-statistic and p-value for each of the covariates in GLM. In Python I am using the stats mode.formula.api to conduct the GLM. formula = 'PropNo_Pred ~ Geography + log10BMI + Cat_OpCavity + CatLes_neles + CatRural_urban + \ CatPred_Control + CatNative_Intro + Midpoint_of_study' mod1 = smf.glm(formula=formula, data=A2, family=sm.families.Binomial()).fit() mod1.summary() After that I am trying to do the ANOVA test for this model using the anova in statsmodels.stats table1