I am trying to run a probit regression in R.
I am wondering which function suits best for it.
I had a look at the glm function. Am I right with this?
For example, does the output of the following code give the result of a probit regression with fixed effects in the "spieler"-level?:
probTc = glm(Esieg~TTRverf+ factor(spieler),family = "binomial", data = datregT)
Related
I am trying to run a Generalized linear mixed model (GLMM) on r, I have two fixed factors and two random factors
however there are a lot of holes in my data set and the I am struggling to find a code to run the glmm all I found is the glm
Can someone please walk me through this, I know very little about R and coding
You can use the lme4 package as well. The command for a generalized linear mixed model is glmer().
Example:
install.packages("lme4") #If you still haven't done it.
library(lme4)
myfirstmodel <- glmer(variable_to_study ~ fixed_variable + (1|random_effect_varible), data = mydataset, family = poisson)
Family = poisson was just an example. Choose the 'family' according to the nature of the variable_to_study (eg. poisson for discrete data).
I'm looking to add VIF to logistic regression in R, using the export_summs function.
This is the current code:
export_summs(model1,model2, error_format = "({p.value})", exp = TRUE)
Any ideas?
Thanks.
You can use library car package and find vif(model1) or vif(model2) to find multicollinearity
This is how you can get VIF of a logistic regression model using jtools package in r. Your_glm_model is your logistic model that is returned from glm function.
summ(`Your_glm_model`, vifs = TRUE)
I am new to R and am trying to reproduce results from my SPSS analyses, but seem to be missing something.
I am trying to run a linear mixed effects model using gls in the nlme package.
The SPSS syntax I am trying to reproduce is:
MIXED Satisfaction_A BY Role
/FIXED=Role | NOINT SSTYPE(3)
/METHOD=ML
/PRINT=SOLUTION TESTCOV
/RANDOM=Role | SUBJECT(focalid) COVTYPE(UNR)
/REPEATED=Role | SUBJECT(dyadid*focalid) COVTYPE(UNR).
Essentially, it is a two-intercept model with nested data where Focal ID is the level-2/nesting variable which contains 2 responses for Satisfaction, distinguished by Role.
The R code I have so far is:
gls(Satisfaction_A ~ Role -1, #Two-intercept approach
data = chlpairwise,
correlation = corSymm(form = ~1|focalid/dyadid),
weights = varIdent(form = ~1|Role),
method = "ML",
na.action = na.omit)
The regression coefficients are very similar to those from SPSS. But what am I missing in the code so that I can view the Covariance Parameters like in SPSS? SPSS Covariance Parameters
Many thanks! I hope to keep learning so that I can eventually give back to this community for all of the help I have received. :)
Probably you need to use the function getVarCov() that returns the marginal covariance matrix from a fitted marginal model. It will also work if you fit a linear mixed effects model using function lme().
I am doing modeling based on ridge regression by R.
I want to make a step-wise for ridge regression,
however, i can only get a error which said
"Error in terms.default(object) : no terms component nor attribute"
My R code:
TempReg = step(lm.ridge(DepVar ~ ., data = RandomVars,lambda = 0),direction="both", trace=0)
My R code when i use general regression (workable):
TempReg = step(lm(DepVar ~ ., data = RandomVars), direction="both", trace=0)
what can i do if i want to make stepwise for ridge
You could try maybe using step-wise first and then ridge regression. But as mentioned, it does not make sense as it is basically Lasso regression. You could also try elastic net regression as it uses both the L1 and L2 penalties.
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.