Sunday, May 22, 2016

Install R in Ubuntu 16.04

I installed Ubuntu 16.04 last month. I encountered errors while installing R in office desktop, I tried through CRAN mirror for India. But at home I tried 0-cloud and installed R without errors. I guess we need choose area specific cran-mirror.

Saturday, April 23, 2016

Factor Rotation in R


There is always a question as what mapping technique that must be used while rotating factors. In fact, rotation is one of the mapping techniques along with other techniques like reflection, projection, scaling, shearing etc.

But it is always common to use rotation as preferred technique compared to other, the reason might be that it is simple to achieve. Rotation again two types, orthogonal and oblique. Which one we need to use for better factor solution? Gorsuch (1983, pp. 203-204) suggests orthogonal rotation if the factors under study are uncorrelated and oblique if the factors are correlated.

There are other studies that suggest the idea of simple structure despite of factor correlations. For instance, Thurstone (1947) proposes 5 rules to achieve simple structure. The rules are as follows (Brown, J. D., 2009): 
  1. Each variable should produce at least one zero loading on some factor.
  2. Each factor should have at least as many zero loadings as there are factors.
  3. Each pair of factors should have variables with significant loadings on one and zero loadings on the other.
  4. Each pair of factors should have a large proportion of zero loadings on both factors (if there are say four or more factors total).
  5. Each pair of factors should have only a few complex variables. 
So, these two ideas i.e. from Gorsuch and Thurstone, might provide a clue regarding rotation technique. Now let us see how to handle with problem in R.

 

Friday, February 12, 2016

Install R very latest or current version in Ubuntu Linux

We may not be able to install the latest version R, when we install R through Software centre in Ubuntu. The following code is useful to install R latest version through terminal in Ubuntu.

1. First try to save the codename of Ubuntu by doing below in terminal.

codename=$(lsb_release -c -s)

Alternatively you can also try
lsb_release -c -s

to know the release name of Ubuntu in Terminal. What we are doing is that we are trying to save the version name in an object "codename", which we will use to update software sources.

2. Now update the software sources list by doing

echo "deb http://ftp.iitm.ac.in/cran/bin/linux/ubuntu $codename/" | sudo tee -a /etc/apt/sources.list > /dev/null  

Now you can open /etc/apt/sources.list through any text editor you may be able to find new line "deb http://ftp.iitm.ac.in/cran/bin/linux/ubuntu $codename/". You can use any other mirror of your interest. For CRAN mirrors please visit https://cran.r-project.org/mirrors.html.

3. Retrieve the apt key and add the apt-repository of R to the key-server.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9  
sudo add-apt-repository ppa:marutter/rdev


4. Update R by doing the below stepts.

sudo apt-get update  
sudo apt-get upgrade  
sudo apt-get install r-base r-base-dev

That's all you should be able to get new R version.

Saturday, December 27, 2014

How to plot points on Indian map by using R Language

I started creating Maps through R. There are number of packages to take care of this. In this post I shall explain as how to fetch map with the help of  "ggmap" and then plot it with "ggplot2". 

We need a data file consisting coordinates (longitudes, latitudes) of any given terrain. In this post I am going to explain plotting points on Indian map. So, the steps are going to be

1. Preparing a data file with logitudes and latitudes
2. Fetching map from google server
3. Plotting points on the server

Step - 1: Preparing a data file with logitudes and latitudes: 

I already prepared a file which consists of coordinates and also a data column of accidents in different cities in India. You can download the file from hereThe data file is basically a CSV (comma separated values) file. It is easy to import CSV file in R (you may also import Excel files but it is not strait).  The following is the procedure to import the (CSV) file.

> my.df <- file.choose="" font="" read.csv="">
> my.df

my,df is my data set (which is basically an object) in which there is data column (variable) "accidents"You may look at the variables (columns) by executing the following command in R editor. 

> edit(my.df)

Step - 2:  Fetching map from google server

The following procedure illustrate as how to get Indian map from google server. We need two packages I am going to invoke the libraries by using command "library"

> library(ggmap)
> library(ggplot2)
> my.map <- get_map="" india="" zoom="5)</span">
> ggmap(my.map)

You can see Indian map popping up in graph canvas adjacent to R console. The following is the graph retrieved from google server.        

Step - 3: Plotting points on the server

Now we are going to identify those cities (listed in our data file) where the accidents are identified. 

> ggmap(my.map)+geom_point(data=my.df, aes(x=my.df$Longitude, y=my.df$Latitude, label=my.df$acci))

We get the following map. 

But the points are not distinct, so let me make them little better by changing the color (red) and size (3.5).

> ggmap(my.map)+geom_point(data=my.df, aes(x=my.df$Longitude, y=my.df$Latitude, label=my.df$acci), color="red", size=3.5, alpha = 0.5)

The following is the map that I get with the help of above statement.

Now I guess it is better to get number of accidents just adjacent to the point. Isn't it? I can get the numbers just adjacent to the point by following statement.

> ggmap(my.map)+geom_point(data=my.df, aes(x=my.df$Longitude, y=my.df$Latitude, label=my.df$acci), color="red")+geom_text(data = my.df, aes(x = my.df$Longitude, y = my.df$Latitude, label = my.df$acci), size=3.5, vjust = 0.5, hjust = -0.75)

The following is the map that we can produce with above statement.

I hope you got the point!

How is it? Now, I am going to give you assignment! Yes, exactly.....
Delete the numbers and try to draw draw a line between any two given points on this map. You can also try on satellite map rather than a terrain map.

All the best!



Tuesday, November 6, 2012

how to choose or change CRAN mirror in R or RStudio

Usually R/Rstudio shows list of CRAN mirror at first glance, while installing packages. Often it seems good to select CRAN mirror interactively. For instance, I had chosen a mirror but I have to change due to certain problems in which case the below command works better.

install.packages("your_favorite_package", chooseCRANmirror())

Thursday, October 25, 2012

RStudio for Ubuntu 12.04

There are many editors to R, like JGR, Emacs + ESS, Rattle (for data mining), Tinn-R, but I personally like RStudio for many reasons. I shall explain about how to install R and RStudio in Ubuntu 12.04 here:


  1. First obtain a copy of RStudio from here.
  2. go to update manager -> settings -> add below apt sources:
        deb http:///bin/linux/ubuntu precise/
        if you are in India; possibly your favorite CRAN mirror can be: http://ftp.iitm.ac.in/cran/; for more mirror, you can peep in to this page.
3. go to terminal; alternatively you can also click ctl+alt+t, to trigger gnome-terminal; then add apt-key with the help of below commands;


gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9  
and  
gpg -a --export E084DAB9 | sudo apt-key add -
 
now update your software sources (respective repositories) with below commands;
 
sudo apt-get update 
sudo apt-get install r-base
now after installation - install your previously downloaded RStudio package with the
help of software center 
 
That's all now your RStudio (much coveted IDE for R) is ready. 
 

Friday, June 15, 2012

Sastri Indo-Canadian Institute & Pondichery University Conference (నా పాండిచేరి యాత్ర)

I started from Pune on 09.06.12, morning 05.00 for 'Shatabdi Express'. I reached Hyderabad at 02.00PM. I got to catch Simhapuri Express, which is scheduled at 10.30 to Nellore, from where I need to catch another train (Pinakini) to leave Chennai, and from Chennai I can travel by Bus. This is my not-so-short itenary of tour. I reached Chennai at 01.30AM, and reached Pondichery at 09.00PM by my friends vehicle (Thanks to Vinob for his help).

This is my first visit to Pondichery, the University is very vast in area and also so sylvanic with lush green campus. As I was already in talk to Prof. Venkatramane, I need to report at guest house 2, where my accommodation was arranged. The accommodation was good, not less than my Thailand Hotel. Room number 207 in International Students Hostel was arranged. Vinobe was also stayed that night in the same room. Vinobe left Pondichery early morning 04.00AM. I was not prepared well for the conference, so I strarted preparing PPTs which are necessary for my presentation. I finished PPTs at 07.00AM. There was a boy who brought a cup of coffee to me.

I left to conference hall (near by cultural centre) along with my other few participants. Morning breakfast was arranged to all participants at the same venue. I proceeded to inaugural session in the adjacent conference hall. There was short film on french colonialism and culture in Pondichery. The inaugural session was so vibrant as His Excellency Lt. Governer Honble. Singh was present. He is really nicest personality I every met till now.

My paper was very fist one in the ground floor (parallel session - 1). I proceeded to the session to present my paper. There were very few presenters, my self along with two other Canadians are scheduled to give talks there. I was not so flinching (as usually I used to be) to present a paper, I was so confident about the innovativeness of my research endeavor. In deed, only one or two really understood my concept. Rest was befuddled about the theme. Later (after I listened to other talks) I understood that my paper was so strong about qualntitative methods, usually people find it difficult to pay attention when it is too technical. But I am sure that for participants it is a learning experience.

The participants asked few questions (I was delighted to get such a response, which I was not extepected) about the methodology. I observed that individuals are not so particular about methods, as most of the papers are so plain and subjective in nature, providing room to intutive cogitation. In fact, I had too much expectations on the research content in papers, but I was upset. I know certain researchers in France and Denmark, but they are very much particular about research, which is not the case here. Any way, I really had good experience, I came to know so many things about western research, attitudes and expectations of the individuals. I should admit that it is one of the good experience to me in my research life.