如何在R中使用clm()获取p值?附VGAM包vglm()有序回归输出
clm() for Partial Proportional Odds Ordinal Regression Got it, let's walk through how to get p-values when using clm() (from the ordinal package) for an ordinal regression that relaxes the proportional odds assumption—just like you did with vglm() from VGAM.
Step 1: Fit the Partial Proportional Odds Model
First, make sure you have the ordinal package installed and loaded. To relax the proportional odds assumption for your PROXIMITY variable, you'll use the scale argument in clm()—this tells the model that PROXIMITY can have different coefficients across the response levels (instead of a single coefficient that applies to all levels, which is the default proportional odds setup).
Here's the code structure, assuming your response variable is named y and your dataset is your_data:
# Install if needed install.packages("ordinal") library(ordinal) # Fit the partial proportional odds model model <- clm(y ~ PROXIMITY, scale = ~ PROXIMITY, data = your_data)
- The
scale = ~ PROXIMITYpart is key here—it's how you specify thatPROXIMITYdoesn't follow the proportional odds assumption. If you had other variables that should still follow the assumption, just leave them in the main formula (they ~ ...part) and only include non-proportional variables in thescaleformula.
Step 2: Extract p-values
To get the p-values (along with coefficients, standard errors, and z-values), just run summary() on your fitted model:
summary(model)
The output will look similar to what you got from vglm(), with two main sections:
- Threshold coefficients: These correspond to the intercepts (
(Intercept):1,(Intercept):2in your VGAM output) that define the boundaries between your 3 response levels. - Coefficients: These are the coefficients for your
PROXIMITYvariable, with separate values for each response level (matchingPROXIMITY2:1,PROXIMITY2:2, etc., from your VGAM results). ThePr(>|z|)column is exactly the p-value you're looking for.
For example, your summary output might look like this:
Threshold coefficients:
Estimate Std. Error z value Pr(>|z|)
y1|y2 0.502 0.541 0.928 0.354
y2|y3 -0.721 0.495 -1.457 0.145Coefficients:
Estimate Std. Error z value Pr(>|z|)
PROXIMITY2 1.101 0.475 2.318 0.0205 *
PROXIMITY3 0.879 0.483 1.820 0.0688 .Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1
Step 3: Extract p-values Programatically (If Needed)
If you want to pull just the p-values into a vector for further analysis, you can use:
# Get all p-values (thresholds + coefficients) p_values <- coef(summary(model))[, 4] # Or just get p-values for the PROXIMITY coefficients prox_p_values <- p_values[grepl("PROXIMITY", names(p_values))]
Quick Note on Model Alignment
The clm() partial proportional odds model works a bit differently under the hood than vglm(), but the core idea is the same: allowing PROXIMITY to have level-specific coefficients. You should see p-values that are consistent with what you got from VGAM once you set up the model correctly.
内容的提问来源于stack exchange,提问作者Amolly

