Can I do added variable plots for a beta regression - r

I am trying to plot the results of a beta regression using added variable plots / partial regression. However, this only seems to be feasible with linear model objects. I am unsing the betareg() function from the betareg package to fit the model and avPlot() from the car package for the visualization of the added variable plot. Is there a way to create added variable plots for beta regression? Thanks a lot!
This is what I have tried so far:
betareg (crop_coverage ~ soil_moisture * weed_coverage, data = df) -> model_a
avPlot(model_a)
Error in UseMethod("avPlot") :
no applicable method for 'avPlot' applied to an object of class "betareg"

Related

Is there a function to obtain pooled standardized coefficient of linear equation modelling related to analysis of a MI database?

I replaced missing data by using MICE package.
I realized the linear equation modelling by using : summary(pool(with(imputed_base_finale,lm(....)))
I tried to obtain standardized coefficients by using the function lm.beta, however it doesn't work.
lm.beta (with(imputed_base_finale,lm(...)))
Error in lm.beta(with(imputed_base_finale, lm(...)))
object has to be of class lm
How can I obtain these standardized coefficients ?
Thank you for you help!!!
lm.scale works on lm objects and adds standardized coefficients. This however was not build to work on mira objects.
Have you considered using scale on the data before you build a model, effectively getting standardized coefficients?
Instead of standardizing the data before imputation, you could also apply it with post processing during imputation.
I am not sure which of these would be the most robust option.
require(mice)
# non-standardized
imp <- mice(nhanes2)
pool(with(imp,lm(chl ~ bmi)))
# standardized
imp_scale <- mice(scale(nhanes2[,c('bmi','chl')]))
pool(with(imp_scale,lm(chl ~ bmi)))

How to extract the value of the loss function of Cox models from glmnet in R?

I fit a given data using Cox model via glmnet R package and my
little R example is:
library(fastcox);data(FHT);attach(FHT) #
library(glmnet)
library(survival)
fit = glmnet(x,Surv(y,status),family="cox",alpha=1)
From the help document, we know glmnet fits penalized models like
-loglik/nobs + λ*penalty
i.e., objective function = loss function + penalty function.
I want to fetch -loglik/nobs (loss function value,
the negative partial log-likelihood of the fitted model
or two term
Taylor series expansions of the log likelihoods) from the fit object.
Any idea? Tks
BTW, we also tried
fit0 = glmnet(x,Surv(y,status),family="cox",alpha=1,lambda=0)
according to -loglik/nobs + λ*penalty, but it shows errors.

Trying to plot a model line in R but it has to many dimensions for abline

I have a binomial GLM run using proportions as the response variable and and multiple variables
glm(formula = GalFailNo3 ~ treatment * diameter1 * foundress,
family = quasibinomial, data = FigDatNo3)
I want to be able to plot the regression line but I am not sure how as I have only ever plotted simple lm models using abline. this is the data below in csv
https://drive.google.com/file/d/0B4KXwQhH5kwQZVNtc0tieXBaSE0/view?usp=sharing
the problem is this model has 8 dimensions and I haven't got a clue where to start, like what function or package will be useful.
any other info I need to present let me know please
I have tried to use the predict function with some dummy values but it doesn't appear to work.
or maybe there is another way to visualise models that I don't know about?

Forest plot from logistf

I have run a few models in for the penalized logistic model in R using the
logistf package. I however wish to plot some forest plots for the data.
The sjPlot package : http://www.strengejacke.de/sjPlot/custplot/
gives excellent function for the glm output, but no function for the logistf function.
Any assistance?
The logistf objects differ in their structure compared to glm objects, but not too much. I've added support for logistf-fitted models, however, 1) model summaries can't be printed and b) predicted probability plots are currently not supported with logistf-models.
I'll update the code on GitHub tonight, so you can try the updated sjp.glm function...
library(sjPlot)
library(logistf)
data(sex2)
fit<-logistf(case ~ age+oc+vic+vicl+vis+dia, data=sex2)
# for this example, axisLimits need to be specified manually
sjp.glm(fit, axisLimits = c(0.05, 25), transformTicks = T)

Classification table and ROC curve - logistic regression in R using lrm

I want to have a classification table for logistic regression using lrm function in rms package and then plot the roc curve.I have perfomed this using glm function.Example code
train<-sample(dim(data)[1],.8*dim(data)[1]) #80-20 training/test
datatrain<-data[train,]
datatest<-data[-train,]
fit<-glm(Target ~ ., data=datatrain,family=binomial()) #Target is 0/1 variable
prob=predict(fit,type=c("response"),datatest)
datatest$prob=prob
library(pROC)
ROC <- roc(Target==1 ~ prob, data = datatest)
plot(ROC)
confusion<-table(prob>0.5,datatest$Target)
errorrate<-sum(diag(confusion))/sum(confusion)
errorrate
How to get the confusion matrix using lrm function?
The lrm function returns a fit object that inherits from the glm-class. That is not explicitly stated in the lrm help page, but it's easy enough to verify. After running the setup code in the first example on the ?lrm page
> f <- lrm(ch ~ age)
> class(f)
[1] "lrm" "rms" "glm"
So you should be able to use the ordinary predict method you were using above. Prof Harrell advises against using split-sample validation and the use of ROC curves for model comparison. He provides mechanisms for better methods in his package.

Resources