Articles by statcompute

Fractional Logit Model with Python

December 16, 2012 | statcompute

[This article was first published on Yet Another Blog in Statistical Computing » S+/R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. In [1]: import pandas as pd In [2]: import statsmodels.api as sm In [3]: data = pd.read_table('/home/liuwensui/Documents/data/csdata.txt') In [4]: Y = data.LEV_LT3 In [5]: X = sm.add_constant(data[['COLLAT1', 'SIZE1', 'PROF2', 'LIQ', 'IND3A']]) In [6]: # Discrete Dependent Variable Models with Logit Link In [7]: mod = sm.Logit(Y, X) In [8]: res = mod.fit() Optimization terminated successfully. Current function value: 882.448249 Iterations 8 In [9]: print res.summary() Logit Regression Results ============================================================================== Dep. Variable: LEV_LT3 No. Observations: 4421 Model: Logit Df Residuals: 4415 Method: MLE Df Model: 5 Date: Sun, 16 Dec 2012 Pseudo R-squ.: 0.04022 Time: 23:40:40 Log-Likelihood: -882.45 converged: True LL-Null: -919.42 LLR p-value: 1.539e-14 ============================================================================== coef std err z P>|z| [95.0% Conf. Int.] ------------------------------------------------------------------------------ COLLAT1 1.2371 0.260 4.756 0.000 0.727 1.747 SIZE1 0.3590 0.037 9.584 0.000 0.286 0.432 PROF2 -3.1431 0.739 -4.254 0.000 -4.591 -1.695 LIQ -1.3825 0.357 -3.867 0.000 -2.083 -0.682 IND3A 0.5466 0.141 3.867 0.000 0.270 0.824 const -7.2498 [...] [Read more...]

Another Way to Access R from Python – PypeR

November 29, 2012 | statcompute

Different from RPy2, PypeR provides another simple way to access R from Python through pipes (http://www.jstatsoft.org/v35/c02/paper). This handy feature enables data analysts to do the data munging with python and the statistical analysis with R by passing objects interactively between two computing systems. Below ... [Read more...]

A Light Touch on RPy2

November 23, 2012 | statcompute

For a statistical analyst, the first step to start a data analysis project is to import the data into the program and then to screen the descriptive statistics of the data. In python, we can easily do so with pandas package. Tonight, I’d like to add some spice to ... [Read more...]

Download Stock Price Online with R

October 11, 2012 | statcompute

[This article was first published on Yet Another Blog in Statistical Computing » S+/R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. library(chron) library(zoo) # STOCK TICKER OF Fifth Third Bancorp stock <- 'FITB' # DEFINE STARTING DATE start.date <- 1 start.month <- 1 start.year <- 2012 # DEFINE ENDING DATE end.date <- 11 end.month <- 10 end.year <- 2012 # DEFINE URL LINK link <- paste("http://ichart.finance.yahoo.com/table.csv?s=", stock, "&a=", as.character(start.month - 1), "&b=", as.character(start.date), "&c=", as.character(start.year), "&d=", as.character(end.month - 1), "&e=", as.character(end.date), "&f=", as.character(end.year), "&g=d&ignore=.csv", sep = '') # DOWNLOAD STOCK PRICE AS CSV FILE download.file(link, "c:/projects/data.csv") # READ THE CSV FILE INTO R data <- read.csv("c:/projects/data.csv") # CONVERT CHARACTER INTO DATE dt <- dates(as.character(data[, 1]), format = "y-m-d") # CONVERT DATA FRAME INTO TS OBJECT ts <- zoo(data[, 2:5], dt) # CREATE A PLOT FOR OPEN/CLOSE/HIGH/LOW PRICES plot(ts, main = stock) To leave a comment for the author, please follow the link and comment on their blog: Yet Another Blog in Statistical Computing » S+/R. R-bloggers.com offers daily e-mail updates about R [...] [Read more...]

Fit and Visualize A MARS Model

October 7, 2012 | statcompute

[This article was first published on Yet Another Blog in Statistical Computing » S+/R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. ################################################# ## FIT A MULTIVARIATE ADAPTIVE REGRESSION ## ## SPLINES MODEL (MARS) USING MDA PACKAGE ## ## DEVELOPED BY HASTIE AND TIBSHIRANI ## ################################################# # LOAD LIBRARIES AND DATA library(MASS); library(mda); data(Boston); # FIT AN ADDITIVE MARS MODEL mars.fit <- mars(Boston[, -14], Boston[14], degree = 1, prune = TRUE, forward.step = TRUE) # SHOW CUT POINTS OF MARS cuts <- mars.fit$cuts[mars.fit$selected.terms, ]; dimnames(cuts) <- list(NULL, names(Boston)[-14]); print(cuts); factor <- mars.fit$factor[mars.fit$selected.terms, ]; dimnames(factor) <- list(NULL, names(Boston)[-14]); print(factor); # EXAMINE THE FITTED FUNCTION BETWEEN EACH IV AND DV par(mfrow = c(3, 5), mar=c(2, 2, 2, 2), pty="s") for (i in 1:13) { xp <- matrix(sapply(Boston[1:13], mean), nrow(Boston), ncol(Boston) - 1, byrow = TRUE); xr <- sapply(Boston, range); xp[, i] <- seq(xr[1, i], xr[2, i], len=nrow(Boston)); xf <- predict(mars.fit, xp); plot(xp[, i], xf, xlab = names(Boston)[i], ylab = "", type = "l"); } To leave a comment for the author, please follow the link [...] [Read more...]
1 6 7 8

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)