I'm using JMP to analyze some sample data to make predictions about the population. My sample is from a destructive QC test, so I obviously want to minimize my sample. I have a response (my Y) and a known factor (a very strong and consistent correlation that is measurable by non-destructive means) but the exact relationship between them varies from lot to lot (the slope and y offset vary).

So, in JMP, I am fitting a line and then showing the "confidence limits for an individual predicted value" which I believe gives me an indicator of how the population is likely to behave. So I'm using that plot to make disposition decisions. I want to automate this process, perhaps using R, but I'm a total novice at R. I could do the math if I was just dealing with a mean and standard deviation, but I don't know how to do it with a fit line and a known factor. Can someone please give me either the general information on how to get the confidence limits around the line, or else tell me how to do the whole thing in R?

Thankss much.

  • $\begingroup$ It's not totally clear what kind of model you're fitting - is this a linear regression model? $\endgroup$ – Macro May 6 '12 at 0:40
  • $\begingroup$ Yes, it's linear regression. $\endgroup$ – Aerik May 7 '12 at 21:52

If your using linear regression I would recommend using the rms package in R. It is very easy to use and has lots of nice features.

Here's an example:

# Load package (remember to install.packages("rms") or this will fail the first time)

# Get a dataset to experiment with
mtcars$am <- factor(mtcars$am, levels=0:1, labels=c("Automatic", "Manual"))

# The rms package needs this work properly
dd <- datadist(mtcars)

# Do the regression
f <- ols(mpg~wt, data=mtcars, x=T, y=T)

# Plot regular mean confidence interval
p <- Predict(f, wt=seq(2.5, 4, by=.001), conf.type="mean")
plot(p, ylim=c(10, 30), col="lightblue")

# Plot wide confidence interval
p <- Predict(f, wt=seq(2.5, 4, by=.001), conf.type="individual")
plot(p, ylim=c(10, 30), col="lightblue")

Gives this output:

Plain line

Now usually you want to test the linearity assumption:

# Try the model with a restricted cubic spline
f <- ols(mpg~rcs(wt, 3), data=mtcars, x=T, y=T)

Gives this output:

> anova(f)
                Analysis of Variance          Response: mpg 

 Factor     d.f. Partial SS MS         F     P     
 wt          2   922.04230  461.021149 65.54 <.0001
  Nonlinear  1    74.31705   74.317047 10.56 0.0029
 REGRESSION  2   922.04230  461.021149 65.54 <.0001
 ERROR      29   204.00489    7.034651             

And if you plot the graphs with the same code as a bove you get this picture:

Regression with a spline

If you want to make your formula more complicated just add that variable:

f <- ols(mpg~rcs(wt, 3)+am, data=mtcars, x=T, y=T)
p <- Predict(f, wt=seq(2.5, 4, by=.001), am=levels(mtcars$am), conf.type="individual")

I don't know anything about JMP, it shouldn't be too difficult but I recommend learning R because it gives you an incredible freedom.

Hope this helped.

  • $\begingroup$ Thank you very much - I haven't been able to get with my coworker who knows much more R than me, but I'm sure this is the ticket. $\endgroup$ – Aerik May 8 '12 at 19:46

You can automate the process within JMP using the JSL (JMP Scripting Language). Start by selecting Script > Save to Script Window from the analysis contextual red-triangle menu. That will give you a script to rerun the platform. You can also issue other commands to the report object that the script creates, such as to save the prediction interval or fit formula.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.