全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 LATEX论坛
2015-9-4 16:38:37
A picture may be worth a 1000 words, but only 10 characters in the R programming languages were required to create this surprisingly expressive chart.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 16:39:56
R is worth learning for these reasons and more. Its growth and maturity have led to widespread adoption and many resources for learning. And now with Microsoft stepping up and including R in more of its offerings, you can expect to hear more about R in the months and years to come.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 18:12:14
From his precious cigarette card collection, to first locking eyes with his baby daughter, to responding to the age of the selfie, the renowned historian has always been fascinated by faces and how they are depicted. But how to begin telling the story of Britain through its portraits?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 18:29:36
Logistic regression is used to analyze the relationship between a dichotomous dependent variable and one or more categorical or continuous independent variables. It specifies the likelihood of the response variable as a function of various predictors. The model expressed as log(odds) = \beta_0 + \beta_1*x_1 + ... + \beta_n*x_n , where \beta refers to the parameters and x_i represents the independent variables. The log(odds), or log of the odds ratio, is defined as ln[\frac{p}{1-p}]. It expresses the natural logarithm of the ratio between the probability that an event will occur, p(Y=1), to the probability that an event will not occur, p(Y=0).
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 19:16:03
My previous post covered the basics of logistic regression. We must now examine the model to understand how well it fits the data and generalizes to other observations. The evaluation process involves the assessment of three distinct areas – goodness of fit, tests of individual predictors, and validation of predicted values – in order to produce the most useful model. While the following content isn’t exhaustive, it should provide a compact ‘cheat sheet’ and guide for the modeling process.

Goodness of Fit: Likelihood Ratio Test
A logistic regression is said to provide a better fit to the data if it demonstrates an improvement over a model with fewer predictors. This occurs by comparing the likelihood of the data under the full model against the likelihood of the data under a model with fewer predictors. The null hypothesis, H_0  holds that the reduced model is true,so an \alpha  for the overall model fit statistic that is less than 0.05  would compel us to reject H_0 .

mod_fit_one <- glm(Class ~ Age + ForeignWorker + Property.RealEstate + Housing.Own +
CreditHistory.Critical, data=training, family="binomial")

mod_fit_two <- glm(Class ~ Age + ForeignWorker, data=training, family="binomial")

library(lmtest)
lrtest(mod_fit_one, mod_fit_two)


Goodness of Fit: Pseudo R^2
With linear regression, the R^2  statistic tells us the proportion of variance in the dependent variable that is explained by the predictors. While no equivilent metric exists for logistic regression, there are a number of R^2  values that can be of value. Most notable is McFadden’s R^2 , which is defined as 1 - \frac{ ln(L_M) }{ ln(L_0) }  where ln(L_M)  is the log likelihood value for the fitted model and ln(L_0)  is the log likelihood for the null model with only an intercept as a predictor. The measure ranges from 0  to just under 1 , with values closer to zero indicating that the model has no predictive power.

library(pscl)
pR2(mod_fit_one) # look for 'McFadden'
Goodness of Fit: Hosmer-Lemeshow Test
The Hosmer-Lemeshow test examines whether the observed proportion of events are similar to the predicted probabilities of occurences in subgroups of the dataset using a pearson chi-square statistic from the 2 x g table of observed and expected frequencies. Small values with large p-values indicate a good fit to the data while large values with p-values below 0.05  indicate a poor fit. The null hypothesis holds that the model fits the data and in the below example we would reject H_0 .



library(MKmisc)
HLgof.test(fit = fitted(mod_fit_one), obs = training$Class)

library(ResourceSelection)
hoslem.test(training$Class, fitted(mod_fit_one), g=10)
Tests of Individual Predictors: Wald Test
A wald test is used to evaluate the statistical significance of each coefficient in the model and is calculated by taking the ratio of the square of the regression coefficient to the square of the standard error of the coefficient. The idea is to test the hypothesis that the coefficient of an independent variable in the model is not significantly different from zero. If the test fails to reject the null hypothesis, this suggests that removing the variable from the model will not substantially harm the fit of that model.

library(survey)

regTermTest(mod_fit_one, "ForeignWorker")
regTermTest(mod_fit_one, "CreditHistory.Critical")


Tests of Individual Predictors: Variable Importance
To assess the relative importance of individual predictors in the model, we can also look at the absolute value of the t-statistic for each model parameter. This technique is utilized by the varImp function in the caret package for general and generalized linear models. The t-statistic for each model parameter helps us determine if it’s significantly different from zero.

mod_fit <- train(Class ~ Age + ForeignWorker + Property.RealEstate + Housing.Own +
CreditHistory.Critical, data=training, method="glm", family="binomial")

varImp(mod_fit)
Validation of Predicted Values: Classification Rate
With predictive models, he most critical metric regards how well the model does in predicting the target variable on out of sample observations. The process involves using the model estimates to predict values on the training set. Afterwards, we will compare the predicted target variable versus the observed values for each observation.

pred = predict(mod_fit, newdata=testing)
accuracy <- table(pred, testing[,"Class"])
sum(diag(accuracy))/sum(accuracy)

pred = predict(mod_fit, newdata=testing)
confusionMatrix(data=pred, testing$Class)


Validation of Predicted Values: ROC Curve
The receiving operating characteristic is a measure of classifier performance. It’s based on the proportion of positive data points that are correctly considered as positive, TPR = \frac{TP}{n(Y=1)} , and the proportion of negative data points that are accuratecly considered as negative, TNR = \frac{TN}{n(Y=0)} . These metrics are expressed through a graphic that shows the trade off between these values. Ultimately, we’re concerned about the area under the ROC curve, or AUROC. That metric ranges from 0.50 to 1.00 , and values above 0.80 indicate that the model does a great job in discriminating between the two categories which comprise our target variable.

library(pROC)
# Compute AUC for predicting Class with the variable CreditHistory.Critical
f1 = roc(Class ~ CreditHistory.Critical, data=training)
plot(f1, col="red")

library(ROCR)
# Compute AUC for predicting Class with the model
prob <- predict(mod_fit_one, newdata=testing, type="response")
pred <- prediction(prob, testing$Class)
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf)

auc <- performance(pred, measure = "auc")
auc <- auc@y.values[[1]]
auc


This post has provided a quick overview of how to evaluate logistic regression models in R. If you have any comments or corrections, please comment below.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 20:06:48
A logistic regression is said to provide a better fit to the data if it demonstrates an improvement over a model with fewer predictors.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 20:07:36
SALT LAKE CITY (AP) — Michigan brought back its former star quarterback Jim Harbaugh to resurrect the program and hopefully improve the position he used to play. The nation found out there's work to be done in Ann Arbor after the Wolverines lost 24-17 to Utah on Thursday night.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-4 20:08:10
link to strings for grep(), dfSplitMerge, dfReshape
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:44:31
comments or corrections
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:48:02
Something to think about when you fire up the grill this weekend.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:48:44
Jonathan Cohn Senior National Correspondent, The Huffington Post
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:49:28
Jonathan Cohn Senior National Correspondent, The Huffington Post
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:50:28
Showing solidarity with workers on Labor Day, President Barack Obama will sign an executive order Monday requiring paid sick leave for employees of federal contractors, including 300,000 who currently receive none.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:51:10
The Minnesota dentist whose killing of Cecil the lion sparked global outraged said Sunday he would return to work this week, and expressed frustration at the animosity directed at those close to him.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:52:39
SHANGHAI Attempts by Chinese policymakers and regulators to soothe the country's jittery markets with promises of financial market reforms and assurances the economy is stabilising had limited impact on Monday, with stocks tumbling in late trade
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:54:23
The French secret service agent who led an attack on a Greenpeace ship that killed photographer Fernando Pereira 30 years ago has apologized publicly for the first time.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:55:53
Sept. 7, 2015: In this photo provided by South Korea's Unification Ministry, South Korea's chief delegate Lee Deok-haeng, second from right, shakes hands with North Korean counterpart Pak Yong Il, second from left, before the Inter-Korean Red Cross .
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:57:35
Police in Las Vegas had an unidentified man in custody after he allegedly walked up to a pair of officers sitting at a stoplight early Sunday afternoon and began firing into their marked SUV. The alleged shooter, armed with a semi-automatic handgun
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:58:18
SAN DIEGO – The Greek gods on Fraternity Row at San Diego State University may have to make room for the Buddha. Planning is underway for a Buddhist fraternity and sorority at the school known for its partying reputation.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:58:50
Atlanta (CNN) Two Atlanta-area brothers are behind bars and charged with multiple felonies after police said they attempted to kill their own parents over the weekend. Yvonne Ervin called 911 Saturday morning and reported that she and husband
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:59:24
Indianapolis Zoo officials are investigating how a cheetah managed to escape from its enclosure, spurring an hour-long lockdown of zoo guests while staff found and tranquilized the animal.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 18:59:58
Hamilton Spectator
An old rivalry within the George W. Bush cabinet over the invasion of Iraq has resurfaced, this time over next-door Iran — and this time it's headed for a different result.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:00:35
A Kentucky county clerk has appealed a judge's decision to put her in jail for refusing to issue marriage licenses to same-sex couples.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:07:18

Los Angeles Times       
One country that won't be taking Syrian refugees: Israel
Los Angeles Times
Israeli Prime Minister Benjamin Netanyahu on Sunday rejected a call to host refugees from Syria and elsewhere, saying that while Israel is "not indifferent to the human tragedy of the refugees," it is not in a position to take them in.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:08:15
Turkish President Recep Tayyip Erdogan vowed to escalate his government's campaign against Kurdish separatists after soldiers were killed in a roadside bomb attack near the Iraqi border.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:08:49
KIEV, Ukraine — International Monetary Fund chief Christine Lagarde has told Ukraine's president that she was impressed with the progress his government has made toward stabilizing the Ukrainian economy.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:09:26
A kayaker fishing off a beach near Malibu, Calif., was bit Saturday by a shark and needed to be airlifted to a nearby
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:12:26
MEXICO CITY Mexico will seek a new investigation into whether the 43 students who disappeared after being abducted by corrupt cops in southwest Mexico last year were burned in a dump, after an independent report dismissed the official account.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-7 19:19:32
Washington (CNN) Former Arkansas Gov. Mike Huckabee compared Rowan County clerk Kim Davis' refusal to issue marriage licenses to same-sex couples to conscientious objections to slavery Sunday.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-9-8 08:53:31
Passengers and crew aboard a Caribbean Carnival Cruise through the holiday weekend got a scare Monday when a fire broke out in one of the ship's engine rooms.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群