It’s not possible to directly measure an abstract concept like intelligence, but it is possible to measure performance on different tests. You could use factor analysis to analyze a set of test scores (the observed values) to try to determine intelligence (the hidden value).

Factor analysis is available in R through the function factanal in the stats package:

factanal(x, factors, data = NULL, covmat = NULL, n.obs = NA,
         subset, na.action, start = NULL,
         scores = c("none", "regression", "Bartlett"),
         rotation = "varimax", control = NULL, ...)

Continue reading »

## S3 method for class 'formula':
prcomp(formula, data = NULL, subset, na.action, ...)

## Default S3 method:
prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE,
       tol = NULL, ...)

 

Here is a description of the arguments to prcomp.

Continue reading »

This returns a vector with the minimum and maximum value:
> range(dow30$Open)
[1]   0.99 122.45

Another useful function is quantile. This function can be used to return the values at different percentiles (specified by the probs argument):

> quantile(dow30$Open, probs=c(0,0.25,0.5,0.75,1.0))
     0%     25%     50%     75%    100%
  0.990  19.655  30.155  51.680 122.450

Continue reading »

> x <- function(i) i^2
> x
function(i) i^2
> x(2)
[1] 4

Some functionality is implemented internally within the R system. These calls are made using the .Internal function. Many functions use .Internal to call internal R system code. For example, the graphics function plot.xy is implemented using .Internal:
> plot.xy
function (xy, type, pch = par("pch"), lty = par("lty"), col = par("col"),
    bg = NA, cex = 1, lwd = par("lwd"), ...)
.Internal(plot.xy(xy, type, pch, lty, col, bg, cex, lwd, ...))
<environment: namespace:graphics>

4.5.1. Creating a Package Directory

To build a package, you need to place all of the package files (code, data, documentation, etc.) inside a single directory. You can create an appropriate directory structure using the R function package.skeleton:

package.skeleton(name = "anRpackage", list,
                 environment = .GlobalEnv,
                 path = ".", force = FALSE, namespace = FALSE,
                 code_files = character())

Continue reading »

To get the list of packages loaded by default

> getOption("defaultPackages")

To see the list of currently loaded packages

> (.packages())

To show all packages available,or you can also enter the library() command with no arguments

> (.packages(all.available=TRUE))
> install.packages(c("tree","maptree"))
> remove.packages(c("tree", "maptree"),.Library)

Continue reading »

3.8. Getting Help

> help(glm)

or, equivalently:

> ?glm

To search for help on an operator, you need to place the operator in backquotes:

> ?`+`

If you’d like to try the examples in a help file, you can use the example function to automatically try them. For example, to see the example for glm, type:

> example(glm)

Continue reading »

R is an object-oriented language. Every object in R has a type. Additionally, every object in R is a member of a class. You can use the class function to determine the class of an object. For example:

> class(teams)
[1] "character"
> class(w)
[1] "numeric"
> class(nleast)
[1] "data.frame"
> class(class)
[1] "function"

In R, you would write the relationship as y ~ x1 + x2 + ... + xn, which is a formula object.

Continue reading »

Array

a <- array(c(1,2,3,4,5,6,7,8,9,10,11,12),dim=c(3,4))

> a
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

a vector with the same contents:

> v <- c(1,2,3,4,5,6,7,8,9,10,11,12) > v [1] 1 2 3 4 5 6 7 8 9 10 11 12

matrix is just a two-dimensional array:

> m <- matrix(data=c(1,2,3,4,5,6,7,8,9,10,11,12),nrow=3,ncol=4)
> m
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

Continue reading »

Today I got a chance to receive phone call from this book’s author, but I missed it. It is TERRIBLY!     >_<Anyway, back to the topic. He wrote a book and have done many good work in R.I roughly read it through and it is a well written and carefully organized book .I collected some of the material for my future use and it should be a good refresh if you already know R or just start to learn it.

All the credits go to Joseph Adler!

—————————————————————————————————————————————————————–

2.3. Batch Mode

R provides a way to run a large set of commands in sequence and save the results to a file. This is called batch mode.

Continue reading »

© 2011 统计代码银行StatCodeBank Suffusion theme by Sayontan Sinha