To calculate the adjusted r-squared in Matlab, you can use the regress
function to perform linear regression and then calculate the adjusted r-squared using the formula:
main.m45 chars2 lines
where R2
is the ordinary r-squared, n
is the number of observations, and p
is the number of predictor variables in the regression model.
Here's an example code snippet:
main.m437 chars17 lines
In this example, we generate some random data, fit a linear regression model using regress
, and then calculate the r-squared and adjusted r-squared values using the formula above. The output should look something like this:
main.m49 chars3 lines
gistlibby LogSnag