glm

R Error in solve.default(V) : 'a' is 0-diml in regTermTest function

这一生的挚爱 提交于 2019-12-07 16:07:03
问题 I'm trying to use regTermTest function in R survey package to test the significance of each variables for logistic regression. However, I got a solver error for one of my variable, "fun". The error is Error in solve.default(V) : 'a' is 0-diml My code for the logistic regression is model2 <- glm(decision~samerace+race_o+field+goal+attr+sinc+intel+fun+amb+shar+like+prob,data=trg2, family=binomial) regTermTest(model2, "fun") I also encountered p = NA result for another variable "amb".

GLM fit (logistic regression) to SQL

我们两清 提交于 2019-12-07 13:56:18
问题 We frequently score data in database directly for simple models like linear or logisitc regression. It is always a little bit tricky to transfer all coefficients from R to SQL correctly. I thought I can make some R to SQL translation for glm result. For numeric variables this is pretty straightforward: library(rpart) fit <- glm(Kyphosis ~ ., data = kyphosis, family = binomial()) coefs <- fit$coef[2:length(fit$coef)] expr <- paste0('1/(1 + exp(-(',fit$coef[1], '+', paste0('(', coefs, '*',

Meaning of “trait” in MCMCglmm

你。 提交于 2019-12-07 12:53:36
问题 Like in this post I'm struggling with the notation of MCMCglmm , especially what is meant by trait . My code ist the following library("MCMCglmm") set.seed(123) y <- sample(letters[1:3], size = 100, replace = TRUE) x <- rnorm(100) id <- rep(1:10, each = 10) dat <- data.frame(y, x, id) mod <- MCMCglmm(fixed = y ~ x, random = ~us(x):id, data = dat, family = "categorical") Which gives me the error message For error structures involving catgeorical data with more than 2 categories pleasue use

hand-rolled R code for Poisson MLE

那年仲夏 提交于 2019-12-07 07:25:36
I'm attempting to write my own function to understand how the Poisson distribution behaves within a Maximum Likelihood Estimation framework (as it applies to GLM). I'm familiar with R's handy glm function, but wanted to try and hand-roll some code to understand what's going on: n <- 10000 # sample size b0 <- 1.0 # intercept b1 <- 0.2 # coefficient x <- runif(n=n, min=0, max=1.5) # generate covariate values lp <- b0+b1*x # linear predictor lambda <- exp(lp) # compute lamda y <- rpois(n=n, lambda=lambda) # generate y-values dta <- data.frame(y=y, x=x) # generate dataset negloglike <- function

How to get values of Z - statistic from glm object?

ぃ、小莉子 提交于 2019-12-07 00:33:16
问题 How can I get values of Z - statistics as a vector from glm object? For example, I have fit <- glm(y ~ 0 + x,binomial) How can I access the column Pr(>|z|) the same way I get estimates of coefficients with fit$coef ? 回答1: I believe that coef(summary(fit))[,"Pr(>|z|)"] will get you what you want. ( summary.glm() returns an object that has a coef() method that returns the coefficient table.) (By the way, if accessor methods exist it's better to use them than to directly access the components of

How to create a loop that will add new variables to a pre define glm model

[亡魂溺海] 提交于 2019-12-06 17:15:05
I would like to create a procedure that will add per each loop a new variable (from a pool of variables) to a glm model that allready contains few of the variables that need to be part of the final model.I than would like to have the results of the loop in a list that will contain the glm formula and results.I know how to do it manually (code is written below) but I would be happy to know how to do it automaticaly. Here is a toy dataset and the relevant code to do the task manually: dat <- read.table(text = "target birds wolfs Country 0 21 7 a 0 8 4 b 1 2 5 c 1 2 4 a 0 8 3 a 1 1 12 a 1 7 10 b

fitting quasi family using glmulti?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 15:36:09
I used the glmulti function in the glmulti package to obtain the best glm model for poisson error distributed data. No problems there. Once I had obtained the best model, I used the Chi-square test to obtain p-values and test statistics for each of the variables entered into the model. The only problem I am encountering is that the data is overdispersed and the Zuur book and Crawley both suggest using the quasi family function to correct for overdispersion. This in itself is not a problem except that the glmulti function does not allow fits to quasi functions. The question I have, is whether

How to set the Coefficient Value in Regression; R

。_饼干妹妹 提交于 2019-12-06 04:44:17
问题 I'm looking for a way to specify the value of a predictor variable. When I run a glm with my current data, the coefficient for one of my variables is close to one. I'd like to set it at .8. I know this will give me a lower R^2 value, but I know a priori that the predictive power of the model will be greater. The weights component of glm looks promising, but I haven't figured it out yet. Any help would be greatly appreciated. 回答1: I believe you are looking for the offset argument in glm . So

How do I use a custom link function in glm?

江枫思渺然 提交于 2019-12-06 04:23:12
问题 I don't want to use the standard log link in glm for Poisson regression, since I have zeros. Consider the following code: foo = 0:10 bar = 2 * foo glm(bar ~ foo, family = poisson(link = "identity")) I get the error: Error: no valid set of coefficients has been found: please supply starting values I'm not certain what this means. Is the "identity" link function what I think it is (i.e. it doesn't transform the data at all)? What does this error mean and how can I resolve it? 回答1: You can get

How can I generate marginal effects for a logit model when using survey weights?

a 夏天 提交于 2019-12-06 03:49:21
问题 I normally generate logit model marginal effects using the mfx package and the logitmfx function. However, the current survey I am using has weights (which have a large effect on the proportion of the DV in the sample because of oversampling in some populations) and logitmfx doesn't appear to have any way to include weights. I have fitted the model with svyglm as follows: library(survey) survey.design <- svydesign(ids = combined.survey$id, weights = combined.survey$weight, data = combined