Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:17:22+00:00 2026-06-17T11:17:22+00:00

I’m not understanding how to fix this problem. G is a set of values

  • 0

I’m not understanding how to fix this problem. G is a set of values for which I know that the range is [0, 1e+12].

> G = c(500,10000, 5001, 103, 10, 10000)
> H = density(G)
> sum(diff(H$x)*H$y) # Area under the curve should be 1

[1] 0.999989

However, to be able to compare two datasets, I want to provide from and to to the density function so that it makes sense to compare these distributions. Therefore, I did this:

> H = density(G, from=0, to=1e+12)
> sum(diff(H$x)*H$y)

[1] 2576.354

Warning message:
In diff(H$x) * H$y :
  longer object length is not a multiple of shorter object length

The reason became evident when I printed the estimated densities:

[1] 1.315415e-04 1.102126e-07 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 9.471181e-26
  [8] 1.565915e-22 2.563577e-26 4.272754e-23 0.000000e+00 0.000000e+00 8.951887e-26 1.516549e-22
 [15] 3.870985e-25 6.612221e-22 0.000000e+00 0.000000e+00 1.275922e-25 2.216194e-22 0.000000e+00
 [22] 0.000000e+00 5.567175e-26 9.835567e-23 0.000000e+00 0.000000e+00 1.866999e-25 3.355962e-22
 [29] 1.544394e-25 2.800493e-22 6.026824e-26 1.102559e-22 0.000000e+00 0.000000e+00 0.000000e+00
....
....
[484] 2.430850e-22 1.346442e-25 0.000000e+00 0.000000e+00 1.135491e-22 6.399622e-26 0.000000e+00
[491] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
[498] 8.914726e-23 5.240562e-26 2.189813e-22 1.297914e-25 4.773404e-22 2.852380e-25 3.289275e-22
[505] 1.981486e-25 1.382136e-23 8.393153e-27 8.090789e-24 4.952458e-27 3.042214e-24 1.876931e-27
[512] 1.809917e-22

While R is correctly estimating the density to be 0 at extreme points, some are non-zero. Is this a floating point error I’m facing or am I doing something fundamentally wrong? Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:17:26+00:00Added an answer on June 17, 2026 at 11:17 am

    C’mon. You failed to reproduce the warning message. I suspect that is the key to the discrepancy. the diff(x) function gives you a vector that is one element shorter than the y.

    R operations include argument recycling, so the first density diff element will get multiplied by the largest y element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I need a function that will clean a strings' special characters. I do NOT
Does anyone know how can I replace this 2 symbol below from the string
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.