After reading Chapter 9 of the textbook, discuss the following questions to the best of your abilities:
-Let's pretend that you recently moved from Italy to the United States. How can you adjust to a new society and connect to people in a different community?
-In your own words, state what does āliving in a diverse worldā mean to you?
-Name two positive effects and two negative effects of using communication technology.
-Define āprejudiceā and name three causes of prejudice.
-Describe why āIā statements are so important to successful communication with a close friend or partner.
Important notice: Your professor will consider these elements when assessing the quality and level of student participation.
Submit initial post(s) early in the session and subsequent responses to the posts of other learners at timely intervals throughout the duration of the session. The goal is to have a dynamic discussion around the topic that lasts throughout the entire session.
Your original post should be within a range of 75-100 words. If a post does not meet the minimum word count of 75, your professor will not count it toward your grade.
Your subsequent contributions responding to a classmate should have 50 to 100 words.
Book: Keys to Success Quick by Carol Carter, Joyce Bishop, Sarah Lyman Karvirts
In: Psychology
Select 3 different sized (order lg lg n, lg n, n, n lg n, n2 , n3 , nk , cn , n!) algorithms to code using a compiler of choice (VB, C++, Java, , etcā¦). An example would be an algorithm to search for a number in a list of n numbers ā ļ±(n), and a second algorithm to sort a list of numbers using a bubble sort ā ļ±(n2 ). You could also choose to just calculate a open form expression like 1 + 2 + 3 + 4 + 5 + 6 + ⦠n for a size n algorithm. Once the algorithms are coded and working (10pts. will be awarded on complexity/substance of algorithms), add a timer to the crucial section of the code that will correspond to the ļ± analysis. I have included some sample Java and C++ timer code below that should work. Show me the programs running/working with the time elapsed outputted for a run. 5pts. Run and time the three algorithms for n = 10, 100, 1000, 10000, etc⦠and chart the different times on a column, bar, or line chart. Turn in a word processed report listing the three algorithms code and the charts displaying the timed results of the runs. 5pts. Use long (16 bit) in Java and long long (16 bit) in C++ for your variables to avoid a memory problem.
In: Computer Science
Writing a caesar cipher in ARM assembly.
INSTRUCTIONS:
Step 1:
The first thing you should do is modify the case conversion program String.s (provided)
Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key.
Assume that all input will be lowercase.
So it'll look like this,
k = 2;
letter = 'a';
newletter = k+letter;
Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY.
Use bl puts to show that everything is working correctly.
You should hard code the plaintext in the assembly file.
Step 2:
If the key + letter is bigger is 'z' then you have to subtract 26.
If the key + letter is less than 'a' then you have to add 26.
STRING.S
.text
.global main
main:
ldr r4,=string
get_another_byte:
ldrb r5,[r4]
cmp r5,#'a'
# blt keep_going
# cmp r5,#'z'
# bgt keep_going
subeq r5,#32
strbge r5,[r4]
keep_going:
add r4,#1
cmp r5,#0
bne get_another_byte
ldr r0,=temp
str lr,[r0]
ldr r0,=string
bl puts
ldr r0,=temp
ldr lr,[r0]
bx lr
.data
string:
.asciz "This is a string"
temp:
.word 0In: Computer Science
The World Bank is considering an application from the country of Equatoria for a large dam project. In order to build this dam, villagers from an entire village will need to be relocated. In addition, there will be some watershed damage and ecological losses due to habitat destruction. Monetary costs and benefits for the dam project are given as follows:
Construction costs: $650 million at the beginning of the first year of the project. Construction costs for the start of the second year of the project will be 12% higher than the first year costs, and at the start of year 3 (the final year of construction) the costs will be 15% higher than the first year costs. Operating costs: $75 million/year (starting in year 3); and then increase to $80 million/year from year 8 onward Hydropower generated: 4 billion kilowatt hours/year (available from year 3) Price of electricity: $0.08/kilowatt hour Irrigation water available from the dam: 20 billion litres/year (available from year 3) Price of water: $0.008/litre Agricultural production lost from flooded lands: $54 million/year (loss from year 2)
Forestry production lost from flooded lands: $28 million/year (loss from year 2) Note: 1 billion = 1000 million
You, as a consultant have been approached by the World Bank to carry out an analysis from which you will provide your recommendations.
Your tasks: A. Calculate the NPV and the B/C using a real discount rate of 4.6%. Set up a basic template to complete your CBA. Put the variables in the clearly labeled cells above your Large Dam Project. Since we are given agricultural and forestry production losses, if we incorporate these we are automatically creating a āwithwithout projectā analysis. Next complete your Large Dam Project with clearly labelled columns. Do this by creating formulae using your variables in the cells above. Always use formulae linked back to the data cells above so that if you wish to change a data cell value (for a sensitivity analysis) then all your calculations will automatically
2
change. Once you have created a formula in one cell of a column you should be able to drag down so that it accurately duplicates the formula right down the column. To do the analysis I want you to complete the columns initially for 10 years of the project. However, we can assume that once built this dam will remain in place indefinitely. So to extend the analysis to cover the long term, follow these instructions:
i) Underneath Yr 10 put Yr 11 to infinity (11 ā infinity).
ii) Since the last few years have the same Net Cash Flow (NCF) and we do not have any further information, we can assume that the future NCFs will remain the same. This means that we can calculate the future NCFs based on these last NCFs and use the formula for a perpetuity that states: PV of all future expected cashflows = NCF/discount rate, (this effectively capitalizes the future NCFs)
iii) To create the formula for this in the NCF cell for yrs 11 ā infinity (in your NCF column), use the NCF cell in year 9 and divide this value by the discount rate cell. (Use the year 9 NCF rather than the one in year 10, because you will shortly be changing the NCF entry in year 10). You have now calculated the PV of all future NCFs, to the beginning of year 11 (as this is the beginning point of yrs11-infinity).
iv) But you want your final PV to be today (year 0) not year 11. Remember that the beginning of year 11 is the same as the end of year 10, so now you can add this cell containing the large value for (NCF/disc. rate) into your calculation for the year 10 NCF. v) Your final column is where you calculate the PV(NCF)s ā i.e. the PV of each entry in your NCF column.
vi) Finally, sum your PV(NCF) column and this sum will give you your NPV. vii) Similarly, for your B/C you will need to calculate the PV(future Costs) and PV(future Bens) in a similar manner (as you did for the NCF) for years 11 ā infinity. This is so that you capture all future streams of costs and also of benefits. Then finally calculate the NPV(Costs) and NPV(Benefits) so that you can use these to calculate your B/C.
Also begin a Word doc. and for Part A. give the NPV(Large Dam) and also the B/C(Large Dam).
B. Now consider an alternative project: several smaller dams constructed to avoid flooding significant agricultural land or forested areas. For this project, total construction costs are exactly half the costs of the large dam project, while operating costs are two-thirds those of the large dam. Power and irrigation benefits are also half as much as those for the large dam. Agricultural land and forests are not affected and the project incurs no ecological or resettlement costs.
(i) Calculate the NPV of this Smaller Dams Project using the discount rate of 4.6%. You already have all the variables set up (for the Large Dam project) so do not create new cells but work from the original cells. Conduct your analysis for the Smaller Dams Project on a new table beneath that for the Large Dam Project (using some or all the same columns). Label the Small Dams Project clearly (all on the one sheet of your spreadsheet file ā this makes marking easier). Include the years 11 ā infinity in your Small Dams analysis in exactly the same way as you did for the Large Dam project.
On your Word doc. for B.
(i) give the NPV(Smaller Dams).
(ii) Now you are to compare both projects under different discount rates. Set up a table with a column containing various discount rates, another column for the NPV for the Large Dam Project and a third column for the NPV for the Small Dams Project. Complete the table and use it to draw a graph that shows the changing NPVs plotted against the discount rate, for both projects on the one graph. Make sure your graph is properly labelled and has an appropriate title that contains your name. On your Word doc. for B (ii) if your decision regarding the two different dam projects were to be based solely on the CBAs calculated thus far, give the range of discount rates for which you would choose the Large Dam Project over the Smaller Dams Project, and vice versa.
(iii) For just the Large Dam Project, carry out this sensitivity analysis: Suppose the amount of hydropower generated was overestimated, and instead 3.2 billion kilowatt hours/year were generated and in addition, the price of electricity was $0.06/kilowatt hour and the price of water was $0.005/litre. Make these changes and make a note of the new NPV and B/C, and then return your analysis to its original numbers for handing in.
On your Word doc. for B
(iii), for the Large Dam Project give the NPV and B/C under this sensitivity analysis. In a sentence what would you say about this? Also explain what the B/C is predicting regarding our investment
C. Finally, in your Word document you are to evaluate the two projects, the Large Dam project (originally, before the sensitivity analysis) and the Smaller Dams project individually and then make comparison between the two. Your evaluation should include a discussion on the costs and benefits not quantified in your spreadsheet analyses. In this discussion make recommendations as to how you could incorporate these costs and benefits into your spreadsheet analysis. Conclude this analysis by giving your final recommendations to the World Bank. 600words
In: Finance
In C++:
This is the problem:
[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate
[(2)] Let Q be a non-empty queue, and let S be an empty stack. Using only the stack and queue ADT functions and a single element variable X, write an algorithm to reverse the order of the elements in Q.
[(3)] Use singly linked lists to implement integers of unlimited size. Each node of the list should store one digit of the integer. You should implement addition, subtraction, multiplication, and exponentiation operations. Limit exponents to be positive integers. What is the asymptotic running time for each of your operations, expressed in terms of the number of digits for the two operands of each function?
[(4)] Implement a program that can input an expression in postfix notation and output its value.
I need number 3 completed.
This is the code:
#include <iostream>
#include <string.h>
#include <stack>
#include <queue>
#include <string>
#include <bits/stdc++.h>
using namespace std;
// Stack type
struct Stack
{
int top;
unsigned capacity;
int* array;
};
// Stack Operations
struct Stack* createStack( unsigned capacity )
{
struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack));
if (!stack) return NULL;
stack->top = -1;
stack->capacity = capacity;
stack->array = (int*) malloc(stack->capacity * sizeof(int));
if (!stack->array) return NULL;
return stack;
}
int isEmpty(struct Stack* stack)
{
return stack->top == -1 ;
}
char peek(struct Stack* stack)
{
return stack->array[stack->top];
}
char pop(struct Stack* stack)
{
if (!isEmpty(stack))
return stack->array[stack->top--] ;
return '$';
}
void push(struct Stack* stack, char op)
{
stack->array[++stack->top] = op;
}
// The main function that returns value of a given postfix expression
int evaluatePostfix(char* exp)
{
// Create a stack of capacity equal to expression size
struct Stack* stack = createStack(strlen(exp));
int i;
// See if stack was created successfully
if (!stack) return -1;
// Scan all characters one by one
for (i = 0; exp[i]; ++i)
{
// If the scanned character is an operand (number here),
// push it to the stack.
if (isdigit(exp[i]))
push(stack, exp[i] - '0');
// If the scanned character is an operator, pop two
// elements from stack apply the operator
else
{
int val1 = pop(stack);
int val2 = pop(stack);
switch (exp[i])
{
case '+': push(stack, val2 + val1); break;
case '-': push(stack, val2 - val1); break;
case '*': push(stack, val2 * val1); break;
case '/': push(stack, val2/val1); break;
}
}
}
return pop(stack);
}
// Utility function to print the queue
void Print(queue<int>& Q)
{
while (!Q.empty()) {
cout << Q.front() << " ";
Q.pop();
}
}
// Function to reverse the queue
void reverseQueue(queue<int>& Q)
{
stack<int> S;
while (!Q.empty()) {
S.push(Q.front());
Q.pop();
}
while (!S.empty()) {
Q.push(S.top());
S.pop();
}
}
void convertTosmall(string& str)
{
int length = str.length();
for (int i = 0; i < length; i++) {
int c = str[i];
if (isupper(c))
str[i] = tolower(c);
}
return;
}
string removeSpaces(string& word) {
string newWord;
for (int i = 0; i < word.length(); i++) {
if (word[i] != ' ') {
newWord += word[i];
}
}
return newWord;
}
int main()
{
while( true )
{
std::string letters;
std::cout << "Please enter a string (Enter - exit): ";
std::getline( std::cin, letters );
convertTosmall(letters);
letters = removeSpaces(letters);
if ( letters.empty() ) break;
std::stack<char>
s( std::stack<char>::container_type( letters.begin(), letters.end() ) );
std::queue<char>
q( std::queue<char>::container_type( letters.begin(), letters.end() ) );
while ( !s.empty() && s.top() == q.front() )
{
s.pop();
q.pop();
}
if ( s.empty() ) std::cout << "The string is a palindrome" << std::endl;
else std::cout << "The string is not a palindrome" << std::endl;
}
queue<int> Q;
Q.push(10);
Q.push(20);
Q.push(30);
Q.push(40);
Q.push(50);
Q.push(60);
Q.push(70);
Q.push(80);
Q.push(90);
Q.push(100);
reverseQueue(Q);
Print(Q);
char exp[] = "231*+9-";
cout<<"\npostfix evaluation: "<< evaluatePostfix(exp);
cout<<"\n"<<endl;
return 0;
}
In: Computer Science
Assignment anthropocentrism, global warming, consumerism-WORTH 15%
North American culture supports excessive consumerism;āconsumerism has encouraged people to seek happiness through constant expansion of their material standard of livingā (Bush, 2008). Adam Smith is arguably the most influential economist of all time. He wrote extensively on capitalism, and he said āconsumption is the sole end and purpose of all production; and the interest of the producer ought to be attended to only so far as it may be necessary for promoting that of the consumerā (Smith, 1776).
Part 1
Please consider the lecture notes and videos when answering the following questions. BE sure to answer in full sentences and paragraph formation. Donāt assume I have read the question.
Part 2: The effects of Global Warming on human life.
The World Health Organisation (2017) found that āBetween 2030 and 2050, climate change is expected to cause approximately 250,000 additional deaths per year, from malnutrition, malaria, diarrhea and heat stress.ā
Be sure to watch the Panopto video āIntroduction to Argumentsā prior to answering the following questions.
Part 3
Part 4- reflection
In: Economics
| Series Legend | Input Area | Net Sales | CE | OR | TB | ||||||||||||||||||||||||||||||||
| Royalty Rate: | 7.3% | Average | Certification Series | Office Reference | True Beginner | ||||||||||||||||||||||||||||||||
| Return Rate: | 10.0% | Highest | |||||||||||||||||||||||||||||||||||
| Bonus Amount: | $500.00 | Lowest | |||||||||||||||||||||||||||||||||||
| Author | Series Code | Software | Quantity Sold | No. Books Returned | Percent Returned | Unit Price | Net Sales | Author Royalties | Bonus | Author Earnings | |||||||||||||||||||||||||||
| Lopez | OR | Word 2016 | 8,584 | 500 | $49.95 | 500 | |||||||||||||||||||||||||||||||
| Krupin | TB | Word 2016 | 1,847 | 271 | $25.00 | 500 | |||||||||||||||||||||||||||||||
| Cote | CE | Word 2016 | 2,684 | 400 | $39.95 | 500 | |||||||||||||||||||||||||||||||
| Yeung | OR | Excel 2016 | 11,841 | 1,042 | $49.95 | 500 | |||||||||||||||||||||||||||||||
| Tremblay | TB | Excel 2016 | 9,475 | 957 | $30.00 | 500 | |||||||||||||||||||||||||||||||
| Torres | CE | Excel 2016 | 8,443 | 327 | $39.95 | 500 | |||||||||||||||||||||||||||||||
| Martin | OR | Access 2016 | 8,064 | 834 | $49.95 | 500 | |||||||||||||||||||||||||||||||
| Alfero | TB | Access 2016 | 3,397 | 331 | $30.00 | 500 | |||||||||||||||||||||||||||||||
| Daniels | CE | Access 2016 | 3,978 | 415 | $34.49 | 500 | |||||||||||||||||||||||||||||||
| Ortiz | OR | PowerPoint 2016 | 1,279 | 120 | $49.95 | 500 | |||||||||||||||||||||||||||||||
| Wong | TB | PowerPoint 2016 | 1,050 | 184 | $25.00 | 500 | |||||||||||||||||||||||||||||||
| Kumar | CE | PowerPoint 2016 | 2,507 | 187 | $34.49 | 500 | |||||||||||||||||||||||||||||||
| Bartalotti | TB | Outlook 2016 | 1,884 | 175 | $25.00 | 500 | |||||||||||||||||||||||||||||||
| Wallace | OR | Windows 10 | 14,750 | 1,839 | $49.95 | 500 | |||||||||||||||||||||||||||||||
| Toulou | TB | Windows 10 | 8,342 | 803 | $25.00 | 500 | |||||||||||||||||||||||||||||||
| Coleman | CE | Windows 10 | 6,124 | 741 | $34.49 | 500 | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
In: Operations Management
Program Requirements
Program Output
Your output should look like this:
| Line 8: using(0) namespace(6) <== using
occurs at position 0 on line 8, namespace occurs at position 6 on
line 8 Line 10: const(0) int(6) Line 12: void(0) const(19) Line 13: void(0) char(20) int(32) const(48) Line 14: bool(0) const(24) char(30) const(42) Line 15: void(0) char(17) Line 16: void(0) Line 17: void(0) Line 19: int(0) Line 21: const(4) ... Number of keywords found = ?? <== Add this line at the end of your output, replace ?? with the correct number |
Program Hints
The keyword file looks like this:
| for if nullptr break int long sizeof return short else friend const static_cast ... |
The C++ program file looks like this:
| #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <fstream> #include <iostream> #include <string> using namespace std; const int DictionarySize = 23907; void getDictionary(const string& filename,string*); void spellCheckLine(char* line, int lineNumber, const string* dictionary); bool wordIsInDictionary(const char* word, const string* dictionary); void toLowerCase(char* text); ... |
istream::getline example
| ifstream fin("oldass3.cpp"); ... char buffer[132]; ... fin.getline(buffer,sizeof(buffer)); // store a line from the input file into buffer |
In: Computer Science
Step 1: Your program will now take its input from this file instead of from the user. Here's what you want to do:
Run your code to make sure that the file is opened and read correctly. Hint: you may test the correctness of code by printing the contents of this file, one string at a time.
//Code to be adjusted
#include<iostream>
#include<string>
using namespace std;
//prompts user for input and returns a string containing userinput
string getUserInput(){
string input;
getline(cin,input);
return input;
}
//returns true if given character is vowel else false
bool isVowel(char c){
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
return true;
return false;
}
//returns true if given character is an alphabet else false
bool isAlphabet(char c){
if((c >= 'a' && c<='z') || (c >= 'A' && c<='Z'))
return true;
return false;
}
//returns true if given character is digit else false
bool isNumber(char c){
if(c >= '0' && c <= '9')
return true;
return false;
}
//Prints the report
void printReport(int vowels, int cons, int digit, int special){
cout<<"Vowels: "<<vowels<<endl;
cout<<"Consonants: "<<cons<<endl;
cout<<"Digits: "<<digit<<endl;
cout<<"Special characters: "<<special<<endl;
}
//driver function
int main(){
//to store user string
string input;
//counters for number of vowels, consonants, digits and special characters respectively
int vowel = 0;
int consonant = 0;
int digit = 0;
int specialChar = 0;
//gets user input
input = getUserInput();
//iterating over input and counting the number of vowels, consonants, digits and special characters
for (int i=0;i<input.length();i++){
if(isVowel(input[i])){
vowel++;
}
else if (isAlphabet(input[i])){
consonant++;
}
else if(isNumber(input[i])){
digit++;
}
else{
specialChar++;
}
}
//Displaying the report
printReport(vowel,consonant,digit,specialChar);
return 0;
}
Ex: If the input file is:
Input
words.txt
Your output (end the following message with a newline)
Could not open file words.txt
Step 2:
void printReport(string userText, int vowelCount, int consoCount, int digitCount, int specialCount)
{
//implement the three rules of checking if the input word is a valid C++ variable or not
//you may copy the code below in your printReport() function
if (isValid) {
cout << "The variable name - " << userText << " - is valid." << endl;
}
else {
cout << "The variable name - " << userText << " - is invalid." << endl;
}
}
You must print the message in printReport() for each word in the input file (words.txt).
At this moment, your main() is going to have code that opens and reads contents of a file, does counting (vowels, consonants, digits, and special characters) and calls printReport(). Go ahead and run it to make sure that your code gives the correct output for a test string.
Step 3: Build a function called getCount() that takes a string parameter (for the inputText that is being analyzed) and four additional parameters corresponding to the count of each kind of character. These would be passed by reference and their value will be set by this function.
Prototype: void getCount(string userText, int& vowelCount, int& consoCount, int& digitCount, int& specialCount);.
Refactor your main() so that it only calls getCount and printReport by passing it appropriate arguments. At this stage, your main() should have code that opens and reads from a file and calls getCount() and printReport() for each word read from the input file. Run your code to make sure it works and gives the correct output for a test string.
getCount() function that does all the counting so as to reduce the code inside main() even further!
Text files:
data1.txt
Ihaveadream
Elponitnatsnoc
yellowtiger
x
cat?dog
star!search
Gameover!
data2.txt
This
file
contains
15
words
It
has
lots
of
letters
and
very
few
special
characters!
Fallis@wesomein$onomaCounty!
In: Computer Science
Homework # 3: Note: Please circle your answers when appropriate! 1) You have a sample of 11 flowers from pea plants. (a) Suppose 7 of them are white, and 4 of them are purple. If you line them up in a row, how many different arrangements can you get? Note: WWWWWWWPPPP is one arrangement, WPWPWPWPWWW is another arrangement, and so on. You do NOT want to actually list all possible arrangements - instead, use what you learned in class to calculate this. (b) Now suppose 4 of them are white and 7 of them are purple. How many different arrangements can you get? (c) How many arrangements do you have for 1 white and 10 purple? (d) How many arrangements do you have for 0 white and 11 purple? 2) In the U.S., about 8.5% of people are B+ for blood type. You take a sample of size 9. You're interested in people who are B+. Figure out the following probabilities: a) Pr{Y = 3} b) Pr{Y = 1} c) Pr{Y < 1} d) Pr{Y > 0} (hint - use (c) to answer this and make sure you know why this works) 3) Mendelian genetics predict that in Labrador retrievers (a type of dog), 75% should have black coat color if both parents are heterozygous (the rest are brown). You mate two parents and get a litter of 6 puppies. Calculate the following: a) The probability of 4 black puppies. b) The probability of 4 brown puppies. c) The probability that 50% of the puppies will be brown. (Comment: You do not need to know anything about genetics to solve this problem. If you're trying to do things like use punnet squares, you're doing things wrong) 4) Refer to problem 3. Calculate the probability of every possible outcome (hint: you need to make seven calculations (you already made three of them in problem 3)). 5) Let's do some R.... Suppose you have the following situation: You have a large jar of beans, 29% black, 71% white. You take a sample of 11 beans. a) Use R to figure out the probability for every single possible outcome. In other words, you need to calculate: Pr{0 black beans in 11 trials} Pr{1 black bean in 11 trials} . . etc. . Pr{11 black beans in 11 trials} b) Once you have this information, you need to plot a barplot that shows you what this distribution looks like. As you might guess, you'll need to use the binomial (in R - see below) to solve this problem. Make sure you present all your results (you should have a list of probabilities and the barplot). _________________________________________________________________________________________ Some R instructions to help you are on the next page. Instructions for copying graphs in/from R are also included at the end. For R problems: be prepared to sketch or list your results. You may be asked to show graphs to the class using the document camera at the front of the room (your recitation instructor will set this up for you). Note the following: NEVER, NEVER, hand in just an R printout: Clean it up and clearly label your answers. Make it obvious where everything is and what/where your conclusions/answers are. You will not do well if all you do is hand in a printout. Due in recitation the week of February 17th . R commands: Caution: Be careful copying and pasting commands into R. Some characters may not copy correctly and give you error messages. This is particularly true for quotes. R does not recognize quotes that look like ā, only quotes that are straight like this: " . I tried to fix this below, but canāt guarantee I caught everything. Bean problem: Here's an example using a sample of 8 beans from a jar with 32% black beans. You should be able to modify the following as needed to answer question 6: For probabilities: You want probabilities for 0 through 8 beans. First we need to create y with 8 numbers: y <- c(0:8) This command says to give āyā the numbers 0 - 8 in sequence; technically ā0:8ā tells R it's a sequence of numbers, and the ācā out front means to combine all the numbers. The ācā isn't really needed (try it!) this time, but it is required in many similar situations so it's a good habit to get into to. Now we just āfeedā our y into the binomial function to get our answers: p <- dbinom( y, size = 8, prob = .32) This should give you āpā with all the binomial probabilities (they'll be in order from 0 to 8; type āpā to get/see the probabilities) If you want to make it look nice, you can do: pr <- data.frame(y,p) pr to make it look even better, follow this with: print(pr,row.names = FALSE) The data.frame command combines the variables you list (in this case, y and p) into a single data set. Unfortunately if you then type āprā R will insist on printing row names as well. If you want to get rid of the row names (theyāre not needed), you need to use the print statement as given above. To get a barplot: To get a barplot, you simply do (see also the homework instructions from last week): barplot(p) This won't look very nice, so you should try to improve it: barplot(p,names.arg = y) Here ānames.argā is the variable that holds the labels you want to put on the x axis (remember we put the numbers 0 - 8 into y). Just try it - you'll see how it works. If you want to improve your graph even more, you can do (review the caution statement above if you have trouble copying and pasting this): barplot(p,names.arg = y, ylab = "frequency", xlab = "number of dark beans") Or even fancier: barplot(p,names.arg = y, ylab = "frequency", xlab = "number of dark beans", col = "blue") To copy/save graphs generated in R or RStudio: You're going to want to save your graphs or copy them into a word processor so that you can hand them in or refer to them during presentations. If you are using RStudio: (If you're given a choice of format to use as you follow these instructions (usually under Windows), choose āmetafileā) Make sure the graph you want is visible in the graphics window. Click on āexportā near the top of the plot window. Select āCopy Plot to Clipboardā The click on āCopy Plotā Open your favorite word processor and paste the graph into your document. Comment: copying graphs this way doesn't always give you the best looking graphs (particularly if you're using Linux). Saving the plot as a high resolution image and then inserting this into your document often gives better results. The details on how to do this are provided below - the following instructions work both with and without Rstudio. If for some strange reason you're not using RStudio or you want to do this just from the command line: Windows: In R, right click the graph, select ācopy as metafileā (don't use bitmap), then open your favorite word processor and paste the graph. Mac OS: You should be able to copy the graph (make sure the graph window is active) from the menu, and then simply paste the graph into Word (or whatever word processor you use). If this doesn't work for some reason, the Linux instructions will work (they'll work with Windows as well). Linux: This is a bit complicated. A simple way to do it is to use the print screen key, but it'll look horrible. Hereās one example of getting good looking graphs: 1) generate the graph on-screen (just as usual) to make sure it looks right. 2) type ājpeg()ā in the command line. There are actually several formats you can pick but jpeg is probably the easiest. 3) generate the graph again (make the graph again). You'll notice that nothing seems to happen. That's okay. It's writing the graph to a jpeg file. 4) now type ādev.off()ā on the command line. 5) the graphics file should now be in your home directory. It'll have a name like āRplotxxx.jpegā, where xxx is some number. You can always sort by modification date in your file browser to find it quickly. 6) You should now be able to insert or copy the file into your text document (e.g. Word, LibreOffice, or whatever you're using). 7) The jpeg may not look terrific (it'll look a lot better than āprint-screenā. You can increase the resolution by doing (in step 2 above)): jpeg(width = 1000,height = 1000) The jpeg command defaults 480 x 480, which isn't that great. You can also use the jpeg command to give it a filename that makes sense, if you want: jpeg(filename = "your-file-name",width = xxx, height = xxx)
In: Statistics and Probability