I am trying to verify whether my data set fits exponential or negative binomial, the function works for exponential but I get the following error using "nbinom":
> compare = fitdistr(A, densfun="nbinom")
Error in fitdistr(A, densfun = "nbinom") : unsupported distribution
Note: I know I need more than this to verify its likely distribution. But the issue I am having is more the fact the "nbinom" isn't functioning
It looks like you're conflating the function you've used, MASS::fitdistr(), with fitdistrplus::fitdist().
From the documentation, you can see "negative binomial" is the character string specifying this distribution in the fitdistr function you've used.
Related
I need to perform a log binomial regression using GEE. I tried to solve this using gee package with the following code:
gee(y~x,id,data = data, family="binomial",link="log",corstr="exchangeable")
Where y is a binary variable 0/1.
When I run that, i got this error:
Error in gee(y~x,id,data = data, family="binomial",link="log",corstr="exchangeable") :
unused argument (link = "log")
I know that the error is straightforward, however, I don't know how to specify the link function inside the gee function. The problem is that the binary outcome is more than 50%. Because of that, OR is not a good proxy for risk interpretation.
Please help.
I have run a cox regression model below
allcause_cox<-coxph(Surv(allcause_time, allcause)~centgroup, data=fulldata)
This has run fine. However I want to return robust standard error. Therefore I have introduced the
cluster(parity)
term into the model, where parity is another variable in my data set. However this won't run. It returns the error
> allcause_cox<-coxph(Surv(allcause_time, allcause)~centgroup, data=fulldata, cluster(parity))
Error in coxph(Surv(allcause_time, allcause)~centgroup, data=fulldata, :
weights must be finite
Is there a solution to this? I have read about the weight term which can be added but I'm not sure what this does.
cluster is in the wrong place, the command should read
allcause_cox<-coxph(Surv(allcause_time, allcause)~centgroup+cluster(parity), data=fulldata)
I have a set of GLMMs fitted with a binary response variable and a set of continuous variables, and I would like to get confidence intervals for each model. I've been using confint() function, at 95% and with the profile method, and it works without any problems if it is applied to a model with no interactions.
However, when I apply confint() to a model with interactions (continuous*continuous), I've been getting this error:
m1CI <- confint(m1, level=0.95, method="profile")
Error in zeta(shiftpar, start = opt[seqpar1][-w]) :
profiling detected new, lower deviance
The model runs without any problem (although I applied an optimizer because some of the models were having problems with convergence), and here is the final form of one of them:
m1 <- glmer(Use~RSr2*W+RSr3*W+RShw*W+RScon*W+
RSmix*W+(1|Pack/Year),
control=glmerControl(optimizer="bobyqa",
optCtrl=list(maxfun=100000)),
data = data0516RS, family=binomial(link="logit"))
Does anyone know why this is happening, and how can I solve it?
I am using R version 3.4.3 and lme4 1.1-17
The problem was solved by following these instructions:
The error message indicates that during profiling, the optimizer found
a fitted value that was significantly better (as characterized by the
'devtol' parameter) than the supposed minimum-deviance solution returned
in the first place. You can boost the 'devtol' parameter (which is
currently set at a conservative 1e-9 ...) if you want to ignore this --
however, the non-monotonic profiles are also warning you that something
may be wonky with the profile.
From https://stat.ethz.ch/pipermail/r-sig-mixed-models/2014q3/022394.html
I used the confint.merModfrom the lme4 package, and boosted the 'devtol' parameter, first to 1e-8, which didn't work for my models, and then to 1e-7. With this value, it worked
I am trying to fit my data using the fitdist() function from the fitdistrplus package in R. I succeeded using a normal and a lognormal distribution via key words 'norm' and 'lnorm' which I found via searching online.
I was not able to get other distributions working; the help of fitdist() says:
distr: A character string "name" naming a distribution for which the corresponding density function dname, the corresponding distribution function pname and the corresponding quantile function qname must be defined, or directly the density function.
I checked and when entering ?norm or ?norm into the R command line, neither function norm() nor lnorm() is found. This confuses me totally.
When I try for example fitdist(data, 'poisson'), I get the following error message:
Error in fitdist(data$time, "poisson") :
The dpoisson function must be defined
I am somewhat a noob in R, can anybody give a hint?
norm() in R is a different function to compute norms of a matrix, so not directly related to the normal distribution.
?Normal brings up the documentation related to the normal distribution, and you'll see the 4 functions dnorm, pnorm, qnorm and rnorm belonging to this family.
If you look at ?Lognormal you'll see the same convention with the typical 4 functions.
More generally, you can look-up ?Distributions, which links all of them. There you can see that the keyword for the poisson distribution should actually be pois.
I am facing an error when trying to run a cross validation on glmnet for family = poisson using an offset.
I managed to replicate the error with the very simple example below:
library(glmnet)
#poisson
N=500; p=20
nzc=5
x=matrix(rnorm(N*p),N,p)
beta=rnorm(nzc)
f = x[,seq(nzc)]%*%beta
mu=exp(f)
y=rpois(N,mu)
exposure=rep(0.5,length(y))
#cross validation
cv=cv.glmnet(x,y,family="poisson",offset=log(exposure),nlambda=50,nfolds=3)
which returns the following error:
Error: No newoffset provided for prediction, yet offset used in fit of
glmnet
I can't figure out what I'm doing wrong here. And wasn't able to find any help on the internet. Would anyone have ideas?
Thanks a lot!
EDIT : this issue is obsolete, and was linked to the version 2.0-12 of the glmnet package - fixed when updating to version 2.0-13
This works:
predict(cv,x,newoffset=log(exposure))
From the documentation for glmnet for the offset parameter:
If supplied, then values must also be supplied to the predict
function.