
Hi Thomas,


Can you please edit my code in way it works. I appericated your help. I need to calculate the R2 in the Z scale and it is not make sense to me.

or Can I have some documentation to read?

Thanks 

Date: Sun, 18 Nov 2012 12:35:03 -0800
From: ml-node+s789695n4649969h90@n4.nabble.com
To: frespider@hotmail.com
Subject: Re: R-Square in WLS



	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.


    -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.



	
	
	
	

	

	
	
		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-tp4649693p4649969.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-tp4649693p4649983.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]


