glm

What does predict.glm(, type=“terms”) actually do?

走远了吗. 提交于 2019-12-09 06:07:49
问题 I am confused with the way predict.glm function in R works. According to the help, The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale. Thus, if my model has form f(y) = X*beta, then command predict(model, X, type='terms') is expected to produce the same matrix X, multiplied by beta element-wise. For example, if I train the following model test.data = data.frame(y = c(0,0,0,1,1,1,1,1,1), x=c(1,2,3,1,2,2,3,3,3)) model =

cost function in cv.glm of boot library in R

这一生的挚爱 提交于 2019-12-09 04:55:28
问题 I am trying to use the crossvalidation cv.glm function from the boot library in R to determine the number of misclassifications when a glm logistic regression is applied. The function has the following signature: cv.glm(data, glmfit, cost, K) with the first two denoting the data and model and K specifies the k-fold. My problem is the cost parameter which is defined as: cost: A function of two vector arguments specifying the cost function for the crossvalidation. The first argument to cost

predict and multiplicative variables / interaction terms in probit regressions

笑着哭i 提交于 2019-12-08 08:02:06
问题 I want to determine the marginal effects of each dependent variable in a probit regression as follows: predict the (base) probability with the mean of each variable for each variable, predict the change in probability compared to the base probability if the variable takes the value of mean + 1x standard deviation of the variable In one of my regressions, I have a multiplicative variable, as follows: my_probit <- glm(a ~ b + c + I(b*c), family = binomial(link = "probit"), data=data) Two

Error converting rxGlm to GLM

此生再无相见时 提交于 2019-12-08 08:01:40
问题 I'm having a problem converting rxGlm models to normal glm models. Every time I try and covert my models I get the same error: Error in qr.lm(object) : lm object does not have a proper 'qr' component. Rank zero or should not have used lm(.., qr=FALSE). Here's a simple example: cols <- colnames(iris) vars <- cols[!cols %in% "Sepal.Length"] form1 <- as.formula(paste("Sepal.Length ~", paste(vars, collapse = "+"))) rx_version <- rxGlm(formula = form1, data = iris, family = gaussian(link = 'log'),

fitting quasi family using glmulti?

。_饼干妹妹 提交于 2019-12-08 05:17:48
问题 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

Step-by-step formula based _R_ codes for GLM and GLMM

落花浮王杯 提交于 2019-12-08 04:58:46
问题 I know how to fit generalized linear models ( GLMs ) and generalized linear mixed models ( GLMMs ) with glm and glmer from lme4 package in R . Being a student of statistics, I'm interested in learning how to fit GLM and GLMM following step-by-step formula bases R codes. I'd highly appreciate if you point out any resource and/or reference in this regard. Thanks in advance. EDiT I'd like to do GLM and GLMM step by step using formula as we do LM using matrix approach. Is there any R book or

hand-rolled R code for Poisson MLE

我怕爱的太早我们不能终老 提交于 2019-12-08 04:46:24
问题 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,

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

柔情痞子 提交于 2019-12-08 03:20:19
问题 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 <-

predict and multiplicative variables / interaction terms in probit regressions

此生再无相见时 提交于 2019-12-07 20:37:32
I want to determine the marginal effects of each dependent variable in a probit regression as follows: predict the (base) probability with the mean of each variable for each variable, predict the change in probability compared to the base probability if the variable takes the value of mean + 1x standard deviation of the variable In one of my regressions, I have a multiplicative variable, as follows: my_probit <- glm(a ~ b + c + I(b*c), family = binomial(link = "probit"), data=data) Two questions: When I determine the marginal effects using the approach above, will the value of the

Prediction in R - GLMM

霸气de小男生 提交于 2019-12-07 17:24:47
问题 When we use a traditional logistic regression and make a prediction in R, for example: library(dplyr) n = 300 xx<-c("r1","r2","r3","r4","r5") xxx<-c("e1","e2","e3") p=0.3 df1 <- data_frame( xx1 = runif(n, min = 0, max = 10), xx2 = runif(n, min = 0, max = 10), xx3 = runif(n, min = 0, max = 10), School = factor(sample(xxx, n,re=TRUE)), Rank = factor(sample(xx, n,re=TRUE)), yx = as.factor(rbinom(n, size = 1, prob = p)) ) df1 mm<-glm(yx ~ xx1 + xx2 + xx3 + School + Rank,binomial,df1) n11 = data