Tossing 3 fair coins in R (2)Tossing 3 fair coins in RSolving statistics question using PythonSimulate coin toss for one week?Outcome of a simulated dice and coin toss in RCoin Toss game in RProbability - Coin TossingCalculating observed values from a coin-toss simulation in RDFA for expected coin tossesUnbiased coin toss of n coins with different success values for each coinImplementing Predictive Posterior Distribution Using StanTossing 3 fair coins in R

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

What are the advantages of simplicial model categories over non-simplicial ones?

Picking the different solutions to the time independent Schrodinger eqaution

On a tidally locked planet, would time be quantized?

Open a doc from terminal, but not by its name

putting logo on same line but after title, latex

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

The IT department bottlenecks progress. How should I handle this?

Calculate sum of polynomial roots

Quoting Keynes in a lecture

What if a revenant (monster) gains fire resistance?

Why Shazam when there is already Superman?

What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?

Limits and Infinite Integration by Parts

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Lowest total scrabble score

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Does IPv6 have similar concept of network mask?

Using substitution ciphers to generate new alphabets in a novel

Angel of Condemnation - Exile creature with second ability

Is aluminum electrical wire used on aircraft?

How does the math work for Perception checks?

Temporarily disable WLAN internet access for children, but allow it for adults

How do you make your own symbol when Detexify fails?



Tossing 3 fair coins in R (2)


Tossing 3 fair coins in RSolving statistics question using PythonSimulate coin toss for one week?Outcome of a simulated dice and coin toss in RCoin Toss game in RProbability - Coin TossingCalculating observed values from a coin-toss simulation in RDFA for expected coin tossesUnbiased coin toss of n coins with different success values for each coinImplementing Predictive Posterior Distribution Using StanTossing 3 fair coins in R













2
















If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).




The experiment has the following distribution:



enter image description here



According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50



And, enter image description here



where n = # of repetitions of the experiment.



Source Code



noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments


According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50



It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.



What is wrong with my code?



Edit:



enter image description here



I have written the following code on the basis of Edward Carney's comment.



noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments


enter image description here




Note: related question.










share|improve this question



















  • 2





    An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

    – Edward Carney
    Mar 8 at 2:32






  • 3





    In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

    – Marius
    Mar 8 at 3:18















2
















If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).




The experiment has the following distribution:



enter image description here



According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50



And, enter image description here



where n = # of repetitions of the experiment.



Source Code



noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments


According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50



It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.



What is wrong with my code?



Edit:



enter image description here



I have written the following code on the basis of Edward Carney's comment.



noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments


enter image description here




Note: related question.










share|improve this question



















  • 2





    An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

    – Edward Carney
    Mar 8 at 2:32






  • 3





    In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

    – Marius
    Mar 8 at 3:18













2












2








2


1







If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).




The experiment has the following distribution:



enter image description here



According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50



And, enter image description here



where n = # of repetitions of the experiment.



Source Code



noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments


According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50



It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.



What is wrong with my code?



Edit:



enter image description here



I have written the following code on the basis of Edward Carney's comment.



noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments


enter image description here




Note: related question.










share|improve this question

















If X = # of heads showing when three coins are tossed, find P(X=1), and E(X).




The experiment has the following distribution:



enter image description here



According to my calculation,
P(X=1) = 0.375 ≈ 0.40
E(X) = 1.50



And, enter image description here



where n = # of repetitions of the experiment.



Source Code



noOfExperiments = 10000;
mySample <- sample(c(0,1,2,3), noOfExperiments, replace = T)
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount / noOfExperiments
eX <- sum(mySample)/noOfExperiments


According to the above code, I obtained
P(X=1) = 0.2518
E(X) = 1.4917 ≈ 1.50



It seems like the value of E(X) is coming well, but the value of P(X=1) is not coming correctly.



What is wrong with my code?



Edit:



enter image description here



I have written the following code on the basis of Edward Carney's comment.



noOfExperiments = 1000;
mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) )
outcomeCount <- length(which(mySample==1))
prob <- outcomeCount/noOfExperiments
eX <- sum(mySample)/noOfExperiments


enter image description here




Note: related question.







r statistics probability






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 3:13







user366312

















asked Mar 8 at 1:52









user366312user366312

3,80146159319




3,80146159319







  • 2





    An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

    – Edward Carney
    Mar 8 at 2:32






  • 3





    In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

    – Marius
    Mar 8 at 3:18












  • 2





    An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

    – Edward Carney
    Mar 8 at 2:32






  • 3





    In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

    – Marius
    Mar 8 at 3:18







2




2





An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

– Edward Carney
Mar 8 at 2:32





An experiment would not involve inserting the probabilities ahead of time. A more realistic simulation can be obtained using mySample <- replicate(noOfExperiments, sum(sample(c(0, 1), 3, replace=T)) followed by table(mySample)/noOfExperiments `.

– Edward Carney
Mar 8 at 2:32




3




3





In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

– Marius
Mar 8 at 3:18





In your original code, you're not using the given probabilities at all - you could apply them using sample(c(0,1,2,3), noOfExperiments, replace = T, prob = c(0.125, 0.375, 0.375, 0.125))

– Marius
Mar 8 at 3:18












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055625%2ftossing-3-fair-coins-in-r-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055625%2ftossing-3-fair-coins-in-r-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived