Suggestion for curve fitting - r

I have this set of data:
X: Y:
0. 0.
0.001417162 0.0118
0.002352761 0.0128
0.003123252 0.0135
0.003866221 0.0138
0.004045083 0.0147
0.005544762 0.0151
0.006260197 0.0156
0.007195755 0.0157
0.007883656 0.0158
0.008805432 0.0159
0.009314465 0.0165
0.010566391 0.0168
0.011047891 0.0186
0.011666955 0.0177
0.012341036 0.0225
0.013193938 0.0399
0.013854235 0.087
0.014500764 0.1479
0.015381122 0.198
0.015601208 0.2586
0.01638525 0.3111
0.016976706 0.3693
0.017691939 0.42
0.018338382 0.4737
0.018861027 0.5223
0.01963122 0.5691
0.021625353 0.6183
0.020923988 0.6684
0.021377815 0.711
0.021927895 0.7551
0.022574222 0.7938
0.023633053 0.8382
0.023646804 0.8742
0.024279325 0.912
0.025131822 0.9495
0.0256543 0.9891
0.026094271 1.0215
0.026685464 1.0596
0.027345378 1.098
0.028101497 1.1328
0.028513912 1.1739
0.029077528 1.1997
0.029723601 1.2339
0.030355902 1.2741
0.031056901 1.3041
0.031428005 1.3383
0.032087723 1.3665
0.032692438 1.3983
0.033242157 1.4262
0.033846824 1.4589
0.034410239 1.4877
0.035248448 1.5222
0.035729364 1.5534
0.036430096 1.5861
0.037034618 1.6179
0.037694064 1.6536
0.038408425 1.6842
0.039067798 1.7121
0.039521096 1.7427
0.040207877 1.7763
0.04071607 1.8075
0.041279177 1.8381
0.04129291 1.8711
0.042707418 1.9065
0.043366544 1.9332
0.043860863 1.9659
0.044368889 1.9959
0.045055371 2.0202
0.045700624 2.0487
0.04626347 2.0796
0.047059639 2.1105
0.047540055 2.1339
0.048308673 2.1618
0.048857648 2.1849
0.049557546 2.2203
0.050229948 2.2425
0.052082233 2.2716
0.051355084 2.2983
0.051945039 2.3193
0.052466363 2.3475
0.053371748 2.3718
0.053851839 2.3937
0.054647359 2.4189
0.055072521 2.4372
0.055675941 2.4633
0.056306742 2.4882
0.057060898 2.5131
0.057691594 2.5332
0.058582712 2.5527
0.059007671 2.5755
0.059597094 2.5941
0.060172767 2.6115
0.065187502 2.6403
0.06131028 2.6592
0.061968042 2.6808
0.062598344 2.6991
0.063173791 2.7246
0.063790292 2.7441
0.064393043 2.7633
0.065091624 2.7795
0.065502522 2.8011
0.066433804 2.8212
0.066598135 2.8368
0.067351271 2.8545
0.067981104 2.8665
0.068610879 2.8845
0.069309041 2.9046
0.069870256 2.9214
0.070253498 2.9355
0.070828319 2.9499
0.07159467 2.9691
0.072046228 2.9856
0.072620893 2.9982
0.07326391 3.0108
0.073893183 3.0255
0.074467682 3.0387
0.075165218 3.0531
0.075862676 3.0654
0.076395973 3.0735
0.077230012 3.0879
0.077571798 3.0996
0.077968246 3.1116
0.078720058 3.1251
0.079485442 3.1332
0.080168736 3.1473
0.080797297 3.1524
0.081671703 3.1647
0.082518656 3.1761
0.082737205 3.1794
0.083242565 3.1911
0.083843476 3.207
0.084594523 3.2157
0.083993693 3.2217
0.086028058 3.2313
0.086806105 3.2412
0.087515804 3.2475
0.087979788 3.2562
0.089221428 3.2658
0.089289641 3.2727
0.090053572 3.2823
0.090599168 3.285
0.091485638 3.2988
0.092508299 3.3006
0.092794607 3.309
0.093585278 3.3177
0.094443969 3.3255
0.095029975 3.336
0.095752165 3.3381
0.096378886 3.3468
0.097182604 3.3498
0.097781901 3.3573
0.098585385 3.3612
0.099238967 3.3702
0.102192566 3.372
0.100464189 3.3816
0.101226388 3.3879
0.101961246 3.396
0.102519116 3.4038
0.103335387 3.4113
0.103920292 3.4134
0.104777107 3.4206
0.105416212 3.423
0.105932869 3.4308
0.106952407 3.4353
0.107550426 3.4431
0.108284246 3.4479
0.108759804 3.4539
0.109439081 3.4587
0.110118251 3.4662
0.11096027 3.4701
0.111802122 3.4749
0.112182257 3.4857
0.113132445 3.4902
0.113878868 3.4929
0.114530181 3.5028
0.11465229 3.5076
0.116063069 3.513
0.116619106 3.5181
0.117378448 3.5247
0.118246089 3.5295
0.118869589 3.5286
0.119479439 3.5364
0.120292424 3.5451
0.120807227 3.5511
0.121728283 3.5565
0.122283519 3.5625
0.123068837 3.5622
0.123745705 3.5691
0.124544254 3.5775
0.125247919 3.5796
0.125924395 3.5868
0.126614273 3.5892
0.128683133 3.5958
0.127993643 3.5991
0.128602023 3.6057
0.129507645 3.6093
0.130115772 3.6132
0.130669753 3.6156
0.131682911 3.6222
0.132263658 3.6234
0.132911821 3.6288
0.133870342 3.6291
0.136717348 3.6336
0.13504451 3.6396
0.135692157 3.6372
0.13621828 3.6432
0.137068001 3.6465
0.141030546 3.6522
0.138470251 3.6501
0.139009423 3.6567
0.140181824 3.6615
0.140532116 3.6633
0.141124835 3.6588
0.141717448 3.6675
0.14257924 3.6711
0.143319661 3.6741
0.143844585 3.6729
0.144813453 3.6753
0.145243967 3.678
0.1472209 3.6849
0.14672342 3.6879
0.147301565 3.6888
0.147866163 3.6933
0.148403782 3.6927
0.149277216 3.6972
0.149962355 3.7011
0.151922897 3.7077
0.151426165 3.7023
0.152070559 3.7089
0.153251595 3.7107
0.153587034 3.7134
0.15429804 3.7191
0.154861361 3.7191
0.155706144 3.7221
0.157086785 3.7206
0.157086785 3.7272
0.156925966 3.7269
0.158480178 3.7335
0.15912306 3.7272
0.159618519 3.7356
0.160381629 3.7359
0.161171304 3.7386
0.161853731 3.7377
0.162415608 3.7398
0.163151233 3.7437
0.163993625 3.7443
0.165062969 3.7533
0.165330242 3.7509
0.166065112 3.7512
0.166866568 3.7569
0.167494215 3.7635
0.168108371 3.7569
0.168829162 3.7638
0.169536423 3.7626
0.173429745 3.7581
0.171070418 3.7617
0.171803762 3.7653
0.172790131 3.7635
0.172936723 3.7644
0.174029244 3.7695
0.174761783 3.7701
0.175334355 3.7668
0.176173017 3.7704
0.176705362 3.7722
0.177490375 3.7701
0.178261854 3.774
0.178979922 3.7797
0.178793775 3.78
0.180774223 3.7887
0.182394664 3.8301
0.18451827 3.8169
0.186282158 3.8067
0.186772642 3.7731
0.188058046 3.7782
0.188587916 3.7734
0.189395747 3.7749
0.189885613 3.7707
0.190560674 3.7734
0.191447234 3.7752
0.192280569 3.7713
0.193007849 3.7704
0.193946376 3.7701
0.194329613 3.7734
0.195188367 3.7647
0.195716677 3.7644
0.196416507 3.7683
0.197142527 3.7695
0.197709986 3.7596
0.198923623 3.7662
0.199714786 3.7617
0.200189355 3.7626
0.2011382 3.7683
0.201915434 3.7665
0.202310538 3.7599
0.203258508 3.7656
0.204153451 3.7569
0.204903352 3.753
0.205311089 3.7512
0.206192075 3.753
0.207033292 3.7461
0.207966146 3.7539
0.208478393 3.7473
0.209318747 3.7425
0.210119413 3.7455
0.21077548 3.7443
0.21140512 3.7425
0.21234924 3.7443
0.213122589 3.7461
0.213751552 3.7443
0.214498207 3.7422
0.215192234 3.7425
0.216030006 3.7395
0.216762788 3.7437
0.217508397 3.7377
0.218096851 3.7446
0.223098604 3.7383
0.219547672 3.7386
0.220187807 3.7395
0.220906094 3.7386
0.221872127 3.7368
0.222381072 3.7404
0.223111647 3.7374
0.223789808 3.7365
0.224207027 3.7278
0.225288796 3.7359
0.225862032 3.7326
0.226487197 3.7368
0.226396039 3.7302
0.227775995 3.7308
0.228426593 3.7287
0.229115997 3.7278
0.229063975 3.7269
0.230312139 3.726
0.23101389 3.7104
plot(x,y)
Can you please give me suggestions of models (I've tried polynomials and I either get a bad fit or a overfit). Thanks!

Just monkeying around in Python/Numpy for a few minutes, it looks like you want a formula like
Yfit(x) = Ymax * (1 - exp(-(x-x0)/a) )
x0 is where the data starts to take off from zero. Looks like x0 = 0.012 give or take a little. Ymax is the maximum value. The parameter a sets how fast the curve rises, and it look like you want a = 0.007 or so.
Polynomials are bad for any data that levels off and holds steady before or after the interesting parts. Polynomials like to wiggle, like a snake trying to go through lined-up croquet wickets. Even fitting loosely with least-squares or whatever, polynomials don't like flatness. But the shape sure looks like a constant minus a decaying exponential - very common in electronics and physics.
The initial zero values, I take to be meaningless and not needing fitting. The Yfit values you get could be clipped to zero when negative, for plotting and comparison.
If exp(-(x-x0)/a) doesn't work well enough, you could try other functions that quickly fade to zero, such as 1/(1+x^p) for some power p>=2, or use a Gaussian exp(-(x-x0)^2 / a^2)
I actually see a slight curve - the Y values go up to max, and then slightly back down. Maybe add a quadratic term to your model, like:
Y_extra_term(x) = ((x-xmax)/b)^2
where xmax is the x value where y is maximum.
(BTW, I'm no expert on R, so use the correct syntax not whatever I write.)

Related

Calculation of Akaike Information Criterion

My data file is given below.
Expt. (Col 1:2) Fit1 (Col 3:4) Fit2 (Col 5:6)
x_expt. y_expt x_fit y_fit x_fit y_fit
2.89394 3.04606 2.95515 3.14485 2.96485 3.16485
2.90727 3.22788 2.96788 3.31939 2.97758 3.34061
2.92788 3.42545 2.98242 3.50303 2.99212 3.52606
2.97576 3.62303 2.99818 3.69758 3.00788 3.72182
2.97394 3.84182 3.01576 3.90182 3.02545 3.92848
3.00061 4.06364 3.03515 4.11818 3.04485 4.14606
3.02788 4.29939 3.05636 4.34545 3.06606 4.37515
3.05758 4.54848 3.08 4.58545 3.0897 4.61697
3.09455 4.80424 3.10606 4.83818 3.11576 4.87212
3.12909 5.07818 3.13515 5.10424 3.14485 5.14061
3.1697 5.37152 3.16667 5.38485 3.17758 5.42364
3.20727 5.65333 3.20182 5.68061 3.21273 5.72182
3.25394 5.98 3.24061 5.99152 3.25212 6.03576
3.30061 6.30909 3.28364 6.32121 3.29576 6.36364
3.35697 6.66061 3.33091 6.66667 3.34364 6.71515
3.41212 7.0303 3.38242 7.02424 3.39636 7.07879
3.47273 7.41818 3.44 7.40606 3.45455 7.46667
3.54606 7.82424 3.50303 7.81212 3.51818 7.87273
3.62242 8.24848 3.57212 8.2303 3.58909 8.29697
3.69939 8.69697 3.64788 8.67879 3.66667 8.74545
3.79212 9.16364 3.73152 9.14545 3.75212 9.21212
3.8903 9.66061 3.82364 9.6303 3.84545 9.70909
4.00242 10.1818 3.92424 10.1455 3.94848 10.2242
4.13212 10.6909 4.03455 10.6849 4.06121 10.7697
4.29697 11.2667 4.15576 11.2546 4.18485 11.3394
4.39273 11.8909 4.28788 11.8485 4.32061 11.9394
4.5503 12.5091 4.43273 12.4727 4.46848 12.5636
4.72061 13.2 4.59152 13.1212 4.63091 13.2242
4.89152 13.8424 4.76424 13.8061 4.80788 13.9091
5.07818 14.5636 4.95333 14.5212 5.00061 14.6303
5.30303 15.3212 5.15879 15.2667 5.21091 15.3818
5.54606 16.0788 5.38303 16.0485 5.44 16.1636
5.79212 16.8909 5.62667 16.8667 5.68848 16.9879
6.07273 17.7273 5.89212 17.7212 5.95939 17.8424
6.35152 18.6303 6.18182 18.6121 6.25455 18.7333
6.67879 19.5394 6.49091 19.5394 6.5697 19.6667
6.99394 20.4727 6.8303 20.503 6.91515 20.6364
7.42424 21.4485 7.19394 21.5091 7.28485 21.6424
7.73939 22.497 7.59394 22.5515 7.69091 22.6909
8.17576 23.5879 8.01818 23.6424 8.12121 23.7758
8.64242 24.7091 8.47879 24.7697 8.58788 24.903
9.12727 25.8242 8.97576 25.9394 9.09091 26.0788
9.59394 27.0727 9.50909 27.1515 9.6303 27.2909
10.1636 28.297 10.0788 28.4061 10.2061 28.5455
10.6909 29.5212 10.6909 29.7091 10.8242 29.8424
11.3939 31.0121 11.3455 31.0485 11.4909 31.1818
12.1152 32.4121 12.0485 32.4364 12.1939 32.5697
12.903 33.8667 12.8 33.8667 12.9455 34
13.6364 35.3515 13.5939 35.3455 13.7515 35.4667
14.4303 36.8546 14.4485 36.8606 14.6 36.9818
15.2849 38.5515 15.3515 38.4242 15.503 38.5394
16.2606 40.1939 16.3091 40.0303 16.4606 40.1455
17.2364 41.8909 17.3212 41.6788 17.4788 41.7879
18.3212 43.7091 18.3939 43.3697 18.5455 43.4727
19.4667 45.5576 19.5273 45.103 19.6788 45.2061
20.5152 46.8849 20.7212 46.8788 20.8667 46.9758
22.0606 49.1758 21.9818 48.6909 22.1152 48.7939
23.3152 51.1879 23.303 50.5515 23.4303 50.6485
24.7212 53.1576 24.6909 52.4485 24.8061 52.5455
26.2121 55.4727 26.1455 54.3879 26.2485 54.4849
a). Col 1:2 represent experimental data.
b). Col 3:4 is fitted data using non-linear least squares fitting using 4 adjustable parameters.
c). Col 5:6 is fitted data using non-linear least squares fitting using 5 adjustable parameters with one parameter fixed to 0.
I wish to calculate AIC for both the fits and conclude which fit is better. Can anybody suggest how to solve this problem in R or Excel?

How to plot an antenna pattern in a polar diagram in Octave?

I'm having some problems with polar plot in Octave. In particular I made a script that combine the horizontal and vertical antenna pattern in order to obtain the 3D antenna pattern of the antenna such that the result is a matrix of 360x360 elements. If I plot the matrix by means of surf function I obtain that image but I would like to get an antenna pattern diagram. How I can do that?
EDIT:
theta3D = linspace(0, 2*pi - (2*pi/360), 360);
phi3D = linspace(0, 2*pi - (2*pi/360), 360);
%% from dBm to dB
maxGainVdB = mGVNnA - 30;
maxGainHdB = mGHNnA - 30;
%% from dB to Watt
maxGainVWatt = 10.^(maxGainVdB/10);
maxGainHWatt = 10.^(maxGainHdB/10);
%% normalization
maxGainVWattNorm = maxGainVWatt./max(maxGainVWatt);
maxGainHWattNorm = maxGainHWatt./max(maxGainHWatt);
%% Gv and Gh
Gv = 10*log10(maxGainVWattNorm);
Gh = 10*log10(maxGainHWattNorm);
%% weighting factors
% where "i" is theta and j is phi
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
w1(i, j) = maxGainVWattNorm(i)*(1 - maxGainHWattNorm(j));
w2(i, j) = maxGainVWattNorm(j)*(1 - maxGainHWattNorm(i));
end
end
%% normalization-related parameter
k = 2; %% As indicated in Chapter 2
%% estimated G
for i = 1 : length(phi3D)
for j = 1 : length(theta3D)
estG(i, j) = ((Gh(i)*w1(i,j) + Gv(j)*w2(i,j))/((w1(i,j)^k + w2(i,j)^k))^(1/k));
end
end
figure
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG)
DATA
mGHNnA = [0.0762 0.0976 0.1207 0.146 0.1744 0.2066 0.2428 0.2827 0.3256 0.3705 0.4165 0.4631 0.5107 0.5602 0.6129 0.6704 0.7334 0.8021 0.8754 0.9518 1.0294 1.1067 1.1834 1.2608 1.3419 1.4318 1.5376 1.6653 1.8213 2.011 2.2382 2.5046 2.8096 3.1494 3.5171 3.8976 4.2687 4.6021 4.8717 5.0727 5.201 5.2687 5.2965 5.3066 5.3189 5.3365 5.3865 5.4558 5.5635 5.7028 5.8633 6.0489 6.2538 6.4708 6.6929 6.914 7.1293 7.3344 7.5209 7.6879 7.8455 7.9974 8.1362 8.2677 8.4072 8.547 8.6955 8.8539 9.025 9.21 9.4099 9.6251 9.8558 10.102 10.362 10.636 10.924 11.224 11.536 11.858 12.189 12.528 12.875 13.229 13.59 13.954 14.323 14.696 15.071 15.447 16.203 16.58 17.089 17.593 18.093 18.588 19.077 19.56 20.036 20.506 20.969 21.424 21.861 22.278 22.683 23.081 23.47 23.856 24.235 24.609 24.98 25.344 25.698 26.037 26.347 26.622 26.87 27.09 27.289 27.459 27.601 27.729 27.849 27.962 28.068 28.158 28.244 28.282 28.272 28.233 28.204 28.181 28.182 28.2 28.21 28.203 28.206 28.181 28.185 28.238 28.346 28.526 28.794 29.158 29.616 30.155 30.753 31.375 31.988 32.556 33.032 33.32 33.435 33.452 33.476 33.597 33.831 34.167 34.581 35.047 35.48 35.784 36.026 36.134 35.959 35.742 35.544 35.466 35.575 35.746 35.995 36.162 36.19 36.11 35.912 35.695 35.529 35.417 35.401 35.464 35.467 35.622 35.747 35.773 35.787 35.827 35.802 35.722 35.596 35.544 35.59 35.687 35.784 35.857 35.867 35.804 35.679 35.462 35.131 34.68 34.179 33.68 33.231 32.833 32.532 32.326 32.18 32.035 31.752 31.265 30.628 29.95 29.221 28.526 27.919 27.419 27.03 26.737 26.542 26.415 26.341 26.301 26.269 26.241 26.212 26.179 26.143 26.102 26.051 25.983 25.892 25.795 25.707 25.636 25.584 25.542 25.502 25.464 25.424 25.362 25.269 25.156 25.013 24.827 24.604 24.343 24.042 23.713 23.361 22.998 22.62 22.229 21.827 21.418 21.004 20.587 20.156 19.72 19.278 18.833 18.385 17.934 17.478 17.018 16.555 16.086 15.614 15.138 14.658 14.175 13.689 13.336 12.982 12.629 12.277 11.926 11.577 11.23 10.887 10.549 10.215 9.8873 9.5665 9.2535 8.9474 8.6508 8.3601 8.0783 7.8076 7.5485 7.2995 7.0654 6.8356 6.6223 6.418 6.2237 6.0401 5.8621 5.6946 5.5356 5.384 5.2382 5.0961 4.9558 4.8113 4.6579 4.5018 4.3427 4.182 4.022 3.8609 3.7051 3.5585 3.4213 3.2873 3.1583 3.032 2.9015 2.7555 2.6037 2.4462 2.284 2.1188 1.9533 1.7903 1.6325 1.4827 1.3435 1.209 1.0844 0.9762 0.8832 0.7952 0.7224 0.6616 0.609 0.5607 0.5128 0.4625 0.4103 0.3567 0.3033 0.2521 0.2051 0.164 0.1295 0.1013 0.0786 0.06 0.0442 0.0304 0.0182 0.0083 0.0019 0 0.0035 0.0125 0.0242 0.0388 0.0564]
and
mGVNnA = [ 1.7 1.1099 0.7069 0.4755 0.2901 0.1465 0.0475 0 0.0014 0.0449 0.1292 0.2868 0.4673 0.7364 1.2223 1.9732 3.0173 4.3603 5.9631 7.7179 9.5019 9.832 8.9113 8.2694 8.0057 8.1343 8.6399 9.5171 10.742 12.285 14.065 16.092 18.473 21.416 25.15 27.353 27.395 26.174 23.967 21.86 20.131 18.734 17.599 16.638 15.887 15.369 15.082 15.024 15.211 15.606 16.196 16.958 17.868 18.867 20 20.151 19.842 19.695 19.725 19.787 19.905 20.082 20.265 20.432 20.595 20.789 21.013 21.281 21.623 22.058 22.536 23.101 23.715 24.38 25.113 25.898 26.737 27.595 28.478 29.381 30.284 31.155 31.971 32.721 33.389 33.969 34.473 34.88 35.237 35.563 35.885 36.251 36.805 37.442 38.143 38.785 39.282 39.452 39.252 38.808 38.293 37.764 37.253 36.773 36.34 35.953 35.634 35.368 35.192 35.093 35.087 35.161 35.305 35.638 35.968 36.19 36.22 36.098 35.797 35.382 35.001 34.788 34.768 34.921 35.411 36.172 36.807 36.485 36.261 35.984 35.618 35.165 34.735 34.498 34.647 35.242 36.268 37.584 38.828 39.695 40.087 40.283 40.635 41.382 42.64 43.356 41.606 40.07 39.359 39.185 39.081 38.836 38.624 38.456 38.255 38.206 38.493 39.266 40.491 41.983 43.328 42.563 40.545 38.503 37.071 36.429 36.194 36.104 35.836 35.579 35.481 35.506 35.707 35.994 36.07 36.031 36.033 36.214 36.667 37.435 38.147 38.873 39.727 40.902 42.706 43.934 43.635 43.926 44.379 44.797 45.114 45.558 46.371 47.239 49.24 52.957 57.002 55.602 53.712 53.855 57.666 52.999 48.404 45.794 44.523 44.54 44.979 45.826 47.281 48.725 49.537 49.035 47.911 45.782 43.136 40.9 39.415 38.682 38.471 38.664 39.083 39.55 39.89 39.954 39.921 40.111 40.907 41.583 41.361 41.264 40.952 40.156 39.005 37.776 36.579 35.531 34.625 33.843 33.158 32.54 32.059 31.661 31.352 31.117 30.908 30.74 30.578 30.447 30.306 30.141 29.997 29.704 29.318 28.964 28.61 28.262 27.903 27.512 27.083 26.622 26.123 25.592 25.037 24.464 23.88 23.292 22.702 22.114 21.537 20.976 20.433 19.985 19.564 19.172 18.811 18.484 18.191 17.938 17.728 17.566 17.458 17.411 17.431 17.437 16.937 16.486 16.093 15.757 15.479 15.269 15.133 15.062 15.072 15.144 15.254 15.407 15.568 15.726 15.86 15.971 16.077 16.2 16.408 16.719 17.174 17.79 18.611 19.673 21.051 22.834 24.971 27.442 29.851 27.032 24.994 23.406 21.624 20.012 18.602 17.435 16.433 15.668 15.115 14.729 14.47 14.339 14.383 14.654 15.252 16.216 14.91 13.992 13.353 12.978 12.89 13.16 13.841 14.942 16.463 18.341 20.559 23.437 26.905 27.021 23.385 19.308 16.1 13.668 11.801 10.36 9.2831 8.5509 8.1662 8.1298 8.4381 7.8963 6.1559 4.6964 3.4785 2.4834 ]
I have no idea which kind of polar plots you are expecting, but the below code may help you to make it as an example.
2D polar plot
% polar plot for G vs. phi, when theta = pi
polar(phi3D, estG(:,length(theta3D)/2+1));
hold on;
% polar plot for G vs. theta, when phi = pi
polar(theta3D, estG(length(phi3D)/2+1,:));
legend("G vs. phi #(theta=pi)","G vs. theta #(phi=pi)");
title("2D radiation pattern");
hold off;
- 3D polar plot
[X, Y] = meshgrid (theta3D, phi3D);
surf(X,Y,estG,'LineStyle','none');
xlabel("theta");
ylabel("phi");
zlabel("G");
colormap("jet");
colorbar
The code that you have included does generate an estimate of gain vs theta and phi, however, you are plotting it on rectangular coordinates. if you noticed, in the resultant figure, the x and y axes are ranging from 0 to 2pi.
you created a (theta, phi, magnitude) data set, and need to convert that to an x,y,z data set.
doing a coordinate transformation, similar to:
xconv = estG.*sin(theta3D).*cos(phi3D);
yconv = estG.*sin(theta3D).*sin(phi3D);
zconv = estG.*cos(theta3D);
may give you what you need.
surf(xconv,yconv,zconv,'Edgecolor','none')
produces:
Since I'm not exactly sure what output would be correct from this data, I can't tell if that quite has it. There may be some ordering issues with mesh and surf plot data that i'm not aware of.
I recommend always starting simple. Work with a unit gain omnidirectional antenna, and see if your process above can go from two circle plots to a sphere. then generate more complex patterns.
for reference, here's a decent set of classroom exercises on 3D parametric plots

R confint method very slow

Here is the code sample
cq = c(15.5193589369923,15.6082097993496,15.3048276641115,15.887944383963,15.3813224284544,14.9723432922121,14.8742353464212,15.0448020475332,15.1584221729435,15.3692219904727,15.2369219681739,15.0804950645883,15.0836397511495,14.8821059462034,14.6827696388115,14.5701385743889,14.8506248103639,14.8475325690146,14.7377458445001,14.6258765734272,15.3585770134881,15.2994209401567,15.5178103826596,15.2411668198437,15.3413307248142,15.3645926457095,15.2241340874265,15.7516405898009,15.7683360263607,15.5852354340738,14.7451372367313,14.650625258402,14.7596201108925,15.0504977144055,15.0178091754821,15.100874342289,14.5156700740607,15.0530667717479,14.754595621435,15.5879633065185,15.3449828894141,15.3112460363113,15.232600495493,15.4378070492087,15.1621663266126,16.0120124580213,16.2104534293435,16.2765899877946,17.1446379330444,17.1717364140053,17.0155350105157,15.5218922723681,15.4543443324508,15.5282690363252,15.0202919978723,15.0410524376083,15.1169661551775,15.335220483258,15.3191814464955,15.0679651604846,14.7270263787123,14.70717761566,14.7907442084919,15.8468089268423,15.6714073529734,15.5478017041242,14.6949593095613,14.7537769900696,14.830942214569,15.0820225358985,15.3454125813989,15.304399073517,15.4159319040107,16.1250033895004,15.5359407225865,15.3251900155103,15.1571914994646,15.412721442436,15.913112918988,15.9852823695227,16.0912887332562,15.4897399161851,15.0710262650299,15.3517226832146,17.0001128578501,17.1040579605654,16.9578316599788,15.8842918497549,15.7016383123704,15.8513519332371,16.9420990886101,17.0793832045434,16.9288868492911,14.9127628979216,14.7689529893246,15.0534122173222,15.3185448628303,15.5507864243439,15.3737185073511,15.4350799532271,15.2414612478027,15.361320770232,15.7401140808761,15.8582795450189,15.7634036480016,15.5797995263497,15.9126261329496,15.9256641722586,15.1308493265056,15.2450158090279,15.0699176510971,15.0368959001792,14.8828877909216,14.8852035927172,15.8253506435753,15.8938440960183,15.888311876759,15.4872886586516,15.5492199156675,15.7313291529313,16.5365758222542,16.8386981731158,16.7239280992675,15.9356391540897,15.7383049532238,15.9409000309973,15.2005952554035,15.0390142751348,15.154888655127,14.6373767323354,14.3087397097081,14.3970067065903,14.6453627024929,14.8109205614192,14.6266778290643,15.5170574352528,15.359943766027,15.5869322081508,15.5246550838727,15.4670382654415,15.4211907882731,16.9534561402918,17.4848334482537,17.3182067272327,15.7804318020053,15.86794322314,15.6532944587946,16.543432367992,16.6848617423114,16.8344939905775,15.5212254647114,15.8348559815603,15.6592827767612,15.3027400892518,15.5498124465958,15.8362202772445,14.8415823671167,15.7307379811374,14.8529575353737,16.6466266958983,16.1687733596343,16.0342973266029,14.5976161739123,14.776507726931,14.6780484406283,15.3927619991024,15.3106866267163,15.2920260038624,15.9666798099925,16.2595244266754,16.1035265916681,16.018233002759,15.8460056716414,16.0722176294152,16.2763177549617,16.364250121284,16.2995041975045,16.3975912697976,16.182759197402,16.1164022801451,16.5026752161837,16.2401540005223,16.3715573563274,18.4119769797938,18.1208386122385,18.0068316479116,17.1455993749728,17.0558275544137,16.9150038143768)
sample = c("CD4 LM","CD4 LM","CD4 JC","CD4 JC","CD4 JC","CD4 BM","CD4 BM","CD4 BM","CD4 MC","CD4 MC","CD4 MC","CD4 TM","CD4 TM","CD4 TM","CD4 MM","CD4 MM","CD4 MM","CD4 SRits","CD4 SRits","CD4 SRits","CD4 GV","CD4 GV","CD4 GV","CD4 WW","CD4 WW","CD4 WW","CD4 CH","CD4 CH","CD4 FJ","CD4 FJ","CD4 KS","CD4 KS","CD4 KS","CD4 NG","CD4 NG","CD4 NG","CD4 CG","CD4 CG","CD4 CG","CD4 CSR","CD4 CSR","CD4 CSR","CD4 JM","CD4 JM","CD4 JM","CD4 DF","CD4 DF","CD4 DF","CD4 AM","CD4 AM","CD4 AM","CD4 BP","CD4 BP","CD4 BP","CD4 ER","CD4 ER","CD4 ER","CD4 SRusse","CD4 SRusse","CD4 SRusse","CD4 DS","CD4 DS","CD4 DS","CD4 KJ","CD4 KJ","CD4 KJ","CD4 GD","CD4 GD","CD4 GD","CD4 KG","CD4 KG","CD4 KG","CD4 KR","CD4 KR","CD4 KR","CD4 FN","CD4 FN","CD4 FN","CD4 RM","CD4 RM","CD4 RM","CD4 LA","CD4 LA","CD4 LA","CD4 EC","CD4 EC","CD4 EC","CD4 KW","CD4 KW","CD4 KW","CD4 HB","CD4 HB","CD4 HB","CD8 LM","CD8 LM","CD8 LM","CD8 JC","CD8 JC","CD8 JC","CD8 BM","CD8 BM","CD8 BM","CD8 MC","CD8 MC","CD8 MC","CD8 TM","CD8 TM","CD8 TM","CD8 MM","CD8 MM","CD8 MM","CD8 SRits","CD8 SRits","CD8 SRits","CD8 GV","CD8 GV","CD8 GV","CD8 WW","CD8 WW","CD8 WW","CD8 CH","CD8 CH","CD8 CH","CD8 FJ","CD8 FJ","CD8 FJ","CD8 KS","CD8 KS","CD8 KS","CD8 NG","CD8 NG","CD8 NG","CD8 CG","CD8 CG","CD8 CG","CD8 CSR","CD8 CSR","CD8 CSR","CD8 JM","CD8 JM","CD8 JM","CD8 DF","CD8 DF","CD8 DF","CD8 AM","CD8 AM","CD8 AM","CD8 BP","CD8 BP","CD8 BP","CD8 ER","CD8 ER","CD8 ER","CD8 SRusse","CD8 SRusse","CD8 SRusse","CD8 DS","CD8 DS","CD8 DS","CD8 KJ","CD8 KJ","CD8 KJ","CD8 GD","CD8 GD","CD8 GD","CD8 KG","CD8 KG","CD8 KG","CD8 KR","CD8 KR","CD8 KR","CD8 FN","CD8 FN","CD8 FN","CD8 RM","CD8 RM","CD8 RM","CD8 LA","CD8 LA","CD8 LA","CD8 EC","CD8 EC","CD8 EC","CD8 KW","CD8 KW","CD8 KW","CD8 HB","CD8 HB","CD8 HB")
df = data.frame(cq, sample)
df.res <- lm(cq~sample, data = df)
require(lsmeans)
t<- pairs(lsmeans(df.res, "sample"))
system.time(tc <- confint(t, level=0.95))
The time taken by the confint function is
user system elapsed
10.58 0.00 10.60
I have tried using confint.default but I get an error
tc <- confint.default(t, level=0.95)
Error: $ operator not defined for this S4 class
It's a bit buried in the documentation, but what's slowing you down is the multiple-comparisons correction computations. There's wide variation in the elapsed time for the available methods. See the Confidence-limit and P-value adjustments section of ?summary.ref.grid for details, and decide which method meets your criteria of being both fast enough and reliable enough for your use case ...
adj <- c("tukey","scheffe","sidak","bonferroni","dunnettx","mvt")
sapply(adj,function(a) system.time(confint(t,adjust=a))["elapsed"])
## tukey.elapsed scheffe.elapsed sidak.elapsed bonferroni.elapsed
9.256 0.195 0.168 0.173
## dunnettx.elapsed mvt.elapsed
14.370 1.821
Here is a fast way:
confint(t,method="Wald")

geometric standard deviation for a log normal distribution

I am trying to calculate geometric standard deviation of each log normal distribution. In the below,for example, I have x data in first row, wich is bin size (from 10 to 1000), and corresponding five y data in the next rows.
10 10.9854 12.0679 13.2571 14.5635 15.9986 17.5751 19.307 21.2095 23.2995 25.5955 28.1177 30.8884 33.9322 37.2759 40.9492 44.9843 49.4171 54.2868 59.6362 65.5129 71.9686 79.0604 86.8511 95.4095 104.811 115.14 126.486 138.95 152.642 167.683 184.207 202.359 222.3 244.205 268.27 294.705 323.746 355.648 390.694 429.193 471.487 517.947 568.987 625.055 686.649 754.312 828.643 910.298 1000
0.0170496 0.0239502 0.0332355 0.0455609 0.0616994 0.0825406 0.109082 0.142408 0.18366 0.233988 0.294489 0.366137 0.449692 0.545614 0.653963 0.774317 0.905696 1.04651 1.19455 1.34698 1.50043 1.65109 1.79482 1.92739 2.04464 2.1427 2.21822 2.26854 2.29184 2.28729 2.25505 2.19628 2.11309 2.00838 1.8857 1.74903 1.60258 1.45057 1.29705 1.1457 0.999738 0.861783 0.733851 0.617327 0.513004 0.421137 0.341527 0.273605 0.216532 0.169284
0.564795 0.577687 0.5902 0.602296 0.61394 0.625095 0.635728 0.645804 0.655292 0.664162 0.672384 0.679932 0.686781 0.692908 0.698293 0.702918 0.706767 0.709826 0.712086 0.713539 0.71418 0.714007 0.71302 0.711223 0.708621 0.705224 0.701043 0.696093 0.69039 0.683953 0.676803 0.668965 0.660464 0.651327 0.641585 0.631268 0.620408 0.609041 0.5972 0.584922 0.572243 0.559201 0.545833 0.532178 0.518272 0.504155 0.489863 0.475433 0.460903 0.446307
1.88874 1.99575 2.1007 2.20265 2.30064 2.39374 2.48101 2.56155 2.63452 2.69913 2.75466 2.80051 2.83615 2.86117 2.87529 2.87836 2.87032 2.85127 2.82144 2.78116 2.7309 2.67121 2.60276 2.52629 2.44262 2.35262 2.2572 2.15731 2.0539 1.94791 1.84027 1.73188 1.62359 1.51621 1.41048 1.30706 1.20656 1.1095 1.01631 0.927365 0.842942 0.763252 0.688433 0.618555 0.553629 0.493609 0.4384 0.387865 0.341834 0.300104
0.190679 0.206669 0.223365 0.240726 0.258699 0.277225 0.296235 0.315651 0.335385 0.355342 0.375418 0.395503 0.41548 0.435228 0.454622 0.473532 0.491829 0.509384 0.526069 0.541758 0.556333 0.569679 0.58169 0.592269 0.60133 0.608797 0.614608 0.618714 0.62108 0.621687 0.620529 0.617615 0.612971 0.606636 0.598663 0.589119 0.578082 0.565642 0.5519 0.536964 0.52095 0.503979 0.486178 0.467675 0.4486 0.429082 0.409249 0.389225 0.36913 0.34908
1.63196 1.69464 1.75432 1.81053 1.8628 1.9107 1.95381 1.99177 2.02423 2.0509 2.07155 2.08598 2.09406 2.09572 2.09094 2.07977 2.06231 2.03872 2.00922 1.97406 1.93356 1.88808 1.83801 1.78377 1.72583 1.66463 1.60068 1.53447 1.46647 1.39719 1.32709 1.25664 1.18628 1.11642 1.04745 0.979718 0.913557 0.849249 0.787045 0.727157 0.669765 0.615008 0.562995 0.513798 0.467461 0.423997 0.383394 0.345615 0.310603 0.27828
So, I have five log normal distributions. (Actually, I have hundreds log normal distributions to be calculated.) Then, I want to calculate each geometric standard deviation, which does not seem to be implemented in r packages. R package ("psych") provides a tool to calculate geometric standard deviation, but not for such data I have..
Instead, it can be calculated following the equation below,
http://www.eng.utoledo.edu/~akumar/IAP1/lung/calculateDiameter.htm
But, I have no idea how to calculate using such equation in r. Hope someone help me to calculate a geometric standard deviation of each log normal distribution either using r package or calculating the equation. Thanks a lot for your help, in advance.
S
The easiest way is probably using:
exp(sd(log(x)))

What datetime format is this?

I have DateTime structure for an old data format that I don't have access to any specs for. There is a field which indicates the datetime of the the data, but it isn't in any format I recognize. It appears to be stored as a 32-bit integer, that increments by 20 for each day. Has anyone ever run across something like this?
EDIT:
Example: 1088631936 DEC = 80 34 E3 40 00 00 00 00 HEX = 09/07/2007
EDIT:
First off, sorry for the delay. I had hoped to do stuff over the weekend, but was unable to.
Second, this date format is weirder than I initially thought. It appears to be some sort of exponential or logarithmic method, as the dates do not change at an increasing rate.
Third, the defunct app that I have for interpreting these values only shows the date portion, so I don't know what the time portion is.
Example data:
(Hex values are big-endian, dates are mm/dd/yyyy)
0x40000000 = 01/01/1900
0x40010000 = 01/01/1900
0x40020000 = 01/01/1900
0x40030000 = 01/01/1900
0x40040000 = 01/01/1900
0x40050000 = 01/01/1900
0x40060000 = 01/01/1900
0x40070000 = 01/01/1900
0x40080000 = 01/02/1900
0x40090000 = 01/02/1900
0x400A0000 = 01/02/1900
0x400B0000 = 01/02/1900
0x400C0000 = 01/02/1900
0x400D0000 = 01/02/1900
0x400E0000 = 01/02/1900
0x400F0000 = 01/02/1900
0x40100000 = 01/03/1900
0x40110000 = 01/03/1900
0x40120000 = 01/03/1900
0x40130000 = 01/03/1900
0x40140000 = 01/04/1900
0x40150000 = 01/04/1900
0x40160000 = 01/04/1900
0x40170000 = 01/04/1900
0x40180000 = 01/05/1900
0x40190000 = 01/05/1900
0x401A0000 = 01/05/1900
0x401B0000 = 01/05/1900
0x401C0000 = 01/06/1900
0x401D0000 = 01/06/1900
0x401E0000 = 01/06/1900
0x401F0000 = 01/06/1900
0x40200000 = 01/07/1900
0x40210000 = 01/07/1900
0x40220000 = 01/08/1900
0x40230000 = 01/08/1900
....
0x40800000 = 05/26/1901
0x40810000 = 06/27/1901
0x40820000 = 07/29/1901
....
0x40D00000 = 11/08/1944
0x40D10000 = 08/29/1947
EDIT: I finally figured this out, but since I've already given up the points for the bounty, I'll hold off on the solution in case anyone wants to give it a shot.
BTW, there is no time component to this, it is purely for storing dates.
It's not integer, it's a 32 bit floating point number. I haven't quite worked out the format yet, it's not IEEE.
Edit: got it. 1 bit sign, 11 bit exponent with an offset of 0x3ff, and 20 bit mantissa with an implied bit to the left. In C, assuming positive numbers only:
double offset = pow(2, (i >> 20) - 0x3ff) * (((i & 0xfffff) + 0x100000) / (double) 0x100000);
This yields 0x40000000 = 2.0, so the starting date must be 12/30/1899.
Edit again: since you were so kind as to accept my answer, and you seem concerned about speed, I thought I'd refine this a little. You don't need the fractional part of the real number, so we can convert straight to integer using only bitwise operations. In Python this time, complete with test results. I've included some intermediate values for better readability. In addition to the restriction of no negative numbers, this version might have problems when the exponent goes over 19, but this should keep you good until the year 3335.
>>> def IntFromReal32(i):
exponent = (i >> 20) - 0x3ff
mantissa = (i & 0xfffff) + 0x100000
return mantissa >> (20 - exponent)
>>> testdata = range(0x40000000,0x40240000,0x10000) + range(0x40800000,0x40830000,0x10000) + [1088631936]
>>> from datetime import date,timedelta
>>> for i in testdata:
print "0x%08x" % i, date(1899,12,30) + timedelta(IntFromReal32(i))
0x40000000 1900-01-01
0x40010000 1900-01-01
0x40020000 1900-01-01
0x40030000 1900-01-01
0x40040000 1900-01-01
0x40050000 1900-01-01
0x40060000 1900-01-01
0x40070000 1900-01-01
0x40080000 1900-01-02
0x40090000 1900-01-02
0x400a0000 1900-01-02
0x400b0000 1900-01-02
0x400c0000 1900-01-02
0x400d0000 1900-01-02
0x400e0000 1900-01-02
0x400f0000 1900-01-02
0x40100000 1900-01-03
0x40110000 1900-01-03
0x40120000 1900-01-03
0x40130000 1900-01-03
0x40140000 1900-01-04
0x40150000 1900-01-04
0x40160000 1900-01-04
0x40170000 1900-01-04
0x40180000 1900-01-05
0x40190000 1900-01-05
0x401a0000 1900-01-05
0x401b0000 1900-01-05
0x401c0000 1900-01-06
0x401d0000 1900-01-06
0x401e0000 1900-01-06
0x401f0000 1900-01-06
0x40200000 1900-01-07
0x40210000 1900-01-07
0x40220000 1900-01-08
0x40230000 1900-01-08
0x40800000 1901-05-26
0x40810000 1901-06-27
0x40820000 1901-07-29
0x40e33480 2007-09-07
Are you sure that values correspond to 09/07/2007?
I ask because 1088631936 are the number of seconds since Linux (et al) zero date: 01/01/1970 00:00:00 to 06/30/2004 21:45:36.
Seems to me reasonable to think the value are seconds since this usual zero date.
Edit: I know it is very possible for this not to be the correct answer. It is just one approach (a valid one) but I think more info is needed (see the comments). Editing this (again) to bring the question to the front in the hope of somebody else to answer it or give ideas. Me: with a fairness, sportive and sharing spirit :D
I'd say that vmarquez is close.
Here are dates 2009-3-21 and 2009-3-22 as unix epochtime:
In [8]: time.strftime("%s", (2009, 3, 21, 1, 1, 0, 0,0,0))
Out[8]: '1237590060'
In [9]: time.strftime("%s", (2009, 3, 22, 1, 1, 0, 0,0,0))
Out[9]: '1237676460'
And here they are in hex:
In [10]: print("%0x %0x" % (1237590060, 1237676460))
49c4202c 49c571ac
If you take only first 5 digits, the growth is 21. Which kinda matches your format, neg?
Some context would be useful. If your data file looks something, literally or at least figuratively, like this file, vmarquez is on the money.
http://www.slac.stanford.edu/comp/net/bandwidth-tests/eventanalysis/all_100days_sep04/node1.niit.pk
That reference is data produced by Available Bandwith Estimation tool (ABwE) -- the curious item is that it actually contains that 1088631936 value as well as the context. That example
date time abw xtr dbcap avabw avxtr avdbcap rtt timestamp
06/30/04 14:43:48 1.000 0.000 1.100 1.042 0.003 1.095 384.387 1088631828
06/30/04 14:45:36 1.100 0.000 1.100 1.051 0.003 1.096 376.408 1088631936
06/30/04 14:47:23 1.000 0.000 1.100 1.043 0.003 1.097 375.196 1088632043
seems to have a seven hour offset from the suggested 21:45:36 time value. (Probably Stanford local, running on Daylight savings time.)
Well, you've only shown us how your program uses 2 of the 8 digits, so we'll have to assume that the other 6 are ignored (because your program could be doing anything it wants with those other digits).
So, we could say that the input format is:
40mn0000
where m and n are two hex digits.
Then, the output is:
01/01/1900 + floor((2^(m+1)-2) + n*2^(m-3)) days
Explanation:
In each example, notice that incrementing n by 1 increases the number of days by 2^(m-3).
Notice that every time n goes from F to 0, m is incremented.
Using these two rules, and playing around with the numbers, you get the equation above.
(Except for floor, which was added because the output doesn't display fractional days).
I suppose you could rewrite this by replacing the two separate hex variables m and n with a single 2-digit hex number H. However, I think that would make the equation a lot uglier.

Resources