Question

In: Math

2. Make a data frame consisting of 20 and 10 columns. Each column j should consist...

2. Make a data frame consisting of 20 and 10 columns. Each column j should consist of 20 values from a normal distribution with mean (i-1) and standard deviation 0.5j. For example, the third column should be normal(mean=2, sd=1.5). Using this data frame, do each of the following (using code, of course):
a. Find the mean and standard deviation for each column.
b. Write code that counts the number of columns for which the sample mean and sample standard deviation are within 20% of the values used to generate the data.
c. Write code that writes the columns from part b to a new data frame.
d. For each value in the new data frame, subtract its column mean and divide by the column standard deviation.

Solution using r and python

Solutions

Expert Solution

Solution using r

# Create matrix of order 20 by 10

M=matrix(rep(0,20*10),nrow=20,ncol=10)

for(j in 1:10){

M[,j]=rnorm(20,mean=j-1,sd=j*0.5)

}

a. Find the mean and standard deviation for each column.

#Find mean and stored in 21st row
M1=rbind(M,apply(M,2,mean))

#Find mean and stored in 22nd row

M1=rbind(M1,apply(M,2,sd))

b. Write code that counts the number of columns for which the sample mean and sample standard deviation are within 20% of the values used to generate the data.

count=0

for(j in 1:10){

mean=j-1

sd=j*0.5

mean1=0

if(M1[21,j]>0.8*mean & M1[21,j]<1.2*mean ){

mean1=1

}

sd1=0

if(M1[22,j]>0.8*sd & M1[22,j]<1.2*sd){

sd1=1

count=count+mean1*sd1

}

c. Write code that writes the columns from part b to a new data frame.

M2=M

d. For each value in the new data frame, subtract its column mean and divide by the column standard deviation.

for(j in 1:10){

M2[,j]=(M2[,j]-mean(M2[,j]))/sd(M2[,j])

}


Related Solutions

Create new Deck object Run testDeck( ) Should get four columns (13 rows each), each column...
Create new Deck object Run testDeck( ) Should get four columns (13 rows each), each column with a unique suit and ranked ace to king Run shuffle( ) then run testDeck( ) again Should get four NEAT columns,(13 rows each) with random numbers and suits in each column Create another Deck object Run testDeal( ) with a parameter of 5 Should get Ace, 2, 3, 4, 5 of spades as the “hand” Now run shuffle( ) then run testDeal( )...
USE R STUDIO. Consider the pressure data frame. There are two columns: temperature and pressure: •...
USE R STUDIO. Consider the pressure data frame. There are two columns: temperature and pressure: • Construct a scatterplot with pressure on the vertical axis and temperature on the horizontal axis. • The graph of the following function passes through the plotted points reasonably well: y = (0.168 + 0.007 ∗ x) ^(20/3). Recall that the differences between the pressure values predicted by the curve (i.e. y) and the observed pressure values (i.e. the pressure values obtained from the data...
Use the following information from the Adjustments columns of a 10-column work sheet.    Adjustments No....
Use the following information from the Adjustments columns of a 10-column work sheet.    Adjustments No. Account Title Dr. Cr. 109 Interest receivable (d) $ 571 124 Office supplies (b) $ 1,628 128 Prepaid insurance (a) 878 164 Accumulated depreciation—Office equipment (c) 3,300 209 Salaries payable (e) 651 409 Interest revenue (d) 571 612 Depreciation expense—Office equipment (c) 3,300 620 Office salaries expense (e) 651 636 Insurance expense—Office equipment (a) 421 637 Insurance expense—Store equipment (a) 457 650 Office supplies...
Requirements: a.   Copy the trial balance above in the first two columns of a 10-column work...
Requirements: a.   Copy the trial balance above in the first two columns of a 10-column work sheet. b.   Prepare adjusting journal entries in journal form from the following information (the fiscal year ends December 31). 1.   Estimated bad debts, .5% of sales less returns and allowances. 2.   Depreciation on building 4% per year; on furniture and fixtures, 10% per year. 3.   Insurance expired during the year, $3,900. 4.   Interest at 12% is payable on the mortgage on January 1 of...
1. Update the direct and indirect columns by placing an X in the appropriate column. 2....
1. Update the direct and indirect columns by placing an X in the appropriate column. 2. The monetary total of direct and indirect costs. Item Cost Direct Indirect IT Salaries and Benefits $1,500 RN Salaries and Benefits $9,600 Utilities and Telephone $3,000 Carpets $1,000 Magazine Subscriptions $ 50 Vehicle Expense $1,775 Exam Table $5,500 End Tables $ 500 Coffee Tables $1,400 Facility Insurance $ 650 Staff Uniforms $1,200 Cleaning Supplies $ 200 Desk Lamps $ 150 Front Desk Flowers $...
1. The fourth pair of columns on a 10-column work sheet prepared at the end of the period would be the
1. The fourth pair of columns on a 10-column work sheet prepared at the end of the period would be theIncome Statement columns.Adjusted Trial Balance columns.Balance Sheet columns.Adjustments columns.2. The third pair of columns on a 10-column work sheet prepared at the end of the period would be theAdjustments columns.Adjusted Trial Balance columns.Income Statement columns.Balance Sheet columns.3. The owner's equity in a business amounted to $52,000 at the beginning of the year and $100,000 at the end of the year....
You have a $2 million portfolio consisting of a $100,000 investment in each of 20 different...
You have a $2 million portfolio consisting of a $100,000 investment in each of 20 different stocks. The portfolio has a beta of 1.05. You are considering selling $100,000 worth of one stock with a beta of 1.15 and using the proceeds to purchase another stock with a beta of 1.3. What will the portfolio's new beta be after these transactions? Do not round intermediate calculations. Round your answer to two decimal places.
Make a Frequency Distribution Chart for the following set of Data 50, 10, 25, 20, 20,...
Make a Frequency Distribution Chart for the following set of Data 50, 10, 25, 20, 20, 20, 50,100, 30, 15
Develop a conceptual data model for the following scenario: The data model should consist of the...
Develop a conceptual data model for the following scenario: The data model should consist of the usual 5 components: E-R diagram, Entity Types (including entity type identifiers), assumptions, additional constraints, and limitations: It is desired to develop a shop database for a shop of different classes of products. A shop sells different classes of products to customers. For each class, it is required to keep the following information: class identification number (class-id) and class name. Each class has one or...
Data mining i have a data column where the required mark is 20 but the data...
Data mining i have a data column where the required mark is 20 but the data fed in to the column is more than 40 , how do you advise me to clean that data, and also please state what data is it for instance noisy or what and also name the method to solve it and please tell how to clean it thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT