Skip to content

lm function - strange error

12 messages · tesssa, R. Michael Weylandt, David Winsemius +3 more

#
I am following a document teaching how to use regression and right at the
onset I get an R error.  I understand that variables "conc" and "signal"
should have the same length but  I am using the what R manual suggests to
drop the error and it is not cooperating.  What gives?   The manual says
that the default is na.ombit by the way, not that it's addition does
anything

How do I make it omit the extra items?  I want to follow this document  but
it seems that R has changed since that one was written 

Here is the code

conc = c(0 10 20 30 40 50)
signal = c (4, 22, 44, 60, 82)
lm( signal ~ conc)

#Error in model.frame.default(formula = signal ~ conc, drop.unused.levels =
TRUE) : 
#variable lengths differ (found for 'conc')


lm (conc~signal, na.action=na.omit)
#Error in model.frame.default(formula = conc ~ signal, na.action = na.omit, 
: 
#variable lengths differ (found for 'signal')


lm (conc~signal, na.action=na.exclude)
#Error in model.frame.default(formula = conc ~ signal, na.action =
na.exclude,  : 
#variable lengths differ (found for 'signal')




--
View this message in context: http://r.789695.n4.nabble.com/lm-function-strange-error-tp4649065.html
Sent from the R help mailing list archive at Nabble.com.
#
On Fri, Nov 9, 2012 at 4:37 PM, tesssa <tesaRants at gmail.com> wrote:
Off the cuff, it seems you're missing commas here.

RMW
#
Can you provide a reference or link to the document?  I think that you have a misprint or a typo in it.

the na.omit is a reference to missing data that is accounted for in the vector, which would appear as NA in the data.

For example this works just fine for me
conc = c(0, 10, 20, 30, 40, 50)
signal = c (4, 22, 44, 60, 82, NA)
lm( signal ~ conc)

as does this

conc = c(0, 10, 20, 30, 40, 50)
signal = c (NA, 4, 22, 44, 60, 82)
lm( signal ~ conc)

but they give very different results.

I don't think R has changed ----someone just make typing mistake.





John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
#
On Nov 9, 2012, at 9:16 AM, tesssa wrote:

            
It might be interesting to have such a supernatural entity zooming around the Rhelp Universe answering prayers from newbies, but alas there is no R.help Message Editor.
Furthermore, you desperately need to read the Posting Guide since you are persistently offering no context in  your follow-up posts.
David Winsemius, MD
Alameda, CA, USA
#
Tessa,

Would you please leave in the context --that is your early remarks and mine?

Most of us on the R-help list do no use nabble and it is really annoying to have to go there to see what was discussed.  I suspect that a lot of readers just don't bother and nabble users lose a lot of possible help that way.

In any case, I think your problem  is a typo in the document.  

 My first suggestion  gives  exactly the same results shown in the document you supplied.  Run this :
conc = c(0, 10, 20, 30, 40, 50)
signal = c (4, 22, 44, 60, 82, NA)
lm.r  <-  lm( signal ~ conc)
summary(lm.r)

I hope this helps.
John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
#
Pehaps the R-Core developers could consider such an editor? I am sure that I would sacrifce a sheep or two ....

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
#
On Fri, Nov 9, 2012 at 2:20 PM, John Kane <jrkrideau at inbox.com> wrote:
I'd chip in two if it edits Nabble posts into comprehensibility.
#
I don't think there are enough sheep in New Zealand for that every bit helps.

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
#
Actually it was not tessa but the original document that was at fault.
   I suspect you may be right that the 0 should not be there but it was in the
   document.
   In any case look at these
   conc = c(10, 20, 30, 40, 50)
   signal = c (4, 22, 44, 60, 82)
   lm.r1  <-  lm( signal ~ conc)
   summary(lm.r)
   conc = c(0,10, 20, 30, 40, 50)
   signal = c (4, 22, 44, 60, 82, NA)
   lm.r  <-  lm( signal ~ conc)
   summary(lm.r)



   John Kane
   Kingston ON Canada

   -----Original Message-----
   From: askibeto at gmail.com
   Sent: Fri, 9 Nov 2012 20:35:05 +0100
   To: jrkrideau at inbox.com
   Subject: Re: [R] lm function - strange error

   Hi Tessa, I agree with John. I think you've made a typo, but looking at your
   data I think the zero concentration should not be there. Try plotting it.
   conc = c(10, 20, 30, 40, 50)
   signal = c (4, 22, 44, 60, 82)
   plot(signal~conc)
   abline(lm(signal~conc))
   2012/11/9 John Kane <[1]jrkrideau at inbox.com>

     Tessa,
     Would you please leave in the context --that is your early remarks and
     mine?
     Most of us on the R-help list do no use nabble and it is really annoying
     to have to go there to see what was discussed.  I suspect that a lot of
     readers just don't bother and nabble users lose a lot of possible help
     that way.
     In any case, I think your problem  is a typo in the document.
      My  first suggestion  gives  exactly the same results shown in the
     document you supplied.  Run this :
     conc = c(0, 10, 20, 30, 40, 50)
     signal = c (4, 22, 44, 60, 82, NA)
     lm.r  <-  lm( signal ~ conc)
     summary(lm.r)
     I hope this helps.

   John Kane
   Kingston ON Canada
   > -----Original Message-----
   > From: [2]tesarants at gmail.com

   > Sent: Fri, 9 Nov 2012 09:36:23 -0800 (PST)
   > To: [3]r-help at r-project.org

   > Subject: Re: [R] lm function - strange error
   >
   > Here is the document
   >
   >
   [4]http://www.montefiore.ulg.ac.be/~kvansteen/GBIO0009-1/ac20092010/Class8/U
   sing%20R%20for%20linear%20regression.pdf
   >

     ____________________________________________________________
     GET   FREE   SMILEYS   FOR   YOUR  IM  &  EMAIL  -  Learn  more  at
     [5]http://www.inbox.com/smileys
     Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and
     most webmails

   ______________________________________________
   [6]R-help at r-project.org mailing list
   [7]https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   [8]http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
     _________________________________________________________________

   [9]3D Marine Aquarium Screensaver Preview 
   Free 3D Marine Aquarium Screensaver
   Watch  dolphins,  sharks  &  orcas  on  your  desktop! Check it out at
   [10]www.inbox.com/marineaquarium

References

   1. mailto:jrkrideau at inbox.com
   2. mailto:tesarants at gmail.com
   3. mailto:r-help at r-project.org
   4. http://www.montefiore.ulg.ac.be/~kvansteen/GBIO0009-1/ac20092010/Class8/Using%20R%20for%20linear%20regression.pdf
   5. http://www.inbox.com/smileys
   6. mailto:R-help at r-project.org
   7. https://stat.ethz.ch/mailman/listinfo/r-help
   8. http://www.R-project.org/posting-guide.html
   9. http://www.inbox.com/marineaquarium
  10. http://www.inbox.com/marineaquarium