R Statistics and Machine Learning
Transcript
Thank you for Alex's introduction and then for you guys coming I didn't expect that But this is kind of like this workshop is kind of pop-up workshop It's very short So I didn't expect that But anyways So today I am going to present something related to statistics and machine learning with R but basically we will talk more like about R and statistics and machine learning but I mean like just an application of R So first of all I would like to tell you all of you already received the handout but I just remind that like just don't read it because we will like do the exercise together during the workshop So just don't read it because all the solution is inside
I also want to ask a question like how many people have a background or have a knowledge in programming anything programming So many of you do not have any experiences in programming right Okay but don't worry about that because like today I will give a really short intro a really brief introduction about R which is a programming language and I will like give you step but step introduction so that you will learn how to use R also So I will talk about four things today First of all I will start by Why should we learn programming and R Especially in the academia So why do we need it and also I will talk about like
which is the main part of today's workshop as the introduction to R and also the data model like we will use the data model to process our data and and also our analysis analyze it and also visualize it and also I will like touch a little bit about why should we care about big data and also the introduction to machine learning and most of the content today will focus on the first two parts and like I will just touch a little bit on the last two parts with exercise So we will do the exercise together So I hope that everyone will get a computer so that we can do exercise
So first of all Why should we learn programming and R So the Google’s Chief Economist says The ability to take data to be able to understand it to process it to extract value from it to visualize it to communicate it that’s going to be a hugely important skill in the next decades which means like in this era like analytic skill is really important to us not only at the professional level but also for the colleges here and also the even like the primary school and also the high school and because now we already have many many data So what we need to do is to try to understand the data and then extract the value from it This is the theme of today We try to understand the data and then extract the value from the data
So why programming First of all Maybe you are asking why we just use SPSS or SAS or other like statistical software as for programming and I would argue first of all we need to like for evidence-based practice or also like open science practice First of all we need to have the reproducibility which means like we have reproduced themselves with that data So what they like SPSS or SAS or other statistical software or one problem is that like most of these software
do not have the comprehensive package to also do the preprocessing of the data Most of us probably preprocess data in Excel or other like Excel-like software But R or programming can like gather all the process together and then we can just like work on all the procedures in one programming language and then which ensure reproducibility of the data and the results and the second like automation Why automation is so important Because like for example like SPSS basically a menu on base software
So when you like come to the data you click and click the menu and then do the analysis on it and then somehow it's quite easy especially like the method is not that hard But when you are using a really like a difficult analysis methodology or using like repeated measures or like you just want to focus subgroup of your data You need to like repeat your clicks all again and the programming can help to release this kind of like burden and automation can really
You can really use programming to automatically run the analysis preprocessing and also the results and also the graph together in programming and most important here what I think is like programming can communicate with each other and because you know like when you get the results from the students for example like they run an analysis for the data and then they told to like the result is standard okay But when you ask him like how can you get this results He probably has the problems to say or he needs to show you the steps in SPSS to show you how they get the results from the data But programming can also release this kind of burden as well Because we can just read it from scripts to know like how
also you can run analysis by itself on your own computer to know like how the results come from and also It is also important that like you can also know other researchers and other people how they get the results from their data or how they get and also we have communicate to review or like if comment to others' methodology So when you know how they get the data Sometimes I don't know like papers or literature can give a detailed description of the methodology
But still sometimes it's really fuzzy and messy and you don't know how to get the results like this So it is quite important to have a script or like using a programming script to describe the process So when you read the script you know what exactly they did for the data and then get the results and so programming language has different kinds of language but why R I mean like of course first of all R is free and open source Open source does not necessarily imply this study But I mean like for this case R is free and it is very important because like if you need to buy a SPSS It costs like For a student costs like
55 Euros or like 60 USD for a license and it's quite expensive for a student actually but R is free and R is open source and open source means it means like everybody can contribute to the R programming So Because everybody can contribute to the R programming to this kind of language and so we also get a huge community support especially R because like people in academia and also in research They always most of them use R to conduct their analysis So therefore like you can always When you encounter like some kind of questions or problems You can also find the solution online because like people may already encounter like some certain kind of problems or difficulties already
So you can look for the solution online and also a huge of people using R means that like they would also contribute a different kind of like update or up-to-date package or statistical methodology to the R community which you can also use it in your own project like this is something good for you because as you know you may not like classical statistics like t-test or ANOVA like already developed in like a hundred years ago But now there is people talking about machine learning
and also different kind of algorithm that help you to analyze data But I mean like this is something new and SPSS does not have the implementation of this kind of new algorithm But R already has it because like people already like programme it and then put it online So you can just download from the internet and also R is a scripting programming language which give you the advantage of what I say about like communication and also the reproduction and also the automations
and also R is highly flexible You can customize anything you want anything you need and also it is highly extensible It is a language You can just like write anything any function any new algorithm and then like implement in your own project and also it's big-data-ready environment which is quite important nowadays But I will also talk a little bit in the later parts So I will just leave it here and most importantly again like R is available on Mac Windows and also Linux It means that everybody can have the same platform to run analysis and this can reduce the errors from the systematic level
But I mean like also there are also other language programming language like Python and also C++ etc. But I mean R is the only language a specifically written for the statistics purpose So for today's course so R is quite suit our needs for the analysis and according to a survey from Kaggle.com Kaggle.com is a platform for practicing data sciences So many people who really interested in big data and also what data scientist will go to this website They have a lot of dataset
You can practice online there and then they did a survey last year and they check like how many people like using which kind of tools in their like daily practice like R is actually ranked number two from all other kind of like software Python is the top but it doesn't matter because like some of the other surveys have a different result which is the R is the best and the Python is the second I mean like it's highly depends on the community and but I mean like one more important fact is like for those data scientists like only a few really a few people using SPSS but most of them using R and Python So this is important because nowadays people are like tends to using tools like R platform to analyze their data
So now we are going into a more practical part of today's workshop which is the introduction to R and the data model and then we will do the things analysis together and so I will try to be like make the talk more interactive and so just ask question if you have any like questions So first of all like I think that most of the computers here have already installed the R But what I need you to do is to install the R Studio which you can find on www.rstudio.com and those who are using their own computer you can also install R on your computer So So first of all You can download R here in the r-project.org But what I need you to do is to download the R Studio
Because R Studio is not on the computer So go to rstudio.com and then go to Products and the go to R Studio and then you can download the R Studio Desktop here So anyone can follow it So if you have question or problem you can just raise your hands or I can help you Desktop? Yup R Studio Desktop So I have downloaded the Download the R Studio Desktop and then install it on your computer and then after it it looks like this
So click here and then drag to Windows and save it and then click run So that R is installed I mean this package and click run and then you will get the R Studio So
So anyone Does anyone have any problem have any problem about installing R Studio okay So why do we need R Studio because R is not an application but it is a script programming language So it means it is not an application it does not have any interface So when you like write on it you need to write through the command line But I mean like it is kind of like disturbing sometimes So for me or for most people They would always suggest using a ID which is the interactive development environment
which is the R Studio which they integrate everything you need in one interface So including the terminal and everything you need to do your development of the script and R Studio is also free and open source which is quite good as well and so when you open up the R Studio it looks like this or a bit different So please turn on Please open your R Studio and we will do the practice on R Studio today So on R Studio you will basically see three or four windows inside the interface So if you cannot find
probably we miss one window on the left hand side but you can just click this button which can open all the all four windows on your interface So basically R Studio contains the Text Editor which it does not run anything but more like a text file You can enter anything you want and also the Console which is the command line You can use it to give a command using the R language and Workspace basically tells you about the variable you have
and also the like path and also editing like global environment read it into variable and also we have a window related to Files, Help and Plotting Window So basically it is It will give you the output here So you can see your plot or other things in this window So So now we are going to some basics of R R basically can act like a calculator so what I need you to do is try to enter some simple operations in the console window
which is in this window You can see there is a little L here So we will just first of all try to enter 14 + 3 and then click enter So So probably like the window we also try to result of the So here is the console So basically you will return So as you can see here When you enter 14 + 3 you will give a and then click the enter and the terminal the console will give you back the result which is 17 right
So I would also So You also try the following operations as well and then see if you can get the results correctly here The second one is like 10 / 12 and then third one is like 3 * 18 and then the last one is like 3 ^ 3 So it will probably give you 27 right Okay So it is As you can see like R can work like as a calculator So you can do any mathematical operations on it So it is quite important because like It means that you can do the method as well and then you can also programme anything related to mathematics
which includes statistics as well and so but I mean like For more complicated operations like log algorithm and also the square root We can also use the log function and the square root function to get the results So basically it is a function I will also describe what a function is in the later slides But first of all let's try log 36 So Log 36 will give you 3.5 something right
Anyone Okay Cool And also try the square root of like 39204 It will give you a number like 198 right Okay So It's really simple formula and besides that and besides like mathematical operations R is also like The R function also allows you to check the logical statements and for example like you can check whether like two items whether they are equal to each other or not equal to each other but we can also check whether like they are greater or less than each other the other and also we can use AND, OR, NOT for the variable and now So What is the output of 50 == 50 + 1 Can you give me the answer Anyone
False right So what if I change the equality to inequality True Ya You are right So basically like this kind of logical statement can check the statements before and after the symbols to check whether they are equal or greater or not Okay So I would also like to introduce you the R basics about the objects R is basically an object-oriented programming language So basically like R within R there are two objects One is data which is used for information storage and the other one is functions and functions will act on data and then give you results or anything you script on So for example here The first one my height is So you can see here is an assignment operator which is the right arrow with a slash
So when you enter my height as assigned to 177 It will not return anything So basically it just like like this but look at the window here You can see there is a value pop up which is my height equals 177 But in your console it will give you nothing Because it just installs this information to this variable 177 But you can also do things like this
So you can also do things like this You can add a lot of variables here a lot of values into one variable So c means like combine or concatenate So you add all these values into one variable So when you add this to your console you will see there is another values pop up height.people which is the number it means this variable is a numeric number a numeric variable contains four numbers 177 156 and 189 and 200 alright
So and also you can add other variable like my weight and so we have this kind of information my height and my weight and then what we can do We can calculate my BMI alright So basically BMI is a function We have the function act on data This is my data my height and my weight So we have the BMI function to calculate based on my height and my weight but you will probably get nothing because it does not have a function like in the current R terminal So we will construct the BMI by ourselves The first of all I will also describe what data type or data class in R R basically contains four data classes The first of all
The first data class is vector So basically it means like the same type of data containing one variable For example like names and the names are assigned to c("Peter" "John" "Mary" "Kate") The are all strings variables so When I copy it to my terminal So you will have the names Peter, John, Mary and Kate Alright How do we check class We can just simply type the class
and then put the names inside the class function and then it will return the type of the class which is the character Okay which also and the IQ score to the terminal and and now we have the IQ scores containing four numbers which is the 100, 125, 143 and 165 So here So basically all the values are numeric So when you type class
IQ It will give you numeric So it means like this variable is a numeric variable Yup Yup Actually you can see in your handout You can look at the handout The first page is the sections of R basic data page 16 I have all the script on it So now we are going to try the list
So list means like combines different types of vector into one variable So basically we can add up the names and the IQ scores together to form a list So that we have a list containing names and IQ scores We can try it on your terminal as well and then put down names.IQ It's assigned to list(names, IQ.scores) So you can also look at like what the variable names.IQ can give you You can see when you type names.IQ and then click enter So basically it will give you a list with
a number 1 and 2 the first one is the names including Peter, John, Mary and Kate and the second array including the IQ scores which is the 100, 125, 143 and 165 Yup and the third type of data class is the matrix
matrix is really special and really important in R statistics because basically many statistical function is run by matrix For example like regression model and also machine learning regression model as well So matrix is something important because it gives you the row and column attributes of everything so you can locate any single data point and also you can see
There is an indicator of the row and column attributes So first of all we can add X as assigned to matrix IQ score and row means number of rows equals to 4 and number of columns equals to 1 So the X will become a matrix you can check class X So it will give you a matrix and I would also like to ask you to try class smaller letter fx as well
So I would like you to try both okay after neter after you define it it's assigned to matrix IQ score and row So does anyone already try the smaller x as well Okay So what is the return results So when you So
When you define upper capital X It's this matrix you will give this result Alright But when you put the small letter x It will tell you the object x is not fine which means actually in the capital or the cases of the letter is important for the R language So you should not mix up the capital X and the smaller x in the language
Alright so we will talk about another important thing in R which is the data frame which is also the table and so first of all I need you to enter df <- data.frame(names, IQ.scores) with a comma between the names and IQ scores So when you enter df which is the short form of data frame normally the people like to use it to indicate it's a data frame and when you put df into
into the terminal and then click enter you will get the result of a table which the table name is names and IQ scores and also with the row indicating 1, 2, 3, 4 Yeah the first row is Peter with IQ 100 and John with IQ of 125 and Mary with IQ of 143 and so on So does anybody get this as well Okay cool So we already know like the basics of the data So it is quite important because like basically the R script is formed by this kind of data in this way so and now we will talk about another object which is the functions
Functions in R contain like two types of functions They are either came from function written by others so basically it is the package written by others You can You can just download from the internet and then install onto your computer and then you can use the functions by loading the package and I will also like tell you how to do that in the later slides But the other thing is the user defined functions Basically it is the function written by yourself
So the basic structure of the function is the name of the function is assigned to a function okay with the argument argument basically is the input variable the input data of the functions and then here is an expression means like how do you want to do with your argument So for everything start I mean like for anyone learning programming the first thing is learn how to print the "Hello World!" So we will also do that as well So the greeting is the name of the function It's assigned to a function with no argument which means like you do not need to enter anything and then this function will do three
it is simple prefunction to the terminal Hello World Remember that slide if it is a strings You need to use a double quotation It means that it is not a variable but simply a strings Okay Print Hello World with a close bracket and then now you can try greeting with an empty bracket So it will give you Hello World right Alright So now What I mention already so first of all I need you to create a function that will calculate BMI and
So we will do it togehter and first of all I would like you to try first and try to construct the functions to calculate the BMI and after like finish you first function actually I already give the solution inside the handout You can check it in the handout and so first of all let's try by yourself first So I already add a function copy a line here
So just give you the equation of BMI because you do not know that The BMI is calculated by by the I also forget the function Yup By the weight divided by the power of two of height Remember that the height is using the the unit of meters instead of centimeters So finish?
Alright So Let's try together Mine is a longer version of BMI So it will also give something else instead of simply the BMI solution For example a people who have a height of 1.8 and then he weights for example 70 kilometers and the result is 21.6 which is the BMI and Your weight is normal That's great and what I did in my function is you can also check using the
You can just enter BMI without anything It will show you the function here So this is something why I said like R is highly flexible because like design the functions of BMI I print the BMI after getting the result I also check whether BMI is within a certain range which also gives you the message whether you are underweight or overweight So the if the if function here means
you can check whether if this condition is fulfilled then you do something else if means like if statement is not fulfilled then you also check the else if statement which also check the BMI whether it's like greater than this number but less than this number and then you print something and then else if and then the last one else means print "Death is coming to you!" basically means that you are really overweight and what you can do I mean R function is quite flexible you can just enter anything you want Maybe someone will argue that why don't I use a calculator because the calculator can just calculate the BMI for me
But for programming actually you can really like do something else instead of just give you a number But also it can print out the things likes print out a message related to the results you get from the functions as well Okay second thing is I would like you to create a function that will print some products of two integers So this is something not difficult and then if you finish this one can you also try to create a function that create a function that given a vector will print by screen the mean and the standard deviation
and also it will optionally also print the median of the vector Remember vector can contain more than one number and I will give you a hint here as you can assign a logical argument in the function which allows you to print or not print the median So for the mean function it's basically mean bracket with something inside and then standard deviation the function of standard deviation is sd The initial of the standard deviation and then bracket something
So if you do have difficulties about like constructing a function You can just check the handout I already like include the solution in it So what I want you to do is basically you grasp the logic behind the functions how we write a function and how we can like make a function work in a way we want Some of you may have the problems using the console to enter the things to construct a function so probably you have construct your functions on the here in the text file first
So for example So Yeah I am sorry that I did not tell you sometimes this space here and the line here is important For example like this function which is the solution of the which is the solution of the challenge question So basically it is a function a and b product of two integers and then it needs to add a curly here a curly bracket here and then you need to open a new line
and then and the sum is assigned to a plus b and then you can also enter another line product is assigned to a times b and then basically you do not need this thing So and then you You can print out the sum and product here So Some of you may like enter all the stuff in the same line which will cause a problem because
because you need to clearly define like because you need to clearly let the programme know that you already end for one command For example sum is assigned to a plus b if you follow by the product is assigned to a times b then the programme does not know that whether you already end your functions So you need to start this line a product is assigned to something into a new line in a new line So and then because you can just copy this function into the console and then plus enter and then you will get the new functions here which called result
and then now you can use the result to do things on the so it will give you the product of 3 the sum of 1 and 2 and then product of 1 and 2 and then you can try to for example try another numbers 5 and 10 So it will also give you It will give you the sum of 5 and 10 which is 15 and then the product of 5 and 10 which is 50
So remember that start a new line for a new stuff So you can look at the solutions for the questions Exercise here and see if you really have any question you can just ask me and So when you look into the handout
For the For the solution of the a bit advanced level you can see that I default print.median equals to a false You can check it and it is the default setting of the functions which means like when you enter result2 with a vector it will give you it will not give you the median printing But when you want the function to print out the median as well you need to specifically let the function know that you want to print the median which you need to print which you need to specifically tell the function print.median equals to true So that the function will also give you the median printing as well So
I think I will move to the next session so if you still have any question you can just discuss to interact So I will just introduce the data model for the analysis of the data and I think like it is quite common for people to especially people working in academia We always need to tackle the data and then do the analysis on it and then do the publication So what we need to do actually is from data processing from getting data and then do the data preprocessing and then do the analysis and visualize it and then make it as a like printable or like publishable figures or tables for people for the journal So the data model actually just describe the process of everything you need to make the raw data to communicable
table or figures for people So basically you can see there are several important items in the model which including the import which talking about importing of the data tidy or which mean we clean the dataset and transform the data table into any table you want for the analysis and then you visualize the transformed table and then get the concept, insight of the data and then run the model
For example regression model linear model on the data and then get further insight and then see whether we need to conduct extra or additional analysis for the data and then we repeat process until we can get some kind of result from here and then use it for communication So we will talk about items step by step but first of all I need you to install a package called tidyverse So tidyverse Tidyverse So tidyverse
is a package a collective package include several basic packages which allows you to manipulate your data and then checking the data and also transform the data you want So first of all you need to install.package("tidyverse") and then you will download something on your computer on your computer So I will also do that as well
So because I already have this package on my computer so it will show me updates of package So for you guys you need to use this script to install the package which will be needed in the following sessions Yup so because Based on data model
So based on the data model we have a lot of process to do before we can communicate our data and results including the import, tidy and transform and also visualize and model So most of the time actually we only touch on the model which is doing the analysis on SPSS for example and then get the results from the SPSS But what is also important in dealing with data is also the tidy and transform and also import of the data So the package tidyverse containing like R package including the "ggplot2" which is used for the visualization the "readr" for the import the "dplyr" for like manipulate your data, table the "tidyr" which is useful for clean up your data and "TIBBLE" and "purrr" something like that So that's why we only
But I mean there are lots of packages right So but the tidyverse including like includes everything you need for data science So you can just install this one instead of like install one by one So that's why we need to do is like install package tidyverse for Okay So now we already install package Now we need to load the package which we use the "library(tidyverse)" library is a function that you can load any package you already install in your computer In this case we load the tidyverse into your computer and normally we need to set a working directory for our data but I mean now I will use online data So we do not need any
We do not need to set a working directory So now I would like you to read a file called "gapminder" using the "read_csv" "read_csv" is a function to read a csv file from this website Sorry I try to "read.csv" ".csv" is also okay but I mean like "read_csv" is specifically for tidyverse So ".csv is also okay Yup I will try here as well
Yup so first of all you need to "library(tidyverse)" and then you read this csv file and then you can see that like this message They just give you the information of the They just basically give you the information of the csv So including "country"
a variable called "country" a variable called "year" a variable called "pop" which is the population and "continent" and "lifeExp" which means the life expectancies and the GDP per capital "gdpPercap" including so you can see that like this datasheet containing six variables including "country", "year", "pop" "continent", "lifeExp" and "gdpPercap" and when you want to see like what really a table you can just use the view function and So when you type in "View(gapminder)"
You will get the table here So you can see the first variable is "country" "year" "pop" "continent" and "lifeExp" and "gdpPercap" six variables right everyone get this? Okay So but I mean this is too long sometimes I can tell you that when this is a really long table You can check the "dim" "dim" means the dimension of the data table So it will give you like 17046 which means this data table contains 1700 rows and with six variables
Sometimes it's too long So I just want to see like for example pure examples of the data table We can just type in "head(gapminder)" So it will give you the first six rows of the table But you can also use "tail" which will give you the last six rows of the table here and if you want to know like which
variable names we have We can also use "names(gapminder)" So it will return you basically the variable names of the table So for this part first of all you need to install the package and then load the package library using the library function and then read the csv from this website and then you can see this table Yup Alright So
So for tidy because like the table we are using is perfectly cleaned So we cannot use it for demonstration but I will just like briefly talk about like why do we need to tidy up our data table For example like dealing with animation data in the data table For example in this case When you use age with a vector variable including three numbers with NA NA means missing data or not available in R and then you use "mean(age)" mean function to calculate the mean of the age in this vector What do you have from the result
So it should give you negative right So it's basically an error message telling you that you cannot calculate anything from the missing data because like your vector contains a missing data containing a missing variable in your vector so that it cannot give you any mean of the age But how do we deal with this So remember to You can either remove it from the age or you can use the default function of the "na.rm" a default function in mean function which is the "na.rm" means remove NA when you calculate the mean It's a default function
The default function of "na.rm" is equals to false So when you explicitly indicate it's true Then it will calculate the mean without the missing data Alright So now we also like as you can see from the table You can look through the table Actually the data table contains like different years data frame data time point For example we have like 2007 2002 So for example if we are only interested in the year of 2007 What can we do So what we can do is we filter only
data in the year 2007 So what we need to do is like here "gapminder" is the oringinal dataset and then we carry out the functions of filter and we only need the data from 2007 So when you carry out this command You will get a new dataset called "gapminder2007" So what if we only interested in country from Asia because we also have the
no it should be continent well from the continent "Asia" So it is not the country here So if we only interested in data from Asia What we can do We can just specify filter continent equals to Asia and then we will get a new dataset called "gapminder_asia" and what if we only interested in population larger than ten million I guess and we can also use the filter function to specify population larger than this number So this is a city called "megacity"
So the function name the new variable name new data frame name is "gapminder_mega" Alright like this name is really arbitrary So you can just like put any name you like and any name like you find reasonable Alright Yup anything any problem here Okay so we will also go into another big part of the R which is called visualization Because human brains process information view it visually more than like reading a report and like texts or many complex stuff from the data directly So data visualization is a quick, easy way to convey concepts in a universal manner
and that;s why data visualization is quite important especially in publication you always look at the look at the figures and table first instead of like looking at the texts So that's why people and you also find like a table is more vivid than the texts That's why data visualization is important So I will introduce you how the "ggplot2" package So basically "ggplot2" is a package that you can create a lot of different kind of figures It is a layer function So it's basically you can create a layer by layer figures using simple command For example first of all I would like to create a figure with the x-axis is the GDP per capital and the life expectancies for the y-axis
So I can call the function ggplot and using the data ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) So you can just like enter this command and then you will get this figure So you can see like there is something right So it just gives you the frame of the figure and then what we need to do now is we add the things we want for the figure For example I would like to add the scatter plot for for the GDP and the life expectancy Basically just map the point for each
GDP per capital to the life expectancy in each row of the data input So I add plus here It means like I add one more layer of "geom_point" means the scatter plot point point with alpha level of 0.5 It means like half transparent and with a size of 0.5 You can also adjust the size to 1 or the alpha to 1 It means like it does not transparent and the size is doubled So you will see a figure So you can see here When you
When you customize For example I want a size of 2 For the geom point So you can see the point is much bigger here than before alright So if you also want to indicate the continent of the data point You can also add the color equals to continent So it will show you that each data point belongs to which continent as well So basically you just need to add one more axis here which is "color = continent" and then you will get this figure
Alright So what if I just interested in the Foe example like the x-axis is the continent and then I am interested in like each continent What is the life expectancy in each continent I can just show you the box plot here So the box plot basically means the median the mean of each continent and then how they distribute in this continent as well and you can see here The Africa has a lower life expectancy than the others based on this figure Alright
and you will also see some of the plot here basically means just the outliers of the data Okay so what if I just want to know like distribution of life expectancy of all people and you can use the histogram So using the x-axis as the x-axis is the life expectancies and then add a geom histogram and then I can see the life expectancy counts
per value So you can see the highest count the most people who have like most people have a life expectancy of like 78 and the lowest is like life expectancy with like something 25 here So So basically you can do things like this and it is a little bit challenge
But I would like you try add on this like we do not have much time today But basically what you can do for R using R you can like create such a beautiful figure using the script you just use and to create a figure like this Basically it's a really vivid and also insightful figure You can see for example here As the GDP increases you can see the life expectancy also increases as well and also you can see like some of the figures are population and the and the
in the figure also like bigger population also implies that you have a longer life expectancy as well and then you can see the cluster of the developed countries has a higher expectancy For example the yellow dot means the Americans Americas here They have a higher life expectancy than those countries in Africa which is the red or pink color here So from a one single figure you can see a lot of like information based on this single figure So please try to config something similar
and try to see whether you can also make a graph like this as well and all the solution as I told you is in the handout You can also check this in the handout and now we are going to the analysis which is the model as well and so first of all We already have some insight from the figure and we would like to do the statistical testing on the figures on the numbers and see whether they really like differentiate each other based on a statistical testing So for example but first of all we need to do some descriptive stat first So we would like to know like for example mean or the mode or the median or the

Ask anything
We've read this whole study set, so questions about it get the best answers.