วันพุธที่ 17 ธันวาคม พ.ศ. 2557

Why we choose to use R programme ?

R is the leading tool for statistics, data analysis, and machine learning.  It is more than a statistical package; it’s a programming language, so you can create your own objects, functions, and packages.
Speaking of packages, there are over 2,000 cutting-edge, To get an idea of what packages are out there, just take a look at these Task Views.  Many packages are submitted prominent members of their respective fields.
Like all programs, R programs explicitly document the steps of your analysis and make it easy to reproduce and/or update analysis, which means you can quickly try many ideas and/or correct issues.
You can easily use it anywhere.  It's platform-independent, so you can use it on any operating system.  And it's free, so you can use it at any employer without having to persuade your boss to purchase a license.
Not only is R free, but it's also open-source.  That means anyone can examine the source code to see exactly what it’s doing.  This also means that you, or anyone, can fix bugs and/or add features, rather than waiting for the vendor to find/fix the bug and/or add the feature--at their discretion--in a future release.
R allows you to integrate with other languages and enables you to interact with many data sources and other statistical packages (psych).
Explicit parallelism is straightforward in R: several packages allow you to take advantage of multiple cores, either on a single machine or across a network.
R has a large, active, and growing community of users.  The mailing lists provide access to many users and package authors who are experts in their respective fields.  Additionally, there are several R conferences every year.

วันพฤหัสบดีที่ 4 ธันวาคม พ.ศ. 2557

CODE 5 : INPUT DATA


INPUT DATA




1     Type the data.For example, names and scores, names and heights.And then,run code by press ctrl+enter.After that,calculate the data by typing name and run code. 



      This picture show the results of the data which is run by typing name and run code.





 Show the values of data when you run code.




CODE 3 : CORELATION


Corelation

     Write Code in Rstudio program
- Head (mtcars) for show data when you chick run



- It will show data about cars when you  chick run.



       “Call the variable names in mtcars”

write code for plot on graph


-          when you chick run it will show blue plots in graph

-          Write code in red squre for “Call the variable names in mtcars”


-          It will show the variable names in mtcars


-          Write  corelation code for show  relations two value


It will show show  relations two value



Write correlation the variable names in mtcars


-          It will show correlation the variable names in mtcars





CODE 7 : COMPARE


I will use package "ggplot2"
when you use about package,you must install ggplot2 package.
After that,I choose the head about "diamonds"by typing head(diamonds).


This picture show  the data of diamonds.


Type name(diamonds).


code name(diamonds) show quality of diamonds which is measure the diamonds.


Type hist(diamonds$carat) and run code by press ctrl+enter.


this picture shows histogram of diamonds$carat.


Use package ggplot to show that clarify can test the quality of diamond.


Graph  show that clarify can test the quality of diamond.


lm is linear model.


linear model show that price and carat are relative.


"Gplot" can use for comparing price and carat.


Comparing carat and price do not clear.


So,I will use color to describe the data clearly.


Not only carat can measure price of diamonds,but also clarity can measure price of diamonds.


Besides,to compare clarity and price,It can compare other quality such as size and cut.


Size and cut can show  real quality of diamonds.So,big size of diamonds and cut of diamonds make the diamonds have expensive price.


if you need to learn more visit :

http://www.ceb-institute.org/bbs/wp-content/uploads/2011/09/handout_ggplot2.pdf

CODE 4 : Regression mode


CODE 4 : Regression mode


Regression model.

1. Write code in RStudio program.
                1) In line1 names(mtcars) is Call the variable names in "mtcars".
                2) in line6 (“psych”) is a package which we are install before and we can call the psych in line7.
                3) y = a+ bx; a = constant and b = slope
                                y is mpg because we want to predict mpg
                                 x is the variable that we believe it can explain the variable of mpg
                4) line30 is build the regression model ( lm : linear model ).





2. When you write code on rstudio program finish, click Run or Ctrl+R  but it is run all.

3. This data are run program the following command to write code on console part.






4. This is data and value which happens on environment part.



5. This part show more function ex.plots, packages, files, etc. From the above command there are hist command, it be histogram show the relation between two values.







6. From the above command there are plot command, it be slope are significant and plot to distribution of datas.





7. This page is overall of RStudio program when you are run program.



CODE 6 : MTCAR DATA





CODE 6 : MTCAR  DATA


1.cars_data <- mtcars
  mean : a regression model with more than 1 independent variable
              and we need to create a dataset by use the data of mtcars


2.cars_data$log_mpg <- log(cars_data$mpg)
  cars_data$log_hp <- log(cars_data$hp)
   model1 <- lm(log_mg ~ log_hp ~ data= cars_data)
   summary(model1)

   mean : to satisfy the regression assumption, transform the mpg and hp
               by take log because the skewness of mpg and hp is positive

              and finally made summary in model 1

3.cor(car_data)
 mean : The relationship between the data in the car_data.




4.cor(car_data$hp, car_data$am)

mean : The relationship between the data hp with information that is relevant am or not .




5.hist(cars_data$am)

mean : made a histogram of car data as am

SECTION 2 :



 1.library(psych)
    describe(cars_data$am)
 mean : call package psych to describe cars_data$am

2. model 2 <- lm(log_mg ~ log_hp + am, data =cars_data)
    summary(model 2)
 
    anova( model 1, model 2)

mean : to check if the model 2 is statistically better than model 1