Sunday, August 4, 2013

R - commands cheat sheet

To read a text file
> data <- read.csv('R - anon answers to total answers.txt',sep=",",header=TRUE)

To convert cells (row-column pairs) satisfying a certain condition to NA.
> data$Column[data$Column == 0] <- NA
> data$Column[data$Column == -Inf] <- NA

To generate a linear model from the data
> linear=lm(data[,2]~data[,1])
> polynomial=lm(data[,2]~data[,1]+I(data[,1]^2))
> loglinear=lm(logdata[,2]~logdata[,1])

To get a summary of the generated models
> summary(linear)
> summary(polynomial)

To plot data
> plot(data[,1],data[,2])
> plot(data[,2]~data[,1])
> plot(log(data[,1]),log(data[,2])) 

Adding text to plot
> text(c(300,300),c(0.8,0.82),labels=c("R^2 = 0.0001","y = 0.00072 * x - 0.163"))

To draw the linear model generated using "lm" command
> abline(linear)

We can draw polynomial curve generated using lm/glm using
> lines(sort(x), linear$fitted.values[order(x)])

To generate log-linear models using the glm package
> glm_test2=glm(data[,2]~data[,1],family=poisson())
> glm_test2=update(glm_test,.~.+I(data[,1]^3),family=poisson())

We can compare different linear models generated using lm or glm commands through anova tests. When there are more than 2 models, model-1 is compared to null hypothesis, model-2 with model-1, model-3 with model-2 and so on.
> anova(glm_test,glm_test2,glm_test3,glm_test4,glm_test5,glm_test6,glm_test7,glm_test8,glm_test9,glm_test10,test = "Chisq")


vmware tools copy-paste feature in Ubuntu

You will need the vmware tools for having the feature to copy-paste feature between the VM and the host machine. Installing vmware tools on an Ubuntu machine was a little tricky.

You can find the instructions at: Installing VMware Tools in an Ubuntu virtual machine (1022525)

References:
1. http://communities.vmware.com/thread/395491?start=0&tstart=0
2. http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalId=1014294
3. http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalId=1022525

Saturday, August 3, 2013

Extract range of lines from text file in unix

It is possible to use command line sed to easily extract a range of lines from a text file. The command to be used is:
sed -n 16224,16482p filename > newfile


Where 16224,16482 are the start line number and end line number, inclusive. This is 1-indexed. 
-nsuppresses echoing the input as output, which you clearly don't want; 
the numbers indicate the range of lines to make the following command operate on; 
the command p prints out the relevant lines.

References:
http://stackoverflow.com/questions/83329/how-can-i-extract-a-range-of-lines-from-a-text-file-on-unix

Motorola Atrix - Unlocking bootloader and reflashing ICS

I recently tried unlocking the boot loader to load Ice Cream Sandwich onto my Atrix MB860 phone. During the process, I had some difficulties, and wanted to document the steps for future reference (and for other's benefit).

Unlocking bootloader

This webpage(Installing Atrix-MROM on an Atrix 4G with 4.5.145 update) mentioned it is possible to unlock Atrix4G with 2.3.6 Gingerbread and 4.5.145 update using the unlock instructions given here: Automatic bootloader UNLOCK/ROOT for AT&T 1.26/1.57/1.83/4.5.91 [UPDATE 07/31/11]

I followed the instructions in Automatic bootloader UNLOCK/ROOT for AT&T 1.26/1.57/1.83/4.5.91 [UPDATE 07/31/11]. To unlock I used option-1 (Automatic Bootloader Unlock for ATT ATRIX 4G Only), and then selected the option 3 (4.5.91). It threw a "unable to boot" screen, and gave around 10 options (first option was RSD and second was fastboot, and some others followed) and automatically started the fastboot mode - but windows was not able to recognize the device. Since the instructions on the terminal were asking us to select the fastboot mode by pressing  "volume down+power" combo, I removed the battery for 30 seconds and tried it multiple times but the phone was not booting. At last after few trials it booted to fastboot mode. the terminal instructions showed an unlock code and asked me to enter it (probably option3 - Apply FIX for "Failed to boot 0x1000"/ NO OS Users (fastboot) must have been initiated). Later the phone restarted automatically and I reached the "Welcome to MOTOBLUR" screen. During the motorola boot screen, I saw "unlocked" on the top left corner.

This video should help out too: http://www.youtube.com/watch?v=S6a0BWquqAc

Flashing ROM

I then selected "Automatic ROOT/CWM for Unlocked ATT ATRIX 4G Only (Tenfar CWM)" for backing up my old ROM.

It is to be noted that the cell battery does not get charged while in the boot menu and connected to a power source (either a computer or the power port on the wall). While trying to flash ROM, I received a "Low battery to flash error". For the battery to charge, I need to flash a ROM and flashing was not possible at the moment.

I purchased an external battery charger like the enercell universal external battery charger and charged the battery completely. Now I was able to flash a new ROM.

I followed the instructions at this XDA forum webpage to solve the soft brick issue during the flash process.

After launching ICS, I was unable to download apps from playstore. So removed the gmail account and re-added it without sync as per this forum .

References:
1. http://forum.xda-developers.com/showthread.php?t=1182871
2. http://forum.xda-developers.com/showthread.php?t=2230432&highlight=unlock+bootloader
3. http://forum.xda-developers.com/showthread.php?t=2262869&highlight=soft+brick
4. http://forums.androidcentral.com/google-nexus-7-tablet/224884-google-play-error-solution-rpc-s-5-aec-0-a.html