Error In Transforming Response
Contents |
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring how to back transform log data developers or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ interpreting log transformed variables in linear regression Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them;
Box Cox Transformation R
it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Compare Linear and Log standard error after transformation in R up vote 0 down vote favorite I created a simple linear model in R m1 <- lm(CD~DBH1, data=a) summary(m1) To increase the model fit I transformed the data to log scale and created a linear model with the transformed data: m5 <- lm(LnCD~LnDBH, data=a) summary(m5) Is it simply possible to compare all results in the summary as $R^2$ and residual standard error or do I need to transform the log scale back? So that means: is the standard error in the log model always lower due to the log scale? r linear share|improve this question edited Apr 1 '15 at 12:09 Nick Cox 28.2k35684 asked Apr 1 '15 at 11:31 Ron James 33 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted The residual standard error (perhaps better described as standard deviation of residuals) on log scale can easily be higher than on the original scale! Consider values considerably below 1 on whatever measurement scale is being used. Then variability as measured on a logarithmic scale will usually be higher than on the original scale. To see this, which is independent of regression and a simple consequence of how logarithms are defined, consider the variability, measured as standard deviation, of 10, 100, 1000; and then their reciprocals; and then the logarithms of both sets. So the common reduction in the numbers you see is just a consequence of commonly using values above 1, and nothing else. The more general point is that variability on log scale (specifically here residual standard errors from a regression) is just that: variability on a logarithmic scale. It is possible to back-transform results such as standard errors back to the original scale, but the results don't have an interpretation that can directly be related to the original regression, nor is that is especially useful. $R^2$ is principle is unit-free and dimensionless, so many people compare $R^2$ before and a
Problem Sets Lecture Notes Home Lecture Notes Stata Logs R Logs Datasets Problem Sets 2.10 Transforming the Data We now consider what to do if the regression diagnostics discussed in the previous section indicate that the model is not adequate. The usual solutions involve transforming the response, transforming the predictors, or both. 2.10.1 Transforming the Response The response is often transformed to achieve linearity and homoscedasticity or constant variance. Examples of variance stabilizing transformations are the square root, which tends to work well for counts, and the arc-sine transformation, which is often appropriate when the response is a proportion. These two solutions have fallen out of fashion as generalized linear models designed specifically http://stats.stackexchange.com/questions/144353/compare-linear-and-log-standard-error-after-transformation-in-r to deal with counts and proportions have increased in popularity. My recommendation in these two cases is to abandon the linear model in favor of better alternatives such as Poisson regression and logistic regression. Transformations to achieve linearity, or linearizing transformations, are still useful. The most popular of them is the logarithm, which is specially useful when one expects effects to be proportional to the response. To fix ideas consider a model with a http://data.princeton.edu/wws509/notes/c2s10.html single predictor \( x \), and suppose the response is expected to increase \( 100\rho \) percent for each point of increase in \( x \). Suppose further that the error term, denoted \( U \), is multiplicative. The model can then be written as \[ Y = \gamma(1+\rho)^x U. \] Taking logs on both sides of the equation, we obtain a linear model for the transformed response \[ \log Y = \alpha + \beta x + \epsilon, \] where the constant is \( \alpha = \log\gamma \), the slope is \( \beta=\log(1+\rho) \) and the error term is \( \epsilon=\log U \). The usual assumption of normal errors is equivalent to assuming that \( U \) has a log-normal distribution. In this example taking logs has transformed a relatively complicated multiplicative model to a familiar linear form. This development shows, incidentally, how to interpret the slope in a linear regression model when the response is in the log scale. Solving for \( \rho \) in terms of \( \beta \), we see that a unit increase in \( x \) is associated with an increase of \( 100(e^\beta-1) \) percent in \( y \). If \( \beta \) is small, \( e^\beta-1 \approx \beta \), so the coefficient can be interpreted directly as a relative effect.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss http://stackoverflow.com/questions/30903792/in-http-how-to-conditionally-transform-a-response-so-that-error-path-is-taken the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each error in other. Join them; it only takes a minute: Sign up in $http how to conditionally transform a response so that error path is taken up vote 0 down vote favorite I have a server api that returns a json string like {status: ok/error, errtext: ..., payload: ...}. When status !== 'ok' I would like my program to take error in transforming the error handling method, the equivalent of $q.reject. I am using http transform to harmonize some of my data structures. My code: var p = $http({ url: url, timeout: cancel.cancel, method: 'GET', headers: addl_headers, transformResponse: _appendTransform($http.defaults.transformResponse, function (data, headers, status) { return _doTransform(data, headers, status); }) }); p.then(function(goodrespObj){...}, function(badnessObj){...}); And function _appendTransform(defaults, transform) { defaults = angular.isArray(defaults) ? defaults : [defaults]; return defaults.concat(transform); } function _doTransform(data, headers, status) { if (data.status !== 'OK') { console.error("bad errtext", data.status, "$http status", status); (X) ????? something smart that will trigger HTTP ERROR path ????? } // ... return f(data); // this is received as "goodrespObj.data" above } If at the point marked (X) if I return the error text, it comes back verbatim to "good" function. How do I indicate a server error, or somehow cause the $q.reject(resp) path in transformResponse? Looking at the code for transformResponse() I can see that user function has no way to touch response.status so is there another way? I am using angular with ionicframework. edit: removed my previous com
be down. Please try the request again. Your cache administrator is webmaster. Generated Tue, 11 Oct 2016 20:17:57 GMT by s_wx1131 (squid/3.5.20)