-2

I just loaded R to my windows machine and included bootstrap routines and the mcr routine for Deming regression. Very basic questions.

  1. How do I imbed Deming regression inside a bootstrap sampling routine?

  2. How do I input my data into R? The data is in an Excel spreadsheet.

Please try to give me a quick way. I am trying to do this today if possible!

Siguza
  • 21,155
  • 6
  • 52
  • 89
  • 2. I prefer saving the table from Excel as a CSV file and then using `read.table` for reading in the data. – Roland Oct 05 '12 at 16:49
  • @Roland Thanks I just started using R. I have loaded the programs but never run anything in R. I just need a quick way and don't punish me for being a newbie please! Excel and CSV seem to be very similar to me. My data set is not very large. I will input it whatever way I can as long as I do it quickly. Maybe I need an R script showing me the whole process. I have R books and am willing to learn and read up on it. But for this time I got to do it quickly. My colleages at CV sadi that the programmers on SO are very helpful to beginners. – Michael R. Chernick Oct 05 '12 at 16:57
  • 2
    The answer to #2 can be found in the aptly named manual ["R Data Import/Export"](http://cran.r-project.org/doc/manuals/R-data.html). It covers both Excel and CSV files therein. This question on [SO](http://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script/6099497#6099497) is also helpful. – Chase Oct 05 '12 at 17:44
  • @Chase Thank you. That settles 2. I still hope to get help with 1. I know the procedures are specialized, but I think that all I need to know is how to how to setup a loop with a bootstrap sample to fed into the regression package. The simulated data is just sampling with replacement from the original data set that I import in Excel. – Michael R. Chernick Oct 05 '12 at 17:55

1 Answers1

6

For the long run you should really read the R Import/Export manual and the Introduction to R (both are installed when you install R).

For the short term, one simple approach is: Open the file using Excel and highlight the section that incudes the data of interest, including a first row that has the column names (if you start on the upper left cell and hold down both ctrl and shift then tap the down arrow, then the right arrow keys it may help with this process). Then right click on the selection and choose "copy".

In R type:

mydata <- read.delim('clipboard', header=TRUE)

If everything worked properly then mydata will now be a dataframe containing your data. If you type:

View(mydata)
summary(mydata)

Then you will get a spreadsheet like window of the data that you can examine (note the capitol "V" in "View") and a quick summary of the data that you can check to make sure that everything makes sense (no means for categorical data, means are computed for numeric data). If these summaries don't make sense, then we will need more detail on your data format.

You can then run the regression by doing something like:

library("mcr")
model1 <- mcreg(mydata$xvar, mydata$yvar, error.ratio=1, method.reg="Deming",
      method.ci="bootstrap")
printSummary(model1)
getCoefficients(model1)
plot(model1)

With xvar and yvar replaced with the appropriate variable names.

You will need to study up on the documentation if you want other options and on how to interpret the results, but this should get you started.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • ++1 Greg. I will print out your answer and use it! On that second line of data should the command be sumary(mydata) or summary(mydata). If there are any typos in your code could you please check and let me know? – Michael R. Chernick Oct 05 '12 at 18:08
  • @MichaelChernick, The version that is spelled correctly and does not give an error is probably the better approach (I have fixed the typo above). I don't see any other typos, but the mcr code is copied (non-verbatim) from the help page for `mcreg` rather than personal experiance. – Greg Snow Oct 05 '12 at 18:11
  • I am playing with the rconsole first without importing the data. I know I will get error messages but I want to make sure that it can find the mcr package. Here is a line of code I tried: library("mcr") with an error message:("mcr"):there is no package called 'mcr' – Michael R. Chernick Oct 05 '12 at 18:28
  • Do I need to create a library first? Sorry for sounding so stupid. – Michael R. Chernick Oct 05 '12 at 18:30
  • 1
    You need to install the "mcr" package first (the library is where all your packages are stored). I had assumed that you had already done this based on the original question. Try running `install.packages("mcr")` and responding to any prompts. Then if that works you can load the package with the `library` function. If you run the command `example(mcreg)` then it will run the examples from the help page (see the help page with `?mcreg`) for you. – Greg Snow Oct 05 '12 at 18:48
  • That worked. I had to go to the PA(1) site. My bootstrap packages were all installed too. If I load the other packages into the library will they be there just for this session or permanently? My data consists only of paired measurements (x,y) with about 60 of them. This is all numerical data. – Michael R. Chernick Oct 05 '12 at 18:59
  • I closed the Rgui and reopened it and found the library still there. So I assume all the packages are stored permanently. Looks like 2 is now solved and i can try to input the data and run your script @GregSnow. Thank you so much!! I will be back to let you know if I have any problems or if it works! – Michael R. Chernick Oct 05 '12 at 19:09
  • You only need to install a package once (well until you update R, get a new computer, etc.). You will need to load the package (using the `library` or `require` function) in each new R session that you want to use it. – Greg Snow Oct 05 '12 at 19:10
  • Now that I am looking at my excel data I find I have 128 pairs almost even distributed across three sites. I need to do a stratified bootstrap. So I resample within each site and then combined for the bootstrap sample that is fed to the Deming regression. How does that change your script? – Michael R. Chernick Oct 05 '12 at 19:25
  • @GreggSnow Does your script provide CIs for the slope and intercept and an R-square for the model? – Michael R. Chernick Oct 05 '12 at 19:31
  • I checked out your website and see that you are a Mormon statistician from Utah. I collaborate with Lacey Gunter who is also a statistician and a Mormon from Utah. She lives near Provo. – Michael R. Chernick Oct 05 '12 at 19:59
  • Someone else will need to help with the specifics on running the regression. I initially helped with how to run the commands (and import the data), but I am not very familiar with the specific methods or the details of the package. I don't know Lacey. – Greg Snow Oct 05 '12 at 20:18
  • Okay thank you. I will try your script and figure out the modifications needed or get help from someone else. You were the one person responding who I know has a degree in statistics – Michael R. Chernick Oct 05 '12 at 20:23