glm

Error with predict and glm.predict in R

狂风中的少年 提交于 2019-12-02 04:41:03
问题 The Problem I trained a linear regression in R to predict this.target from city , variables in data frame data . This trainig is done on a subset of the data, which is specified by train.index . model = glm('data[, this.target] ~ data$city', data = data, subset = train.index) I am trying to test this model on the held out data, which is specified by test.index . predictions = predict(model, data[test.index, ]) For whatever reason, this second step creates an error and a warning. Error in

Change reference group using glm with binomial family

£可爱£侵袭症+ 提交于 2019-12-02 03:41:08
问题 When I run a binomial regression in R with an independed factor variable consisting of three levels "Higher" , "Middle" and "Lower" of which I want to change the reference category using relevel I get this error: “Error in relevel.ordered(cbsnivcat3, "Lower") : 'relevel' only for factors” I have checked whether cbsnivcat3 is a factor > is.factor(data$cbsnivcat3) [1] TRUE > levels(data$cbsnivcat3) [1] "Higher" "Middle" "Lower" > t1m4=glm(tertiary ~ relevel(cbsnivcat3, "Lower") , family =

cv.glm variable lengths differ

半世苍凉 提交于 2019-12-02 02:46:25
问题 I am trying to cv.glm on a linear model however each time I do I get the error Error in model.frame.default(formula = lindata$Y ~ 0 + lindata$HomeAdv + : variable lengths differ (found for 'air-force-falcons') air-force-falcons is the first variable in the dataset lindata. When I run glm I get no errors. All the variables are in a single dataset and there are no missing values. > linearmod5<- glm(lindata$Y ~ 0 + lindata$HomeAdv + ., data=lindata, na.action="na.exclude") > set.seed(1) > cv.err

Error with predict and glm.predict in R

一曲冷凌霜 提交于 2019-12-02 02:13:45
The Problem I trained a linear regression in R to predict this.target from city , variables in data frame data . This trainig is done on a subset of the data, which is specified by train.index . model = glm('data[, this.target] ~ data$city', data = data, subset = train.index) I am trying to test this model on the held out data, which is specified by test.index . predictions = predict(model, data[test.index, ]) For whatever reason, this second step creates an error and a warning. Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : invalid type (NULL) for

Change reference group using glm with binomial family

做~自己de王妃 提交于 2019-12-02 00:11:30
When I run a binomial regression in R with an independed factor variable consisting of three levels "Higher" , "Middle" and "Lower" of which I want to change the reference category using relevel I get this error: “Error in relevel.ordered(cbsnivcat3, "Lower") : 'relevel' only for factors” I have checked whether cbsnivcat3 is a factor > is.factor(data$cbsnivcat3) [1] TRUE > levels(data$cbsnivcat3) [1] "Higher" "Middle" "Lower" > t1m4=glm(tertiary ~ relevel(cbsnivcat3, "Lower") , family = binomial, data = data) Error in relevel.ordered(cbsnivcat3, "Lower") : 'relevel' only for factors but the

Multi-way interaction: easy way to get numerical coefficient estimates?

丶灬走出姿态 提交于 2019-12-01 21:12:15
问题 Let's say there's a 4-way interaction, with a 2x2x2 factorial design plus a continuous variable. Factors have the default contrast coding ( contr.treatment ). Here's an example: set.seed(1) cat1 <- as.factor(sample(letters[1:2], 1000, replace = TRUE)) cat2 <- as.factor(sample(letters[3:4], 1000, replace = TRUE)) cat3 <- as.factor(sample(letters[5:6], 1000, replace = TRUE)) cont1 <- rnorm(1000) resp <- rnorm(1000) df <- data.frame(cat1, cat2, cat3, cont1, resp) mod <- lm(resp ~ cont1 * cat1 *

Error: please supply starting values

倖福魔咒の 提交于 2019-12-01 19:32:40
问题 I am conducting a log binomial regression in R. I want to control for covariates in the model (age and BMI- both continuous variables) whereas the dependent variable is Outcome(Yes or No) and independent variable is Group (1 or 2). fit<-glm(Outcome~Group, data=data.1, family=binomial(link="log")) and it works fine. When I try putting age in the model, it still works fine. However, when I put BMI in the model, it gives me the following: Error: no valid set of coefficients has been found:

Error: please supply starting values

試著忘記壹切 提交于 2019-12-01 18:43:18
I am conducting a log binomial regression in R. I want to control for covariates in the model (age and BMI- both continuous variables) whereas the dependent variable is Outcome(Yes or No) and independent variable is Group (1 or 2). fit<-glm(Outcome~Group, data=data.1, family=binomial(link="log")) and it works fine. When I try putting age in the model, it still works fine. However, when I put BMI in the model, it gives me the following: Error: no valid set of coefficients has been found: please supply starting values I have been tried different combination of starting values such as: fit<-glm

predict.glm() with three new categories in the test data (r)(error)

倾然丶 夕夏残阳落幕 提交于 2019-12-01 14:13:34
I have a data set called data which has 481 092 rows. I split data into two equal halves: The first halve (row 1: 240 546) is called train and was used for the glm() ; the second halve (row 240 547 : 481 092) is called test and should be used to validate the model; Then I started the regression: testreg <- glm(train$returnShipment ~ train$size + train$color + train$price + train$manufacturerID + train$salutation + train$state + train$age + train$deliverytime, family=binomial(link="logit"), data=train) Now the prediction: prediction <- predict.glm(testreg, newdata=test, type="response") gives

How to get probability from GLM output

删除回忆录丶 提交于 2019-12-01 13:41:48
I'm extremely stuck at the moment as I am trying to figure out how to calculate the probability from my glm output in R. I know the data is very insignificant but I would really love to be shown how to get the probability from an output like this. I was thinking of trying inv.logit() but didn't know what variables to put within the brackets. The data is from occupancy study. I'm assessing the success of a hair trap method versus a camera trap in detecting 3 species (red squirrel, pine marten and invasive grey squirrel). I wanted to see what affected detection (or non detection) of the various