
<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="https://www2.math.binghamton.edu/lib/exe/css.php?s=feed" type="text/css"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Department of Mathematics and Statistics, Binghamton University people:kargin:math447</title>
    <subtitle></subtitle>
    <link rel="alternate" type="text/html" href="https://www2.math.binghamton.edu/"/>
    <id>https://www2.math.binghamton.edu/</id>
    <updated>2026-04-09T04:20:59-04:00</updated>
    <generator>FeedCreator 1.7.2-ppt DokuWiki</generator>
<link rel="self" type="application/atom+xml" href="https://www2.math.binghamton.edu/feed.php" />
    <entry>
        <title>Examples of R-code</title>
        <link rel="alternate" type="text/html" href="https://www2.math.binghamton.edu/p/people/kargin/math447/r_example2"/>
        <published>2016-04-11T20:33:36-04:00</published>
        <updated>2016-04-11T20:33:36-04:00</updated>
        <id>https://www2.math.binghamton.edu/p/people/kargin/math447/r_example2</id>
        <summary>
&lt;h5 id=&quot;examples_of_r-code&quot;&gt;Examples of R-code&lt;/h5&gt;
&lt;div class=&quot;level5&quot;&gt;

&lt;/div&gt;

&lt;h4 id=&quot;examplecovariance_calculation_by_numerical_double_integral&quot;&gt;Example: Covariance calculation by numerical double integral.&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;#First, install the package &amp;quot;cubature&amp;quot; with install.packages(&amp;quot;cubature&amp;quot;).
#You only need to do it once.

library(cubature) # load the package &amp;quot;cubature&amp;quot;
f &amp;lt;- function(x) { 6 * x[1] * (x[2] &amp;gt; x[1])} # This is the density, &amp;quot;x&amp;quot; is a 2D-vector

E.XY &amp;lt;- adaptIntegrate(function(x) x[1]*x[2]*f(x), lowerLimit = c(0, 0), 
                       upperLimit = c(1, 1))
E.X &amp;lt;- adaptIntegrate(function(x) x[1]*f(x), lowerLimit = c(0, 0), 
                      upperLimit = c(1, 1))
E.Y &amp;lt;- adaptIntegrate(function(x) x[2]*f(x), lowerLimit = c(0, 0), 
                      upperLimit = c(1, 1))

cov.XY &amp;lt;- E.XY$integral - E.X$integral * E.Y$integral #E.X, E.Y, E.XY have several fields like 
                                                      #E.X$integral E.X$error and so on. 
                                                      #We need only the integral field.
cov.XY
&lt;/pre&gt;

&lt;/div&gt;
</summary>
    </entry>
    <entry>
        <title>Examples of R-code</title>
        <link rel="alternate" type="text/html" href="https://www2.math.binghamton.edu/p/people/kargin/math447/r_examples"/>
        <published>2016-03-05T15:40:31-04:00</published>
        <updated>2016-03-05T15:40:31-04:00</updated>
        <id>https://www2.math.binghamton.edu/p/people/kargin/math447/r_examples</id>
        <summary>
&lt;h5 id=&quot;examples_of_r-code&quot;&gt;Examples of R-code&lt;/h5&gt;
&lt;div class=&quot;level5&quot;&gt;

&lt;/div&gt;

&lt;h4 id=&quot;exampleapproximation_of_the_gaussian_distribution_by_sums_of_bernoulli_and_uniform_random_variables&quot;&gt;Example: Approximation of the Gaussian distribution by sums of Bernoulli and uniform random variables.&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;#Generating data
repet &amp;lt;- 10000
size &amp;lt;- 100 
p &amp;lt;- .5
data &amp;lt;- (rbinom(repet, size, p) - size * p) / sqrt(size * p * (1-p))
hist(data, freq = FALSE)

#Histograms

#By default you get a frequency histogram. 
#To get a density you set &amp;quot;freq = FALSE&amp;quot;.
#To control the number of bins use &amp;quot;breaks = &amp;quot;. 

hist(data, breaks = size/2, col = &amp;#039;red&amp;#039;, freq = FALSE)

#Plotting the pdf of the normal distribution

x &amp;lt;- seq(min(data) - 1, max(data) + 1, .01)
lines(x, dnorm(x), col=&amp;#039;green&amp;#039;, lwd = 4)
 
#similar exercise for uniform random variables.

size &amp;lt;- 3 
data &amp;lt;- runif(repet * size)
data.matrix  &amp;lt;- matrix(data, nrow = size)
mu &amp;lt;- size * 1/2
sigma &amp;lt;- sqrt(size * 1/12)
data &amp;lt;- (colSums(data.matrix) - mu )/ sigma
hist(data, breaks = 100, col = &amp;#039;red&amp;#039;, freq = FALSE)
lines(x, dnorm(x), col = &amp;#039;green&amp;#039;, lwd = 4)&lt;/pre&gt;

&lt;/div&gt;
</summary>
    </entry>
</feed>
