background preloader

R

Facebook Twitter

R Spatial

Colors in R. Developing Geographic Thematic Maps with R. Ggplot2 - Getting error while using fortify function in R (ggplot) R - SQL Server RODBC Connection. R - How to save a plot as image on the disk. Lattice Graphs. The lattice package, written by Deepayan Sarkar, attempts to improve on base R graphics by providing better defaults and the ability to easily display multivariate relationships. In particular, the package supports the creation of trellis graphs - graphs that display a variable or the relationship between variables, conditioned on one or more other variables. The typical format is graph_type(formula, data=) where graph_type is selected from the listed below. formula specifies the variable(s) to display and any conditioning variables . For example ~x|A means display numeric variable x for each level of factor A. y~x | A*B means display the relationship between numeric variables y and x separately for every combination of factor A and B levels.

~x means display numeric variable x alone. Here are some examples. . # Lattice Examples library(lattice) attach(mtcars) # kernel density plot densityplot(~mpg, main="Density Plot", xlab="Miles per Gallon") click to view Customizing Lattice Graphs. Lattice: control size of axis title and axis labels. Quick-R: Home Page. Using R for statistical analyses - Basic Stats. Chi-squared tests Tests for association are easily performed in R. The basc function is chisq.test() The first stage is to arrange your data in a .CSV file. Use row and column names. Don't forget that variable names in R can contain letters and numbers but the only punctuation allowed is a period. The second stage is to read your data file into memory and give it a sensible name.

To perform the Chi-squared test you type something like the following: > chisq.test(your.data) Pearson's Chi-squared test data: your.data X-squared = 121.5774, df = 8, p-value < 2.2e-16 This gives you a basic result but you will want more than that in order to interpret the statistic. The test produces more data than is displayed, to see what you have to work with type: > names(chisq.test(your.data)) [1] "statistic" "parameter" "p.value" "method" "data.name" "observed" [7] "expected" "residuals" This shows us that there are other data that we can call upon to help us.

In this instance we might try: > names(your.chi) Pearson's Chi-squared Test for Count Data. Description chisq.test performs chi-squared contingency table tests and goodness-of-fit tests. Usage chisq.test(x, y = NULL, correct = TRUE, p = rep(1/length(x), length(x)), rescale.p = FALSE, simulate.p.value = FALSE, B = 2000) Arguments Details If x is a matrix with one row or column, or if x is a vector and y is not given, then a goodness-of-fit test is performed (x is treated as a one-dimensional contingency table). If x is a matrix with at least two rows and columns, it is taken as a two-dimensional contingency table: the entries of x must be non-negative integers. If simulate.p.value is FALSE, the p-value is computed from the asymptotic chi-squared distribution of the test statistic; continuity correction is only used in the 2-by-2 case (if correct is TRUE, the default). In the contingency table case simulation is done by random sampling from the set of all contingency tables with given marginals, and works only if the marginals are strictly positive.

Value Source References Hope, A. Pearson's Chi-squared Test for Count Data. History search backward in R. Running a script. Cookbook for R » Cookbook for R.