0

I am currently trying to log returns for the variance gamma(VG) distribution and comparing it to the normal distribution. I have attached a pic example of what I'm looking for. I am trying to produce a histogram likin R studio?enter image description here Can someone please give an example code of how it's done? Thank you. I am using the following data:

dput(x)
c(2510, 2510.03, 2447.89, 2531.94, 2549.69, 2574.41, 2584.96, 
    2596.64, 2596.26, 2582.61, 2610.3, 2616.1, 2635.96, 2670.71, 
    2632.9, 2638.7, 2642.33, 2664.76, 2643.85, 2640, 2681.05, 2704.1, 
    2706.53, 2724.87, 2737.7, 2731.61, 2706.05, 2707.88, 2709.8, 
    2744.73, 2753.03, 2745.73, 2775.6, 2779.76, 2784.7, 2774.88, 
    2792.67, 2796.11, 2793.9, 2792.38, 2784.49, 2803.69, 2792.81, 
    2789.65, 2771.45, 2748.93, 2743.07, 2783.3, 2791.52, 2810.92, 
    2808.48, 2822.48, 2832.94, 2832.57, 2824.23, 2854.88, 2800.71, 
    2798.36, 2818.46, 2805.37, 2815.44, 2834.4, 2867.19, 2867.24, 
    2873.4, 2879.39, 2892.74, 2895.77, 2878.2, 2888.21, 2888.32, 
    2907.41, 2905.58, 2907.06, 2900.45, 2905.03, 2907.97, 2933.68, 
    2927.25, 2926.17, 2939.88, 2943.03, 2945.83, 2923.73, 2917.52, 
    2945.64, 2932.47, 2884.05, 2879.42, 2870.72, 2881.4, 2811.87, 
    2834.41, 2850.96, 2876.32, 2859.53, 2840.23, 2864.36, 2856.27, 
    2822.24, 2826.06, 2802.39, 2783.02, 2788.86, 2752.06, 2744.45, 
    2803.27, 2826.15, 2843.49, 2873.34, 2886.73, 2885.72, 2879.84, 
    2891.64, 2886.98, 2889.67, 2917.75, 2926.46, 2954.18, 2950.46, 
    2945.35, 2917.38, 2913.78, 2924.92, 2941.76, 2964.33, 2973.01, 
    2995.82, 2990.41, 2975.95, 2979.63, 2993.07, 2999.91, 3013.77, 
    3014.3, 3004.04, 2984.42, 2995.11, 2976.61, 2985.03, 3005.47, 
    3019.56, 3003.67, 3025.86, 3020.97, 3013.18, 2980.38, 2953.56, 
    2932.05, 2844.74, 2881.77)
Waldi
  • 39,242
  • 6
  • 30
  • 78

1 Answers1

0

OK R-newb, you've posted code that throws about 100 errors. You were too lazy to put in all the needed commas to allow the c function to properly create a vector. So what is the proper lazy way to do that? Laziness is, of course, a "programming virtue". Look that quotation by a famous computer giant: https://www.google.com/search?safe=strict&sxsrf=ALeKk02Md5FRxdAGzgtnkhN9OSls0c0luw:1595040070508&q=three+great+virtues+of+a+programmer&sa=X&ved=2ahUKEwjPh7im49XqAhWZGTQIHYtIB1wQ1QIoAHoECAwQAQ&biw=1506&bih=728

Here's proper (lazy) code to create a [MCVE] in R:

x<-scan(text=
     "2510 2510.03 2447.89 2531.94 2549.69 2574.41 2584.96 2596.64 2596.26 2582.61 2610.30
     2616.10 2635.96 2670.71 2632.90 2638.70 2642.33 2664.76 2643.85 2640.00 2681.05
     2704.10 2706.53 2724.87 2737.70 2731.61 2706.05 2707.88 2709.80 2744.73 2753.03
     2745.73 2775.60 2779.76 2784.70 2774.88 2792.67 2796.11 2793.90 2792.38 2784.49
     2803.69 2792.81 2789.65 2771.45 2748.93 2743.07 2783.30 2791.52 2810.92 2808.48
     2822.48 2832.94 2832.57 2824.23 2854.88 2800.71 2798.36 2818.46 2805.37 2815.44
     2834.40 2867.19 2867.24 2873.40 2879.39 2892.74 2895.77 2878.20 2888.21 2888.32
     2907.41 2905.58 2907.06 2900.45 2905.03 2907.97 2933.68 2927.25 2926.17 2939.88
     2943.03 2945.83 2923.73 2917.52 2945.64 2932.47 2884.05 2879.42 2870.72 2881.40
     2811.87 2834.41 2850.96 2876.32 2859.53 2840.23 2864.36 2856.27 2822.24 2826.06
     2802.39 2783.02 2788.86 2752.06 2744.45 2803.27 2826.15 2843.49 2873.34 2886.73
     2885.72 2879.84 2891.64 2886.98 2889.67 2917.75 2926.46 2954.18 2950.46 2945.35
     2917.38 2913.78 2924.92 2941.76 2964.33 2973.01 2995.82 2990.41 2975.95 2979.63
     2993.07 2999.91 3013.77 3014.30 3004.04 2984.42 2995.11 2976.61 2985.03 3005.47
     3019.56 3003.67 3025.86 3020.97 3013.18 2980.38 2953.56 2932.05 2844.74 2881.77",
         what = numeric())

Now that I've solved the first problem, I'll see if I can solve the desired question. Back in a bit.

How to create a histogram with more bars than the default:

hist(x) # the default

How to look up stuff:

 ?hist 

So it's the breaks parameter and supplying it witha single numeric value will accomplish the task:

 hist(x, 30)

Now, how to overlay a "Normal" curve on that figure? Well, I'd suggest searching for the answer, because it's almost surely already been asked. See that bar at the top of the page? It's a search bar:

https://stackoverflow.com/search?q=overlay+a+%22Normal%22+curve+histogram

So here's an on-point prior answer that you should go to an upvote the questioner and the answerer:

Overlay normal curve to histogram in R

And no answer would be complete without a ggplot answer, so here's the second highest voted answer in that list of 30 potential duplicates that does it within the ggplotter-verse:

Overlay histogram with density curve

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Wish I'd seen the `x <- scan(text = ` before I put in the commas, while thinking, there must be several better ways... – Chris Jul 18 '20 at 03:56
  • As far as I could see you put in exactly one comma, whereas you would have needed a bit more like 140 of them. – IRTFM Jul 18 '20 at 06:10
  • Thank you everyone for the help :) I will try this out :) –  Jul 18 '20 at 15:26