Question

Write a c code program to solve 5a. Given the data as follows: x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,3

Write a c code program to solve

5a. Given the data as follows:

x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42};

y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48}.

Compute the average, variance and standard deviation (S.D.) of x and y separately.

5b. Given the data as follows:

x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42};

y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48}.

Compute Linear regression, i.e., find a and b such that y=ax+b results in the smallest total error.

5c. For the data given in problem 5, check the relationship between average(x) and average(y), and also the relationship between S.D.(x) and S.D. (y). Explain your observation.

Please write out the programs and have screenshots of the outputs

Homework Answers

Answer #1

5a. Code in C and output

#include <stdio.h>
#include <math.h>

float sum(int arr[]){
    float result = 0;
    for(int i = 0; i<100;i++){
        result += arr[i];
    }
    return result;
}

float avg(float total){
    return total / 100;
}

float var(int arr[], float myu){
    float result = 0;
    for(int i = 0; i <100; i++){
        result +=   ((arr[i] - myu)*(arr[i] - myu))/100;
    }
    return result;
}

float std(float variance){
    return sqrt(variance);
}

int main(){

    // intialize the data 
    int x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42};
    int y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48};

    float x_bar = avg(sum(x));
    float y_bar = avg(sum(y));

    float x_var = var(x,x_bar);
    float y_var = var(y,y_bar);
    
    float x_std = std(x_var);
    float y_std = std(y_var);


    printf("The average of X = %f\n", x_bar);
    printf("The average of Y = %f\n", y_bar);
    printf("The variance of X = %f\n", x_var);
    printf("The variance of Y = %f\n", y_var);
    printf("The std deviation of X = %f\n", x_std);
    printf("The std deviation of Y = %f\n", y_std);
    return 0;
}

5b. Code and output

#include <stdio.h>
#include <math.h>

float sum(int arr[]){
    float result = 0;
    for(int i = 0; i<100;i++){
        result += arr[i];
    }
    return result;
}

float sum_2(int arr[]){
    float result = 0;
    for(int i = 0; i<100;i++){
        result += pow(arr[i],2);
    }
    return result;
}


float sumxy(int arr1[], int arr2[]){
    float result = 0;
    for(int i = 0; i<100;i++){
        result += arr1[i] * arr2[i];
    }
    return result;
}

int main(){

    // intialize the data 
    int x[100] = {61,58,97,7,72,91,20,90,83,67,66,54,15,62,38,44,60,88,12,99,86,45,84,30,52,76,39,27,27,59,45,45,98,80,22,95,6,3,21,30,37,86,95,7,41,95,23,5,1,22,68,14,71,39,37,97,9,26,42,71,75,4,79,32,42,9,35,13,31,95,78,83,12,21,60,2,28,67,21,69,11,45,13,52,26,16,43,56,31,74,35,5,41,33,36,6,75,8,30,42};
    int y[100] = {75,63,113,23,79,96,35,99,102,81,69,70,29,65,43,63,65,89,23,100,98,54,101,42,54,90,42,46,28,74,61,60,106,98,32,108,9,20,30,49,53,91,98,10,46,100,28,14,8,39,80,32,86,54,55,100,12,36,48,85,80,9,92,45,62,29,50,30,39,98,94,96,32,37,80,5,43,73,34,79,23,64,22,54,42,24,53,62,44,91,48,15,60,40,37,7,91,28,45,48};

    int n = 100;

    float sum_xy = sumxy(x,y);

    // Y = aX + b
    // by linear regression formulas to calculate the slope and intercept
    float a = (sum(y)*sum_2(x) - sum(x)*sum_xy) / (n*sum_2(x) - pow(sum(x),2));
    float b = (n*sum_xy - sum(x)*sum(y)) / (n*sum_2(x) - pow(sum(x),2));

    printf("For the linear regression (Y = aX + b), we get a = %f, b = %f\n", a,b);
  
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. You are given the following data to fit a simple linear regression x 1 2...
1. You are given the following data to fit a simple linear regression x 1 2 3 4 5 y -2 4 2 -1 0 Using linear least squares, determine the t-value for testing the hypothesis that no linear relationship exist between y and x. (a) 0.01, (b) 0.03, (c) 0.09, (d) 0.11, (e) 0.13
An operation research analyst investing the relationship between production lot size (x) and the average production...
An operation research analyst investing the relationship between production lot size (x) and the average production cost per unit (y). A study of recent operations provides the following data: x 100 120 140 160 180 200 220 240 260 280 300 y $9.73 9.61 8.15 6.98 5.87 4.98 5.09 4.79 4.02 4.46 3.82 The analyst suspects that a piecewise linear regression model should be fit to these data. Estimate the parameters in such a model assuming that the slope of...
Please write the answer legibly. Thank you. The age (X) and glucose levels (Y) of 6...
Please write the answer legibly. Thank you. The age (X) and glucose levels (Y) of 6 patients are calculated in order to see if there is a relationship between these two variables. The following data was collected: SP xy = 478 SS x = 1241 SS y = 656 Calculate the correlation coefficient using the formula: r = SPxy / √ SSx SSy => [sq root of SSx SSy ] ---------------------------- Using the correlation coefficient (r) derived from above and...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3,...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 n = 12 b) Calculate 1) the average or average 2) quartile-1 3) quartile-2 or medium 4) quartile-3 5) Draw box diagram (Box & Wisker) II. PROBABILITY 1. Answer the questions using the following contingency table, which collects the results of a study to 400 customers of a store where you want to analyze the payment method. _______B__________BC_____ A...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
Given the codes for X^2(chisq) and G^2(likelihood rato test statisic). Please write the following code in...
Given the codes for X^2(chisq) and G^2(likelihood rato test statisic). Please write the following code in R. (e) (2 points) What proportion (pN ) of the observations generated in part a above, has |χ2 − G2| > 0.05? Note: The proportion you are calculating here (i.e. pN ) is an estimate of P(|χ2 −G2|>0.05). (f) (7 points) In the questions above, we did the calculations with a sample of size n=10. Nowlet’smakeitn=100. Withn=100,calculatepN forN = 200, 400, 600, · ·...
Question 1: The data table shows the sugar content of a fruit (Sugar) for different numbers...
Question 1: The data table shows the sugar content of a fruit (Sugar) for different numbers of days after picking (Days). Days Sugar 0 7.9 1 12.0 3 9.5 4 11.3 5 11.8 6 10.3 7 4.2 8 0.8 HAND CALCULATIONS: The dependent (Y) variable is sugar content and the independent (X) variable is number of days after picking (Days). Do the following by hand, SHOWING WORK. You may use SAS/R to check your answers if you want. (a) Find...
Use the given data set to complete parts? (a) through? (c) below.? (Use alphaequals?0.05.) x 10...
Use the given data set to complete parts? (a) through? (c) below.? (Use alphaequals?0.05.) x 10 8 13 9 11 14 6 4 12 7 5 y 9.14 8.13 8.75 8.77 9.26 8.11 6.13 3.11 9.13 7.27 4.74 LOADING... Click here to view a table of critical values for the correlation coefficient. a. Construct a scatterplot. Choose the correct graph below. A. 0 4 8 12 16 0 2 4 6 8 10 x y A scatterplot has a horizontal...
A statistical program is recommended. Consider the following data for two variables, x and y. xi...
A statistical program is recommended. Consider the following data for two variables, x and y. xi 135 110 130 145 175 160 120 yi 145 105 120 115 130 130 110 (a) Compute the standardized residuals for these data. (Round your answers to two decimal places.) xi yi Standardized Residuals 135 145 110 105 130 120 145 115 175 130 160 130 120 110 Do the data include any outliers? Explain. (Round your answers to two decimal places.) The standardized...
Use the given data set to complete parts​ (a) through​ (c) below.​ (Use alphaαequals=​0.05.) x 1010...
Use the given data set to complete parts​ (a) through​ (c) below.​ (Use alphaαequals=​0.05.) x 1010 88 1313 99 1111 1414 66 44 1212 77 55 y 7.467.46 6.766.76 12.7412.74 7.117.11 7.827.82 8.848.84 6.086.08 5.385.38 8.168.16 6.436.43 5.735.73 LOADING... Click here to view a table of critical values for the correlation coefficient. a. Construct a scatterplot. Choose the correct graph below. A. 04812160481216xy A scatterplot has a horizontal x-scale from 0 to 16 in increments of 2 and a vertical...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT