Statistical significance of a nls model in R - r

I have some multiple linear models without intercept like below:
Y = a*X1 + b*X2 + c*X3
However this model is a linear model, but since it does not have an intercept we have to write it as a non-linear model in R:
model1= nls(Y ~ a*X1+b*X2, data = trainDat, start = list(a = 1, b=1))
The problem is that the summary(model1) does not give us the statistics of the model like F-statistics because it is not lm.
How can we report the significance of these models in R?

Related

maximum likelihood estimation of parameters following polynomial logistic regression

enter image description here
this is the datset, library(frair), data=gammarus
i want to estimate the parameters p0, p1 p2 and p3 formula is
*NA/No= exp(P0+ P1*density+ P2*density^2+P3*density^3)/(1+exp(P0+P1*density+ P2*density^2+P3*density^3))*, where Na is prey eaten and No is prey offered
Setup
library(dplyr)
library(frair)
d <- gammarus %>% mutate(y = eaten/(eaten + alive))
Step 1: Regression
You can estimate the coefficients from an equation with the lm (linear model) function:
lm(y ~ density, data = d)
Step 2: Polynomial regression
To have a polynomial functional form instead, you can use the poly function. The first argument is the variable, the second is the degree of the polynomial, and you must then specify whether you want a raw or an orthogonal polynomial. In our case it would be a raw polynomial, check this post for more detail.
You can estimate the four coefficients from by replacing density with a third degree raw polynomial of density:
lm(y ~ poly(density, 3, raw = T), data = d)
Step 3: Logistic regression
The final step is to switch from the linear to the logistic . For this you would need the glm function (generalized linear model) and you must specify that you want a logit (and not a probit for instance, cf. this post) specification with family = binomial(link = "logit").
glm(y ~ poly(density, 3, raw = T), data = d, family = binomial(link = "logit"))

How to calculate McFadden's Pseudo-R^2 from a pooled (after multiple imputation) weighted quasibinomial logistic model in R?

I am trying to fit a quasibinomial logistic model in R (8 predictor variables). I used multiple imputation with the mice package, 5 iterations. I have analytic weights that I am integrating the the regression model as well. I wanted to calculate McFadden's Peudo-R^2 in these circumstances, but I wasn't sure how to go about this, since the model is both pooled and weighted.
Here is the code for the imputation.
imp <- mice(data, maxit = 5, predictorMatrix = predM, method = meth, print = TRUE)
data_imputed <- complete(data, action="long", include = TRUE)
data_imputed <- as.mids(data_imputed)
Here is the code for my model. I have two continuous predictors, four binary predictors, and two categorical predictors. The analytic weights are non-integers and are preprovided in the dateset I'm working with.
model <- with(data_imputed, glm(Y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8, weights = wt, family = quasibinomial(link = "logit")))
I tried using the pscl package with the pR2(), without success.
The mice package also has a pool.r.squared() function, but it's only for linear regressions and doesn't give any pseudo-R^2.
As I am not the most familiar with quasibinomial logistic regressions (I am fitting one because the standard logistic regression can't handle non-integer weights to my understanding), perhaps the McFadden pseudo-R2 isn't even good to compute. Any enlightenment is appreciated.

Validating a model and introducing a new predictor in glm

I am hitting my head against the computer...
I have a prediction model in R that goes like this
m.final.glm <- glm(binary_outcome ~ rcs(PredictorA, parms=kn.a) + rcs(PredictorB, parms=kn.b) + PredictorC , family = "binomial", data = train_data)
I want to validate this model on test_data2 - first by updating the linear predictor (lp)
train_data$lp <- predict(m.final.glm, train_data)
test_data2$lp <- predict(m.final.glm, test_data2)
lp2 <- predict(m.final.glm, test_data2)
m.update2.lp <- glm(binary_outcome ~ 1, family="binomial", offset=lp2, data=test_data2)
m.update2.lp$coefficients[1]
m.final.update2.lp <- m.final.glm
m.final.update2.lp$coefficients[1] <- m.final.update2.lp$coefficients[1] + m.update2.lp$coefficients[1]
m.final.update2.lp$coefficients[1]
p2.update.lp <- predict(m.final.update2.lp, test_data2, type="response")
This gets me to the point where I have updated the linear predictor, i.e. in the summary of the model only the intercept is different, but the coefficients of each predictor are the same.
Next, I want to include a new predictor (it is categorical, if that matters), PredictorD, into the updated model. This means that the model has to have the updated linear predictor and the same coefficients for Predictors A, B and C but the model also has to contain Predictor D and estimate its significance.
How do I do this? I will be very grateful if you could help me with this. Thanks!!!

How to extract the expression of smooth function from a generalized additive model

I have a problem extracting the expression of fitted smooth function in generalized additive model.
I fitted a additive model like this:
library(mgcv)
model <- gam(y ~ x1 + x2 + s(x3, bs = "cr"), data = newdata)
I could plot the fitted smooth function of s(x3), but I want get the exact expression for it and get its derivative. How can I manage to achieve that?

non linear regression 'abline'

Still quite new to R (and statistics to be honest) and I have currently only used it for simple linear regression models. But now one of my data sets clearly shows a inverted U pattern. I think I have to do a quadratic regression analysis on this data, but I'm not sure how. What I tried so far is:
independentvar2 <- independentvar^2
regression <- lm(dependentvar ~ independentvar + independentvar2)
summary (regression)
plot (independentvar, dependentvar)
abline (regression)
While this would work for a normal linear regression, it doesn't work for non-linear regressions. Can I even use the lm function since I thought that meant linear model?
Thanks
Bert
This example is from this SO post by #Tom Liptrot.
plot(speed ~ dist, data = cars)
fit1 = lm(speed ~ dist, cars) #fits a linear model
plot(speed ~ dist, data = cars)
abline(fit1) #puts line on plot
fit2 = lm(speed ~ I(dist^2) + dist, cars) #fits a model with a quadratic term
fit2line = predict(fit2, data.frame(dist = -10:130))

Resources