Re: [R] random uniform sample of points on an ellipsoid (e.g. WG
Alberto == Alberto Vieira Ferreira Monteiro [EMAIL PROTECTED] writes: Alberto I guess this sample is required for some practical Alberto application, say a simulation for something done over the Alberto Earth. Then, I also guess that the sample does not have to be Alberto _absolutely_ exact, but a reasonable approximation can do Alberto it. And the ellipsoid is a rotation ellipsoid. Alberto This is my suggestion: Alberto (1) Divide the Ellipsoid by latitudes in _n_ horizontal Alberto slices in such a way that each slice can be considered Alberto almost spherical. Of course here lies the problem: Alberto depending on the purpose of the simulation, _n_ would be so Alberto big as to make it impractical Alberto (2) Compute the area of each slice (there are formulas for Alberto that, whose error is not very big - again, we rely on the Alberto purpose of the simulation) Alberto (3) Chose a random slice based on weight = area Alberto (4) Chose the random latitude by a uniform from the minimum Alberto to the maximum latitude (a much better approximation would Alberto give higher weight to the latitude closer to the equator) Alberto (5) lon = 2 pi runif(1) # :-) Alberto Now the question is: do you know the formulas to compute the Alberto area in (2)? I know these formulas exist, I learned them in Alberto the last century, but I can't remember them and I don't know Alberto how to find them. This is essentially the approach I (and my local helpers) have taken. With garden-variety calculus, we have derived a function t(z) that maps equal area over the oblate ellipsoid. We select t from a uniform distribution and then find the corresponding z dimension. The expression is quite hairy, but apparently analytically correct (I haven't found any errors yet), if possibly unstable numerically. The derivative with respect to z of area on the ellipsoid at a plane of latitude intersecting at a height z above the equator, where the ellipsoid has been scaled such that a is the polar radius and the equatorial radius is 1, is: dA/dz = 2 * pi * f where f = sqrt((z^2 * (1 - a^2))/a^4 + 1) You find the function t(z) such that dA/dt is constant. Then you select from a uniform distribution and then find the value of z that corresponds. -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.
[R] random uniform sample of points on an ellipsoid (e.g. WGS84)
I am interested in making a random sample from a uniform distribution of points over the surface of the earth, using the WGS84 ellipsoid as a model for the earth. I know how to do this for a sphere, but would like to do better. I can supply random numbers, want latitude longitude pairs out. Can anyone point me at a solution? Thanks very much. -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch 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.
[R] solving for a 2D transformation matrix
We have recently digitized a set of points from some scanned engineering drawings (in the form of PDFs). The digitization resulted in x,y page coordinates for each point. The scans were not aligned perfectly so there is a small rotation, and furthermore each projection (e.g. the yz-plane) on the drawing has a different offset from the page origin to the projection origin. From the dimensions indicated on the drawing, I know the intended world coordinates of a subset of the points. I want to use this subset of points to compute a best-fit transformation matrix so that the remaining points can be converted to world coordinates. The transformation matrix is (I think) of the form: [ x' ] [ a11 a12 a13 ] [ x ] | y' | = | a21 a22 a23 | | y | [ w' ] [ a31 a32 a33 ] [ w ] where: x,y = page coordinates x',y' = world coordinates a13 = translation of x a23 = translation of y a11 = scale * cos(theta) a12 = sin(theta) a21 = -sin(theta) a22 = scale * cos(theta) a31 = 0 a31 = 0 a33 = 1 w' = 1 w = 1 Can anyone give me a pointer on how to go about solving for the transformation matrix given a set of points, where x,y and x',y' are available? I sense the presence a solution lingering in the murky mists, (some kind of least squares?) but I am not sure what it is or how to go about it exactly. Thanks for your help! -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] formula parsing, using parts ...
Uwe == Uwe Ligges [EMAIL PROTECTED] writes: Russell I am writing a little abstraction for a series of tests. For Russell example, I am running an anova and kruskal.test on a Russell one-factor model. That isn't a particular problem, I have an Russell interface like: my.function - function(model,data) { Russell print(deparse(substitute(data))) a - anova(lm(formula,data)) Russell print(a) if(a$Pr(F)[1] 0.05) { pairwise.t.test(???) } b Russell - kruskal.test(formula,data) print(b) if ... } I want to Russell run each test, then depending on the resulting p-value, run Russell pairwise tests. I am getting into trouble where I put the Russell ??? above. The pairwise.t.test has a different interface, Russell that seems to want me to dismember the formula into Russell constituent parts to feed in. The other alternative is to Russell give my.function the constituent parts and let it build the Russell model. I haven't figured out how to do either one. Can Russell someone give me some pointers? Uwe See ?formula and its See Also Section on how to do formula Uwe manipulation. There's also an example on how to construct a Uwe formula. In order to use the 'as.formula(paste(response, ~ ,factor))' approach, response and factor seem to need to be strings (at least they seem to if response is log(x) or the like). Whereas, for pairwise.t.test they need to be names. What is the proper way to do that? -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] formula parsing, using parts ...
Uwe == Uwe Ligges [EMAIL PROTECTED] writes: Russell I am writing a little abstraction for a series of tests. For Russell example, I am running an anova and kruskal.test on a Russell one-factor model. That isn't a particular problem, I have an Russell interface like: my.function - function(model,data) { Russell print(deparse(substitute(data))) a - anova(lm(formula,data)) Russell print(a) if(a$Pr(F)[1] 0.05) { pairwise.t.test(???) } b Russell - kruskal.test(formula,data) print(b) if ... } I want to Russell run each test, then depending on the resulting p-value, run Russell pairwise tests. I am getting into trouble where I put the Russell ??? above. The pairwise.t.test has a different interface, Russell that seems to want me to dismember the formula into Russell constituent parts to feed in. The other alternative is to Russell give my.function the constituent parts and let it build the Russell model. I haven't figured out how to do either one. Can Russell someone give me some pointers? Uwe See ?formula and its See Also Section on how to do formula Uwe manipulation. There's also an example on how to construct a Uwe formula. Russell In order to use the 'as.formula(paste(response, ~ Russell ,factor))' approach, response and factor seem to need to be Russell strings (at least they seem to if response is log(x) or the Russell like). Whereas, for pairwise.t.test they need to be names. Russell What is the proper way to do that? Uwe In order to run pairwise.t.test() you can simply get() the values Uwe from objects: Uwe Let's change the example in ?pairwise.t.test: Uwe data(airquality) Uwe attach(airquality) Uwe Month - factor(Month, labels = month.abb[5:9]) Uwe x - Ozone Uwe y - Month Uwe pairwise.t.test(get(x), get(y)) Suppose I want x to be log(Ozone)? The get() function doesn't help me there. -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] formula parsing, using parts ...
Uwe == Uwe Ligges [EMAIL PROTECTED] writes: Russell Suppose I want x to be log(Ozone)? The get() function Russell doesn't help me there. Uwe eval(parse(text=x)) Ah, that seems to have done it. Thanks! -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] variance component analysis for nested model
Pascal == Pascal A Niklaus [EMAIL PROTECTED] writes: Pascal lme should do the job (r1,r2,r3 are your random factors): Pascal library(nlme) y.lme - lme(y ~ 1,random = ~ 1 | r1/r2/r3) Pascal summary(y.lme) Pascal This is equivalent to a call to varcomp in S-Plus Thanks! This was the clue I needed. -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] formula parsing, using parts ...
I am writing a little abstraction for a series of tests. For example, I am running an anova and kruskal.test on a one-factor model. That isn't a particular problem, I have an interface like: my.function - function(model,data) { print(deparse(substitute(data))) a - anova(lm(formula,data)) print(a) if(a$Pr(F)[1] 0.05) { pairwise.t.test(???) } b - kruskal.test(formula,data) print(b) if ... } I want to run each test, then depending on the resulting p-value, run pairwise tests. I am getting into trouble where I put the ??? above. The pairwise.t.test has a different interface, that seems to want me to dismember the formula into constituent parts to feed in. The other alternative is to give my.function the constituent parts and let it build the model. I haven't figured out how to do either one. Can someone give me some pointers? -- Russell Senior ``I have nine fingers; you have ten.'' [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] variance component analysis for nested model
Given a set of data: names(data) [1] city house visitvalue I am looking for a way to compute the variance components of the nested model (ie, visit 1 at house 2 at city 3 isn't related to visit 1 and house 2 at city 4), but different houses in the same city may be related, and different visits to the same house are probably related. I want to be able to compute how much of the total variance of value is explained by each of these. How can I do that in R? Thanks! -- Russell Senior ``shtal latta wos ba padre u prett tu nashtonfi [EMAIL PROTECTED] mrlosh'' -- Bashgali Kafir for ``If you have had diarrhoea many days you will surely die.'' __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] estimating quantiles from binned data
Spencer == Spencer Graves [EMAIL PROTECTED] writes: Russell Suppose I have a set of binned data, counts exceeding a Russell series of arbitrary thresholds, a total N, a minimum and Russell maximum, those sorts of things. Is there a standard method Russell for estimating arbitrary quantiles from this? My initial Russell thought is that the counts and min/max give me solutions at Russell various points along the empirical cdf. As the data are Russell roughly log-normal, I thought maybe I could use piece-wise Russell log-normal distributions between these points to estimate the Russell arbitrary quantiles I am interested in. Are there better Russell thought out methods than this? Thanks! Spencer Have you considered making a normal probability plot? This is probably not practical, given I have on the order of 7000 sets of binned data to evaluate. I have prior knowledge of the data involved (i.e. when we have an actual sample rather than just bin counts), and though it isn't perfect, log normal usually isn't too bad particularly in comparison to a standard normal distribution. I also want to match at the points where we know the quantiles precisely (i.e. at bin boundaries). Spencer The image of a mixture of lognormals would suggest limits on Spencer the accuracy of such interpolation. Oh, there are limits, no doubt. I guess the main point of my query is to evaluate whether there are better, more theoretically sound methods than the one I extracted from my hat. -- Russell Senior ``shtal latta wos ba padre u prett tu nashtonfi [EMAIL PROTECTED] mrlosh'' -- Bashgali Kafir for ``If you have had diarrhoea many days you will surely die.'' __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help