EART 20170 Computing Data Analysis Communication skills Lecturer

  • Slides: 36
Download presentation
EART 20170 Computing, Data Analysis & Communication skills Lecturer: Dr Paul Connolly (F 18

EART 20170 Computing, Data Analysis & Communication skills Lecturer: Dr Paul Connolly (F 18 – Sackville Building) p. connolly@manchester. ac. uk 2. Computing (Excel statistics/modelling) 2 lectures assessed practical work Course notes etc: http: //cloudbase. phy. umist. ac. uk/people/connolly Recommended reading: Cheeney. (1983) Statistical methods in Geology. George, Allen & Unwin

Plan n Two more lectures plus drop-in sessions in computer labs n Assessment handed

Plan n Two more lectures plus drop-in sessions in computer labs n Assessment handed out today and need to hand in by 16: 00, Tuesday December 12 th.

Lecture 4 n Using Microsoft excel n Cell referencing and naming datasets n Entering

Lecture 4 n Using Microsoft excel n Cell referencing and naming datasets n Entering formulas n Worksheet formulas n Statistical functions and add-ins n Analysing the Gaussian and T- distributions in Excel.

Using Microsoft Excel Worksheet Cell reference Function bar Basic functions

Using Microsoft Excel Worksheet Cell reference Function bar Basic functions

Using Microsoft Excel Entering data Can also `import’ text files Can name worksheets

Using Microsoft Excel Entering data Can also `import’ text files Can name worksheets

Cell referencing n Several different ways of referencing the information in a cell. n

Cell referencing n Several different ways of referencing the information in a cell. n A 1 reference style n Difference between absolute and relative references

The A 1 reference style To refer to Use The cell in column A

The A 1 reference style To refer to Use The cell in column A and row 10 A 10 The range of cells in column A and rows 10 through 20 A 10: A 20 The range of cells in row 15 and columns B through E B 15: E 15 All cells in row 5 5: 5 All cells in rows 5 through 10 5: 10 All cells in column H H: H All cells in columns H through J H: J The range of cells in columns A through E and rows 10 through 20 A 10: E 20

To refer to another worksheet n Example you can use: n =My. Sheet!B 1:

To refer to another worksheet n Example you can use: n =My. Sheet!B 1: B 10 n You can also use worksheet functions in the same way n =Average(My. Sheet!B 1: B 10) n The worksheets must be in the same workbook

Relative, absolute and mixed references n A relative cell reference, such as A 1,

Relative, absolute and mixed references n A relative cell reference, such as A 1, is based on the relative position of the cell. If the position of the cell that contains the reference changes, the reference itself is changed. n An absolute cell reference, such as $A$1, always refers to a cell in a specific location. If the position of the cell that contains the formula changes, the absolute reference remains the same. n A mixed reference has either an absolute column and relative row, or absolute row and relative column. An absolute column reference takes the form $A 1, $B 1, and so on. An absolute row reference takes the form A$1, B$1, and so on.

Relative references Suppose I enter that cell b 2 is equal to a 1.

Relative references Suppose I enter that cell b 2 is equal to a 1. If I copy cell b 2 to b 3, the relative reference automatically adjusts to be the next cell relative to a 1 – a 2! This is the default in Excel

Absolute references If I put in an absolute cell reference, the cell reference does

Absolute references If I put in an absolute cell reference, the cell reference does not change when copied to other cells

Mixed references What happens if I copy a relative column, absolute row reference to

Mixed references What happens if I copy a relative column, absolute row reference to the c 3 cell? The relative column reference adjusts, but the absolute column reference does not

Naming datasets You can name a dataset by selecting it with the mouse (left

Naming datasets You can name a dataset by selecting it with the mouse (left clicking and dragging) and entering the name in the `reference box’ The name must not have any `spaces’. The name can be used as a reference in that worksheet.

Aside: An example of plotting data in excel There are many ways of plotting

Aside: An example of plotting data in excel There are many ways of plotting the data that get the same result Usually you will do this by trial and error (i. e. create a plot and edit it Say you wanted to plot two similar things on the same graph, one a line and one a histogram Start by selecting all three columns and go to insert->chart

Aside: An example of plotting data in excel In this case you want to

Aside: An example of plotting data in excel In this case you want to plot a custom line and column plot Select Custom types and find the line column graph

Aside: An example of plotting data in excel As you can see, Excel wants

Aside: An example of plotting data in excel As you can see, Excel wants to plot all three columns, which we don’t want in this case But you can remove the first column by clicking on the Series tab, highlighting the series you want to remove and clicking remove

Aside: An example of plotting data in excel Clicking next you can play around

Aside: An example of plotting data in excel Clicking next you can play around with many settings and annotate your plot This requires some playing with to investigate all the options

Aside: An example of plotting data in excel As you can see the bar

Aside: An example of plotting data in excel As you can see the bar chart has large gaps which is not what we want You can change this by right clicking on the bars and selecting Format Data Series… On the next dialog, click on the options tab and set the Gap widths to 0

Entering formulas n You can use Excel just like a calculator n This involves

Entering formulas n You can use Excel just like a calculator n This involves entering numerical expressions n For example: imagine I wanted to calculate the mean of 3 numbers: 2, 3 and 7 n I could enter in cell a 1: n =(2+3+7)/3

Entering formulas n A better way might be to enter the values in cells,

Entering formulas n A better way might be to enter the values in cells, a 1, a 2 and a 3 n This is still repetitive for large datasets, but it is useful for calculating things like t-values n But Excel has many worksheet functions…

Worksheet functions n Functions are predefined formulas that perform calculations by using specific values,

Worksheet functions n Functions are predefined formulas that perform calculations by using specific values, called arguments, in a particular order, or structure. Functions can be used to perform simple or complex calculations. For example, the `average’ function calculates the mean of data in a given range. n =average(a 1: a 10) n =average(data 1) n Excel has a huge library of functions like this. Using them takes practice but it is best to learn by doing examples.

Worksheet functions n The easiest way to start using functions is to `insert’ one

Worksheet functions n The easiest way to start using functions is to `insert’ one into the worksheet. n Have a cell highlighted and click on the insert>function tab.

Worksheet functions n The insert function dialog pops- up. n You can either search

Worksheet functions n The insert function dialog pops- up. n You can either search for a function or find it yourself. n Usually you will want to use a certain category such as `statistical’ and find the function in that category

Worksheet functions n Next you will get a dialog asking you to put in

Worksheet functions n Next you will get a dialog asking you to put in cell references for the function. n This dialog changes for different functions. n For the above example using the `average’ function we could put in A 1: A 3 in the first text box and click OK. n The mean will appear in the cell. Note that when you become efficient with excel you will use shortcuts for inserting functions and wont need to use this dialog.

Statistical worksheet functions (hint, hint) n n n n Average(a 1: a 3) [average(data

Statistical worksheet functions (hint, hint) n n n n Average(a 1: a 3) [average(data 1)] Stdev(a 1: a 3) [stdev(data 1)] Var(a 1: a 3) [variance] Stdevp(a 1: a 3) [stdevp(data 1)] Sqrt($a$1) [sqrt(a 1)] ^2 [to the power] Sum(a 1: a 3) [sum(data 1)] pearson(a 1: a 3, b 1: b 3) [pearson(data 1, data 2)] Rsq(a 1: a 3, b 1: b 3) [rsq(data 1, data 2)] Quartile(a 1: a 20, 0. 25) [quartile(data 1, 0. 5] Mode(a 1: a 20) [mode(data 1)] Normdist(a 1, mean, std, TRUE) Norminv(p, mean, std) Tdist(a 1, 8, 2) [students t-distribution] Tinv(p, 8) [inverse of t-distribution] Ttest(data 1, data 2, tails, type) [comparing two means] probability of rejecting null hypothesis (if this is less than significance level, reject null hypothesis). Type should equal 2.

Analysing the Gaussian (normal) distribution n The function normdist has the following prototype: n

Analysing the Gaussian (normal) distribution n The function normdist has the following prototype: n NORMDIST(x, mean, std, cumulative) n It returns the value of a Gaussian distribution with n n given mean and standard deviation at x. Cumulative is either set to `FALSE’ or `TRUE’ If it is set to FALSE the function will return the actual value of the Gaussian distribution at x. If it is set to TRUE the function will return the cumulative distribution at x (i. e. this is the table from lecture 3). Confidence level of a given interval. Eg what is the probability of a value lying in the interval. . .

Analysing the Gaussian (normal) distribution n The function norminv has the following n n

Analysing the Gaussian (normal) distribution n The function norminv has the following n n prototype: NORMINV(p, mean, std) It returns the x value associated with the cumulative probability of p Useful for assessing levels of significance. Eg what are the limits on x at a given confidence level? This method is used more frequently for the tdistribution

Analysing the tdistribution n n n n You still need to remember the formulas

Analysing the tdistribution n n n n You still need to remember the formulas for (1) estimating the interval for the mean; (2) testing the significance of the correlation coefficient; and (3) if two means are equal. The function tdist has the following prototype: TDIST(x, df, tails) It returns the significance level (alpha) of a t-distribution with given degrees of freedom. Tails is either set to 1 or 2. If it is set to 1 the function will return the accumulation of probability from infinity to x. If it is set to 2 the function will return the accumulation of probability in both tails. Not used too often

Analysing the tdistribution n The function tinv has the following prototype: n TINV(alpha, df)

Analysing the tdistribution n The function tinv has the following prototype: n TINV(alpha, df) n It returns the critical value for the t-distribution corresponding to a significance level, alpha. n By default it is a two tailed confidence level, but for a one tailed confidence level substitute 2 x(alpha) for alpha. n Used in hypothesis testing.

Excel has a quick way of comparing two means: n The student t-test. n

Excel has a quick way of comparing two means: n The student t-test. n If they have the same length we can use the TTEST function n But rather than giving us the critical t-value, it gives us a critical probability for rejection. n What if this is less than the significance value, alpha? Rejection Acceptance T-critical We reject the null hypothesis

Random number generation n This is very useful in computational science. n They are

Random number generation n This is very useful in computational science. n They are not really random numbers, they are generated by an algorithm. n But it is difficult to get random numbers on a computer. n The worksheet function rand() generates random numbers between 0 and 1. n Hence to generate a normally distributed random number sequence, with a given mean and standard deviation we can use: n Norminv(rand(), mean, std) n Over many generations, the variable will have the given mean and standard deviation

Random number generation Over a large number of generations, the mean approaches that of

Random number generation Over a large number of generations, the mean approaches that of the true random variable

Next lecture n Propagation of errors. n Many people struggled with this on the

Next lecture n Propagation of errors. n Many people struggled with this on the test. n There is an easy way to do it with Excel. n Lets go back to our example measuring bed thickness. We know that x=12. 1 0. 3 m and y=4. 2 0. 2 m. n So if we generate many values of x and y with the above means and std, then add all these together we could calculate the mean and std of the result.

Error propagation n Using a computer we can generate many normally distributed variables and

Error propagation n Using a computer we can generate many normally distributed variables and therefore find the distribution of the answer. n Hence we can directly calculate the error (standard deviation) in the answer. n This is useful as it can be done for complicated equations with ease. n This is called the Monte Carlo method of propagating errors.

One more thing n Worksheet functions can also take text arguments and return text.

One more thing n Worksheet functions can also take text arguments and return text. n If you are doing a hypothesis test you might want a statement that tells you to either accept or reject the null hypothesis n You can use the `IF’ construct n =IF(logical test, if true, if false) n E. g. IF(tvalue>tcrit, ”Accept alternate hypothesis”, ”Accept null hypothesis”). n IF can also return numeric values.

Homework n Have a look at using some of the functions in excel. n

Homework n Have a look at using some of the functions in excel. n Especially for manipulating cells and calculating means, standard deviations. n Try calculating z-values and t-values from the table from handout 3 in excel to see if you can get them correct. n This will help for Tuesdays practical labs. n REMEMBER: please check the student notice board for your allotted time.