Tell me more ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

The given problem is as follows:

Recall that $\log 2 = \int_0^1 1/(x+1) dx$. Hence, by using a uniform $(0,1)$ generator, approximate $\log 2$. Obtain an error of estimation in terms of a large sample 95% confidence interval. If you have access to the statistical package R, write an R function for the estimate and the error of estimation. Obtain your estimate for 10,000 simulations and compare it to the true value.

My answer:

$$\int_0^1 1/(x+1) dx = (1-0)\int_0^1 1/(x+1) dx/(1-0) = \int_0^1 1/(x+1) f(x) dx = E(1/(x+1))$$

Where f(x)=1, 0

And then I calculated log 2 from the calculator and got 0.6931471806

From R, I got 0.6920717

So, from the weak law of large numbers, we can see that the sample mean is approaching the actual mean as n gets larger.

My Question:

Is my answer correct? Can I use the calculator to approximate log 2?

Thanks in advance

share|improve this question
1  
You are supposed to use $\log 2 = \int_0 ^1 \frac {1}{x+1}\, dx$ and the uniform distribution, to approximate $\log 2$. Not supposed to type $\log 2$ into your calculator and see what you get... So your answer is wrong (without knowing what the numerical value of $\log 2$ is.) – Calvin Lin Jan 29 at 8:50
@CalvinLin I multiplied by the integral with (1-0) because I divided dx by (1-0) (since I want to turn the integral into an expectation...so I need to multiply it by some function, and I chose that function to be f(x)=1, 0<x<1. The problem is...that when I calculate the expectation, I get log 2...so it doesn't really help much unless I use the calculator. Can you give me a hint if my answer is wrong? – Artus Jan 29 at 9:06
I don't see an answer of yours to the problem, so I can't comment if it's right or wrong. I believe that you are supposed to generate several random variables, and then calculate the mean of $\frac {1}{x+1}$ to approximate $\log 2$. (I believe that) You can use the weak law of large numbers to tell you how many variables you need, in order to get a 95% CI. – Calvin Lin Jan 29 at 9:16
@CalvinLin Actually, I'm sorry, I forgot to tell you...I know I didn't compute the confidence interval yet. I was just wondering if I was correct so far? – Artus Jan 29 at 9:23
I edited your question to make the distinction clearer between the given problem and your own work, as I understood it. Please check that I did not change the intent. – Rahul Narain Jan 29 at 10:32

1 Answer

up vote 1 down vote accepted

You are supposed to generate $n = 10000$ random variables in R. You could obtain them by typing

x<-runif(10000)

This generate $x_1, \ldots, x_n$ from a uniform $U \left( 0, 1 \right)$.

To get an estimate of $\log \left( 2 \right)$, you compute the sum $$ \frac{1}{n}\sum_{i = 1}^n \frac{1}{x_i + 1} $$ which converges by the law of large number to $E \left[ \frac{1}{1 + x} \right] = \log \left( 2 \right)$

share|improve this answer
Yes I did get the sample mean for a size of 10,000 from R. It was 0.6920717. I then compared it with what I got from the calculator. Is that correct? – Artus Jan 29 at 10:49
Yes. However, don't forget that if you run the R code again, you will obtain a different answer than 0.6920717 (because the sample is random), but still an answer close to $\log(2)$. That is why you will have to look at the confidence interval to assess how accurate the estimator is. – Learner Jan 29 at 10:58
Ok thanks. Actually, I was just asking if what I did so far was correct...I know I had to find the confidence interval too, but that wasn't my question. Anyways thanks. – Artus Jan 29 at 11:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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