Subjects
Home
mod jk2 https
Donation of JAXP 1 3 Sources to Apache
R annoyances
RE: Finding out when the aspnet admin worker process has recycled
Favorite Linux Distribution
eigenvalues of a circulant matrix
Apache Install
Reachin apache from outside
Ant should have an ext directory
Warning: Documentroot doesn 't exist
Can this be Done?
RE: Multilanguage Application
RE: Simple Question On setting up Sub Domain site
Lack of independence in anova()
How to close connection instead of sending 403?
winning the case for ANT
Re: adding php
New Ant GUI 'Ant 's Nest '
Narrowing Down A Strange Problem
Ant Task: sshexec
R Graph Gallery : categorization of the graphs
I 've been hacked, I need some help please
RE: Anyone working with DotNetNuke?
RE: Exception Handling Opinion
hex format
RE: IIS stopped working :(
<for > Build Failed:problem
RE: Separation of Objects from Logic
RE: Tracking pages with long request execution time
sending email to multiple destination
Web Site
ant UI
Easy cut & paste from Excel to R?
Win32 Apache Restart
Improving Tasks
HELP! PLEASE!
RE: Adding Controls to a Page
read table
RE: ASPNET account doesn 't exist!
Best way to uninstall Apache2 on red hat
from win to linux how to web page
XMLParseException changes and creation of XMLLocator2
Re Post: rewrite backslash to forward slash
Target or macrodef?
Page display problem XPSP2
Authentication problems
Dynamic Dictionary Data Type?
Newbie unable access my www from outside
off topic question: Latex and R in industries
Conflict between xtable and Hmisc when using Sweave?
Very old problem without any new solution
mod rewrite help
Basic Authentication question
RE: Code Security
calling ant from java program
prevent double signing
Re: Controlling Copy/Paste/Print
Using R to illustrate the Central Limit Theorem
web server slow too much slow
access to user directories
Links
Home
Official R Project Site
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Re:logistic regression

Re:logistic regression

2005-02-08       - By Vito Ricci
Reply:     1     2     3     4  

Hi,

I don't know if a pseudo squared R for glm exists in
any R package, but I find some interesting functions
in S mailing list:

http://www.math.yorku.ca/Who/Faculty/Monette/S-news/0422.html

Here are some functions for calculating (pseudo-)R^2,
which may be of use to some.

Rsquared <- function(object)
{
# object is an lm, glm or gam object
# Rsquared() is implemented only for glm or gam
objects with
# one of the three link/variance combinations:
# (1) log and mu (which is canonical for Poisson),
# (2) logit and mu(1-mu) (which is canonical for
binomial), or
# (3) identity and constant (which is canonical for
gaussian).
# However these link/variance pairs may have been
passed to quasi()
# to allow for overdispersion.
UseMethod("Rsquared")
}

Rsquared.lm <-
function(o)
{
R2 <- summary.lm(o)$r.squared
names(R2) <- "Rsquared"
R2
}

Rsquared.glm <-
function(o)
{ def <- family(o)$family[-1] # character vector of
link and variance
typ <- matrix(c("Logit: log(mu/(1 - mu))", "Log:
log(mu)", "Identity: mu",
"Binomial: mu(1-mu)", "Identity: mu", "Constant: 1" ),
2, 3, byrow=T) #
# typ is matrix of supported link and variance
combinations
ml <- match(def[1],typ[1,], nomatch=-1)
mv <- pmatch(def[2],typ[2,], nomatch=-1)
if ( (ml != mv) || (ml <1 ) )
stop("Implemented only for canonical links for
gaussian, binomial or poisson
(with optional provision for overdispersion using
quasi)")
if (ml == 3)
return(Rsquared.lm(o)) # gaussian family
# Remainder of code is for binomial and poisson
families (perhaps with provision for overdispersion)
n <- length(o$residuals)
# number of observations
R2 <- (1 - exp((o$deviance - o$null.deviance)/n))/(1 -
exp( - o$null.deviance/n))
names(R2) <- "pseudo.Rsquared"
R2
}

http://www.math.yorku.ca/Who/Faculty/Monette/S-news/0408.html

Here are some functions for calculating (pseudo-)R^2,
which may be of use to some.

Rsquared <- function(o){
# o is an lm, glm or gam object
UseMethod("Rsquared")
}

Rsquared.lm _ function(o) {
R2 <- summary(o)$r.squared
names(R2) <- 'Rsquared'
R2
}

Rsquared.glm <- function(o) {
n <- length(o$residuals) # number of observations
R2 <- ( 1 - exp( (o$deviance - o$null.deviance)/n ) )
/ ( 1 - exp( -o$null.deviance/n ) )
names(R2) <- 'pseudo.Rsquared'
R2
}


I don't know if S code is completely running in R
environment.

See:
http://www.econ.ucdavis.edu/faculty/cameron/research/je97preprint.pdf

Hoping I helped you!
you wrote:

Hi,

I'm using glm function to do logistic regression and
now I want to know if it exists a kind of R-squared
with this function in order to check the model.

Thank you.

=====
Diventare costruttori di soluzioni
Became solutions' constructors

"The business of the statistician is to catalyze
the scientific learning process."  
George E. P. Box

Top 10 reasons to become a Statistician

    1. Deviation is considered normal
    2. We feel complete and sufficient
    3. We are 'mean' lovers
    4. Statisticians do it discretely and continuously
    5. We are right 95% of the time
    6. We can legally comment on someone's posterior distribution
    7. We may not be normal, but we are transformable
    8. We never have to say we are certain
    9. We are honestly significantly different
   10. No one wants our jobs


Visitate il portale http://www.modugno.it/
e in particolare la sezione su Palese  http://www.modugno.it/archivio/palese/

______________________________________________
R-help@(protected) mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html