Hi Peter,
why you are involving -1 with this concept? Can you explain more please Cheers Date: Sun, 18 Nov 2012 23:28:26 -0800 From: ml-node+s789695n4650012...@n4.nabble.com To: frespi...@hotmail.com Subject: Re: R-Square in WLS On Nov 18, 2012, at 21:32 , Thomas Lumley wrote: > On Fri, Nov 16, 2012 at 4:48 PM, frespider <[hidden email]> wrote: > >> Hi, >> >> I am fitting a weighted least square regression and trying to compute >> SSE,SST and SSReg but I am not getting SST = SSReg + SSE and I dont know >> what I am coding wrong. Can you help please? >> > > > For a start, you need to replace your mu and muZ by weighted means. The -1 in the model formulas also suggests that there will be problems even in the non-weighted case. The addition formula for SSDs works for successive model reductions, so it is required that the span of the design matrix X contains the vector of all ones. > > -thomas > > [snip] > >> ############################## Y = Log(Z) Scale >> #################################### >> Yhat <- X%*%bhat # predicted values >> mu <- mean(Y) >> To <- Y - mu >> Er <- Y - Yhat >> Re <- Yhat - mu >> lgSST <- sum(Weights*(To)^2) # log SST >> lgSSE <- sum(Weights*(Er)^2) # log SSE >> lgSSR <- sum(Weights*(Re)^2) # log SSR >> lgR-sq <- lgSSR/lgSST >> ############################### Z Scale >> ###################################### >> Z <- exp(Y) >> muZ <- mean(Z) >> Zhat <- exp(Yhat+0.5*Sigma2) >> ToZ <- Z-muZ >> ErZ <- Z - Zhat >> ReZ <- Zhat - muZ >> SST <- sum(Weights*(ToZ)^2) # SST >> SSE <- sum(Weights*(ErZ)^2) # SSE >> SSR <- sum(Weights*(ReZ)^2) # SSR >> Rsq <- SSR/SST >> >> I don't understand what is wrong with the code. The sum square regression >> plus the sum square error do not add up to the sum square total in both the >> Y scale and Z scale. Y is a normal distribution and Z is log normally >> distributed. Where is the error? >> Also, is there a way to calculate the weighted sum square? >> >> > > -thomas > > -- > Thomas Lumley > Professor of Biostatistics > University of Auckland > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: [hidden email] Priv: [hidden email] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/R-Square-in-WLS-tp4649693p4650012.html To unsubscribe from R-Square in WLS, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/R-Square-in-WLS-tp4649693p4650032.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.