Plotting Single Covariate Regression Line in a Multivariate Model - r

I am able to create a multivariate linear regression model using
lmex = lm(overweight$h_egfr_cystc96 ~ overweightlogblood + overweight$age_96, data = overweight)
Which returns values for the intercept, estimate, p-value, etc.
I want to plot a single regression line for one of my variables: overweightlogblood
If I use
ggplot(overweight,aes(y=h_egfr_cystc96,x=overweightlogblood))+geom_point()+geom_smooth(method="lm")
It gives me a nice plot, but this is for the univariate model. I would like the plot to feature a regression line (with 95% CI) for the intercept and estimate of a single covariate in a multivariate model. Any ideas?
Thank you in advance!

Related

How to interpret the residual plots of Poisson Mixed-effect Regression (glmmTMB )and remove outliers?

I ran a Poisson mixed-effect model (glmmTMB) to examine the eye fixations on words while reading. Based on my study design, I built a Poisson model and got the residual plots as beneath. "CONDITION" is a between-subject categorical variable with 3 types, and "fixation_count" is a count variable. It seems that my model has no issue with dispersion but the KS test and outlier tests were significant.
Q1. May I know how to understand the significant KS test and outlier tests? How to identify the outliers and remove them?
Q2. May I know how to understand the residual vs. predicted plot? Is there something wrong with the plot?
Q3. How to understand the red vertical lines in the DHARMa plot and the outlier test plot? Should the line be at the center of the histogram?
model<- glmmTMB(fixation_count~ CONDITION+ (1|PARTICIPANT) +
(1| WORD) + offset(log(TRIAL_TIME_1)),
data = my_data, ziformula=~1, family = poisson)
summary (model)
res <- simulateResiduals(model, plot = TRUE)
testOverdispersion (model)
testResiduals(res)

How to obtain the QQ plot of a spline model R

I have a model that I've fitted using splines:
ssfit.3 <- smooth.spline(anage$lifespan ~ log(anage$Metabolic.by.mass),
df = 3)
I'm trying to obtain the model diagnostics such as the residual plot and the QQ plot for this model. I know for a linear model you can do
plot(lm)
which outputs all the different plots. How can I do this with spline models since plot(ssfit.3) does not output the same?
Extract the residuals and use qqnorm()/qqline().
example(smooth.spline) ## to get a model to work with
qqnorm(residuals(s2m))
qqline(residuals(s2m))

How can I get the probability density function from a regression random forest?

I am using random-forest for a regression problem to predict the label values of Test-Y for a given set of Test-X (new values of features). The model has been trained over a given Train-X (features) and Train-Y (labels). "randomForest" of R serves me very well in predicting the numerical values of Test-Y. But this is not all I want.
Instead of only a number, I want to use random-forest to produce a probability density function. I searched for a solution for several days and here is I found so far:
"randomForest" doesn't produce probabilities for regression, but only in classification. (via "predict" and setting type=prob).
Using "quantregForest" provides a nice way to make and visualize prediction intervals. But still not the probability density function!
Any other thought on this?
Please see the predict.all parameter of the predict.randomForest function.
library("ggplot2")
library("randomForest")
data(mpg)
rf = randomForest(cty ~ displ + cyl + trans, data = mpg)
# Predict the first car in the dataset
pred = predict(rf, newdata = mpg[1, ], predict.all = TRUE)
hist(pred$individual)
The histogram of 500 "elementary" predictions looks like this:
You can also use quantregForest with a very fine grid of quantiles, convert them into a "cumulative distribution function (cdf)" with R-function ecdf and convert this cdf into a density estimation with a kernel density estimator.

Quantile regression analysis in R

I have noticed that whenever I try to plot the coefficient graphs with their confidence intervals (CI) with the normal OLS coefficients and their CI, I get an error whenever I force the regression through the origin.
So if I use this code (engel is data for an quantile regression example in R):
data(engel)
fit1 <- rq(foodexp ~ income, tau = c(0.1,0.25,0.5,0.75,0.9), data = engel)
plot(summary(fit1))
I have no problem and my coefficeint graphs are drawn. But if I use this:
data(engel)
fit1 <- rq(foodexp ~ 0+income, tau = c(0.1,0.25,0.5,0.75,0.9), data = engel)
plot(summary(fit1))
I have a problem because the intercept goes through the origin. How can I get the plots as in the first code for the quantile regression without the intercept.

Determining the values of beta in a logistic regression equation

I read about logistic regression on Wikipedia and it talks of the equation where z, the output depends on the values of beta1, beta2, beta3, and so on which are termed as regression coefficients along with beta0, which is the intercept.
How do you determine the values of these coefficients and intercept given a sample set where we know the output probability and the values of the input dependent factors?
Use R. Here's a video: www.youtube.com/watch?v=Yv05RjKpEKY

Resources